@redsift/charts 10.1.0-alpha.0 → 10.1.0-alpha.2

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.
package/index.d.ts CHANGED
@@ -59,6 +59,7 @@ interface AxisProps extends Omit<ComponentProps<'g'>, 'scale'> {
59
59
  tickRotation?: number;
60
60
  tickSize?: number;
61
61
  tickValues?: TicksSpec;
62
+ tickRemodelling?: (tickValues: any[]) => any[];
62
63
  /** Variant. */
63
64
  variant?: AxisVariant;
64
65
  /** X position. */
@@ -96,6 +97,12 @@ type ChartAxesProps = {
96
97
  xAxisTickSize?: AxisProps['tickSize'];
97
98
  /** X axis tick values. */
98
99
  xAxisTickValues?: AxisProps['tickValues'];
100
+ /** X axis min value. */
101
+ xAxisMinValue?: number | string;
102
+ /** X axis min value. */
103
+ xAxisMaxValue?: number | string;
104
+ /** Y axis tick remodelling. */
105
+ xAxisTickRemodelling?: (tickValues: any[]) => any[];
99
106
  /** Y axis variant. */
100
107
  yAxisVariant?: AxisVariant;
101
108
  /** Y axis placement. */
@@ -110,6 +117,12 @@ type ChartAxesProps = {
110
117
  yAxisTickSize?: AxisProps['tickSize'];
111
118
  /** Y axis tick values. */
112
119
  yAxisTickValues?: AxisProps['tickValues'];
120
+ /** Y axis min value. */
121
+ yAxisMinValue?: number | string;
122
+ /** Y axis min value. */
123
+ yAxisMaxValue?: number | string;
124
+ /** Y axis tick remodelling. */
125
+ yAxisTickRemodelling?: (tickValues: any[]) => any[];
113
126
  };
114
127
 
115
128
  type JSONValue = string | number | boolean | Date | {
package/index.js CHANGED
@@ -741,9 +741,10 @@ const computeTicks = _ref => {
741
741
  tickValues,
742
742
  tickSize,
743
743
  tickPadding,
744
- tickRotation
744
+ tickRotation,
745
+ tickRemodelling
745
746
  } = _ref;
746
- const values = getScaleTicks(scale, tickValues);
747
+ const values = tickRemodelling ? tickRemodelling(getScaleTicks(scale, tickValues)) : getScaleTicks(scale, tickValues);
747
748
  const position = 'bandwidth' in scale ? centerScale(scale) : scale;
748
749
  const line = {
749
750
  lineX: 0,
@@ -808,7 +809,7 @@ const computeTicks = _ref => {
808
809
  };
809
810
  };
810
811
 
811
- const _excluded$n = ["className", "length", "legend", "legendOffset", "legendPosition", "position", "scale", "tickPadding", "tickRotation", "tickSize", "tickValues", "tickFormat", "variant", "x", "y"];
812
+ const _excluded$n = ["className", "length", "legend", "legendOffset", "legendPosition", "position", "scale", "tickPadding", "tickRotation", "tickSize", "tickValues", "tickFormat", "tickRemodelling", "variant", "x", "y"];
812
813
  const COMPONENT_NAME$a = 'Axis';
813
814
  const CLASSNAME$a = 'redsift-axis';
814
815
  const DEFAULT_PROPS$a = {
@@ -837,6 +838,7 @@ const Axis = /*#__PURE__*/forwardRef((props, ref) => {
837
838
  tickSize,
838
839
  tickValues,
839
840
  tickFormat,
841
+ tickRemodelling,
840
842
  variant,
841
843
  x,
842
844
  y
@@ -907,7 +909,8 @@ const Axis = /*#__PURE__*/forwardRef((props, ref) => {
907
909
  tickValues,
908
910
  tickSize: tickSize,
909
911
  tickPadding: tickPadding,
910
- tickRotation: tickRotation
912
+ tickRotation: tickRotation,
913
+ tickRemodelling
911
914
  });
912
915
  const transition = Gt(ticks, _objectSpread2(_objectSpread2({}, config), {}, {
913
916
  keys: tick => tick.key,
@@ -1600,7 +1603,7 @@ const RenderedOrdinalBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1600
1603
  }))));
1601
1604
  });
1602
1605
 
1603
- const _excluded$h = ["barProps", "className", "data", "id", "isBarSelected", "labelDecorator", "margins", "onBarClick", "size", "sortingMethod", "barRole", "colorTheme", "tooltipVariant", "xAxisVariant", "xAxisPlacement", "xAxisTickFormat", "xAxisTickPadding", "xAxisTickRotation", "xAxisTickSize", "xAxisTickValues", "yAxisVariant", "yAxisPlacement", "yAxisTickFormat", "yAxisTickPadding", "yAxisTickRotation", "yAxisTickSize", "yAxisTickValues", "dateParser"];
1606
+ const _excluded$h = ["barProps", "className", "data", "id", "isBarSelected", "labelDecorator", "margins", "onBarClick", "size", "sortingMethod", "barRole", "colorTheme", "tooltipVariant", "xAxisVariant", "xAxisPlacement", "xAxisTickFormat", "xAxisTickPadding", "xAxisTickRotation", "xAxisTickSize", "xAxisTickValues", "xAxisMinValue", "xAxisMaxValue", "xAxisTickRemodelling", "yAxisVariant", "yAxisPlacement", "yAxisTickFormat", "yAxisTickPadding", "yAxisTickRotation", "yAxisTickSize", "yAxisTickValues", "yAxisMinValue", "yAxisMaxValue", "yAxisTickRemodelling", "dateParser"];
1604
1607
  const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1605
1608
  const {
1606
1609
  barProps,
@@ -1623,6 +1626,9 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1623
1626
  xAxisTickRotation,
1624
1627
  xAxisTickSize,
1625
1628
  xAxisTickValues,
1629
+ xAxisMinValue,
1630
+ xAxisMaxValue,
1631
+ xAxisTickRemodelling,
1626
1632
  yAxisVariant: propsYAxisVariant,
1627
1633
  yAxisPlacement,
1628
1634
  yAxisTickFormat,
@@ -1630,6 +1636,9 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1630
1636
  yAxisTickRotation,
1631
1637
  yAxisTickSize,
1632
1638
  yAxisTickValues,
1639
+ yAxisMinValue,
1640
+ yAxisMaxValue,
1641
+ yAxisTickRemodelling,
1633
1642
  dateParser
1634
1643
  } = props,
1635
1644
  forwardedProps = _objectWithoutProperties(props, _excluded$h);
@@ -1659,22 +1668,38 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1659
1668
  let barWidth = chartWidth / (numberOfRows * 2) - gap;
1660
1669
  const scaleX = (() => {
1661
1670
  if (xScaleType === 'number') {
1671
+ var _ref, _ref2;
1662
1672
  const domain = extent(data, d => d.key);
1673
+ domain[0] = (_ref = xAxisMinValue) !== null && _ref !== void 0 ? _ref : domain[0];
1674
+ domain[1] = (_ref2 = xAxisMaxValue) !== null && _ref2 !== void 0 ? _ref2 : domain[1];
1663
1675
  const gap = domain[1] - domain[0];
1664
1676
  domain[0] -= gap * 0.1;
1665
1677
  domain[1] += gap * 0.1;
1666
1678
  return scaleLinear().domain(domain).range([0, chartWidth]).nice();
1667
1679
  } else if (xScaleType === 'dateString' || xScaleType === 'Date') {
1680
+ var _ref3, _ref4;
1668
1681
  const domain = xScaleType === 'dateString' ? extent(data, d => Date.parse(d.key)) : extent(data, d => d.key.valueOf());
1682
+ domain[0] = (_ref3 = xAxisMinValue) !== null && _ref3 !== void 0 ? _ref3 : domain[0];
1683
+ domain[1] = (_ref4 = xAxisMaxValue) !== null && _ref4 !== void 0 ? _ref4 : domain[1];
1669
1684
  const startDate = xAxisTickValues && typeof xAxisTickValues.offset === 'function' ? xAxisTickValues.offset(new Date(domain[0]), -1) : new Date(domain[0]);
1670
1685
  const endDate = xAxisTickValues && typeof xAxisTickValues.offset === 'function' ? xAxisTickValues.offset(new Date(domain[1]), 0) : new Date(domain[1]);
1671
1686
  return scaleTime().domain([startDate, endDate]).range([0, chartWidth]).nice();
1672
1687
  } else {
1673
- return scalePoint().domain(xAxisTickValues && Array.isArray(xAxisTickValues) ? xAxisTickValues : data.map(d => d.key)).range([0, chartWidth]);
1688
+ var _ref5, _ref6;
1689
+ const domain = xAxisTickValues && Array.isArray(xAxisTickValues) ? xAxisTickValues : data.map(d => d.key);
1690
+ domain[0] = (_ref5 = xAxisMinValue) !== null && _ref5 !== void 0 ? _ref5 : domain[0];
1691
+ domain[1] = (_ref6 = xAxisMaxValue) !== null && _ref6 !== void 0 ? _ref6 : domain[1];
1692
+ return scalePoint().domain(domain).range([0, chartWidth]);
1674
1693
  }
1675
1694
  })();
1676
1695
  const scaleY = (() => {
1696
+ var _ref7, _ref8;
1677
1697
  const domain = extent(data, d => d.value);
1698
+ domain[0] = (_ref7 = yAxisMinValue) !== null && _ref7 !== void 0 ? _ref7 : domain[0];
1699
+ domain[1] = (_ref8 = yAxisMaxValue) !== null && _ref8 !== void 0 ? _ref8 : domain[1];
1700
+ if (domain[1] === 0 && domain[0] === 0) {
1701
+ domain[1] = 1;
1702
+ }
1678
1703
  return scaleLinear().domain(domain).range([chartHeight, 0]).nice();
1679
1704
  })();
1680
1705
  const xAxisTickFormat = propsXAxisTickFormat !== null && propsXAxisTickFormat !== void 0 ? propsXAxisTickFormat : xScaleType === 'Date' || xScaleType === 'dateString' ? scaleX.tickFormat() : undefined;
@@ -1716,7 +1741,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1716
1741
  });
1717
1742
  if (xScaleType) {
1718
1743
  const minimalGap = Math.min(...bars.map((bar, i) => i > 0 ? Math.abs(bar.key - bars[i - 1].key) : undefined).filter(k => k)) * 0.9;
1719
- barWidth = Math.min(chartWidth / ((scaleX.domain()[1] - scaleX.domain()[0]) / minimalGap), barWidth);
1744
+ barWidth = Math.min(barWidth, chartWidth / ((scaleX.domain()[1] - scaleX.domain()[0]) / minimalGap), chartWidth / (xAxisTickValues ? xAxisTickValues.range(scaleX.domain()[0], scaleX.domain()[1]).length : 1));
1720
1745
  }
1721
1746
  return /*#__PURE__*/React__default.createElement(StyledBarChart, _extends({}, forwardedProps, {
1722
1747
  id: id,
@@ -1770,6 +1795,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1770
1795
  tickRotation: xAxisTickRotation,
1771
1796
  tickSize: xAxisTickSize,
1772
1797
  tickFormat: xAxisTickFormat,
1798
+ tickRemodelling: xAxisTickRemodelling,
1773
1799
  variant: xAxisVariant
1774
1800
  }) : null, ['top', 'both'].includes(xAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
1775
1801
  position: "top",
@@ -1782,6 +1808,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1782
1808
  tickRotation: xAxisTickRotation,
1783
1809
  tickSize: xAxisTickSize,
1784
1810
  tickFormat: xAxisTickFormat,
1811
+ tickRemodelling: xAxisTickRemodelling,
1785
1812
  variant: xAxisVariant
1786
1813
  }) : null, ['left', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
1787
1814
  position: "left",
@@ -1794,6 +1821,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1794
1821
  tickRotation: yAxisTickRotation,
1795
1822
  tickSize: yAxisTickSize,
1796
1823
  tickFormat: yAxisTickFormat,
1824
+ tickRemodelling: yAxisTickRemodelling,
1797
1825
  variant: yAxisVariant
1798
1826
  }) : null, ['right', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
1799
1827
  position: "right",
@@ -1806,6 +1834,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1806
1834
  tickRotation: yAxisTickRotation,
1807
1835
  tickSize: yAxisTickSize,
1808
1836
  tickFormat: yAxisTickFormat,
1837
+ tickRemodelling: yAxisTickRemodelling,
1809
1838
  variant: yAxisVariant
1810
1839
  }) : null))));
1811
1840
  });
@@ -2465,7 +2494,7 @@ const EmptyLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2465
2494
  })))));
2466
2495
  });
2467
2496
 
2468
- const _excluded$9 = ["className", "data", "dotRole", "id", "isDotSelected", "labelDecorator", "legendDecorator", "legendVariant", "legendProps", "margins", "onDotClick", "size", "sortingMethod", "colorTheme", "tooltipDecorator", "tooltipVariant", "xAxisVariant", "xAxisPlacement", "xAxisTickFormat", "xAxisTickPadding", "xAxisTickRotation", "xAxisTickSize", "xAxisTickValues", "yAxisVariant", "yAxisPlacement", "yAxisTickFormat", "yAxisTickPadding", "yAxisTickRotation", "yAxisTickSize", "yAxisTickValues", "dateParser"];
2497
+ const _excluded$9 = ["className", "data", "dotRole", "id", "isDotSelected", "labelDecorator", "legendDecorator", "legendVariant", "legendProps", "margins", "onDotClick", "size", "sortingMethod", "colorTheme", "tooltipDecorator", "tooltipVariant", "xAxisVariant", "xAxisPlacement", "xAxisTickFormat", "xAxisTickPadding", "xAxisTickRotation", "xAxisTickSize", "xAxisTickValues", "xAxisMinValue", "xAxisMaxValue", "xAxisTickRemodelling", "yAxisVariant", "yAxisPlacement", "yAxisTickFormat", "yAxisTickPadding", "yAxisTickRotation", "yAxisTickSize", "yAxisTickValues", "yAxisMinValue", "yAxisMaxValue", "yAxisTickRemodelling", "dateParser"];
2469
2498
  const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2470
2499
  const {
2471
2500
  className,
@@ -2491,6 +2520,9 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2491
2520
  xAxisTickRotation,
2492
2521
  xAxisTickSize,
2493
2522
  xAxisTickValues,
2523
+ xAxisMinValue,
2524
+ xAxisMaxValue,
2525
+ xAxisTickRemodelling,
2494
2526
  yAxisVariant,
2495
2527
  yAxisPlacement,
2496
2528
  yAxisTickFormat,
@@ -2498,6 +2530,9 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2498
2530
  yAxisTickRotation,
2499
2531
  yAxisTickSize,
2500
2532
  yAxisTickValues,
2533
+ yAxisMinValue,
2534
+ yAxisMaxValue,
2535
+ yAxisTickRemodelling,
2501
2536
  dateParser
2502
2537
  } = props,
2503
2538
  forwardedProps = _objectWithoutProperties(props, _excluded$9);
@@ -2522,20 +2557,36 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2522
2557
  const chartWidth = width - margins.left - margins.right;
2523
2558
  const scaleX = (() => {
2524
2559
  if (xScaleType === 'number') {
2560
+ var _ref, _ref2;
2525
2561
  const domain = extent(data, d => d.key[0]);
2562
+ domain[0] = (_ref = xAxisMinValue) !== null && _ref !== void 0 ? _ref : domain[0];
2563
+ domain[1] = (_ref2 = xAxisMaxValue) !== null && _ref2 !== void 0 ? _ref2 : domain[1];
2526
2564
  return scaleLinear().domain(domain).range([0, chartWidth]).nice();
2527
2565
  } else if (xScaleType === 'dateString') {
2566
+ var _ref3, _ref4;
2528
2567
  const domain = extent(data, d => Date.parse(d.key[0]));
2568
+ domain[0] = (_ref3 = xAxisMinValue) !== null && _ref3 !== void 0 ? _ref3 : domain[0];
2569
+ domain[1] = (_ref4 = xAxisMaxValue) !== null && _ref4 !== void 0 ? _ref4 : domain[1];
2529
2570
  return scaleTime().domain([new Date(domain[0]), new Date(domain[1])]).range([0, chartWidth]).nice();
2530
2571
  } else if (xScaleType === 'Date') {
2572
+ var _ref5, _ref6;
2531
2573
  const domain = extent(data, d => d.key[0].valueOf());
2574
+ domain[0] = (_ref5 = xAxisMinValue) !== null && _ref5 !== void 0 ? _ref5 : domain[0];
2575
+ domain[1] = (_ref6 = xAxisMaxValue) !== null && _ref6 !== void 0 ? _ref6 : domain[1];
2532
2576
  return scaleTime().domain([new Date(domain[0]), new Date(domain[1])]).range([0, chartWidth]).nice();
2533
2577
  } else {
2534
- return scalePoint().domain(xAxisTickValues && Array.isArray(xAxisTickValues) ? xAxisTickValues : data.map(d => d.key[0])).range([0, chartWidth]);
2578
+ var _ref7, _ref8;
2579
+ const domain = xAxisTickValues && Array.isArray(xAxisTickValues) ? xAxisTickValues : data.map(d => d.key[0]);
2580
+ domain[0] = (_ref7 = xAxisMinValue) !== null && _ref7 !== void 0 ? _ref7 : domain[0];
2581
+ domain[1] = (_ref8 = xAxisMaxValue) !== null && _ref8 !== void 0 ? _ref8 : domain[1];
2582
+ return scalePoint().domain(domain).range([0, chartWidth]);
2535
2583
  }
2536
2584
  })();
2537
2585
  const scaleY = (() => {
2586
+ var _ref9, _ref10;
2538
2587
  const domain = extent(data, d => d.value);
2588
+ domain[0] = (_ref9 = yAxisMinValue) !== null && _ref9 !== void 0 ? _ref9 : domain[0];
2589
+ domain[1] = (_ref10 = yAxisMaxValue) !== null && _ref10 !== void 0 ? _ref10 : domain[1];
2539
2590
  return scaleLinear().domain(domain).range([chartHeight, 0]).nice();
2540
2591
  })();
2541
2592
  const xAxisTickFormat = propsXAxisTickFormat !== null && propsXAxisTickFormat !== void 0 ? propsXAxisTickFormat : xScaleType === 'Date' || xScaleType === 'dateString' ? scaleX.tickFormat() : undefined;
@@ -2643,6 +2694,7 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2643
2694
  tickRotation: xAxisTickRotation,
2644
2695
  tickSize: xAxisTickSize,
2645
2696
  tickFormat: xAxisTickFormat,
2697
+ tickRemodelling: xAxisTickRemodelling,
2646
2698
  variant: xAxisVariant
2647
2699
  }) : null, ['top', 'both'].includes(xAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
2648
2700
  position: "top",
@@ -2655,6 +2707,7 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2655
2707
  tickRotation: xAxisTickRotation,
2656
2708
  tickSize: xAxisTickSize,
2657
2709
  tickFormat: xAxisTickFormat,
2710
+ tickRemodelling: xAxisTickRemodelling,
2658
2711
  variant: xAxisVariant
2659
2712
  }) : null, ['left', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
2660
2713
  position: "left",
@@ -2667,6 +2720,7 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2667
2720
  tickRotation: yAxisTickRotation,
2668
2721
  tickSize: yAxisTickSize,
2669
2722
  tickFormat: yAxisTickFormat,
2723
+ tickRemodelling: yAxisTickRemodelling,
2670
2724
  variant: yAxisVariant
2671
2725
  }) : null, ['right', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
2672
2726
  position: "right",
@@ -2679,6 +2733,7 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2679
2733
  tickRotation: yAxisTickRotation,
2680
2734
  tickSize: yAxisTickSize,
2681
2735
  tickFormat: yAxisTickFormat,
2736
+ tickRemodelling: yAxisTickRemodelling,
2682
2737
  variant: yAxisVariant
2683
2738
  }) : null))), hasCategory && legendVariant !== LineChartLegendVariant.none ? /*#__PURE__*/React__default.createElement(Legend, _extends({
2684
2739
  data: statsByCategory.map(d => _objectSpread2(_objectSpread2({}, d), {}, {