@redsift/charts 9.3.3 → 9.4.0

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.
Files changed (4) hide show
  1. package/index.d.ts +159 -21
  2. package/index.js +635 -105
  3. package/index.js.map +1 -1
  4. package/package.json +2 -2
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { brush, select, scaleOrdinal, zoom, interpolateRound, interpolate, scaleLinear, sum, scalePoint, arc, pie, min, extent, descending, scaleSqrt, max } from 'd3';
1
+ import { brush, select, scaleOrdinal, zoom, interpolateRound, interpolate, scaleLinear, sum, scalePoint, extent, scaleTime, line, arc, pie, min, descending, scaleSqrt, max } from 'd3';
2
2
  import { RedsiftColorPresentationBlueDefault, RedsiftColorPresentationGreyDark, RedsiftColorPresentationGreenDefault, RedsiftColorPresentationPinkDefault, RedsiftColorPresentationAquaDefault, RedsiftColorPresentationBrownDefault, RedsiftColorPresentationRedDefault, RedsiftColorPresentationYellowDefault, RedsiftColorPresentationPurpleDefault, RedsiftColorPresentationOrangeDefault, RedsiftColorPresentationGreyDefault, RedsiftColorPresentationGreenDark, RedsiftColorPresentationPinkDark, RedsiftColorPresentationAquaDark, RedsiftColorPresentationBrownDark, RedsiftColorPresentationRedDark, RedsiftColorPresentationYellowDark, RedsiftColorPresentationPurpleDark, RedsiftColorPresentationOrangeDark, RedsiftColorPresentationBlueDark, RedsiftColorPresentationGreenDarker, RedsiftColorPresentationPinkDarker, RedsiftColorPresentationAquaDarker, RedsiftColorPresentationBrownDarker, RedsiftColorPresentationRedDarker, RedsiftColorPresentationYellowDarker, RedsiftColorPresentationPurpleDarker, RedsiftColorPresentationOrangeDarker, RedsiftColorPresentationBlueDarker, RedsiftColorPresentationGreyDarker, RedsiftColorPresentationGreenDarkerer, RedsiftColorPresentationPinkDarkerer, RedsiftColorPresentationAquaDarkerer, RedsiftColorPresentationBrownDarkerer, RedsiftColorPresentationRedDarkerer, RedsiftColorPresentationYellowDarkerer, RedsiftColorPresentationPurpleDarkerer, RedsiftColorPresentationOrangeDarkerer, RedsiftColorPresentationBlueDarkerer, RedsiftColorPresentationGreyDarkerer, RedsiftColorPresentationGreenLight, RedsiftColorPresentationPinkLight, RedsiftColorPresentationAquaLight, RedsiftColorPresentationBrownLight, RedsiftColorPresentationRedLight, RedsiftColorPresentationYellowLight, RedsiftColorPresentationPurpleLight, RedsiftColorPresentationOrangeLight, RedsiftColorPresentationBlueLight, RedsiftColorPresentationGreyLight, RedsiftColorPresentationGreenLighter, RedsiftColorPresentationPinkLighter, RedsiftColorPresentationAquaLighter, RedsiftColorPresentationBrownLighter, RedsiftColorPresentationRedLighter, RedsiftColorPresentationYellowLighter, RedsiftColorPresentationPurpleLighter, RedsiftColorPresentationOrangeLighter, RedsiftColorPresentationBlueLighter, RedsiftColorPresentationGreyLighter, RedsiftColorPresentationGreenLighterer, RedsiftColorPresentationPinkLighterer, RedsiftColorPresentationAquaLighterer, RedsiftColorPresentationBrownLighterer, RedsiftColorPresentationRedLighterer, RedsiftColorPresentationYellowLighterer, RedsiftColorPresentationPurpleLighterer, RedsiftColorPresentationOrangeLighterer, RedsiftColorPresentationBlueLighterer, RedsiftColorPresentationGreyLighterer, useId, Text, Number as Number$1, baseStyling, baseContainer, focusRing, Flexbox, warnIfNoAccessibleLabelFound, Heading, Button } from '@redsift/design-system';
3
3
  import * as React from 'react';
4
4
  import React__default, { useRef, useEffect, useMemo, useState, useLayoutEffect, forwardRef, useCallback, useContext } from 'react';
@@ -77,8 +77,8 @@ const getColorScale = (theme, domain, isEmpty) => {
77
77
  } else if (typeof theme === 'string') {
78
78
  d3colors = scaleOrdinal().domain(domain).range(scheme[theme]).unknown(monochrome);
79
79
  } else if (typeof theme === 'object') {
80
- if (Object.keys(theme).includes('success') && Object.keys(theme).includes('danger') && Object.keys(theme).includes('warning')) {
81
- d3colors = scaleOrdinal().domain([theme.success, theme.warning, theme.danger, ...(theme.neutral ? [theme.neutral] : [])]).range([successDangerScheme.success, successDangerScheme.warning, successDangerScheme.danger, ...(theme.neutral ? [successDangerScheme.neutral] : [])]).unknown(monochrome);
80
+ if (Object.keys(theme).includes('success') || Object.keys(theme).includes('danger') || Object.keys(theme).includes('warning')) {
81
+ d3colors = scaleOrdinal().domain([...(theme.success ? [theme.success] : []), ...(theme.warning ? [theme.warning] : []), ...(theme.danger ? [theme.danger] : []), ...(theme.neutral ? [theme.neutral] : [])]).range([...(theme.success ? [successDangerScheme.success] : []), ...(theme.warning ? [successDangerScheme.warning] : []), ...(theme.danger ? [successDangerScheme.danger] : []), ...(theme.neutral ? [successDangerScheme.neutral] : [])]).unknown(monochrome);
82
82
  } else {
83
83
  d3colors = scaleOrdinal().domain(Object.keys(theme)).range(Object.values(theme)).unknown(monochrome);
84
84
  }
@@ -92,7 +92,7 @@ const useColor = _ref => {
92
92
  theme,
93
93
  category
94
94
  } = _ref;
95
- const colorScale = useMemo(() => getColorScale(theme, data.map(d => d[category])), [theme]);
95
+ const colorScale = useMemo(() => getColorScale(theme, data.map(d => typeof category === 'string' ? d[category] : category(d))), [theme]);
96
96
  return colorScale;
97
97
  };
98
98
 
@@ -274,13 +274,15 @@ const TooltipVariant = {
274
274
  none: 'none',
275
275
  label: 'label',
276
276
  value: 'value',
277
- percent: 'percent'
277
+ percent: 'percent',
278
+ custom: 'custom'
278
279
  };
279
280
  /** LEGEND */
280
281
  const LabelVariant = {
281
282
  label: 'label',
282
283
  value: 'value',
283
- percent: 'percent'
284
+ percent: 'percent',
285
+ custom: 'custom'
284
286
  };
285
287
 
286
288
  const ChartSize = {
@@ -315,7 +317,7 @@ var k=/^--/;function I(t,e){return e==null||typeof e=="boolean"||e===""?"":typeo
315
317
  */
316
318
  const StyledDataPoint = styled(it.g)``;
317
319
 
318
- const _excluded$k = ["children", "className", "data", "id", "index", "isSelected", "labelDecorator", "onClick", "role", "tooltipVariant"];
320
+ const _excluded$p = ["children", "className", "data", "id", "index", "isSelected", "labelDecorator", "onClick", "role", "tooltipVariant"];
319
321
  const DataPoint = /*#__PURE__*/forwardRef((props, ref) => {
320
322
  const {
321
323
  children,
@@ -329,7 +331,7 @@ const DataPoint = /*#__PURE__*/forwardRef((props, ref) => {
329
331
  role,
330
332
  tooltipVariant
331
333
  } = props,
332
- forwardedProps = _objectWithoutProperties(props, _excluded$k);
334
+ forwardedProps = _objectWithoutProperties(props, _excluded$p);
333
335
  const [_id] = useId();
334
336
  const id = propsId !== null && propsId !== void 0 ? propsId : _id;
335
337
  const text = labelDecorator ? labelDecorator(data, {
@@ -439,10 +441,10 @@ const config = (() => ({
439
441
  immediate: false
440
442
  }))();
441
443
 
442
- const _excluded$j = ["className", "createArc", "hasStroke", "previousData"];
443
- const COMPONENT_NAME$a = 'Arc';
444
- const CLASSNAME$a = 'redsift-arc';
445
- const DEFAULT_PROPS$a = {
444
+ const _excluded$o = ["className", "createArc", "hasStroke", "previousData"];
445
+ const COMPONENT_NAME$c = 'Arc';
446
+ const CLASSNAME$c = 'redsift-arc';
447
+ const DEFAULT_PROPS$c = {
446
448
  color: monochrome,
447
449
  index: 0,
448
450
  previousData: {
@@ -471,7 +473,7 @@ const Arc = /*#__PURE__*/forwardRef((props, ref) => {
471
473
  hasStroke,
472
474
  previousData
473
475
  } = props,
474
- forwardedProps = _objectWithoutProperties(props, _excluded$j);
476
+ forwardedProps = _objectWithoutProperties(props, _excluded$o);
475
477
  const interpolator = interpolate(previousData, data);
476
478
  const isSelectable = role === 'option';
477
479
  const isDeselected = isSelectable && propsIsSelected === false;
@@ -495,19 +497,19 @@ const Arc = /*#__PURE__*/forwardRef((props, ref) => {
495
497
  fill: isDeselected ? 'var(--redsift-color-neutral-lightgrey)' : color
496
498
  }));
497
499
  });
498
- Arc.className = CLASSNAME$a;
499
- Arc.defaultProps = DEFAULT_PROPS$a;
500
- Arc.displayName = COMPONENT_NAME$a;
500
+ Arc.className = CLASSNAME$c;
501
+ Arc.defaultProps = DEFAULT_PROPS$c;
502
+ Arc.displayName = COMPONENT_NAME$c;
501
503
 
502
504
  /**
503
505
  * Component style.
504
506
  */
505
507
  const StyledArcs = styled.g``;
506
508
 
507
- const _excluded$i = ["arcs", "className", "color", "hasLabels", "hasStroke", "id", "labelDecorator", "onClick", "role", "sliceProps", "tooltipVariant"];
508
- const COMPONENT_NAME$9 = 'Arcs';
509
- const CLASSNAME$9 = 'redsift-arcs';
510
- const DEFAULT_PROPS$9 = {};
509
+ const _excluded$n = ["arcs", "className", "color", "hasLabels", "hasStroke", "id", "labelDecorator", "onClick", "role", "sliceProps", "tooltipVariant"];
510
+ const COMPONENT_NAME$b = 'Arcs';
511
+ const CLASSNAME$b = 'redsift-arcs';
512
+ const DEFAULT_PROPS$b = {};
511
513
  const Arcs = /*#__PURE__*/forwardRef((props, ref) => {
512
514
  const {
513
515
  arcs,
@@ -522,7 +524,7 @@ const Arcs = /*#__PURE__*/forwardRef((props, ref) => {
522
524
  sliceProps,
523
525
  tooltipVariant
524
526
  } = props,
525
- forwardedProps = _objectWithoutProperties(props, _excluded$i);
527
+ forwardedProps = _objectWithoutProperties(props, _excluded$n);
526
528
  const [_id] = useId();
527
529
  const id = propsId !== null && propsId !== void 0 ? propsId : _id;
528
530
  const animatedProps = J(_objectSpread2(_objectSpread2({}, config), {}, {
@@ -577,9 +579,9 @@ const Arcs = /*#__PURE__*/forwardRef((props, ref) => {
577
579
  }, arcLabelDecorator ? arcLabelDecorator(arc.data) : arc.data.data.key);
578
580
  })) : null);
579
581
  });
580
- Arcs.className = CLASSNAME$9;
581
- Arcs.defaultProps = DEFAULT_PROPS$9;
582
- Arcs.displayName = COMPONENT_NAME$9;
582
+ Arcs.className = CLASSNAME$b;
583
+ Arcs.defaultProps = DEFAULT_PROPS$b;
584
+ Arcs.displayName = COMPONENT_NAME$b;
583
585
 
584
586
  /**
585
587
  * Component variant.
@@ -638,6 +640,9 @@ const getScaleTicks = (scale, spec) => {
638
640
  if (typeof spec === 'number' && isFinite(spec) && Math.floor(spec) === spec) {
639
641
  return scale.ticks(spec);
640
642
  }
643
+ if (typeof spec === 'function') {
644
+ return scale.ticks(spec);
645
+ }
641
646
  }
642
647
 
643
648
  // non linear scale default
@@ -730,10 +735,10 @@ const computeTicks = _ref => {
730
735
  };
731
736
  };
732
737
 
733
- const _excluded$h = ["className", "length", "legend", "legendOffset", "legendPosition", "position", "scale", "tickPadding", "tickRotation", "tickSize", "tickValues", "variant", "x", "y"];
734
- const COMPONENT_NAME$8 = 'Axis';
735
- const CLASSNAME$8 = 'redsift-axis';
736
- const DEFAULT_PROPS$8 = {
738
+ const _excluded$m = ["className", "length", "legend", "legendOffset", "legendPosition", "position", "scale", "tickPadding", "tickRotation", "tickSize", "tickValues", "tickFormat", "variant", "x", "y"];
739
+ const COMPONENT_NAME$a = 'Axis';
740
+ const CLASSNAME$a = 'redsift-axis';
741
+ const DEFAULT_PROPS$a = {
737
742
  position: AxisPosition.bottom,
738
743
  legendOffset: -32,
739
744
  legendPosition: 'end',
@@ -758,11 +763,12 @@ const Axis = /*#__PURE__*/forwardRef((props, ref) => {
758
763
  tickRotation,
759
764
  tickSize,
760
765
  tickValues,
766
+ tickFormat,
761
767
  variant,
762
768
  x,
763
769
  y
764
770
  } = props,
765
- forwardedProps = _objectWithoutProperties(props, _excluded$h);
771
+ forwardedProps = _objectWithoutProperties(props, _excluded$m);
766
772
  const axis = getAxisType(position);
767
773
  const axisRef = ref || useRef();
768
774
  const animatedProps = J(_objectSpread2(_objectSpread2({}, config), {}, {
@@ -878,7 +884,7 @@ const Axis = /*#__PURE__*/forwardRef((props, ref) => {
878
884
  dominantBaseline: textBaseline,
879
885
  textAnchor: textAlign,
880
886
  transform: transitionProps.textTransform
881
- }, `${tick.value}`) : null);
887
+ }, `${tickFormat ? tickFormat(tick.value) : tick.value}`) : null);
882
888
  }) : null, variant === AxisVariant.default || variant === AxisVariant.line || variant === AxisVariant.lineTick ? /*#__PURE__*/React__default.createElement(it.line, {
883
889
  className: `${Axis.className}__line`,
884
890
  x1: 0,
@@ -887,9 +893,9 @@ const Axis = /*#__PURE__*/forwardRef((props, ref) => {
887
893
  y2: config.immediate ? axis === 'x' ? 0 : length : animatedProps.lineY2
888
894
  }) : null, legendNode);
889
895
  });
890
- Axis.className = CLASSNAME$8;
891
- Axis.defaultProps = DEFAULT_PROPS$8;
892
- Axis.displayName = COMPONENT_NAME$8;
896
+ Axis.className = CLASSNAME$a;
897
+ Axis.defaultProps = DEFAULT_PROPS$a;
898
+ Axis.displayName = COMPONENT_NAME$a;
893
899
 
894
900
  /**
895
901
  * Component variant.
@@ -956,10 +962,10 @@ const StyledBar = styled(DataPoint)`
956
962
  }}}
957
963
  `;
958
964
 
959
- const _excluded$g = ["className", "gap", "height", "maxHeight", "orientation", "previousData", "scale", "width"];
960
- const COMPONENT_NAME$7 = 'Bar';
961
- const CLASSNAME$7 = 'redsift-bar';
962
- const DEFAULT_PROPS$7 = {
965
+ const _excluded$l = ["className", "gap", "height", "maxHeight", "orientation", "previousData", "scale", "width"];
966
+ const COMPONENT_NAME$9 = 'Bar';
967
+ const CLASSNAME$9 = 'redsift-bar';
968
+ const DEFAULT_PROPS$9 = {
963
969
  color: monochrome,
964
970
  index: 0,
965
971
  gap: 5,
@@ -995,7 +1001,7 @@ const Bar = /*#__PURE__*/forwardRef((props, ref) => {
995
1001
  scale,
996
1002
  width
997
1003
  } = props,
998
- forwardedProps = _objectWithoutProperties(props, _excluded$g);
1004
+ forwardedProps = _objectWithoutProperties(props, _excluded$l);
999
1005
  const interpolator = interpolate(((_data = previousData.data) === null || _data === void 0 ? void 0 : _data.value) || 0, data.data.value);
1000
1006
  const text = labelDecorator ? labelDecorator(data, {
1001
1007
  index,
@@ -1035,9 +1041,9 @@ const Bar = /*#__PURE__*/forwardRef((props, ref) => {
1035
1041
  "aria-hidden": true
1036
1042
  }, text) : null);
1037
1043
  });
1038
- Bar.className = CLASSNAME$7;
1039
- Bar.defaultProps = DEFAULT_PROPS$7;
1040
- Bar.displayName = COMPONENT_NAME$7;
1044
+ Bar.className = CLASSNAME$9;
1045
+ Bar.defaultProps = DEFAULT_PROPS$9;
1046
+ Bar.displayName = COMPONENT_NAME$9;
1041
1047
 
1042
1048
  var reset$1 = "Reset";
1043
1049
  var enUS = {
@@ -1089,10 +1095,10 @@ const StyledChartContainerCaption = styled.p`
1089
1095
  margin: 8px;
1090
1096
  `;
1091
1097
 
1092
- const _excluded$f = ["aria-label", "aria-labelledby", "description", "chartProps", "chartRef", "children", "className", "id", "title", "onReset"];
1093
- const COMPONENT_NAME$6 = 'ChartContainer';
1094
- const CLASSNAME$6 = 'redsift-chart-container';
1095
- const DEFAULT_PROPS$6 = {};
1098
+ const _excluded$k = ["aria-label", "aria-labelledby", "description", "chartProps", "chartRef", "children", "className", "id", "title", "onReset"];
1099
+ const COMPONENT_NAME$8 = 'ChartContainer';
1100
+ const CLASSNAME$8 = 'redsift-chart-container';
1101
+ const DEFAULT_PROPS$8 = {};
1096
1102
  const ChartContainer = /*#__PURE__*/forwardRef((props, ref) => {
1097
1103
  const {
1098
1104
  'aria-label': propsAriaLabel,
@@ -1106,7 +1112,7 @@ const ChartContainer = /*#__PURE__*/forwardRef((props, ref) => {
1106
1112
  title,
1107
1113
  onReset
1108
1114
  } = props,
1109
- forwardedProps = _objectWithoutProperties(props, _excluded$f);
1115
+ forwardedProps = _objectWithoutProperties(props, _excluded$k);
1110
1116
  const [_id] = useId();
1111
1117
  const id = propsId !== null && propsId !== void 0 ? propsId : _id;
1112
1118
  warnIfNoAccessibleLabelFound(props, [title]);
@@ -1140,9 +1146,9 @@ const ChartContainer = /*#__PURE__*/forwardRef((props, ref) => {
1140
1146
  className: `${ChartContainer.className}__description`
1141
1147
  }, description) : null));
1142
1148
  });
1143
- ChartContainer.className = CLASSNAME$6;
1144
- ChartContainer.defaultProps = DEFAULT_PROPS$6;
1145
- ChartContainer.displayName = COMPONENT_NAME$6;
1149
+ ChartContainer.className = CLASSNAME$8;
1150
+ ChartContainer.defaultProps = DEFAULT_PROPS$8;
1151
+ ChartContainer.displayName = COMPONENT_NAME$8;
1146
1152
 
1147
1153
  /**
1148
1154
  * Component style.
@@ -1187,7 +1193,7 @@ const StyledBarChartEmptyText = styled.div`
1187
1193
  }
1188
1194
  `;
1189
1195
 
1190
- const sizeToDimension$2 = size => {
1196
+ const sizeToDimension$3 = size => {
1191
1197
  if (typeof size !== 'string') {
1192
1198
  return size;
1193
1199
  }
@@ -1214,7 +1220,7 @@ const sizeToDimension$2 = size => {
1214
1220
  }
1215
1221
  };
1216
1222
 
1217
- const _excluded$e = ["className", "emptyComponent", "size", "localeText"];
1223
+ const _excluded$j = ["className", "emptyComponent", "size", "localeText"];
1218
1224
  const EmptyBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1219
1225
  const {
1220
1226
  className,
@@ -1222,8 +1228,8 @@ const EmptyBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1222
1228
  size,
1223
1229
  localeText
1224
1230
  } = props,
1225
- forwardedProps = _objectWithoutProperties(props, _excluded$e);
1226
- const chartDimensions = sizeToDimension$2(size);
1231
+ forwardedProps = _objectWithoutProperties(props, _excluded$j);
1232
+ const chartDimensions = sizeToDimension$3(size);
1227
1233
  const width = chartDimensions.width;
1228
1234
  const height = chartDimensions.height;
1229
1235
  const margins = {
@@ -1259,19 +1265,19 @@ const EmptyBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1259
1265
  })))));
1260
1266
  });
1261
1267
 
1262
- const _excluded$d = ["className"];
1268
+ const _excluded$i = ["className"];
1263
1269
  const LoadingBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1264
1270
  const {
1265
1271
  className
1266
1272
  } = props,
1267
- forwardedProps = _objectWithoutProperties(props, _excluded$d);
1273
+ forwardedProps = _objectWithoutProperties(props, _excluded$i);
1268
1274
  return /*#__PURE__*/React__default.createElement(StyledBarChart, _extends({}, forwardedProps, {
1269
1275
  className: className,
1270
1276
  ref: ref
1271
1277
  }), "Loading...");
1272
1278
  });
1273
1279
 
1274
- const _excluded$c = ["areXLabelsRotated", "barProps", "caping", "className", "data", "id", "isBarSelected", "labelDecorator", "onBarClick", "orientation", "others", "size", "barRole", "theme", "tooltipVariant"];
1280
+ const _excluded$h = ["areXLabelsRotated", "barProps", "caping", "className", "data", "id", "isBarSelected", "labelDecorator", "onBarClick", "orientation", "others", "size", "barRole", "theme", "tooltipVariant"];
1275
1281
  const RenderedBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1276
1282
  const {
1277
1283
  areXLabelsRotated,
@@ -1290,7 +1296,7 @@ const RenderedBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1290
1296
  theme,
1291
1297
  tooltipVariant
1292
1298
  } = props,
1293
- forwardedProps = _objectWithoutProperties(props, _excluded$c);
1299
+ forwardedProps = _objectWithoutProperties(props, _excluded$h);
1294
1300
  const cache = useRef();
1295
1301
  const {
1296
1302
  data,
@@ -1305,7 +1311,7 @@ const RenderedBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1305
1311
  cache.current = data;
1306
1312
  });
1307
1313
  const isHorizontal = orientation === BarOrientation.horizontal;
1308
- const chartDimensions = sizeToDimension$2(size);
1314
+ const chartDimensions = sizeToDimension$3(size);
1309
1315
  const width = chartDimensions.width;
1310
1316
  const height = chartDimensions.height;
1311
1317
  const margins = {
@@ -1394,10 +1400,10 @@ const RenderedBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1394
1400
  }))));
1395
1401
  });
1396
1402
 
1397
- const _excluded$b = ["areXLabelsRotated", "caping", "chartRef", "className", "data", "emptyComponent", "id", "isBarSelected", "labelDecorator", "localeText", "onBarClick", "orientation", "others", "size", "barRole", "theme", "tooltipVariant"];
1398
- const COMPONENT_NAME$5 = 'BarChart';
1399
- const CLASSNAME$5 = 'redsift-barchart';
1400
- const DEFAULT_PROPS$5 = {
1403
+ const _excluded$g = ["areXLabelsRotated", "caping", "chartRef", "className", "data", "emptyComponent", "id", "isBarSelected", "labelDecorator", "localeText", "onBarClick", "orientation", "others", "size", "barRole", "theme", "tooltipVariant"];
1404
+ const COMPONENT_NAME$7 = 'BarChart';
1405
+ const CLASSNAME$7 = 'redsift-barchart';
1406
+ const DEFAULT_PROPS$7 = {
1401
1407
  isBarSelected: () => true,
1402
1408
  orientation: BarOrientation.horizontal,
1403
1409
  others: true,
@@ -1428,7 +1434,7 @@ const BarChart = /*#__PURE__*/forwardRef((props, ref) => {
1428
1434
  theme,
1429
1435
  tooltipVariant
1430
1436
  } = props,
1431
- forwardedProps = _objectWithoutProperties(props, _excluded$b);
1437
+ forwardedProps = _objectWithoutProperties(props, _excluded$g);
1432
1438
  const [_id] = useId();
1433
1439
  const id = propsId !== null && propsId !== void 0 ? propsId : _id;
1434
1440
  if (propsData === undefined || propsData === null) {
@@ -1469,22 +1475,42 @@ const BarChart = /*#__PURE__*/forwardRef((props, ref) => {
1469
1475
  ref: ref
1470
1476
  }));
1471
1477
  });
1472
- BarChart.className = CLASSNAME$5;
1473
- BarChart.defaultProps = DEFAULT_PROPS$5;
1474
- BarChart.displayName = COMPONENT_NAME$5;
1478
+ BarChart.className = CLASSNAME$7;
1479
+ BarChart.defaultProps = DEFAULT_PROPS$7;
1480
+ BarChart.displayName = COMPONENT_NAME$7;
1481
+
1482
+ /**
1483
+ * Component's variant.
1484
+ */
1485
+ const DotVariant = {
1486
+ plain: 'plain',
1487
+ hollow: 'hollow'
1488
+ };
1489
+
1490
+ /**
1491
+ * Component props.
1492
+ */
1475
1493
 
1476
1494
  /**
1477
1495
  * Component style.
1478
1496
  */
1479
1497
  const StyledDot = styled(DataPoint)`
1480
- circle {
1481
- fill-opacity: 0.7;
1482
- }
1483
-
1484
1498
  ${_ref => {
1485
1499
  let {
1486
- $clickable
1500
+ $variant
1487
1501
  } = _ref;
1502
+ return css`
1503
+ circle {
1504
+ fill-opacity: ${$variant === DotVariant.hollow ? 1 : 0.7};
1505
+ }
1506
+ `;
1507
+ }}
1508
+
1509
+
1510
+ ${_ref2 => {
1511
+ let {
1512
+ $clickable
1513
+ } = _ref2;
1488
1514
  return $clickable ? css`
1489
1515
  cursor: pointer;
1490
1516
 
@@ -1505,15 +1531,16 @@ const StyledDot = styled(DataPoint)`
1505
1531
  }}}
1506
1532
  `;
1507
1533
 
1508
- const _excluded$a = ["className", "scaleX", "scaleY"];
1509
- const COMPONENT_NAME$4 = 'Dot';
1510
- const CLASSNAME$4 = 'redsift-dot';
1511
- const DEFAULT_PROPS$4 = {
1534
+ const _excluded$f = ["className", "scaleX", "scaleY", "variant"];
1535
+ const COMPONENT_NAME$6 = 'Dot';
1536
+ const CLASSNAME$6 = 'redsift-dot';
1537
+ const DEFAULT_PROPS$6 = {
1512
1538
  color: monochrome,
1513
1539
  index: 0,
1514
1540
  labelDecorator: datum => {
1515
1541
  return datum.data.key[2] !== undefined && datum.data.key[2] !== null ? datum.data.key[2] : `${datum.data.key[0]},${datum.data.key[1]}`;
1516
- }
1542
+ },
1543
+ variant: DotVariant.plain
1517
1544
  };
1518
1545
  const Dot = /*#__PURE__*/forwardRef((props, ref) => {
1519
1546
  const {
@@ -1526,25 +1553,29 @@ const Dot = /*#__PURE__*/forwardRef((props, ref) => {
1526
1553
  const {
1527
1554
  className,
1528
1555
  scaleX,
1529
- scaleY
1556
+ scaleY,
1557
+ variant
1530
1558
  } = props,
1531
- forwardedProps = _objectWithoutProperties(props, _excluded$a);
1559
+ forwardedProps = _objectWithoutProperties(props, _excluded$f);
1532
1560
  const isSelectable = role === 'option';
1533
1561
  const isDeselected = isSelectable && propsIsSelected === false;
1534
1562
  return /*#__PURE__*/React__default.createElement(StyledDot, _extends({}, forwardedProps, {
1535
1563
  ref: ref,
1536
1564
  className: classNames(Dot.className, className),
1537
- $clickable: Boolean(onClick)
1565
+ $clickable: Boolean(onClick),
1566
+ $variant: variant
1538
1567
  }), /*#__PURE__*/React__default.createElement("circle", {
1539
1568
  cx: scaleX(data.x),
1540
1569
  cy: scaleY(data.y),
1541
1570
  r: data.r,
1542
- fill: isDeselected ? 'var(--redsift-color-neutral-lightgrey)' : color
1571
+ fill: variant === DotVariant.hollow ? 'var(--redsift-color-neutral-white)' : isDeselected ? 'var(--redsift-color-neutral-lightgrey)' : color,
1572
+ stroke: isDeselected ? 'var(--redsift-color-neutral-lightgrey)' : color,
1573
+ strokeWidth: variant === DotVariant.hollow ? '2' : '0'
1543
1574
  }));
1544
1575
  });
1545
- Dot.className = CLASSNAME$4;
1546
- Dot.defaultProps = DEFAULT_PROPS$4;
1547
- Dot.displayName = COMPONENT_NAME$4;
1576
+ Dot.className = CLASSNAME$6;
1577
+ Dot.defaultProps = DEFAULT_PROPS$6;
1578
+ Dot.displayName = COMPONENT_NAME$6;
1548
1579
 
1549
1580
  /**
1550
1581
  * Component style.
@@ -1601,10 +1632,10 @@ const StyledLegendItem = styled.li`
1601
1632
  }}}
1602
1633
  `;
1603
1634
 
1604
- const _excluded$9 = ["className", "color", "data", "id", "total", "variant"];
1605
- const COMPONENT_NAME$3 = 'LegendItem';
1606
- const CLASSNAME$3 = 'redsift-legend-item';
1607
- const DEFAULT_PROPS$3 = {
1635
+ const _excluded$e = ["className", "color", "data", "id", "variant"];
1636
+ const COMPONENT_NAME$5 = 'LegendItem';
1637
+ const CLASSNAME$5 = 'redsift-legend-item';
1638
+ const DEFAULT_PROPS$5 = {
1608
1639
  color: monochrome,
1609
1640
  index: 0
1610
1641
  };
@@ -1621,10 +1652,9 @@ const LegendItem = /*#__PURE__*/forwardRef((props, ref) => {
1621
1652
  color,
1622
1653
  data,
1623
1654
  id: propsId,
1624
- total,
1625
1655
  variant
1626
1656
  } = props,
1627
- forwardedProps = _objectWithoutProperties(props, _excluded$9);
1657
+ forwardedProps = _objectWithoutProperties(props, _excluded$e);
1628
1658
  const [_id] = useId();
1629
1659
  const id = propsId !== null && propsId !== void 0 ? propsId : _id;
1630
1660
  const text = labelDecorator ? labelDecorator(data, {
@@ -1667,11 +1697,11 @@ const LegendItem = /*#__PURE__*/forwardRef((props, ref) => {
1667
1697
  variant: "inherit"
1668
1698
  }), /*#__PURE__*/React__default.createElement(Text, {
1669
1699
  variant: "caption"
1670
- }, text)) : variant === LabelVariant.percent && total ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Number$1, {
1700
+ }, text)) : variant === LabelVariant.percent && data.data.percent ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Number$1, {
1671
1701
  as: "b",
1672
1702
  maximumFractionDigits: 2,
1673
1703
  type: "percent",
1674
- value: data.data.value / total,
1704
+ value: data.data.percent,
1675
1705
  variant: "inherit"
1676
1706
  }), /*#__PURE__*/React__default.createElement(Text, {
1677
1707
  variant: "caption"
@@ -1679,15 +1709,15 @@ const LegendItem = /*#__PURE__*/forwardRef((props, ref) => {
1679
1709
  variant: "caption"
1680
1710
  }, text) : /*#__PURE__*/React__default.createElement(React__default.Fragment, null, text));
1681
1711
  });
1682
- LegendItem.className = CLASSNAME$3;
1683
- LegendItem.defaultProps = DEFAULT_PROPS$3;
1684
- LegendItem.displayName = COMPONENT_NAME$3;
1712
+ LegendItem.className = CLASSNAME$5;
1713
+ LegendItem.defaultProps = DEFAULT_PROPS$5;
1714
+ LegendItem.displayName = COMPONENT_NAME$5;
1685
1715
 
1686
- const _excluded$8 = ["className", "data", "isLegendItemSelected", "labelDecorator", "legendItemRole", "onLegendItemClick", "variant", "width"],
1716
+ const _excluded$d = ["className", "data", "isLegendItemSelected", "labelDecorator", "legendItemRole", "onLegendItemClick", "variant", "width"],
1687
1717
  _excluded2 = ["color"];
1688
- const COMPONENT_NAME$2 = 'Legend';
1689
- const CLASSNAME$2 = 'redsift-chart-legend';
1690
- const DEFAULT_PROPS$2 = {
1718
+ const COMPONENT_NAME$4 = 'Legend';
1719
+ const CLASSNAME$4 = 'redsift-chart-legend';
1720
+ const DEFAULT_PROPS$4 = {
1691
1721
  isLegendItemSelected: () => true,
1692
1722
  variant: LabelVariant.label
1693
1723
  };
@@ -1702,23 +1732,25 @@ const Legend = /*#__PURE__*/forwardRef((props, ref) => {
1702
1732
  variant,
1703
1733
  width
1704
1734
  } = props,
1705
- forwardedProps = _objectWithoutProperties(props, _excluded$8);
1735
+ forwardedProps = _objectWithoutProperties(props, _excluded$d);
1706
1736
  const total = sum(data, d => d.value);
1707
1737
  return /*#__PURE__*/React__default.createElement(StyledLegend, _extends({}, forwardedProps, {
1708
1738
  className: classNames(Legend.className, className),
1709
1739
  ref: ref,
1710
1740
  $width: width
1711
1741
  }), data.map((_ref, index) => {
1742
+ var _datum$percent;
1712
1743
  let {
1713
1744
  color
1714
1745
  } = _ref,
1715
1746
  datum = _objectWithoutProperties(_ref, _excluded2);
1716
1747
  return /*#__PURE__*/React__default.createElement(LegendItem, {
1717
1748
  data: {
1718
- data: datum
1749
+ data: _objectSpread2(_objectSpread2({}, datum), {}, {
1750
+ percent: (_datum$percent = datum.percent) !== null && _datum$percent !== void 0 ? _datum$percent : datum.value / total
1751
+ })
1719
1752
  },
1720
1753
  color: color,
1721
- total: total,
1722
1754
  variant: variant,
1723
1755
  index: index,
1724
1756
  isSelected: Boolean(isLegendItemSelected({
@@ -1731,9 +1763,507 @@ const Legend = /*#__PURE__*/forwardRef((props, ref) => {
1731
1763
  });
1732
1764
  }));
1733
1765
  });
1734
- Legend.className = CLASSNAME$2;
1735
- Legend.defaultProps = DEFAULT_PROPS$2;
1736
- Legend.displayName = COMPONENT_NAME$2;
1766
+ Legend.className = CLASSNAME$4;
1767
+ Legend.defaultProps = DEFAULT_PROPS$4;
1768
+ Legend.displayName = COMPONENT_NAME$4;
1769
+
1770
+ /**
1771
+ * Component style.
1772
+ */
1773
+ const StyledLine = styled('g')``;
1774
+
1775
+ const _excluded$c = ["className", "createLine", "previousData"];
1776
+ const COMPONENT_NAME$3 = 'Line';
1777
+ const CLASSNAME$3 = 'redsift-line';
1778
+ const DEFAULT_PROPS$3 = {
1779
+ color: monochrome,
1780
+ previousData: []
1781
+ };
1782
+ const Line = /*#__PURE__*/forwardRef((props, ref) => {
1783
+ const {
1784
+ color,
1785
+ data,
1786
+ isSelected: propsIsSelected,
1787
+ role
1788
+ } = props;
1789
+ const {
1790
+ className,
1791
+ createLine,
1792
+ previousData
1793
+ } = props,
1794
+ forwardedProps = _objectWithoutProperties(props, _excluded$c);
1795
+ const interpolator = interpolate(previousData, data);
1796
+ const isSelectable = role === 'option';
1797
+ const isDeselected = isSelectable && propsIsSelected === false;
1798
+ const animatedProps = J(_objectSpread2(_objectSpread2({}, config), {}, {
1799
+ to: async next => {
1800
+ await next({
1801
+ t: 1
1802
+ });
1803
+ },
1804
+ from: {
1805
+ t: 0
1806
+ }
1807
+ }));
1808
+ return /*#__PURE__*/React__default.createElement(StyledLine, _extends({}, forwardedProps, {
1809
+ ref: ref,
1810
+ className: classNames(Line.className, className)
1811
+ }), /*#__PURE__*/React__default.createElement(it.path, {
1812
+ d: config.immediate ? createLine(data) : animatedProps.t.to(t => createLine(interpolator(t))),
1813
+ fill: "none",
1814
+ stroke: isDeselected ? 'var(--redsift-color-neutral-lightgrey)' : color,
1815
+ strokeWidth: 2
1816
+ }));
1817
+ });
1818
+ Line.className = CLASSNAME$3;
1819
+ Line.defaultProps = DEFAULT_PROPS$3;
1820
+ Line.displayName = COMPONENT_NAME$3;
1821
+
1822
+ /**
1823
+ * Component's labels variant.
1824
+ */
1825
+ const LineChartLabelVariant = {
1826
+ none: 'none',
1827
+ externalLabel: 'externalLabel',
1828
+ externalLabelValue: 'externalLabelValue',
1829
+ externalLabelPercent: 'externalLabelPercent'
1830
+ };
1831
+
1832
+ /**
1833
+ * Component props.
1834
+ */
1835
+
1836
+ /**
1837
+ * Component style.
1838
+ */
1839
+ const StyledLineChart = styled(ChartContainer)``;
1840
+ const StyledLineChartEmptyText = styled.div`
1841
+ position: absolute;
1842
+ top: 0;
1843
+ left: 0;
1844
+ height: 100%;
1845
+ width: 100%;
1846
+ display: flex;
1847
+ flex-direction: column;
1848
+ justify-content: center;
1849
+ align-items: center;
1850
+ pointer-events: none;
1851
+
1852
+ > * {
1853
+ max-width: ${_ref => {
1854
+ let {
1855
+ $maxWidth
1856
+ } = _ref;
1857
+ return $maxWidth;
1858
+ }}px;
1859
+ }
1860
+
1861
+ > span {
1862
+ font-family: var(--redsift-typography-font-family-poppins);
1863
+ color: var(--redsift-color-neutral-black);
1864
+ font-size: ${_ref2 => {
1865
+ let {
1866
+ $textSize
1867
+ } = _ref2;
1868
+ return $textSize;
1869
+ }}px;
1870
+ line-height: ${_ref3 => {
1871
+ let {
1872
+ $textSize
1873
+ } = _ref3;
1874
+ return $textSize;
1875
+ }}px;
1876
+ }
1877
+ `;
1878
+
1879
+ const _excluded$b = ["className"];
1880
+ const LoadingLineChart = /*#__PURE__*/forwardRef((props, ref) => {
1881
+ const {
1882
+ className
1883
+ } = props,
1884
+ forwardedProps = _objectWithoutProperties(props, _excluded$b);
1885
+ return /*#__PURE__*/React__default.createElement(StyledLineChart, _extends({}, forwardedProps, {
1886
+ className: className,
1887
+ ref: ref
1888
+ }), "Loading...");
1889
+ });
1890
+
1891
+ const sizeToDimension$2 = size => {
1892
+ if (typeof size !== 'string') {
1893
+ return size;
1894
+ }
1895
+ switch (size) {
1896
+ case ChartSize.small:
1897
+ return {
1898
+ width: 600,
1899
+ height: 300,
1900
+ fontSize: 30
1901
+ };
1902
+ case ChartSize.medium:
1903
+ default:
1904
+ return {
1905
+ width: 750,
1906
+ height: 375,
1907
+ fontSize: 34
1908
+ };
1909
+ case ChartSize.large:
1910
+ return {
1911
+ width: 900,
1912
+ height: 450,
1913
+ fontSize: 38
1914
+ };
1915
+ }
1916
+ };
1917
+ const statsBy = arr => {
1918
+ const counts = arr.reduce((prev, curr) => {
1919
+ if (!curr.value) {
1920
+ return prev;
1921
+ }
1922
+ if (!prev[curr.key[1]]) {
1923
+ prev[curr.key[1]] = {
1924
+ value: curr.value,
1925
+ min: curr.value,
1926
+ max: curr.value,
1927
+ values: [curr.value]
1928
+ };
1929
+ } else {
1930
+ prev[curr.key[1]] = {
1931
+ value: prev[curr.key[1]].value + curr.value,
1932
+ min: Math.min(prev[curr.key[1]].min, curr.value),
1933
+ max: Math.max(prev[curr.key[1]].max, curr.value),
1934
+ values: [...prev[curr.key[1]].values, curr.value]
1935
+ };
1936
+ }
1937
+ return prev;
1938
+ }, {});
1939
+ return Object.keys(counts).map(key => ({
1940
+ key: key,
1941
+ value: counts[key].value,
1942
+ min: counts[key].min,
1943
+ max: counts[key].max,
1944
+ values: counts[key].values,
1945
+ first: counts[key].values[0],
1946
+ last: counts[key].values[counts[key].values.length - 1],
1947
+ trending: {
1948
+ overall: (counts[key].values[counts[key].values.length - 1] - counts[key].values[0]) * 100 / counts[key].values[0]
1949
+ }
1950
+ })).sort((a, b) => a.value === b.value ? a.key > b.key ? 1 : -1 : a.value < b.value ? 1 : -1);
1951
+ };
1952
+
1953
+ const _excluded$a = ["className", "data", "emptyComponent", "localeText", "size"];
1954
+ const EmptyLineChart = /*#__PURE__*/forwardRef((props, ref) => {
1955
+ const {
1956
+ className,
1957
+ data: propsData,
1958
+ emptyComponent,
1959
+ localeText,
1960
+ size
1961
+ } = props,
1962
+ forwardedProps = _objectWithoutProperties(props, _excluded$a);
1963
+ const cache = useRef();
1964
+ const data = propsData;
1965
+ useEffect(() => {
1966
+ cache.current = data;
1967
+ });
1968
+ const chartDimensions = sizeToDimension$2(size);
1969
+ const width = chartDimensions.width;
1970
+ const height = chartDimensions.height;
1971
+ const margins = {
1972
+ top: 16,
1973
+ left: 48,
1974
+ right: 16,
1975
+ bottom: 48
1976
+ };
1977
+ const chartWidth = width - margins.left - margins.right;
1978
+ return /*#__PURE__*/React__default.createElement(StyledLineChart, _extends({}, forwardedProps, {
1979
+ className: className,
1980
+ ref: ref
1981
+ }), emptyComponent !== null && emptyComponent !== void 0 ? emptyComponent : /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(StyledLineChartEmptyText, {
1982
+ $maxWidth: width,
1983
+ $textSize: chartDimensions.fontSize / 2
1984
+ }, /*#__PURE__*/React__default.createElement("span", null, localeText === null || localeText === void 0 ? void 0 : localeText.emptyChartText)), /*#__PURE__*/React__default.createElement("svg", {
1985
+ width: width,
1986
+ height: height
1987
+ }, /*#__PURE__*/React__default.createElement("g", {
1988
+ transform: `translate(${margins.left},${margins.top})`
1989
+ }, /*#__PURE__*/React__default.createElement(Axis, {
1990
+ position: "bottom",
1991
+ length: width - 32,
1992
+ scale: scaleLinear().domain([]).range([0, chartWidth]),
1993
+ x: 0,
1994
+ y: height,
1995
+ tickValues: 4
1996
+ })))));
1997
+ });
1998
+
1999
+ const _excluded$9 = ["className", "data", "dotRole", "id", "isDotSelected", "labelDecorator", "labelVariant", "legendProps", "onDotClick", "size", "theme", "tooltipVariant", "xAxisVariant", "xAxisPlacement", "xAxisTickFormat", "xAxisTickValues", "yAxisVariant", "yAxisPlacement", "dateParser"];
2000
+ const isValidDate = value => {
2001
+ const date = new Date(value);
2002
+ return date instanceof Date && !isNaN(date) && !isNaN(Date.parse(value));
2003
+ };
2004
+ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2005
+ const {
2006
+ className,
2007
+ data: propsData,
2008
+ dotRole,
2009
+ id,
2010
+ isDotSelected,
2011
+ labelDecorator,
2012
+ labelVariant,
2013
+ legendProps,
2014
+ onDotClick,
2015
+ size,
2016
+ theme,
2017
+ tooltipVariant,
2018
+ xAxisVariant,
2019
+ xAxisPlacement,
2020
+ xAxisTickFormat: propsXAxisTickFormat,
2021
+ xAxisTickValues,
2022
+ yAxisVariant,
2023
+ yAxisPlacement,
2024
+ dateParser
2025
+ } = props,
2026
+ forwardedProps = _objectWithoutProperties(props, _excluded$9);
2027
+ const cache = useRef();
2028
+ const xScaleType = propsData[0].key[0] instanceof Date ? 'Date' : typeof propsData[0].key[0] === 'number' ? 'number' : typeof propsData[0].key[0] === 'string' && isValidDate(propsData[0].key[0]) ? 'dateString' : typeof propsData[0].key[0] === 'string' ? 'string' : undefined;
2029
+ const data = xScaleType === 'number' ? propsData.filter(datum => typeof datum.key[0] === 'number' && !Number.isNaN(datum.key[0])) : xScaleType === 'dateString' ? propsData.filter(datum => isValidDate(datum.key[0])) : xScaleType === 'string' ? propsData.filter(datum => typeof datum.key[0] === 'string') : xScaleType === 'Date' ? propsData.filter(datum => datum.key[0] instanceof Date) : propsData;
2030
+ useEffect(() => {
2031
+ cache.current = data;
2032
+ });
2033
+ const svgRef = useRef();
2034
+ const chartDimensions = sizeToDimension$2(size);
2035
+ const width = chartDimensions.width;
2036
+ const height = chartDimensions.height;
2037
+ const margins = {
2038
+ top: xAxisVariant === AxisVariant.default || xAxisVariant === AxisVariant.tickValue ? 24 : 8,
2039
+ left: yAxisVariant === AxisVariant.default || yAxisVariant === AxisVariant.tickValue ? 48 : 8,
2040
+ right: yAxisVariant === AxisVariant.default || yAxisVariant === AxisVariant.tickValue ? 48 : 8,
2041
+ bottom: xAxisVariant === AxisVariant.default || xAxisVariant === AxisVariant.tickValue ? 24 : 8
2042
+ };
2043
+ const chartHeight = height - margins.top - margins.bottom;
2044
+ const chartWidth = width - margins.left - margins.right;
2045
+ const scaleX = (() => {
2046
+ if (xScaleType === 'number') {
2047
+ const domain = extent(data, d => d.key[0]);
2048
+ return scaleLinear().domain(domain).range([0, chartWidth]).nice();
2049
+ } else if (xScaleType === 'dateString') {
2050
+ const domain = extent(data, d => Date.parse(d.key[0]));
2051
+ return scaleTime().domain([new Date(domain[0]), new Date(domain[1])]).range([0, chartWidth]).nice();
2052
+ } else if (xScaleType === 'Date') {
2053
+ const domain = extent(data, d => d.key[0].valueOf());
2054
+ return scaleTime().domain([new Date(domain[0]), new Date(domain[1])]).range([0, chartWidth]).nice();
2055
+ } else {
2056
+ return scalePoint().domain(xAxisTickValues && Array.isArray(xAxisTickValues) ? xAxisTickValues : data.map(d => d.key[0])).range([0, chartWidth]);
2057
+ }
2058
+ })();
2059
+ const scaleY = (() => {
2060
+ const domain = extent(data, d => d.value);
2061
+ return scaleLinear().domain(domain).range([chartHeight, 0]).nice();
2062
+ })();
2063
+ const xAxisTickFormat = propsXAxisTickFormat !== null && propsXAxisTickFormat !== void 0 ? propsXAxisTickFormat : xScaleType === 'Date' || xScaleType === 'dateString' ? scaleX.tickFormat() : undefined;
2064
+ const hasCategory = data[0] && data[0].key.length >= 2 && data[0].key[1] !== null && data[0].key[1] !== undefined;
2065
+ const statsByCategory = statsBy(data);
2066
+ const colorScale = useColor({
2067
+ data: statsByCategory,
2068
+ theme: theme,
2069
+ category: d => d.key
2070
+ });
2071
+ const circles = data.sort((a, b) => {
2072
+ if (xScaleType === 'number') {
2073
+ if (a.key[0] < b.key[0]) return -1;
2074
+ if (a.key[0] > b.key[0]) return 1;
2075
+ return 0;
2076
+ } else if (xScaleType === 'dateString') {
2077
+ if (Date.parse(a.key[0]) < Date.parse(b.key[0])) return -1;
2078
+ if (Date.parse(a.key[0]) > Date.parse(b.key[0])) return 1;
2079
+ return 0;
2080
+ } else if (xScaleType === 'Date') {
2081
+ if (a.key[0].valueOf() < b.key[0].valueOf()) return -1;
2082
+ if (a.key[0].valueOf() > b.key[0].valueOf()) return 1;
2083
+ return 0;
2084
+ } else if (xScaleType === 'string' && xAxisTickValues && Array.isArray(xAxisTickValues)) {
2085
+ if (xAxisTickValues.indexOf(a.key[0]) < xAxisTickValues.indexOf(b.key[0])) return -1;
2086
+ if (xAxisTickValues.indexOf(a.key[0]) > xAxisTickValues.indexOf(b.key[0])) return 1;
2087
+ return 0;
2088
+ }
2089
+ return 0;
2090
+ }).filter(d => d.value !== null).map(d => ({
2091
+ category: d.key[1],
2092
+ x: xScaleType === 'dateString' ? dateParser ? dateParser(d.key[0]) : new Date(Date.parse(d.key[0])) : d.key[0],
2093
+ y: d.value,
2094
+ data: {
2095
+ key: d.key,
2096
+ value: d.value
2097
+ },
2098
+ points: [d]
2099
+ }));
2100
+ const lines = hasCategory ? Object.values(circles.reduce((prev, curr) => {
2101
+ if (!prev[curr.category]) {
2102
+ prev[curr.category] = [];
2103
+ }
2104
+ prev[curr.category].push(curr);
2105
+ return prev;
2106
+ }, {})) : [circles];
2107
+ const createLine = line().x(d => scaleX(d.x)).y(d => scaleY(d.y));
2108
+ return /*#__PURE__*/React__default.createElement(StyledLineChart, _extends({}, forwardedProps, {
2109
+ id: id,
2110
+ className: className,
2111
+ ref: ref
2112
+ }), /*#__PURE__*/React__default.createElement(Flexbox, {
2113
+ flexDirection: "column",
2114
+ alignItems: "center",
2115
+ gap: "8"
2116
+ }, /*#__PURE__*/React__default.createElement("svg", {
2117
+ ref: svgRef,
2118
+ width: width,
2119
+ height: height
2120
+ }, /*#__PURE__*/React__default.createElement("g", {
2121
+ transform: `translate(${margins.left},${margins.top})`
2122
+ }, lines.map((line, index) => {
2123
+ return /*#__PURE__*/React__default.createElement(Line, {
2124
+ color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(line[0].category),
2125
+ data: line.filter(point => point.y !== null),
2126
+ createLine: createLine,
2127
+ key: `line _${index}`
2128
+ });
2129
+ })), /*#__PURE__*/React__default.createElement("g", {
2130
+ transform: `translate(${margins.left},${margins.top})`
2131
+ }, circles.map((circle, index) => {
2132
+ const scaleXDomain = scaleX.domain();
2133
+ const scaleYDomain = scaleY.domain();
2134
+ if (xScaleType === 'number' && (circle.x < scaleXDomain[0] || circle.x > scaleXDomain[1] || circle.y < scaleYDomain[0] || circle.y > scaleYDomain[1])) {
2135
+ return null;
2136
+ }
2137
+ const to = _objectSpread2(_objectSpread2({}, circle), {}, {
2138
+ r: 4
2139
+ });
2140
+ return /*#__PURE__*/React__default.createElement(Dot, {
2141
+ color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(circle.category),
2142
+ data: to,
2143
+ isSelected: Boolean(isDotSelected === null || isDotSelected === void 0 ? void 0 : isDotSelected(to)),
2144
+ key: `circle _${index}`,
2145
+ labelDecorator: labelDecorator,
2146
+ onClick: onDotClick,
2147
+ role: dotRole,
2148
+ scaleX: scaleX,
2149
+ scaleY: scaleY,
2150
+ tooltipVariant: tooltipVariant,
2151
+ variant: DotVariant.hollow
2152
+ });
2153
+ })), /*#__PURE__*/React__default.createElement("g", {
2154
+ transform: `translate(${margins.left},${margins.top})`
2155
+ }, ['bottom', 'both'].includes(xAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
2156
+ position: "bottom",
2157
+ length: chartWidth,
2158
+ scale: scaleX,
2159
+ x: 0,
2160
+ y: chartHeight,
2161
+ tickValues: xAxisTickValues !== null && xAxisTickValues !== void 0 ? xAxisTickValues : 8,
2162
+ variant: xAxisVariant,
2163
+ tickFormat: xAxisTickFormat
2164
+ }) : null, ['top', 'both'].includes(xAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
2165
+ position: "top",
2166
+ length: chartWidth,
2167
+ scale: scaleX,
2168
+ x: 0,
2169
+ y: 0,
2170
+ tickValues: xAxisTickValues !== null && xAxisTickValues !== void 0 ? xAxisTickValues : 8,
2171
+ variant: xAxisVariant,
2172
+ tickFormat: xAxisTickFormat
2173
+ }) : null, ['left', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
2174
+ position: "left",
2175
+ length: chartHeight,
2176
+ scale: scaleY,
2177
+ x: 0,
2178
+ y: chartHeight,
2179
+ tickValues: 8,
2180
+ variant: yAxisVariant
2181
+ }) : null, ['right', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
2182
+ position: "right",
2183
+ length: chartHeight,
2184
+ scale: scaleY,
2185
+ x: chartWidth,
2186
+ y: chartHeight,
2187
+ tickValues: 8,
2188
+ variant: yAxisVariant
2189
+ }) : null))), hasCategory && labelVariant !== LineChartLabelVariant.none ? /*#__PURE__*/React__default.createElement(Legend, _extends({
2190
+ data: statsByCategory.map(d => _objectSpread2(_objectSpread2({}, d), {}, {
2191
+ color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(d.key)
2192
+ })),
2193
+ variant: labelVariant === LineChartLabelVariant.externalLabelValue ? LabelVariant.value : labelVariant === LineChartLabelVariant.externalLabelPercent ? LabelVariant.percent : LabelVariant.label
2194
+ }, legendProps)) : null);
2195
+ });
2196
+
2197
+ const _excluded$8 = ["className", "data", "dotRole", "emptyComponent", "id", "isDotSelected", "labelVariant", "localeText", "onDotClick", "size", "theme", "tooltipVariant"];
2198
+ const COMPONENT_NAME$2 = 'LineChart';
2199
+ const CLASSNAME$2 = 'redsift-line-chart';
2200
+ const DEFAULT_PROPS$2 = {
2201
+ labelVariant: LineChartLabelVariant.externalLabel,
2202
+ localeText: {
2203
+ emptyChartText: 'No Data'
2204
+ },
2205
+ size: ChartSize.medium,
2206
+ theme: ColorTheme.dark,
2207
+ tooltipVariant: TooltipVariant.none,
2208
+ xAxisVariant: AxisVariant.default,
2209
+ xAxisPlacement: 'bottom',
2210
+ yAxisVariant: AxisVariant.default,
2211
+ yAxisPlacement: 'left'
2212
+ };
2213
+ const LineChart = /*#__PURE__*/forwardRef((props, ref) => {
2214
+ const {
2215
+ className,
2216
+ data: propsData,
2217
+ dotRole,
2218
+ emptyComponent,
2219
+ id: propsId,
2220
+ isDotSelected,
2221
+ labelVariant,
2222
+ localeText,
2223
+ onDotClick,
2224
+ size,
2225
+ theme,
2226
+ tooltipVariant
2227
+ } = props,
2228
+ forwardedProps = _objectWithoutProperties(props, _excluded$8);
2229
+ const [_id] = useId();
2230
+ const id = propsId !== null && propsId !== void 0 ? propsId : _id;
2231
+ if (propsData === undefined || propsData === null) {
2232
+ return /*#__PURE__*/React__default.createElement(LoadingLineChart, _extends({
2233
+ id: id
2234
+ }, forwardedProps, {
2235
+ ref: ref
2236
+ }));
2237
+ }
2238
+ if (propsData.length === 0) {
2239
+ return /*#__PURE__*/React__default.createElement(EmptyLineChart, _extends({
2240
+ data: propsData,
2241
+ emptyComponent: emptyComponent,
2242
+ localeText: localeText,
2243
+ size: size
2244
+ }, forwardedProps, {
2245
+ ref: ref
2246
+ }));
2247
+ }
2248
+ return /*#__PURE__*/React__default.createElement(RenderedLineChart, _extends({
2249
+ className: classNames(LineChart.className, className),
2250
+ data: propsData,
2251
+ dotRole: dotRole,
2252
+ id: id,
2253
+ isDotSelected: isDotSelected,
2254
+ labelVariant: labelVariant,
2255
+ localeText: localeText,
2256
+ onDotClick: onDotClick,
2257
+ size: size,
2258
+ theme: theme,
2259
+ tooltipVariant: tooltipVariant
2260
+ }, forwardedProps, {
2261
+ ref: ref
2262
+ }));
2263
+ });
2264
+ LineChart.className = CLASSNAME$2;
2265
+ LineChart.defaultProps = DEFAULT_PROPS$2;
2266
+ LineChart.displayName = COMPONENT_NAME$2;
1737
2267
 
1738
2268
  /**
1739
2269
  * Component variant.
@@ -2744,5 +3274,5 @@ ScatterPlot.className = CLASSNAME;
2744
3274
  ScatterPlot.defaultProps = DEFAULT_PROPS;
2745
3275
  ScatterPlot.displayName = COMPONENT_NAME;
2746
3276
 
2747
- export { Arc, Arcs, Axis, AxisPosition, AxisVariant, Bar, BarChart, BarOrientation, ChartContainer, ChartSize, ColorTheme, DataPoint, Dot, LabelVariant, Legend, PieChart, PieChartLabelVariant, PieChartVariant, ScatterPlot, ScatterPlotLabelVariant, ScatterPlotVariant, StyledArc, StyledArcs, StyledAxis, StyledBar, StyledBarChart, StyledBarChartEmptyText, StyledChartContainer, StyledChartContainerCaption, StyledChartContainerTitle, StyledDataPoint, StyledDot, StyledLegend, StyledPieChart, StyledPieChartCenterText, StyledPieChartEmptyText, StyledScatterPlot, StyledScatterPlotEmptyText, TooltipVariant, empty, getColorScale, monochrome, scheme, successDangerScheme, useBrush, useColor, useFormatCategoricalData, useZoom };
3277
+ export { Arc, Arcs, Axis, AxisPosition, AxisVariant, Bar, BarChart, BarOrientation, ChartContainer, ChartSize, ColorTheme, DataPoint, Dot, DotVariant, LabelVariant, Legend, Line, LineChart, LineChartLabelVariant, PieChart, PieChartLabelVariant, PieChartVariant, ScatterPlot, ScatterPlotLabelVariant, ScatterPlotVariant, StyledArc, StyledArcs, StyledAxis, StyledBar, StyledBarChart, StyledBarChartEmptyText, StyledChartContainer, StyledChartContainerCaption, StyledChartContainerTitle, StyledDataPoint, StyledDot, StyledLegend, StyledLine, StyledLineChart, StyledLineChartEmptyText, StyledPieChart, StyledPieChartCenterText, StyledPieChartEmptyText, StyledScatterPlot, StyledScatterPlotEmptyText, TooltipVariant, empty, getColorScale, monochrome, scheme, successDangerScheme, useBrush, useColor, useFormatCategoricalData, useZoom };
2748
3278
  //# sourceMappingURL=index.js.map