@vizzly/dashboard 0.15.0-dev-0bf2cc62e2eca0a88e685afc885c2424ce22349c → 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.
@@ -4740,7 +4740,7 @@ var BarChart = function BarChart(config) {
4740
4740
 
4741
4741
  var attributesSchema$3 = function attributesSchema(config) {
4742
4742
  return Joi.object(_extends({}, baseAttributesSchema(config.attributesSchemaOptions), timeDimensionQuerySchema(config.queryEngineConfig, config.attributesSchemaOptions), {
4743
- stacked: Joi.valid(true, false),
4743
+ stacked: Joi.valid(true, false, '100%'),
4744
4744
  legend: Joi.valid(true, false),
4745
4745
  labels: Joi.valid(true, false).optional(),
4746
4746
  type: Joi.valid('barChartV2').required(),
@@ -8000,7 +8000,7 @@ var HorizontalBarChart = function HorizontalBarChart(config) {
8000
8000
 
8001
8001
  var attributesSchema$b = function attributesSchema(config) {
8002
8002
  return Joi.object(_extends({}, baseAttributesSchema(config.attributesSchemaOptions), timeDimensionQuerySchema(config.queryEngineConfig, config.attributesSchemaOptions), {
8003
- stacked: Joi.valid(true, false),
8003
+ stacked: Joi.valid(true, false, '100%'),
8004
8004
  legend: Joi.valid(true, false),
8005
8005
  labels: Joi.valid(true, false).optional(),
8006
8006
  type: Joi.valid('horizontalBarChartV2').required(),
@@ -34738,9 +34738,10 @@ var getLabelDictionary = function getLabelDictionary(formattedData, keys) {
34738
34738
  };
34739
34739
  var getFormattedValue = function getFormattedValue(value, dictionary) {
34740
34740
  var _dictionary$normalize;
34741
- if (!dictionary) return value;
34742
- var normalizedKey = normalizeKey(value);
34743
- 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;
34744
34745
  };
34745
34746
  var getAllChartValues = function getAllChartValues(data, keys) {
34746
34747
  var allValues = [];
@@ -45844,7 +45845,8 @@ var BarStacked = function BarStacked(_ref) {
45844
45845
  height = _ref.height,
45845
45846
  width = _ref.width,
45846
45847
  showLabels = _ref.showLabels,
45847
- labelDictionary = _ref.labelDictionary;
45848
+ labelDictionary = _ref.labelDictionary,
45849
+ isStacked100 = _ref.isStacked100;
45848
45850
  var handleGetXValue = function handleGetXValue(d) {
45849
45851
  var xValue = d[xScaleKey];
45850
45852
  if (xScaleDataType === 'string') return String(xValue);
@@ -45871,7 +45873,7 @@ var BarStacked = function BarStacked(_ref) {
45871
45873
  },
45872
45874
  height: height,
45873
45875
  width: width,
45874
- offset: "none",
45876
+ offset: isStacked100 ? 'expand' : 'none',
45875
45877
  children: function children(barStacks) {
45876
45878
  return barStacks.map(function (barStack) {
45877
45879
  return barStack.bars.map(function (bar) {
@@ -46014,6 +46016,7 @@ var BarChart$5 = function BarChart(_ref) {
46014
46016
  var showDetailedSubGroupingLabels = !options.stacked && numberOfDimensions === 2 && width > 450;
46015
46017
  var hasBottomTitle = chart.x.title != null;
46016
46018
  var hasLeftTitle = chart.y.title != null;
46019
+ var isStacked100 = options.stacked === '100%';
46017
46020
  var _useGroupingAxisBaseL = useGroupingAxisBaseLineShift({
46018
46021
  hasBottomTitle: hasBottomTitle,
46019
46022
  hasLeftTitle: hasLeftTitle,
@@ -46024,13 +46027,24 @@ var BarChart$5 = function BarChart(_ref) {
46024
46027
  leftOffset = _useGroupingAxisBaseL.leftOffset;
46025
46028
  var margin = buildMargin(chart.y.ticks, options.axis.showYAxisLabels, hasLeftTitle, hasBottomTitle, showDetailedSubGroupingLabels);
46026
46029
  var innerWidth = width - margin.left - margin.right;
46027
- 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));
46028
46031
  var xKey = chart.x.key;
46029
46032
  var xScaleKey = chart.x.scale.key;
46030
46033
  var xScaleDataType = chart.x.scale.dataType;
46031
46034
  var xScale = useBarXScale(xScaleDataType, innerWidth, xScaleKey, chart.data);
46032
46035
  var yScaleKeys = chart.y.keys;
46033
- 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]);
46034
46048
  var yTickValues = chart.y.ticks.map(function (tick) {
46035
46049
  return Number(tick.value);
46036
46050
  });
@@ -46169,7 +46183,8 @@ var BarChart$5 = function BarChart(_ref) {
46169
46183
  height: innerHeight,
46170
46184
  width: innerWidth,
46171
46185
  showLabels: options.showLabels,
46172
- labelDictionary: formattedLabelsDict
46186
+ labelDictionary: formattedLabelsDict,
46187
+ isStacked100: isStacked100
46173
46188
  })]
46174
46189
  })]
46175
46190
  }), tooltipData && jsx("g", {
@@ -46666,7 +46681,8 @@ var HorizontalBarStacked = function HorizontalBarStacked(_ref) {
46666
46681
  height = _ref.height,
46667
46682
  width = _ref.width,
46668
46683
  showLabels = _ref.showLabels,
46669
- labelDictionary = _ref.labelDictionary;
46684
+ labelDictionary = _ref.labelDictionary,
46685
+ isStacked100 = _ref.isStacked100;
46670
46686
  var handleGetYValue = function handleGetYValue(d) {
46671
46687
  var yValue = d[yScaleKey];
46672
46688
  if (yScaleDataType === 'string') return String(yValue);
@@ -46693,7 +46709,7 @@ var HorizontalBarStacked = function HorizontalBarStacked(_ref) {
46693
46709
  },
46694
46710
  height: height,
46695
46711
  width: width,
46696
- offset: "none",
46712
+ offset: isStacked100 ? 'expand' : 'none',
46697
46713
  children: function children(barStacks) {
46698
46714
  return barStacks.map(function (barStack) {
46699
46715
  return barStack.bars.map(function (bar) {
@@ -47023,9 +47039,21 @@ var HorizontalBarChart$3 = function HorizontalBarChart(_ref) {
47023
47039
  var margin = buildMarginForHorizontalChart(chart.x.ticks, chart.y.ticks, options.axis.showXAxisLabels, options.axis.showYAxisLabels, hasLeftTitle, hasBottomTitle);
47024
47040
  var legendOffset = options.showLegend ? 50 : 10;
47025
47041
  var innerWidth = width - margin.left - margin.right + groupingAxisBaselineShift;
47026
- 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%';
47027
47044
  var xScaleKeys = chart.x.keys;
47028
- 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]);
47029
47057
  var barGroupXScale = useHorizontalBarXScale(innerWidth, chart.x.scale, 0);
47030
47058
  var xTickValues = chart.x.ticks.map(function (tick) {
47031
47059
  return Number(tick.value);
@@ -47230,7 +47258,8 @@ var HorizontalBarChart$3 = function HorizontalBarChart(_ref) {
47230
47258
  height: innerHeight,
47231
47259
  width: innerWidth,
47232
47260
  showLabels: options.showLabels,
47233
- labelDictionary: formattedLabelsDict
47261
+ labelDictionary: formattedLabelsDict,
47262
+ isStacked100: isStacked100
47234
47263
  })]
47235
47264
  })]
47236
47265
  }), tooltipData && jsx("g", {
@@ -50169,6 +50198,35 @@ var AreaChartV2 = function AreaChartV2(props) {
50169
50198
  });
50170
50199
  };
50171
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
+
50172
50230
  var buildBarChartRepresentation = function buildBarChartRepresentation(_ref) {
50173
50231
  var _xKeys$, _axisTitles$x, _axisTitles$y;
50174
50232
  var axisTitles = _ref.axisTitles,
@@ -50271,6 +50329,7 @@ var buildBarChartRepresentation = function buildBarChartRepresentation(_ref) {
50271
50329
  }
50272
50330
  if (stacked) {
50273
50331
  data = fillMissingKeysForChartData(data);
50332
+ if (stacked === '100%') data = convertToStackedPercentages(data, yKeys, xKey);
50274
50333
  }
50275
50334
  return data;
50276
50335
  }();
@@ -50297,7 +50356,7 @@ var buildBarChartRepresentation = function buildBarChartRepresentation(_ref) {
50297
50356
  nullValue: nullValue,
50298
50357
  order: order,
50299
50358
  goalLines: goalLines,
50300
- stacked: stacked
50359
+ stacked: stacked === true || stacked === '100%'
50301
50360
  });
50302
50361
 
50303
50362
  // ----- Lines -----
@@ -50496,14 +50555,14 @@ var BarChartV2View = function BarChartV2View(props) {
50496
50555
  overflowX: 'hidden'
50497
50556
  },
50498
50557
  children: function children(parent) {
50499
- var _props$attributes$lab;
50558
+ var _props$attributes$sta, _props$attributes$lab;
50500
50559
  if (chartRepresentation.bars.length === 0) return jsx(LoadingComponent, {});
50501
50560
  return jsx(BarChart$5, {
50502
50561
  width: parent.width,
50503
50562
  height: parent.height,
50504
50563
  chart: adjustTicks(chartRepresentation, parent.width, parent.height, xKeyField),
50505
50564
  options: {
50506
- stacked: !!props.attributes.stacked,
50565
+ stacked: (_props$attributes$sta = props.attributes.stacked) != null ? _props$attributes$sta : false,
50507
50566
  removeStroke: false,
50508
50567
  showRoundedTotal: false,
50509
50568
  showLegend: props.attributes.legend,
@@ -54039,6 +54098,7 @@ var buildHorizontalBarChartRepresentation = function buildHorizontalBarChartRepr
54039
54098
  }
54040
54099
  if (stacked) {
54041
54100
  data = fillMissingKeysForChartData(data);
54101
+ if (stacked === '100%') data = convertToStackedPercentages(data, xKeys, yKey);
54042
54102
  }
54043
54103
  return data;
54044
54104
  }();
@@ -54065,7 +54125,7 @@ var buildHorizontalBarChartRepresentation = function buildHorizontalBarChartRepr
54065
54125
  nullValue: nullValue,
54066
54126
  order: order,
54067
54127
  goalLines: goalLines,
54068
- stacked: stacked
54128
+ stacked: stacked === true || stacked === '100%'
54069
54129
  });
54070
54130
  var flippedTicks = {
54071
54131
  x: {
@@ -54273,14 +54333,14 @@ var HorizontalBarChartV2View = function HorizontalBarChartV2View(props) {
54273
54333
  overflowX: 'hidden'
54274
54334
  },
54275
54335
  children: function children(parent) {
54276
- var _props$attributes$lab;
54336
+ var _props$attributes$sta, _props$attributes$lab;
54277
54337
  if (chartRepresentation.bars.length === 0) return jsx(LoadingComponent, {});
54278
54338
  return jsx(HorizontalBarChart$3, {
54279
54339
  width: parent.width,
54280
54340
  height: parent.height,
54281
54341
  chart: adjustTicksForHorizontalChart(chartRepresentation, parent.width, parent.height, yKeyField),
54282
54342
  options: {
54283
- stacked: !!props.attributes.stacked,
54343
+ stacked: (_props$attributes$sta = props.attributes.stacked) != null ? _props$attributes$sta : false,
54284
54344
  removeStroke: false,
54285
54345
  showRoundedTotal: false,
54286
54346
  showLegend: props.attributes.legend,
@@ -64799,7 +64859,8 @@ var ChartSettingsSection = function ChartSettingsSection(_ref) {
64799
64859
  label: textOverride('stacked', 'Stacked'),
64800
64860
  value: true
64801
64861
  }];
64802
- if (attributes.type === 'barChart' || attributes.type === 'areaChart') {
64862
+ var chartTypes = ['areaChart', 'barChart', 'barChartV2', 'horizontalBarChartV2'];
64863
+ if (chartTypes.includes(attributes.type)) {
64803
64864
  options.push({
64804
64865
  label: textOverride('stacked_100prc', 'Stacked (100%)'),
64805
64866
  value: '100%'
@@ -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-0bf2cc62e2eca0a88e685afc885c2424ce22349c",
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",