@vizzly/dashboard 0.14.4-dev-f592adcabadc611d0e867520c138d5a939466968 → 0.14.4-dev-dcdf669a67550a23017aa4648c565ad57c836104

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.
@@ -1,11 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import { ChartTheme } from '../../../types';
3
- import { WaterfallChartOptions, WaterfallChartRepresentation } from '../../../../../shared-logic/src/WaterfallChart/types';
3
+ import { Step, WaterfallChartOptions, WaterfallChartRepresentation } from '../../../../../shared-logic/src/WaterfallChart/types';
4
4
  export declare type WaterfallChartProps = {
5
5
  width: number;
6
6
  height: number;
7
7
  chart: WaterfallChartRepresentation;
8
+ steps: Step[];
8
9
  options: WaterfallChartOptions;
9
10
  theme?: ChartTheme;
10
11
  };
11
- export declare const WaterfallChart: ({ height, width, options, chart, theme }: WaterfallChartProps) => JSX.Element | null;
12
+ export declare const WaterfallChart: ({ height, width, options, chart, steps, theme }: WaterfallChartProps) => JSX.Element | null;
@@ -48154,17 +48154,13 @@ var Legend$2 = function Legend(_ref) {
48154
48154
  color: 'green',
48155
48155
  yKey: 'increase',
48156
48156
  style: {
48157
- type: 'line',
48158
- strokeDasharray: null,
48159
- strokeWidth: 2
48157
+ type: 'bar'
48160
48158
  }
48161
48159
  }, {
48162
48160
  color: 'red',
48163
48161
  yKey: 'decrease',
48164
48162
  style: {
48165
- type: 'line',
48166
- strokeDasharray: null,
48167
- strokeWidth: 2
48163
+ type: 'bar'
48168
48164
  }
48169
48165
  }];
48170
48166
  var keys = {
@@ -48202,6 +48198,7 @@ var WaterfallChart$2 = function WaterfallChart(_ref) {
48202
48198
  width = _ref.width,
48203
48199
  options = _ref.options,
48204
48200
  chart = _ref.chart,
48201
+ steps = _ref.steps,
48205
48202
  theme = _ref.theme;
48206
48203
  //Waterfall TODO: fix chart for other x types
48207
48204
  if (chart.x.scale.dataType === 'date_time' || chart.x.scale.dataType === 'number') {
@@ -48217,10 +48214,10 @@ var WaterfallChart$2 = function WaterfallChart(_ref) {
48217
48214
  hideTooltip = _useTooltip.hideTooltip,
48218
48215
  showTooltip = _useTooltip.showTooltip;
48219
48216
  var chartCopy = _.cloneDeep(chart);
48220
- var data = chartCopy.data,
48221
- x = chartCopy.x,
48217
+ var x = chartCopy.x,
48222
48218
  y = chartCopy.y;
48223
- var showTotalBar = options.showTotalBar;
48219
+ var xKey = x.key;
48220
+ var yKey = y.key;
48224
48221
  var conditionalFormattingRules = [{
48225
48222
  yKey: y.key,
48226
48223
  operator: '>',
@@ -48232,44 +48229,8 @@ var WaterfallChart$2 = function WaterfallChart(_ref) {
48232
48229
  value: 0,
48233
48230
  color: 'red'
48234
48231
  }];
48235
- var xKey = x.key;
48236
- var yKey = y.key;
48237
- var cumulativeTotal = 0;
48238
- var steps = data.map(function (item) {
48239
- var xValue = item[xKey].value;
48240
- var yValue = Number(item[yKey].value);
48241
- var prevTotal = cumulativeTotal;
48242
- cumulativeTotal += yValue;
48243
- return {
48244
- x: xValue,
48245
- y: yValue,
48246
- start: prevTotal,
48247
- end: cumulativeTotal
48248
- };
48249
- });
48250
- if (showTotalBar) {
48251
- var _data$push;
48252
- steps.push({
48253
- x: "Total",
48254
- y: cumulativeTotal,
48255
- start: 0,
48256
- end: cumulativeTotal
48257
- });
48258
- data.push((_data$push = {}, _data$push[x.key] = {
48259
- value: "Total",
48260
- formattedValue: "Total"
48261
- }, _data$push[y.key] = {
48262
- value: cumulativeTotal,
48263
- formattedValue: null
48264
- }, _data$push));
48265
- x.ticks.push({
48266
- value: "Total",
48267
- formattedValue: "Total",
48268
- scaleValue: "Total"
48269
- });
48270
- }
48271
48232
  var formattedYAxisForBarChart = _extends({}, y, {
48272
- keys: [y.key]
48233
+ keys: [yKey]
48273
48234
  });
48274
48235
  var adjustedChartRepresentation = React.useMemo(function () {
48275
48236
  return adjustTicks$1(_extends({}, chartCopy), width);
@@ -48394,15 +48355,14 @@ var WaterfallChart$2 = function WaterfallChart(_ref) {
48394
48355
  if (xScaleDataType === 'string') return xValue;
48395
48356
  return;
48396
48357
  }, [xScaleKey, xScaleDataType]);
48358
+ if (width === 0 || height === 0 || xScale == null) return null;
48397
48359
  return jsxRuntime.jsxs(jsxRuntime.Fragment, {
48398
- children: [jsxRuntime.jsxs("svg", {
48360
+ children: [jsxRuntime.jsxs(ChartWrapper$1, {
48399
48361
  width: width,
48400
- height: height - (options.showLegend ? 40 : 0),
48362
+ height: height,
48363
+ showLegend: options.showLegend,
48401
48364
  onMouseMove: handleMouseMove,
48402
48365
  onMouseLeave: handleMouseLeave,
48403
- style: {
48404
- display: 'block'
48405
- },
48406
48366
  children: [jsxRuntime.jsxs(group.Group, {
48407
48367
  left: margin.left,
48408
48368
  top: margin.top,
@@ -48555,6 +48515,111 @@ function getNiceInterval$1(interval) {
48555
48515
  return niceFraction * Math.pow(10, exponent);
48556
48516
  }
48557
48517
 
48518
+ var getYTicks = function getYTicks(_ref) {
48519
+ var yMinValue = _ref.yMinValue,
48520
+ yMaxValue = _ref.yMaxValue,
48521
+ approxYAxisLabelCount = _ref.approxYAxisLabelCount,
48522
+ formattingFunctionY = _ref.formattingFunctionY;
48523
+ var yTicks = [];
48524
+ var yTickInterval = getNiceInterval$1((yMaxValue - yMinValue) / (approxYAxisLabelCount - 1));
48525
+ for (var i = 0; i < approxYAxisLabelCount; i++) {
48526
+ var value = (yMinValue + i) * yTickInterval;
48527
+ var formattedValue = formattingFunctionY(value);
48528
+ yTicks.push({
48529
+ value: value,
48530
+ formattedValue: formattedValue,
48531
+ scaleValue: value
48532
+ });
48533
+ }
48534
+ return yTicks;
48535
+ };
48536
+
48537
+ var getRepresentationData = function getRepresentationData(_ref) {
48538
+ var content = _ref.content,
48539
+ xKey = _ref.xKey,
48540
+ yKey = _ref.yKey,
48541
+ approxYAxisLabelCount = _ref.approxYAxisLabelCount,
48542
+ showTotalBar = _ref.showTotalBar,
48543
+ formattingFunctionY = _ref.formattingFunctionY;
48544
+ var data = [];
48545
+ var steps = [];
48546
+ var xTicks = [];
48547
+ var yValueSum = 0;
48548
+ var yMinValue = 0;
48549
+ var yMaxValue = 0;
48550
+ content.forEach(function (dataItem, index) {
48551
+ var _data$push;
48552
+ var xValueIndex = 0;
48553
+ var yValueIndex = 1;
48554
+ var xValue = dataItem[xValueIndex].value;
48555
+ var xFormattedValue = dataItem[xValueIndex].formattedValue;
48556
+ var yValue = Number(dataItem[yValueIndex].value);
48557
+ var yValueDiff = yValue;
48558
+ if (index > 0) {
48559
+ var prevYValue = Number(content[index - 1][yValueIndex].value);
48560
+ yValueDiff = yValue - prevYValue;
48561
+ }
48562
+ var prevYValueSum = yValueSum;
48563
+ yValueSum += yValueDiff;
48564
+ data.push((_data$push = {}, _data$push[xKey] = {
48565
+ value: xValue,
48566
+ formattedValue: xFormattedValue
48567
+ }, _data$push[yKey] = {
48568
+ value: yValueDiff,
48569
+ formattedValue: formattingFunctionY(yValueDiff)
48570
+ }, _data$push));
48571
+ xTicks.push({
48572
+ value: xValue,
48573
+ formattedValue: xFormattedValue,
48574
+ scaleValue: xValue
48575
+ });
48576
+ steps.push({
48577
+ x: xValue,
48578
+ y: yValue,
48579
+ start: prevYValueSum,
48580
+ end: yValueSum
48581
+ });
48582
+ yMinValue = Math.floor(Math.min(yMinValue, yValue));
48583
+ yMaxValue = Math.ceil(Math.max(yMaxValue, yValue));
48584
+ });
48585
+ if (showTotalBar) {
48586
+ var _data$push2;
48587
+ var totalLabel = 'Total';
48588
+ steps.push({
48589
+ x: totalLabel,
48590
+ y: yValueSum,
48591
+ start: 0,
48592
+ end: yValueSum
48593
+ });
48594
+ data.push((_data$push2 = {}, _data$push2[xKey] = {
48595
+ value: totalLabel,
48596
+ formattedValue: totalLabel
48597
+ }, _data$push2[yKey] = {
48598
+ value: yValueSum,
48599
+ formattedValue: formattingFunctionY(yValueSum)
48600
+ }, _data$push2));
48601
+ xTicks.push({
48602
+ value: totalLabel,
48603
+ formattedValue: totalLabel,
48604
+ scaleValue: totalLabel
48605
+ });
48606
+ }
48607
+ var yTicks = getYTicks({
48608
+ yMinValue: yMinValue,
48609
+ yMaxValue: yMaxValue,
48610
+ approxYAxisLabelCount: approxYAxisLabelCount,
48611
+ formattingFunctionY: formattingFunctionY
48612
+ });
48613
+ return {
48614
+ data: data,
48615
+ steps: steps,
48616
+ xTicks: xTicks,
48617
+ yTicks: yTicks,
48618
+ yMinValue: yMinValue,
48619
+ yMaxValue: yMaxValue
48620
+ };
48621
+ };
48622
+
48558
48623
  var buildWaterfallChartRepresentation = function buildWaterfallChartRepresentation(_ref) {
48559
48624
  var _formattedResult$fiel, _formattedResult$fiel2, _axisTitles$x, _axisTitles$y;
48560
48625
  var approxYAxisLabelCount = _ref.approxYAxisLabelCount,
@@ -48565,6 +48630,7 @@ var buildWaterfallChartRepresentation = function buildWaterfallChartRepresentati
48565
48630
  numberFormatOptions = _ref.numberFormatOptions,
48566
48631
  pivotConfig = _ref.pivotConfig,
48567
48632
  result = _ref.result,
48633
+ showTotalBar = _ref.showTotalBar,
48568
48634
  _valueAlias = _ref.valueAlias,
48569
48635
  xAxisFormat = _ref.xAxisFormat,
48570
48636
  xAxisPrefix = _ref.xAxisPrefix,
@@ -48572,34 +48638,12 @@ var buildWaterfallChartRepresentation = function buildWaterfallChartRepresentati
48572
48638
  yAxisFormat = _ref.yAxisFormat,
48573
48639
  yAxisPrefix = _ref.yAxisPrefix,
48574
48640
  yAxisPostfix = _ref.yAxisPostfix;
48575
- var allPrefixes = {};
48576
- var allPostfixes = {};
48577
- var nullValues = {};
48578
- var activeNumberFormats = {};
48579
48641
  var activeDateTimeFormats = {};
48580
- result.fields.forEach(function (field) {
48581
- if (pivotConfig.x.includes(field.id)) {
48582
- allPostfixes[field.id] = xAxisPostfix;
48583
- allPrefixes[field.id] = xAxisPrefix;
48584
- if (xAxisFormat) {
48585
- if (field.outputDataType === 'number' && numberFormatOptions[xAxisFormat]) {
48586
- activeNumberFormats[field.id] = xAxisFormat;
48587
- } else if (dateTimeFormatOptions[xAxisFormat]) {
48588
- activeDateTimeFormats[field.id] = xAxisFormat;
48589
- }
48590
- }
48591
- } else if (!pivotConfig.y.includes(field.id)) {
48592
- allPostfixes[field.id] = yAxisPostfix;
48593
- allPrefixes[field.id] = yAxisPrefix;
48594
- yAxisFormat = yAxisFormat || '_vizzly_compact';
48595
- if (numberFormatOptions[yAxisFormat]) {
48596
- activeNumberFormats[field.id] = yAxisFormat;
48597
- }
48598
- }
48599
-
48600
- // Set the null value aliases
48601
- nullValues[field.id] = nullValue;
48602
- });
48642
+ var _buildFieldFormatMaps = buildFieldFormatMaps(result, pivotConfig, xAxisPrefix, xAxisPostfix, xAxisFormat, yAxisPrefix, yAxisPostfix, yAxisFormat, nullValue, numberFormatOptions),
48643
+ allPrefixes = _buildFieldFormatMaps.allPrefixes,
48644
+ allPostfixes = _buildFieldFormatMaps.allPostfixes,
48645
+ nullValues = _buildFieldFormatMaps.nullValues,
48646
+ activeNumberFormats = _buildFieldFormatMaps.activeNumberFormats;
48603
48647
  var params = {
48604
48648
  defaultFormats: defaultFormats,
48605
48649
  dateTimeFormatOptions: dateTimeFormatOptions,
@@ -48623,6 +48667,18 @@ var buildWaterfallChartRepresentation = function buildWaterfallChartRepresentati
48623
48667
  activeDateTimeFormats: activeDateTimeFormats
48624
48668
  };
48625
48669
  var formattedResult = formatResult(result, params);
48670
+ var formattingFunctionY = function formattingFunctionY(value) {
48671
+ // Use any y axis field as they are all formatted in the same way (for now...);
48672
+ var nonPivotField = formattedResult.fields.find(function (resultField) {
48673
+ return ![].concat(pivotConfig.x, pivotConfig.y).includes(resultField.id);
48674
+ });
48675
+ if (!nonPivotField) return '';
48676
+ return formattedResult.formatterFunc(value, {
48677
+ fieldId: nonPivotField.fieldId,
48678
+ "function": nonPivotField["function"],
48679
+ outputDataType: nonPivotField.outputDataType
48680
+ }).formattedValue;
48681
+ };
48626
48682
  var keys = formattedResult.fields.map(function (field) {
48627
48683
  var _ref2;
48628
48684
  var key = field.fieldId;
@@ -48637,58 +48693,21 @@ var buildWaterfallChartRepresentation = function buildWaterfallChartRepresentati
48637
48693
  var xKey = (_formattedResult$fiel = formattedResult.fields[0]) == null ? void 0 : _formattedResult$fiel.fieldId;
48638
48694
  var yKey = (_formattedResult$fiel2 = formattedResult.fields[1]) == null ? void 0 : _formattedResult$fiel2.fieldId;
48639
48695
  var content = formattedResult.content;
48640
- var data = [];
48641
- var xTicks = [];
48642
- var yTicks = [];
48643
- var yMinValue = 0;
48644
- var yMaxValue = 0;
48645
- content.forEach(function (dataItem, index) {
48646
- var _data$push;
48647
- var xValueIndex = 0;
48648
- var yValueIndex = 1;
48649
- var xValue = dataItem[xValueIndex].value;
48650
- var xFormattedValue = dataItem[xValueIndex].formattedValue;
48651
- var yValue = dataItem[yValueIndex].value;
48652
- var yFormattedValue = dataItem[yValueIndex].formattedValue;
48653
- var yValueDiff = index === 0 ? yValue : yValue - content[index - 1][yValueIndex].value;
48654
- data.push((_data$push = {}, _data$push[xKey] = {
48655
- value: xValue,
48656
- formattedValue: xFormattedValue
48657
- }, _data$push[yKey] = {
48658
- value: yValueDiff,
48659
- formattedValue: yFormattedValue
48660
- }, _data$push));
48661
- xTicks.push({
48662
- value: xValue,
48663
- formattedValue: xFormattedValue,
48664
- scaleValue: xValue
48665
- });
48666
- yMinValue = Math.floor(Math.min(yMinValue, yValue));
48667
- yMaxValue = Math.ceil(Math.max(yMaxValue, yValue));
48668
- });
48669
- var formattingFunctionY = function formattingFunctionY(value) {
48670
- // Use any y axis field as they are all formatted in the same way (for now...);
48671
- var nonPivotField = formattedResult.fields.find(function (resultField) {
48672
- return ![].concat(pivotConfig.x, pivotConfig.y).includes(resultField.id);
48673
- });
48674
- if (!nonPivotField) return '';
48675
- return formattedResult.formatterFunc(value, {
48676
- fieldId: nonPivotField.fieldId,
48677
- "function": nonPivotField["function"],
48678
- outputDataType: nonPivotField.outputDataType
48679
- }).formattedValue;
48680
- };
48681
- var yTickInterval = getNiceInterval$1((yMaxValue - yMinValue) / (approxYAxisLabelCount - 1));
48682
- for (var i = 0; i < approxYAxisLabelCount; i++) {
48683
- var value = (yMinValue + i) * yTickInterval;
48684
- var formattedValue = formattingFunctionY(value);
48685
- yTicks.push({
48686
- value: value,
48687
- formattedValue: formattedValue,
48688
- scaleValue: value
48689
- });
48690
- }
48691
- var chart = {
48696
+ var _getRepresentationDat = getRepresentationData({
48697
+ content: content,
48698
+ xKey: xKey,
48699
+ yKey: yKey,
48700
+ approxYAxisLabelCount: approxYAxisLabelCount,
48701
+ showTotalBar: showTotalBar,
48702
+ formattingFunctionY: formattingFunctionY
48703
+ }),
48704
+ data = _getRepresentationDat.data,
48705
+ steps = _getRepresentationDat.steps,
48706
+ xTicks = _getRepresentationDat.xTicks,
48707
+ yTicks = _getRepresentationDat.yTicks,
48708
+ yMinValue = _getRepresentationDat.yMinValue,
48709
+ yMaxValue = _getRepresentationDat.yMaxValue;
48710
+ var chartRepresentation = {
48692
48711
  keys: _extends({}, keys[0], keys[1]),
48693
48712
  x: {
48694
48713
  title: (_axisTitles$x = axisTitles == null ? void 0 : axisTitles.x) != null ? _axisTitles$x : null,
@@ -48720,7 +48739,10 @@ var buildWaterfallChartRepresentation = function buildWaterfallChartRepresentati
48720
48739
  },
48721
48740
  data: data
48722
48741
  };
48723
- return chart;
48742
+ return {
48743
+ waterfallChartRepresentation: chartRepresentation,
48744
+ waterfallChartSteps: steps
48745
+ };
48724
48746
  };
48725
48747
 
48726
48748
  var WaterfallChartView = function WaterfallChartView(props) {
@@ -48790,12 +48812,9 @@ var WaterfallChartView = function WaterfallChartView(props) {
48790
48812
  if (isLoading(result)) return jsxRuntime.jsx(LoadingComponent, {});
48791
48813
  if (hasFailed(result)) return jsxRuntime.jsx(FailedToLoadDataNotice, {});
48792
48814
  if (isEmpty(result)) return jsxRuntime.jsx(NoResultContentToShowNotice, _extends({}, headerProps));
48793
- var showHeadline = React.useMemo(function () {
48794
- return headlineAvailable(order, headline, timeDimension);
48795
- }, [order, headline, timeDimension]);
48815
+ var showHeadline = headlineAvailable(order, headline, timeDimension);
48796
48816
  var pivotConfig = init$c(props);
48797
- var chartRepresentation = React.useMemo(function () {
48798
- return buildWaterfallChartRepresentation({
48817
+ var _buildWaterfallChartR = buildWaterfallChartRepresentation({
48799
48818
  approxYAxisLabelCount: approxYAxisLabelCount === 'auto' ? 10 : approxYAxisLabelCount,
48800
48819
  axisTitles: axisTitles,
48801
48820
  dateTimeFormatOptions: dateTimeFormatOptions,
@@ -48804,6 +48823,7 @@ var WaterfallChartView = function WaterfallChartView(props) {
48804
48823
  numberFormatOptions: numberFormatOptions,
48805
48824
  pivotConfig: pivotConfig,
48806
48825
  result: result,
48826
+ showTotalBar: true,
48807
48827
  valueAlias: valueAlias,
48808
48828
  xAxisFormat: xAxisFormat,
48809
48829
  xAxisPrefix: xAxisPrefix,
@@ -48811,8 +48831,9 @@ var WaterfallChartView = function WaterfallChartView(props) {
48811
48831
  yAxisFormat: yAxisFormat,
48812
48832
  yAxisPrefix: yAxisPrefix,
48813
48833
  yAxisPostfix: yAxisPostfix
48814
- });
48815
- }, [approxYAxisLabelCount, axisTitles, dateTimeFormatOptions, defaultFormats, dataSetId, dimension, numberFormatOptions, pivotConfig, result, valueAlias, xAxisFormat, xAxisPrefix, xAxisPostfix, yAxisFormat, yAxisPrefix, yAxisPostfix]);
48834
+ }),
48835
+ chartRepresentation = _buildWaterfallChartR.waterfallChartRepresentation,
48836
+ steps = _buildWaterfallChartR.waterfallChartSteps;
48816
48837
  return jsxRuntime.jsx(React.Suspense, {
48817
48838
  fallback: jsxRuntime.jsx(LoadingComponent, {}),
48818
48839
  children: jsxRuntime.jsxs(ViewWrapper, {
@@ -48820,8 +48841,12 @@ var WaterfallChartView = function WaterfallChartView(props) {
48820
48841
  queriesAreChanging: queriesAreChanging,
48821
48842
  children: [jsxRuntime.jsx(ViewHeader, _extends({}, headerProps, {
48822
48843
  paddingBottom: showHeadline ? '0.5rem' : undefined
48823
- })), showHeadline && jsxRuntime.jsx(HeadlineStats, _extends({}, props)), jsxRuntime.jsx(ChartWrapper, {
48824
- disabledFeatures: library != null ? library : false,
48844
+ })), showHeadline && jsxRuntime.jsx(HeadlineStats, _extends({}, props)), jsxRuntime.jsx("div", {
48845
+ className: styles({
48846
+ flex: '1',
48847
+ position: 'relative'
48848
+ }),
48849
+ "aria-disabled": props.library,
48825
48850
  children: jsxRuntime.jsx(responsive.ParentSize, {
48826
48851
  style: {
48827
48852
  position: 'absolute',
@@ -48830,13 +48855,12 @@ var WaterfallChartView = function WaterfallChartView(props) {
48830
48855
  overflowX: 'hidden'
48831
48856
  },
48832
48857
  children: function children(parent) {
48858
+ if (chartRepresentation.data.length === 0) return jsxRuntime.jsx(LoadingComponent, {});
48833
48859
  return jsxRuntime.jsx(WaterfallChart$2, {
48834
48860
  width: parent.width,
48835
48861
  height: parent.height,
48836
48862
  options: {
48837
48863
  showLegend: showLegend(legend, (theme == null ? void 0 : theme.detail) === 'verbose'),
48838
- showTotalBar: true,
48839
- // Waterfall TODO: check if this should be configurable via dashboard
48840
48864
  showTooltipRoundedTotal: true,
48841
48865
  removeStroke: false,
48842
48866
  axis: {
@@ -48845,7 +48869,8 @@ var WaterfallChartView = function WaterfallChartView(props) {
48845
48869
  }
48846
48870
  },
48847
48871
  theme: theme == null ? void 0 : theme.charts,
48848
- chart: chartRepresentation
48872
+ chart: chartRepresentation,
48873
+ steps: steps
48849
48874
  });
48850
48875
  }
48851
48876
  })