@cubejs-client/core
Advanced tools
Comparing version 0.5.2 to 0.6.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [0.6.0](https://github.com/statsbotco/cubejs-client/compare/v0.5.2...v0.6.0) (2019-04-09) | ||
### Features | ||
* QueryBuilder heuristics. Playground area, table and number implementation. ([c883a48](https://github.com/statsbotco/cubejs-client/commit/c883a48)) | ||
## [0.5.2](https://github.com/statsbotco/cubejs-client/compare/v0.5.1...v0.5.2) (2019-04-05) | ||
@@ -8,0 +19,0 @@ |
@@ -19,2 +19,5 @@ import 'core-js/modules/es6.number.constructor'; | ||
import momentRange from 'moment-range'; | ||
import 'core-js/modules/web.dom.iterable'; | ||
import 'core-js/modules/es6.array.iterator'; | ||
import 'core-js/modules/es6.object.keys'; | ||
import 'core-js/modules/es6.array.is-array'; | ||
@@ -202,3 +205,3 @@ import 'core-js/modules/es6.regexp.split'; | ||
return _this2.axisValuesString(xValues); | ||
}); | ||
}); // eslint-disable-next-line no-unused-vars | ||
@@ -230,4 +233,5 @@ var measureValue = function measureValue(row, measure, xValues) { | ||
}, {}); | ||
}; | ||
}; // eslint-disable-next-line no-unused-vars | ||
measureValue = function measureValue(row, measure, xValues) { | ||
@@ -247,3 +251,4 @@ return row[measure] || 0; | ||
}), unnest, groupByXAxis, toPairs)(this.loadResponse.data); | ||
var allYValues = pipe(map(function (_ref6) { | ||
var allYValues = pipe(map( // eslint-disable-next-line no-unused-vars | ||
function (_ref6) { | ||
var _ref7 = _slicedToArray(_ref6, 2), | ||
@@ -257,3 +262,4 @@ xValuesString = _ref7[0], | ||
})); | ||
}), unnest, uniq)(xGrouped); | ||
}), unnest, uniq)(xGrouped); // eslint-disable-next-line no-unused-vars | ||
return xGrouped.map(function (_ref9) { | ||
@@ -309,3 +315,3 @@ var _ref10 = _slicedToArray(_ref9, 2), | ||
category: _this3.axisValuesString(xValues, ', '), | ||
//TODO deprecated | ||
// TODO deprecated | ||
x: _this3.axisValuesString(xValues, ', ') | ||
@@ -324,2 +330,52 @@ }, yValuesArray.map(function (_ref15) { | ||
}, { | ||
key: "tablePivot", | ||
value: function tablePivot(pivotConfig) { | ||
var normalizedPivotConfig = this.normalizePivotConfig(pivotConfig); | ||
var valueToObject = function valueToObject(valuesArray, measureValue) { | ||
return function (field, index) { | ||
return _defineProperty({}, field === 'measures' ? valuesArray[index] : field, field === 'measures' ? measureValue : valuesArray[index]); | ||
}; | ||
}; | ||
return this.pivot(pivotConfig).map(function (_ref19) { | ||
var xValues = _ref19.xValues, | ||
yValuesArray = _ref19.yValuesArray; | ||
return yValuesArray.map(function (_ref20) { | ||
var _ref21 = _slicedToArray(_ref20, 2), | ||
yValues = _ref21[0], | ||
m = _ref21[1]; | ||
return normalizedPivotConfig.x.map(valueToObject(xValues, m)).concat(normalizedPivotConfig.y.map(valueToObject(yValues, m))).reduce(function (a, b) { | ||
return Object.assign(a, b); | ||
}, {}); | ||
}); | ||
}).reduce(function (a, b) { | ||
return a.concat(b); | ||
}); | ||
} | ||
}, { | ||
key: "tableColumns", | ||
value: function tableColumns(pivotConfig) { | ||
var _this4 = this; | ||
var normalizedPivotConfig = this.normalizePivotConfig(pivotConfig); | ||
var column = function column(field) { | ||
return field === 'measures' ? (_this4.query().measures || []).map(function (m) { | ||
return { | ||
key: m, | ||
title: _this4.loadResponse.annotation.measures[m].title | ||
}; | ||
}) : [{ | ||
key: field, | ||
title: (_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]).title | ||
}]; | ||
}; | ||
return normalizedPivotConfig.x.map(column).concat(normalizedPivotConfig.y.map(column)).reduce(function (a, b) { | ||
return a.concat(b); | ||
}); | ||
} | ||
}, { | ||
key: "totalRow", | ||
@@ -332,3 +388,3 @@ value: function totalRow() { | ||
value: function categories(pivotConfig) { | ||
//TODO | ||
// TODO | ||
return this.chartPivot(pivotConfig); | ||
@@ -339,3 +395,3 @@ } | ||
value: function seriesNames(pivotConfig) { | ||
var _this4 = this; | ||
var _this5 = this; | ||
@@ -345,6 +401,6 @@ pivotConfig = this.normalizePivotConfig(pivotConfig); | ||
return { | ||
title: _this4.axisValuesString(pivotConfig.y.find(function (d) { | ||
title: _this5.axisValuesString(pivotConfig.y.find(function (d) { | ||
return d === 'measures'; | ||
}) ? dropLast(1, axisValues).concat(_this4.loadResponse.annotation.measures[ResultSet.measureFromAxis(axisValues)].title) : axisValues, ', '), | ||
key: _this4.axisValuesString(axisValues) | ||
}) ? dropLast(1, axisValues).concat(_this5.loadResponse.annotation.measures[ResultSet.measureFromAxis(axisValues)].title) : axisValues, ', '), | ||
key: _this5.axisValuesString(axisValues) | ||
}; | ||
@@ -508,2 +564,19 @@ }); | ||
}, { | ||
key: "defaultTimeDimensionNameFor", | ||
value: function defaultTimeDimensionNameFor(memberName) { | ||
var _this2 = this; | ||
var _memberName$split3 = memberName.split('.'), | ||
_memberName$split4 = _slicedToArray(_memberName$split3, 1), | ||
cube = _memberName$split4[0]; | ||
if (!this.cubesMap[cube]) { | ||
return null; | ||
} | ||
return Object.keys(this.cubesMap[cube].dimensions || {}).find(function (d) { | ||
return _this2.cubesMap[cube].dimensions[d].type === 'time'; | ||
}); | ||
} | ||
}, { | ||
key: "filterOperatorsForMember", | ||
@@ -510,0 +583,0 @@ value: function filterOperatorsForMember(memberName, memberType) { |
@@ -23,2 +23,5 @@ 'use strict'; | ||
var momentRange = _interopDefault(require('moment-range')); | ||
require('core-js/modules/web.dom.iterable'); | ||
require('core-js/modules/es6.array.iterator'); | ||
require('core-js/modules/es6.object.keys'); | ||
require('core-js/modules/es6.array.is-array'); | ||
@@ -206,3 +209,3 @@ require('core-js/modules/es6.regexp.split'); | ||
return _this2.axisValuesString(xValues); | ||
}); | ||
}); // eslint-disable-next-line no-unused-vars | ||
@@ -234,4 +237,5 @@ var measureValue = function measureValue(row, measure, xValues) { | ||
}, {}); | ||
}; | ||
}; // eslint-disable-next-line no-unused-vars | ||
measureValue = function measureValue(row, measure, xValues) { | ||
@@ -251,3 +255,4 @@ return row[measure] || 0; | ||
}), ramda.unnest, groupByXAxis, ramda.toPairs)(this.loadResponse.data); | ||
var allYValues = ramda.pipe(ramda.map(function (_ref6) { | ||
var allYValues = ramda.pipe(ramda.map( // eslint-disable-next-line no-unused-vars | ||
function (_ref6) { | ||
var _ref7 = _slicedToArray(_ref6, 2), | ||
@@ -261,3 +266,4 @@ xValuesString = _ref7[0], | ||
})); | ||
}), ramda.unnest, ramda.uniq)(xGrouped); | ||
}), ramda.unnest, ramda.uniq)(xGrouped); // eslint-disable-next-line no-unused-vars | ||
return xGrouped.map(function (_ref9) { | ||
@@ -313,3 +319,3 @@ var _ref10 = _slicedToArray(_ref9, 2), | ||
category: _this3.axisValuesString(xValues, ', '), | ||
//TODO deprecated | ||
// TODO deprecated | ||
x: _this3.axisValuesString(xValues, ', ') | ||
@@ -328,2 +334,52 @@ }, yValuesArray.map(function (_ref15) { | ||
}, { | ||
key: "tablePivot", | ||
value: function tablePivot(pivotConfig) { | ||
var normalizedPivotConfig = this.normalizePivotConfig(pivotConfig); | ||
var valueToObject = function valueToObject(valuesArray, measureValue) { | ||
return function (field, index) { | ||
return _defineProperty({}, field === 'measures' ? valuesArray[index] : field, field === 'measures' ? measureValue : valuesArray[index]); | ||
}; | ||
}; | ||
return this.pivot(pivotConfig).map(function (_ref19) { | ||
var xValues = _ref19.xValues, | ||
yValuesArray = _ref19.yValuesArray; | ||
return yValuesArray.map(function (_ref20) { | ||
var _ref21 = _slicedToArray(_ref20, 2), | ||
yValues = _ref21[0], | ||
m = _ref21[1]; | ||
return normalizedPivotConfig.x.map(valueToObject(xValues, m)).concat(normalizedPivotConfig.y.map(valueToObject(yValues, m))).reduce(function (a, b) { | ||
return Object.assign(a, b); | ||
}, {}); | ||
}); | ||
}).reduce(function (a, b) { | ||
return a.concat(b); | ||
}); | ||
} | ||
}, { | ||
key: "tableColumns", | ||
value: function tableColumns(pivotConfig) { | ||
var _this4 = this; | ||
var normalizedPivotConfig = this.normalizePivotConfig(pivotConfig); | ||
var column = function column(field) { | ||
return field === 'measures' ? (_this4.query().measures || []).map(function (m) { | ||
return { | ||
key: m, | ||
title: _this4.loadResponse.annotation.measures[m].title | ||
}; | ||
}) : [{ | ||
key: field, | ||
title: (_this4.loadResponse.annotation.dimensions[field] || _this4.loadResponse.annotation.timeDimensions[field]).title | ||
}]; | ||
}; | ||
return normalizedPivotConfig.x.map(column).concat(normalizedPivotConfig.y.map(column)).reduce(function (a, b) { | ||
return a.concat(b); | ||
}); | ||
} | ||
}, { | ||
key: "totalRow", | ||
@@ -336,3 +392,3 @@ value: function totalRow() { | ||
value: function categories(pivotConfig) { | ||
//TODO | ||
// TODO | ||
return this.chartPivot(pivotConfig); | ||
@@ -343,3 +399,3 @@ } | ||
value: function seriesNames(pivotConfig) { | ||
var _this4 = this; | ||
var _this5 = this; | ||
@@ -349,6 +405,6 @@ pivotConfig = this.normalizePivotConfig(pivotConfig); | ||
return { | ||
title: _this4.axisValuesString(pivotConfig.y.find(function (d) { | ||
title: _this5.axisValuesString(pivotConfig.y.find(function (d) { | ||
return d === 'measures'; | ||
}) ? ramda.dropLast(1, axisValues).concat(_this4.loadResponse.annotation.measures[ResultSet.measureFromAxis(axisValues)].title) : axisValues, ', '), | ||
key: _this4.axisValuesString(axisValues) | ||
}) ? ramda.dropLast(1, axisValues).concat(_this5.loadResponse.annotation.measures[ResultSet.measureFromAxis(axisValues)].title) : axisValues, ', '), | ||
key: _this5.axisValuesString(axisValues) | ||
}; | ||
@@ -512,2 +568,19 @@ }); | ||
}, { | ||
key: "defaultTimeDimensionNameFor", | ||
value: function defaultTimeDimensionNameFor(memberName) { | ||
var _this2 = this; | ||
var _memberName$split3 = memberName.split('.'), | ||
_memberName$split4 = _slicedToArray(_memberName$split3, 1), | ||
cube = _memberName$split4[0]; | ||
if (!this.cubesMap[cube]) { | ||
return null; | ||
} | ||
return Object.keys(this.cubesMap[cube].dimensions || {}).find(function (d) { | ||
return _this2.cubesMap[cube].dimensions[d].type === 'time'; | ||
}); | ||
} | ||
}, { | ||
key: "filterOperatorsForMember", | ||
@@ -514,0 +587,0 @@ value: function filterOperatorsForMember(memberName, memberType) { |
{ | ||
"name": "@cubejs-client/core", | ||
"version": "0.5.2", | ||
"version": "0.6.0", | ||
"description": "cube.js client", | ||
@@ -29,3 +29,3 @@ "main": "dist/cubejs-client-core.js", | ||
}, | ||
"gitHead": "cec5fc81a8caad49c8d37520eca791fbe17152ed" | ||
"gitHead": "8dfcbe0750319b25382f7f5cec38f94a20bfce1c" | ||
} |
@@ -56,2 +56,11 @@ import { unnest, fromPairs } from 'ramda'; | ||
defaultTimeDimensionNameFor(memberName) { | ||
const [cube] = memberName.split('.'); | ||
if (!this.cubesMap[cube]) { | ||
return null; | ||
} | ||
return Object.keys(this.cubesMap[cube].dimensions || {}) | ||
.find(d => this.cubesMap[cube].dimensions[d].type === 'time'); | ||
} | ||
filterOperatorsForMember(memberName, memberType) { | ||
@@ -58,0 +67,0 @@ const member = this.resolveMember(memberName, memberType); |
@@ -1,2 +0,4 @@ | ||
import { groupBy, pipe, toPairs, uniq, filter, map, unnest, dropLast, equals, reduce, minBy, maxBy } from 'ramda'; | ||
import { | ||
groupBy, pipe, toPairs, uniq, filter, map, unnest, dropLast, equals, reduce, minBy, maxBy | ||
} from 'ramda'; | ||
import Moment from 'moment'; | ||
@@ -8,17 +10,12 @@ import momentRange from 'moment-range'; | ||
const TIME_SERIES = { | ||
day: (range) => | ||
Array.from(range.by('day')) | ||
.map(d => d.format('YYYY-MM-DDT00:00:00.000')), | ||
month: (range) => | ||
Array.from(range.snapTo('month').by('month')) | ||
.map(d => d.format('YYYY-MM-01T00:00:00.000')), | ||
year: (range) => | ||
Array.from(range.snapTo('year').by('year')) | ||
.map(d => d.format('YYYY-01-01T00:00:00.000')), | ||
hour: (range) => | ||
Array.from(range.by('hour')) | ||
.map(d => d.format('YYYY-MM-DDTHH:00:00.000')), | ||
week: (range) => | ||
Array.from(range.snapTo('isoweek').by('week')) | ||
.map(d => d.startOf('isoweek').format('YYYY-MM-DDT00:00:00.000')) | ||
day: (range) => Array.from(range.by('day')) | ||
.map(d => d.format('YYYY-MM-DDT00:00:00.000')), | ||
month: (range) => Array.from(range.snapTo('month').by('month')) | ||
.map(d => d.format('YYYY-MM-01T00:00:00.000')), | ||
year: (range) => Array.from(range.snapTo('year').by('year')) | ||
.map(d => d.format('YYYY-01-01T00:00:00.000')), | ||
hour: (range) => Array.from(range.by('hour')) | ||
.map(d => d.format('YYYY-MM-DDTHH:00:00.000')), | ||
week: (range) => Array.from(range.snapTo('isoweek').by('week')) | ||
.map(d => d.startOf('isoweek').format('YYYY-MM-DDT00:00:00.000')) | ||
}; | ||
@@ -39,7 +36,6 @@ | ||
axisValues(axis) { | ||
const query = this.loadResponse.query; | ||
const { query } = this.loadResponse; | ||
return row => { | ||
const value = (measure) => | ||
axis.filter(d => d !== 'measures') | ||
.map(d => row[d] != null ? row[d] : null).concat(measure ? [measure] : []); | ||
const value = (measure) => axis.filter(d => d !== 'measures') | ||
.map(d => (row[d] != null ? row[d] : null)).concat(measure ? [measure] : []); | ||
if (axis.find(d => d === 'measures') && (query.measures || []).length) { | ||
@@ -66,4 +62,4 @@ return query.measures.map(value); | ||
normalizePivotConfig(pivotConfig) { | ||
const query = this.loadResponse.query; | ||
let timeDimensions = (query.timeDimensions || []).filter(td => !!td.granularity); | ||
const { query } = this.loadResponse; | ||
const timeDimensions = (query.timeDimensions || []).filter(td => !!td.granularity); | ||
pivotConfig = pivotConfig || (timeDimensions.length ? { | ||
@@ -87,3 +83,3 @@ x: timeDimensions.map(td => td.dimension), | ||
return axisValues[axisValues.length - 1]; | ||
}; | ||
} | ||
@@ -94,3 +90,3 @@ timeSeries(timeDimension) { | ||
} | ||
let dateRange = timeDimension.dateRange; | ||
let { dateRange } = timeDimension; | ||
if (!dateRange) { | ||
@@ -123,2 +119,3 @@ const dates = pipe( | ||
// eslint-disable-next-line no-unused-vars | ||
let measureValue = (row, measure, xValues) => row[measure]; | ||
@@ -137,3 +134,6 @@ | ||
groupByXAxis = (rows) => { | ||
const byXValues = groupBy(({ xValues }) => moment(xValues[0]).format(moment.HTML5_FMT.DATETIME_LOCAL_MS), rows); | ||
const byXValues = groupBy( | ||
({ xValues }) => moment(xValues[0]).format(moment.HTML5_FMT.DATETIME_LOCAL_MS), | ||
rows | ||
); | ||
return series.map(d => ({ [d]: byXValues[d] || [{ xValues: [d], row: {} }] })) | ||
@@ -143,2 +143,3 @@ .reduce((a, b) => Object.assign(a, b), {}); | ||
// eslint-disable-next-line no-unused-vars | ||
measureValue = (row, measure, xValues) => row[measure] || 0; | ||
@@ -157,2 +158,3 @@ } | ||
map( | ||
// eslint-disable-next-line no-unused-vars | ||
([xValuesString, rows]) => unnest(rows.map(({ row }) => this.axisValues(pivotConfig.y)(row))) | ||
@@ -164,4 +166,5 @@ ), | ||
// eslint-disable-next-line no-unused-vars | ||
return xGrouped.map(([xValuesString, rows]) => { | ||
const xValues = rows[0].xValues; | ||
const { xValues } = rows[0]; | ||
const yGrouped = pipe( | ||
@@ -175,6 +178,7 @@ map(({ row }) => this.axisValues(pivotConfig.y)(row).map(yValues => ({ yValues, row }))), | ||
yValuesArray: unnest(allYValues.map(yValues => { | ||
let measure = pivotConfig.x.find(d => d === 'measures') ? | ||
const measure = pivotConfig.x.find(d => d === 'measures') ? | ||
ResultSet.measureFromAxis(xValues) : | ||
ResultSet.measureFromAxis(yValues); | ||
return (yGrouped[this.axisValuesString(yValues)] || [{ row: {} }]).map(({ row }) => [yValues, measureValue(row, measure, xValues)]) | ||
return (yGrouped[this.axisValuesString(yValues)] || | ||
[{ row: {} }]).map(({ row }) => [yValues, measureValue(row, measure, xValues)]); | ||
})) | ||
@@ -191,3 +195,3 @@ }; | ||
return this.pivot(pivotConfig).map(({ xValues, yValuesArray }) => ({ | ||
category: this.axisValuesString(xValues, ', '), //TODO deprecated | ||
category: this.axisValuesString(xValues, ', '), // TODO deprecated | ||
x: this.axisValuesString(xValues, ', '), | ||
@@ -202,2 +206,38 @@ ...( | ||
tablePivot(pivotConfig) { | ||
const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig); | ||
const valueToObject = | ||
(valuesArray, measureValue) => ( | ||
(field, index) => ({ | ||
[field === 'measures' ? valuesArray[index] : field]: field === 'measures' ? measureValue : valuesArray[index] | ||
}) | ||
); | ||
return this.pivot(pivotConfig).map(({ xValues, yValuesArray }) => ( | ||
yValuesArray.map(([yValues, m]) => ( | ||
normalizedPivotConfig.x.map(valueToObject(xValues, m)) | ||
.concat(normalizedPivotConfig.y.map(valueToObject(yValues, m))) | ||
.reduce((a, b) => Object.assign(a, b), {}) | ||
)) | ||
)).reduce((a, b) => a.concat(b)); | ||
} | ||
tableColumns(pivotConfig) { | ||
const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig); | ||
const column = field => ( | ||
field === 'measures' ? | ||
(this.query().measures || []).map(m => ({ key: m, title: this.loadResponse.annotation.measures[m].title })) : | ||
[{ | ||
key: field, | ||
title: ( | ||
this.loadResponse.annotation.dimensions[field] || | ||
this.loadResponse.annotation.timeDimensions[field] | ||
).title | ||
}] | ||
); | ||
return normalizedPivotConfig.x.map(column) | ||
.concat(normalizedPivotConfig.y.map(column)) | ||
.reduce((a, b) => a.concat(b)); | ||
} | ||
totalRow() { | ||
@@ -207,3 +247,3 @@ return this.chartPivot()[0]; | ||
categories(pivotConfig) { //TODO | ||
categories(pivotConfig) { // TODO | ||
return this.chartPivot(pivotConfig); | ||
@@ -220,3 +260,3 @@ } | ||
key: this.axisValuesString(axisValues) | ||
})) | ||
})); | ||
} | ||
@@ -223,0 +263,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
523955
14688