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

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,35 @@ 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];
1678
1700
  return scaleLinear().domain(domain).range([chartHeight, 0]).nice();
1679
1701
  })();
1680
1702
  const xAxisTickFormat = propsXAxisTickFormat !== null && propsXAxisTickFormat !== void 0 ? propsXAxisTickFormat : xScaleType === 'Date' || xScaleType === 'dateString' ? scaleX.tickFormat() : undefined;
@@ -1716,7 +1738,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1716
1738
  });
1717
1739
  if (xScaleType) {
1718
1740
  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);
1741
+ 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
1742
  }
1721
1743
  return /*#__PURE__*/React__default.createElement(StyledBarChart, _extends({}, forwardedProps, {
1722
1744
  id: id,
@@ -1770,6 +1792,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1770
1792
  tickRotation: xAxisTickRotation,
1771
1793
  tickSize: xAxisTickSize,
1772
1794
  tickFormat: xAxisTickFormat,
1795
+ tickRemodelling: xAxisTickRemodelling,
1773
1796
  variant: xAxisVariant
1774
1797
  }) : null, ['top', 'both'].includes(xAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
1775
1798
  position: "top",
@@ -1782,6 +1805,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1782
1805
  tickRotation: xAxisTickRotation,
1783
1806
  tickSize: xAxisTickSize,
1784
1807
  tickFormat: xAxisTickFormat,
1808
+ tickRemodelling: xAxisTickRemodelling,
1785
1809
  variant: xAxisVariant
1786
1810
  }) : null, ['left', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
1787
1811
  position: "left",
@@ -1794,6 +1818,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1794
1818
  tickRotation: yAxisTickRotation,
1795
1819
  tickSize: yAxisTickSize,
1796
1820
  tickFormat: yAxisTickFormat,
1821
+ tickRemodelling: yAxisTickRemodelling,
1797
1822
  variant: yAxisVariant
1798
1823
  }) : null, ['right', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
1799
1824
  position: "right",
@@ -1806,6 +1831,7 @@ const RenderedLinearBarChart = /*#__PURE__*/forwardRef((props, ref) => {
1806
1831
  tickRotation: yAxisTickRotation,
1807
1832
  tickSize: yAxisTickSize,
1808
1833
  tickFormat: yAxisTickFormat,
1834
+ tickRemodelling: yAxisTickRemodelling,
1809
1835
  variant: yAxisVariant
1810
1836
  }) : null))));
1811
1837
  });
@@ -2465,7 +2491,7 @@ const EmptyLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2465
2491
  })))));
2466
2492
  });
2467
2493
 
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"];
2494
+ 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
2495
  const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2470
2496
  const {
2471
2497
  className,
@@ -2491,6 +2517,9 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2491
2517
  xAxisTickRotation,
2492
2518
  xAxisTickSize,
2493
2519
  xAxisTickValues,
2520
+ xAxisMinValue,
2521
+ xAxisMaxValue,
2522
+ xAxisTickRemodelling,
2494
2523
  yAxisVariant,
2495
2524
  yAxisPlacement,
2496
2525
  yAxisTickFormat,
@@ -2498,6 +2527,9 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2498
2527
  yAxisTickRotation,
2499
2528
  yAxisTickSize,
2500
2529
  yAxisTickValues,
2530
+ yAxisMinValue,
2531
+ yAxisMaxValue,
2532
+ yAxisTickRemodelling,
2501
2533
  dateParser
2502
2534
  } = props,
2503
2535
  forwardedProps = _objectWithoutProperties(props, _excluded$9);
@@ -2522,20 +2554,36 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2522
2554
  const chartWidth = width - margins.left - margins.right;
2523
2555
  const scaleX = (() => {
2524
2556
  if (xScaleType === 'number') {
2557
+ var _ref, _ref2;
2525
2558
  const domain = extent(data, d => d.key[0]);
2559
+ domain[0] = (_ref = xAxisMinValue) !== null && _ref !== void 0 ? _ref : domain[0];
2560
+ domain[1] = (_ref2 = xAxisMaxValue) !== null && _ref2 !== void 0 ? _ref2 : domain[1];
2526
2561
  return scaleLinear().domain(domain).range([0, chartWidth]).nice();
2527
2562
  } else if (xScaleType === 'dateString') {
2563
+ var _ref3, _ref4;
2528
2564
  const domain = extent(data, d => Date.parse(d.key[0]));
2565
+ domain[0] = (_ref3 = xAxisMinValue) !== null && _ref3 !== void 0 ? _ref3 : domain[0];
2566
+ domain[1] = (_ref4 = xAxisMaxValue) !== null && _ref4 !== void 0 ? _ref4 : domain[1];
2529
2567
  return scaleTime().domain([new Date(domain[0]), new Date(domain[1])]).range([0, chartWidth]).nice();
2530
2568
  } else if (xScaleType === 'Date') {
2569
+ var _ref5, _ref6;
2531
2570
  const domain = extent(data, d => d.key[0].valueOf());
2571
+ domain[0] = (_ref5 = xAxisMinValue) !== null && _ref5 !== void 0 ? _ref5 : domain[0];
2572
+ domain[1] = (_ref6 = xAxisMaxValue) !== null && _ref6 !== void 0 ? _ref6 : domain[1];
2532
2573
  return scaleTime().domain([new Date(domain[0]), new Date(domain[1])]).range([0, chartWidth]).nice();
2533
2574
  } else {
2534
- return scalePoint().domain(xAxisTickValues && Array.isArray(xAxisTickValues) ? xAxisTickValues : data.map(d => d.key[0])).range([0, chartWidth]);
2575
+ var _ref7, _ref8;
2576
+ const domain = xAxisTickValues && Array.isArray(xAxisTickValues) ? xAxisTickValues : data.map(d => d.key[0]);
2577
+ domain[0] = (_ref7 = xAxisMinValue) !== null && _ref7 !== void 0 ? _ref7 : domain[0];
2578
+ domain[1] = (_ref8 = xAxisMaxValue) !== null && _ref8 !== void 0 ? _ref8 : domain[1];
2579
+ return scalePoint().domain(domain).range([0, chartWidth]);
2535
2580
  }
2536
2581
  })();
2537
2582
  const scaleY = (() => {
2583
+ var _ref9, _ref10;
2538
2584
  const domain = extent(data, d => d.value);
2585
+ domain[0] = (_ref9 = yAxisMinValue) !== null && _ref9 !== void 0 ? _ref9 : domain[0];
2586
+ domain[1] = (_ref10 = yAxisMaxValue) !== null && _ref10 !== void 0 ? _ref10 : domain[1];
2539
2587
  return scaleLinear().domain(domain).range([chartHeight, 0]).nice();
2540
2588
  })();
2541
2589
  const xAxisTickFormat = propsXAxisTickFormat !== null && propsXAxisTickFormat !== void 0 ? propsXAxisTickFormat : xScaleType === 'Date' || xScaleType === 'dateString' ? scaleX.tickFormat() : undefined;
@@ -2643,6 +2691,7 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2643
2691
  tickRotation: xAxisTickRotation,
2644
2692
  tickSize: xAxisTickSize,
2645
2693
  tickFormat: xAxisTickFormat,
2694
+ tickRemodelling: xAxisTickRemodelling,
2646
2695
  variant: xAxisVariant
2647
2696
  }) : null, ['top', 'both'].includes(xAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
2648
2697
  position: "top",
@@ -2655,6 +2704,7 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2655
2704
  tickRotation: xAxisTickRotation,
2656
2705
  tickSize: xAxisTickSize,
2657
2706
  tickFormat: xAxisTickFormat,
2707
+ tickRemodelling: xAxisTickRemodelling,
2658
2708
  variant: xAxisVariant
2659
2709
  }) : null, ['left', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
2660
2710
  position: "left",
@@ -2667,6 +2717,7 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2667
2717
  tickRotation: yAxisTickRotation,
2668
2718
  tickSize: yAxisTickSize,
2669
2719
  tickFormat: yAxisTickFormat,
2720
+ tickRemodelling: yAxisTickRemodelling,
2670
2721
  variant: yAxisVariant
2671
2722
  }) : null, ['right', 'both'].includes(yAxisPlacement) ? /*#__PURE__*/React__default.createElement(Axis, {
2672
2723
  position: "right",
@@ -2679,6 +2730,7 @@ const RenderedLineChart = /*#__PURE__*/forwardRef((props, ref) => {
2679
2730
  tickRotation: yAxisTickRotation,
2680
2731
  tickSize: yAxisTickSize,
2681
2732
  tickFormat: yAxisTickFormat,
2733
+ tickRemodelling: yAxisTickRemodelling,
2682
2734
  variant: yAxisVariant
2683
2735
  }) : null))), hasCategory && legendVariant !== LineChartLegendVariant.none ? /*#__PURE__*/React__default.createElement(Legend, _extends({
2684
2736
  data: statsByCategory.map(d => _objectSpread2(_objectSpread2({}, d), {}, {