@vizzly/dashboard 0.15.0-dev-304623eadd21ab4d934b2446ffd1f7a4c56d7067 → 0.15.0-dev-cbddccd98a4baff445756f4e7ff1398b9f72901c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1835,26 +1835,6 @@ function removeEmptyConditions(conditions) {
1835
1835
  });
1836
1836
  });
1837
1837
  }
1838
- var buildAdvancedFilters = function buildAdvancedFilters(filterValue, field, dataSetId) {
1839
- if (!filterValue) return [];
1840
- var hasValidConditions = Array.isArray(filterValue) && filterValue.every(function (conditionGroup) {
1841
- return Array.isArray(conditionGroup);
1842
- });
1843
- if (hasValidConditions) {
1844
- filterValue = removeEmptyConditions(filterValue);
1845
- if (filterValue.length === 0) return [];
1846
- if (field.dataSetId !== dataSetId) return [];
1847
- var correctFiltersForField = filterValue.map(function (conditionGroup) {
1848
- return conditionGroup.filter(function (filter) {
1849
- return filter.field === field.fieldId;
1850
- });
1851
- }).filter(function (conditionGroup) {
1852
- return conditionGroup.length > 0;
1853
- });
1854
- return correctFiltersForField;
1855
- }
1856
- return [];
1857
- };
1858
1838
  function getFilterDataType(filter, dataSets) {
1859
1839
  var _filter$appliesToFiel;
1860
1840
  if (filter.type == SINGLE_SELECT_FILTER || filter.type == DATE_FILTER || filter.type == DATE_AND_TIME_FILTER) {
@@ -1874,6 +1854,10 @@ function getFilterDataType(filter, dataSets) {
1874
1854
  }
1875
1855
 
1876
1856
  var toQueryAttributesFilter = function toQueryAttributesFilter(dataSet, filter, customTimeRangeFuncs) {
1857
+ // For any filter that already contains the full filter object,
1858
+ if (isAdditionalFilter(filter.value)) {
1859
+ return removeEmptyConditions(filter.value || []);
1860
+ }
1877
1861
  return filter.appliesToFields.flatMap(function (field) {
1878
1862
  var _filter$value, _filter$value2, _filter$value3;
1879
1863
  if (field.dataSetId != dataSet.id) return [];
@@ -1939,8 +1923,6 @@ var toQueryAttributesFilter = function toQueryAttributesFilter(dataSet, filter,
1939
1923
  op: '=',
1940
1924
  value: value
1941
1925
  }]];
1942
- } else if (isAdditionalFilter(filter.value)) {
1943
- return buildAdvancedFilters(filter.value, field, dataSet.id);
1944
1926
  } else if (filter.type == MULTI_SELECT_FILTER && filter.value.length > 0) {
1945
1927
  return [[{
1946
1928
  field: field.fieldId,
@@ -4758,7 +4740,7 @@ var BarChart = function BarChart(config) {
4758
4740
 
4759
4741
  var attributesSchema$3 = function attributesSchema(config) {
4760
4742
  return Joi.object(_extends({}, baseAttributesSchema(config.attributesSchemaOptions), timeDimensionQuerySchema(config.queryEngineConfig, config.attributesSchemaOptions), {
4761
- stacked: Joi.valid(true, false),
4743
+ stacked: Joi.valid(true, false, '100%'),
4762
4744
  legend: Joi.valid(true, false),
4763
4745
  labels: Joi.valid(true, false).optional(),
4764
4746
  type: Joi.valid('barChartV2').required(),
@@ -8018,7 +8000,7 @@ var HorizontalBarChart = function HorizontalBarChart(config) {
8018
8000
 
8019
8001
  var attributesSchema$b = function attributesSchema(config) {
8020
8002
  return Joi.object(_extends({}, baseAttributesSchema(config.attributesSchemaOptions), timeDimensionQuerySchema(config.queryEngineConfig, config.attributesSchemaOptions), {
8021
- stacked: Joi.valid(true, false),
8003
+ stacked: Joi.valid(true, false, '100%'),
8022
8004
  legend: Joi.valid(true, false),
8023
8005
  labels: Joi.valid(true, false).optional(),
8024
8006
  type: Joi.valid('horizontalBarChartV2').required(),
@@ -34756,9 +34738,10 @@ var getLabelDictionary = function getLabelDictionary(formattedData, keys) {
34756
34738
  };
34757
34739
  var getFormattedValue = function getFormattedValue(value, dictionary) {
34758
34740
  var _dictionary$normalize;
34759
- if (!dictionary) return value;
34760
- var normalizedKey = normalizeKey(value);
34761
- return (_dictionary$normalize = dictionary[normalizedKey]) != null ? _dictionary$normalize : value;
34741
+ var actualValue = (value == null ? void 0 : value.value) !== undefined ? value.value : value;
34742
+ if (!dictionary) return actualValue;
34743
+ var normalizedKey = normalizeKey(actualValue);
34744
+ return (_dictionary$normalize = dictionary[normalizedKey]) != null ? _dictionary$normalize : actualValue;
34762
34745
  };
34763
34746
  var getAllChartValues = function getAllChartValues(data, keys) {
34764
34747
  var allValues = [];
@@ -45862,7 +45845,8 @@ var BarStacked = function BarStacked(_ref) {
45862
45845
  height = _ref.height,
45863
45846
  width = _ref.width,
45864
45847
  showLabels = _ref.showLabels,
45865
- labelDictionary = _ref.labelDictionary;
45848
+ labelDictionary = _ref.labelDictionary,
45849
+ isStacked100 = _ref.isStacked100;
45866
45850
  var handleGetXValue = function handleGetXValue(d) {
45867
45851
  var xValue = d[xScaleKey];
45868
45852
  if (xScaleDataType === 'string') return String(xValue);
@@ -45889,7 +45873,7 @@ var BarStacked = function BarStacked(_ref) {
45889
45873
  },
45890
45874
  height: height,
45891
45875
  width: width,
45892
- offset: "none",
45876
+ offset: isStacked100 ? 'expand' : 'none',
45893
45877
  children: function children(barStacks) {
45894
45878
  return barStacks.map(function (barStack) {
45895
45879
  return barStack.bars.map(function (bar) {
@@ -46032,6 +46016,7 @@ var BarChart$5 = function BarChart(_ref) {
46032
46016
  var showDetailedSubGroupingLabels = !options.stacked && numberOfDimensions === 2 && width > 450;
46033
46017
  var hasBottomTitle = chart.x.title != null;
46034
46018
  var hasLeftTitle = chart.y.title != null;
46019
+ var isStacked100 = options.stacked === '100%';
46035
46020
  var _useGroupingAxisBaseL = useGroupingAxisBaseLineShift({
46036
46021
  hasBottomTitle: hasBottomTitle,
46037
46022
  hasLeftTitle: hasLeftTitle,
@@ -46042,13 +46027,24 @@ var BarChart$5 = function BarChart(_ref) {
46042
46027
  leftOffset = _useGroupingAxisBaseL.leftOffset;
46043
46028
  var margin = buildMargin(chart.y.ticks, options.axis.showYAxisLabels, hasLeftTitle, hasBottomTitle, showDetailedSubGroupingLabels);
46044
46029
  var innerWidth = width - margin.left - margin.right;
46045
- var innerHeight = height - margin.top - margin.bottom - (options.showLegend ? 50 : 0) - (showDetailedSubGroupingLabels ? 50 : 0) + (options.axis.showXAxisLabels ? 0 : 25);
46030
+ var innerHeight = Math.max(0, height - margin.top - margin.bottom - (options.showLegend ? 50 : 0) - (showDetailedSubGroupingLabels ? 50 : 0) + (options.axis.showXAxisLabels ? 0 : 25));
46046
46031
  var xKey = chart.x.key;
46047
46032
  var xScaleKey = chart.x.scale.key;
46048
46033
  var xScaleDataType = chart.x.scale.dataType;
46049
46034
  var xScale = useBarXScale(xScaleDataType, innerWidth, xScaleKey, chart.data);
46050
46035
  var yScaleKeys = chart.y.keys;
46051
- var yScale = useYScale(innerHeight, chart.y.scale);
46036
+ var defaultYScale = useYScale(innerHeight, chart.y.scale);
46037
+ var yScale = useMemo(function () {
46038
+ if (isStacked100) {
46039
+ return scaleLinear({
46040
+ range: [innerHeight, 0],
46041
+ domain: [0, 1],
46042
+ nice: true,
46043
+ round: true
46044
+ });
46045
+ }
46046
+ return defaultYScale;
46047
+ }, [innerHeight, defaultYScale, options.stacked]);
46052
46048
  var yTickValues = chart.y.ticks.map(function (tick) {
46053
46049
  return Number(tick.value);
46054
46050
  });
@@ -46187,7 +46183,8 @@ var BarChart$5 = function BarChart(_ref) {
46187
46183
  height: innerHeight,
46188
46184
  width: innerWidth,
46189
46185
  showLabels: options.showLabels,
46190
- labelDictionary: formattedLabelsDict
46186
+ labelDictionary: formattedLabelsDict,
46187
+ isStacked100: isStacked100
46191
46188
  })]
46192
46189
  })]
46193
46190
  }), tooltipData && jsx("g", {
@@ -46684,7 +46681,8 @@ var HorizontalBarStacked = function HorizontalBarStacked(_ref) {
46684
46681
  height = _ref.height,
46685
46682
  width = _ref.width,
46686
46683
  showLabels = _ref.showLabels,
46687
- labelDictionary = _ref.labelDictionary;
46684
+ labelDictionary = _ref.labelDictionary,
46685
+ isStacked100 = _ref.isStacked100;
46688
46686
  var handleGetYValue = function handleGetYValue(d) {
46689
46687
  var yValue = d[yScaleKey];
46690
46688
  if (yScaleDataType === 'string') return String(yValue);
@@ -46711,7 +46709,7 @@ var HorizontalBarStacked = function HorizontalBarStacked(_ref) {
46711
46709
  },
46712
46710
  height: height,
46713
46711
  width: width,
46714
- offset: "none",
46712
+ offset: isStacked100 ? 'expand' : 'none',
46715
46713
  children: function children(barStacks) {
46716
46714
  return barStacks.map(function (barStack) {
46717
46715
  return barStack.bars.map(function (bar) {
@@ -47041,9 +47039,21 @@ var HorizontalBarChart$3 = function HorizontalBarChart(_ref) {
47041
47039
  var margin = buildMarginForHorizontalChart(chart.x.ticks, chart.y.ticks, options.axis.showXAxisLabels, options.axis.showYAxisLabels, hasLeftTitle, hasBottomTitle);
47042
47040
  var legendOffset = options.showLegend ? 50 : 10;
47043
47041
  var innerWidth = width - margin.left - margin.right + groupingAxisBaselineShift;
47044
- var innerHeight = height - margin.top - margin.bottom - legendOffset;
47042
+ var innerHeight = Math.max(0, height - margin.top - margin.bottom - legendOffset);
47043
+ var isStacked100 = options.stacked === '100%';
47045
47044
  var xScaleKeys = chart.x.keys;
47046
- var xScale = useHorizontalBarXScale(innerWidth, chart.x.scale, -groupingAxisBaselineShift);
47045
+ var defaultXScale = useHorizontalBarXScale(innerWidth, chart.x.scale, -groupingAxisBaselineShift);
47046
+ var xScale = useMemo(function () {
47047
+ if (isStacked100) {
47048
+ return scaleLinear({
47049
+ range: [-groupingAxisBaselineShift, innerWidth + -groupingAxisBaselineShift],
47050
+ domain: [0, 1],
47051
+ nice: true,
47052
+ round: true
47053
+ });
47054
+ }
47055
+ return defaultXScale;
47056
+ }, [innerWidth, defaultXScale, groupingAxisBaselineShift, options.stacked]);
47047
47057
  var barGroupXScale = useHorizontalBarXScale(innerWidth, chart.x.scale, 0);
47048
47058
  var xTickValues = chart.x.ticks.map(function (tick) {
47049
47059
  return Number(tick.value);
@@ -47248,7 +47258,8 @@ var HorizontalBarChart$3 = function HorizontalBarChart(_ref) {
47248
47258
  height: innerHeight,
47249
47259
  width: innerWidth,
47250
47260
  showLabels: options.showLabels,
47251
- labelDictionary: formattedLabelsDict
47261
+ labelDictionary: formattedLabelsDict,
47262
+ isStacked100: isStacked100
47252
47263
  })]
47253
47264
  })]
47254
47265
  }), tooltipData && jsx("g", {
@@ -50187,6 +50198,35 @@ var AreaChartV2 = function AreaChartV2(props) {
50187
50198
  });
50188
50199
  };
50189
50200
 
50201
+ function convertToStackedPercentages(data, yKeys, xKey) {
50202
+ if (!xKey || yKeys.length === 0) {
50203
+ return data;
50204
+ }
50205
+ return data.map(function (item) {
50206
+ var convertedItem = _extends({}, item);
50207
+ var total = 0;
50208
+ yKeys.forEach(function (key) {
50209
+ var _item$key;
50210
+ var value = Number((_item$key = item[key]) == null ? void 0 : _item$key.value) || 0;
50211
+ total += value;
50212
+ });
50213
+ if (total === 0) {
50214
+ return convertedItem;
50215
+ }
50216
+ yKeys.forEach(function (key) {
50217
+ if (item[key]) {
50218
+ var value = Number(item[key].value) || 0;
50219
+ var percentage = value / total;
50220
+ convertedItem[key] = _extends({}, item[key], {
50221
+ value: percentage,
50222
+ originalValue: item[key].value
50223
+ });
50224
+ }
50225
+ });
50226
+ return convertedItem;
50227
+ });
50228
+ }
50229
+
50190
50230
  var buildBarChartRepresentation = function buildBarChartRepresentation(_ref) {
50191
50231
  var _xKeys$, _axisTitles$x, _axisTitles$y;
50192
50232
  var axisTitles = _ref.axisTitles,
@@ -50289,6 +50329,7 @@ var buildBarChartRepresentation = function buildBarChartRepresentation(_ref) {
50289
50329
  }
50290
50330
  if (stacked) {
50291
50331
  data = fillMissingKeysForChartData(data);
50332
+ if (stacked === '100%') data = convertToStackedPercentages(data, yKeys, xKey);
50292
50333
  }
50293
50334
  return data;
50294
50335
  }();
@@ -50315,7 +50356,7 @@ var buildBarChartRepresentation = function buildBarChartRepresentation(_ref) {
50315
50356
  nullValue: nullValue,
50316
50357
  order: order,
50317
50358
  goalLines: goalLines,
50318
- stacked: stacked
50359
+ stacked: stacked === true || stacked === '100%'
50319
50360
  });
50320
50361
 
50321
50362
  // ----- Lines -----
@@ -50514,14 +50555,14 @@ var BarChartV2View = function BarChartV2View(props) {
50514
50555
  overflowX: 'hidden'
50515
50556
  },
50516
50557
  children: function children(parent) {
50517
- var _props$attributes$lab;
50558
+ var _props$attributes$sta, _props$attributes$lab;
50518
50559
  if (chartRepresentation.bars.length === 0) return jsx(LoadingComponent, {});
50519
50560
  return jsx(BarChart$5, {
50520
50561
  width: parent.width,
50521
50562
  height: parent.height,
50522
50563
  chart: adjustTicks(chartRepresentation, parent.width, parent.height, xKeyField),
50523
50564
  options: {
50524
- stacked: !!props.attributes.stacked,
50565
+ stacked: (_props$attributes$sta = props.attributes.stacked) != null ? _props$attributes$sta : false,
50525
50566
  removeStroke: false,
50526
50567
  showRoundedTotal: false,
50527
50568
  showLegend: props.attributes.legend,
@@ -54057,6 +54098,7 @@ var buildHorizontalBarChartRepresentation = function buildHorizontalBarChartRepr
54057
54098
  }
54058
54099
  if (stacked) {
54059
54100
  data = fillMissingKeysForChartData(data);
54101
+ if (stacked === '100%') data = convertToStackedPercentages(data, xKeys, yKey);
54060
54102
  }
54061
54103
  return data;
54062
54104
  }();
@@ -54083,7 +54125,7 @@ var buildHorizontalBarChartRepresentation = function buildHorizontalBarChartRepr
54083
54125
  nullValue: nullValue,
54084
54126
  order: order,
54085
54127
  goalLines: goalLines,
54086
- stacked: stacked
54128
+ stacked: stacked === true || stacked === '100%'
54087
54129
  });
54088
54130
  var flippedTicks = {
54089
54131
  x: {
@@ -54291,14 +54333,14 @@ var HorizontalBarChartV2View = function HorizontalBarChartV2View(props) {
54291
54333
  overflowX: 'hidden'
54292
54334
  },
54293
54335
  children: function children(parent) {
54294
- var _props$attributes$lab;
54336
+ var _props$attributes$sta, _props$attributes$lab;
54295
54337
  if (chartRepresentation.bars.length === 0) return jsx(LoadingComponent, {});
54296
54338
  return jsx(HorizontalBarChart$3, {
54297
54339
  width: parent.width,
54298
54340
  height: parent.height,
54299
54341
  chart: adjustTicksForHorizontalChart(chartRepresentation, parent.width, parent.height, yKeyField),
54300
54342
  options: {
54301
- stacked: !!props.attributes.stacked,
54343
+ stacked: (_props$attributes$sta = props.attributes.stacked) != null ? _props$attributes$sta : false,
54302
54344
  removeStroke: false,
54303
54345
  showRoundedTotal: false,
54304
54346
  showLegend: props.attributes.legend,
@@ -64817,7 +64859,8 @@ var ChartSettingsSection = function ChartSettingsSection(_ref) {
64817
64859
  label: textOverride('stacked', 'Stacked'),
64818
64860
  value: true
64819
64861
  }];
64820
- if (attributes.type === 'barChart' || attributes.type === 'areaChart') {
64862
+ var chartTypes = ['areaChart', 'barChart', 'barChartV2', 'horizontalBarChartV2'];
64863
+ if (chartTypes.includes(attributes.type)) {
64821
64864
  options.push({
64822
64865
  label: textOverride('stacked_100prc', 'Stacked (100%)'),
64823
64866
  value: '100%'
@@ -44,5 +44,5 @@ export declare enum DateOp {
44
44
  export declare function inclusiveExclusiveCurrent(op: DateOp, filter: DateFilter | DateAndTimeFilter): string;
45
45
  export declare function getCascadeOptionsFilters(globalFilters: AdditionalFilter[], dataSets: DataSet[], dateFilterOptions: DateTimeFilterOptions, variables: VariableList, cascadeFilterSelection?: boolean): OptionalFilters | undefined;
46
46
  export declare const updateFilterForOptionalPulledFromOptions: (filter: AdditionalFilter) => AdditionalFilter;
47
- export declare const buildAdvancedFilters: (filterValue: QueryAttributes.Filter[][], field: Field, dataSetId: string) => QueryAttributes.Filter[][];
47
+ export declare function removeEmptyConditions(conditions: QueryAttributes.Filter[][]): QueryAttributes.Filter[][];
48
48
  export declare function getFilterDataType(filter: AdditionalFilter, dataSets: DataSet[]): "string" | "number" | "boolean" | "date_time" | "string[]" | undefined;
@@ -35,7 +35,7 @@ interface buildBarChartRepresentationArgs {
35
35
  yAxisPrefix: string;
36
36
  approxYAxisLabelCount: number;
37
37
  seriesLabelFormatter: seriesLabelFormatter;
38
- stacked?: boolean;
38
+ stacked?: boolean | '100%';
39
39
  }
40
40
  export declare const buildBarChartRepresentation: ({ axisTitles, colors, conditionalFormattingAttributes, dateTimeFormatOptions, defaultFormats, goalLineAttributes, nullValue, numberFormatOptions, order, pivotConfig, result, xAxisFormat, xAxisPostfix, xAxisPrefix, yAxisFormat, yAxisPostfix, yAxisPrefix, approxYAxisLabelCount, seriesLabelFormatter, valueAlias, stacked, }: buildBarChartRepresentationArgs) => BarChartRepresentation;
41
41
  export {};
@@ -0,0 +1 @@
1
+ export declare function convertToStackedPercentages(data: Record<string, any>[], yKeys: string[], xKey: string | null): Record<string, any>[];
@@ -239,7 +239,7 @@ export declare namespace Component {
239
239
  };
240
240
  export type BarChartV2Attributes = BaseAttributes & BaseQueryAttributes & {
241
241
  type: 'barChartV2';
242
- stacked?: boolean;
242
+ stacked?: boolean | '100%';
243
243
  xAxisPrefix: string;
244
244
  yAxisPrefix: string;
245
245
  xAxisPostfix: string;
@@ -297,7 +297,7 @@ export declare namespace Component {
297
297
  };
298
298
  export type HorizontalBarChartV2Attributes = BaseAttributes & BaseQueryAttributes & {
299
299
  type: 'horizontalBarChartV2';
300
- stacked?: boolean;
300
+ stacked?: boolean | '100%';
301
301
  xAxisPrefix: string;
302
302
  yAxisPrefix: string;
303
303
  xAxisPostfix: string;
@@ -35,7 +35,7 @@ interface buildHorizontalBarChartRepresentationArgs {
35
35
  yAxisPrefix: string;
36
36
  approxXAxisLabelCount: number;
37
37
  seriesLabelFormatter: seriesLabelFormatter;
38
- stacked?: boolean;
38
+ stacked?: boolean | '100%';
39
39
  }
40
40
  export declare const buildHorizontalBarChartRepresentation: ({ axisTitles, colors, conditionalFormattingAttributes, dateTimeFormatOptions, defaultFormats, goalLineAttributes, nullValue, numberFormatOptions, order, pivotConfig, result, xAxisFormat, xAxisPostfix, xAxisPrefix, yAxisFormat, yAxisPostfix, yAxisPrefix, approxXAxisLabelCount, seriesLabelFormatter, valueAlias, stacked, }: buildHorizontalBarChartRepresentationArgs) => HorizontalBarChartRepresentation;
41
41
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vizzly/dashboard",
3
3
  "author": "james@vizzly.co",
4
- "version": "0.15.0-dev-304623eadd21ab4d934b2446ffd1f7a4c56d7067",
4
+ "version": "0.15.0-dev-cbddccd98a4baff445756f4e7ff1398b9f72901c",
5
5
  "source": "src/index.tsx",
6
6
  "types": "./dist/dashboard/src/index.d.ts",
7
7
  "module": "./dist/dashboard.esm.js",