tinybase 8.5.0-beta.2 → 8.5.0-beta.3

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.
@@ -71,9 +71,15 @@ var SourceType = /* @__PURE__ */ ((SourceType2) => {
71
71
  SourceType2[(SourceType2['Table'] = 2)] = 'Table';
72
72
  return SourceType2;
73
73
  })(SourceType || {});
74
- const CHART_SERIES = '_tinybaseChartSeries';
75
- const isChartSeriesComponent = (component) =>
76
- typeof component == 'function' && component[CHART_SERIES] === true;
74
+ const SERIES = '_tinybaseChartSeries';
75
+ const X_AXIS = '_tinybaseChartXAxis';
76
+ const Y_AXIS = '_tinybaseChartYAxis';
77
+ const isSeriesComponent = (component) =>
78
+ typeof component == 'function' && component[SERIES] === true;
79
+ const isXAxisComponent = (component) =>
80
+ typeof component == 'function' && component[X_AXIS] === true;
81
+ const isYAxisComponent = (component) =>
82
+ typeof component == 'function' && component[Y_AXIS] === true;
77
83
  const CartesianChartContext = createContext(null);
78
84
  const useCartesianChartContext = () => {
79
85
  const context = useContext(CartesianChartContext);
@@ -95,6 +101,7 @@ const arrayOrValueEqual = (value1, value2) =>
95
101
  isArray(value1) && isArray(value2)
96
102
  ? arrayIsEqual(value1, value2)
97
103
  : value1 === value2;
104
+ const arraySort = (array, sorter) => array.sort(sorter);
98
105
  const arrayForEach = (array, cb) => array.forEach(cb);
99
106
  const arrayJoin = (array, sep = EMPTY_STRING) => array.join(sep);
100
107
  const arrayMap = (array, cb) => array.map(cb);
@@ -300,7 +307,7 @@ const getBounds = (kind, points) => {
300
307
  }
301
308
  return [points[0]?.[1], points[size(points) - 1]?.[1], yMin, yMax];
302
309
  };
303
- const getYTicks = ([, , yMin, yMax], [, height], labelSize) => {
310
+ const getYTicks = ([, , yMin, yMax], [, height], labelSize, tickCount) => {
304
311
  if (isUndefined(yMin) || isUndefined(yMax)) {
305
312
  return [];
306
313
  }
@@ -310,26 +317,26 @@ const getYTicks = ([, , yMin, yMax], [, height], labelSize) => {
310
317
  return getTicks(
311
318
  yMin,
312
319
  yMax,
313
- TARGET_TICKS,
320
+ getTickCount(tickCount),
314
321
  labelSize,
315
322
  height,
316
323
  isInteger(yMin) && isInteger(yMax),
317
324
  );
318
325
  };
319
- const getXTicks = (kind, [xMin, xMax], [width], labelSize) =>
326
+ const getXTicks = (kind, [xMin, xMax], [width], labelSize, tickCount) =>
320
327
  kind == 'line' && isNumber(xMin) && isNumber(xMax) && xMin != xMax
321
328
  ? getTicks(
322
329
  xMin,
323
330
  xMax,
324
- TARGET_TICKS,
331
+ getTickCount(tickCount),
325
332
  labelSize,
326
333
  width,
327
334
  isInteger(xMin) && isInteger(xMax),
328
335
  )
329
336
  : [];
330
337
  const getTickBounds = ([xMin, xMax, yMin, yMax], xTicks, yTicks) => [
331
- arrayIsEmpty(xTicks) ? xMin : mathMin(xMin, xTicks[0]),
332
- arrayIsEmpty(xTicks) ? xMax : mathMax(xMax, xTicks[size(xTicks) - 1]),
338
+ arrayIsEmpty(xTicks) ? xMin : getMinTickBound(xMin, xTicks[0]),
339
+ arrayIsEmpty(xTicks) ? xMax : getMaxTickBound(xMax, xTicks[size(xTicks) - 1]),
333
340
  arrayIsEmpty(yTicks) ? yMin : mathMin(yMin ?? infinity, yTicks[0]),
334
341
  arrayIsEmpty(yTicks)
335
342
  ? yMax
@@ -408,6 +415,12 @@ const getDomain = (values) => {
408
415
  const min = mathMin(...values);
409
416
  return min == infinity ? [0, 0] : [min, mathMax(...values)];
410
417
  };
418
+ const getMinTickBound = (bound, tick) =>
419
+ isNumber(bound) ? mathMin(bound, tick) : tick;
420
+ const getMaxTickBound = (bound, tick) =>
421
+ isNumber(bound) ? mathMax(bound, tick) : tick;
422
+ const getTickCount = (tickCount = TARGET_TICKS) =>
423
+ isFiniteNumber(tickCount) ? mathMax(mathRound(tickCount), 1) : TARGET_TICKS;
411
424
  const getRounded = (value) => mathRound(value * 1e6) / 1e6;
412
425
  const getXValue = (cell) =>
413
426
  isNumber(cell)
@@ -867,7 +880,7 @@ const BarSeries = (props) => {
867
880
  }),
868
881
  });
869
882
  };
870
- BarSeries[CHART_SERIES] = true;
883
+ BarSeries[SERIES] = true;
871
884
 
872
885
  const INTEGER = /^\d+$/;
873
886
  const getPoolFunctions = () => {
@@ -952,8 +965,10 @@ const isLayoutEqual = ([chartSize1, chartStyle1], [chartSize2, chartStyle2]) =>
952
965
  arrayIsEqual(chartSize1, chartSize2) &&
953
966
  arrayIsEqual(chartStyle1, chartStyle2);
954
967
 
955
- const XAxis = ({
968
+ const XAxis$1 = ({
969
+ className,
956
970
  points,
971
+ tickFormatter,
957
972
  xTicks,
958
973
  xMin,
959
974
  xMax,
@@ -967,7 +982,7 @@ const XAxis = ({
967
982
  const [plotX, plotY, plotWidth, plotHeight] = plotFrame;
968
983
  const titleGap = mathMax(axisHeight - tickSize - tickGap - 2 * fontSize, 0);
969
984
  return /* @__PURE__ */ jsxs('g', {
970
- className: 'x',
985
+ className: getAxisClassName$1('x', className),
971
986
  dominantBaseline: 'hanging',
972
987
  textAnchor: 'middle',
973
988
  children: [
@@ -989,7 +1004,7 @@ const XAxis = ({
989
1004
  {
990
1005
  x: plotX + x,
991
1006
  y: plotY + plotHeight + tickSize + tickGap,
992
- children: string(xValue),
1007
+ children: getTickLabel(xValue, tickFormatter),
993
1008
  },
994
1009
  rowId,
995
1010
  ),
@@ -1001,7 +1016,7 @@ const XAxis = ({
1001
1016
  {
1002
1017
  x: plotX + x,
1003
1018
  y: plotY + plotHeight + tickSize + tickGap,
1004
- children: tick,
1019
+ children: getTickLabel(tick, tickFormatter),
1005
1020
  },
1006
1021
  tick,
1007
1022
  );
@@ -1016,8 +1031,14 @@ const XAxis = ({
1016
1031
  ],
1017
1032
  });
1018
1033
  };
1034
+ const getAxisClassName$1 = (baseClassName, className) =>
1035
+ className == null ? baseClassName : `${baseClassName} ${className}`;
1036
+ const getTickLabel = (tick, tickFormatter) =>
1037
+ tickFormatter?.(tick) ?? string(tick);
1019
1038
 
1020
- const YAxis = ({
1039
+ const YAxis$1 = ({
1040
+ className,
1041
+ tickFormatter,
1021
1042
  yTicks,
1022
1043
  yMin,
1023
1044
  yMax,
@@ -1031,7 +1052,7 @@ const YAxis = ({
1031
1052
  return isNullish(yMin) || isNullish(yMax)
1032
1053
  ? null
1033
1054
  : /* @__PURE__ */ jsxs('g', {
1034
- className: 'y',
1055
+ className: getAxisClassName('y', className),
1035
1056
  children: [
1036
1057
  /* @__PURE__ */ jsx('path', {
1037
1058
  className: 'line',
@@ -1049,7 +1070,11 @@ const YAxis = ({
1049
1070
  const y = plotHeight - getScale(tick, yMin, yMax, plotHeight);
1050
1071
  return /* @__PURE__ */ jsx(
1051
1072
  'text',
1052
- {x: plotX - tickSize - tickGap, y: plotY + y, children: tick},
1073
+ {
1074
+ x: plotX - tickSize - tickGap,
1075
+ y: plotY + y,
1076
+ children: tickFormatter?.(tick) ?? string(tick),
1077
+ },
1053
1078
  tick,
1054
1079
  );
1055
1080
  }),
@@ -1064,8 +1089,12 @@ const YAxis = ({
1064
1089
  ],
1065
1090
  });
1066
1091
  };
1092
+ const getAxisClassName = (baseClassName, className) =>
1093
+ className == null ? baseClassName : `${baseClassName} ${className}`;
1067
1094
 
1068
1095
  const Axes = ({
1096
+ xAxis,
1097
+ yAxis,
1069
1098
  points,
1070
1099
  xTicks,
1071
1100
  yTicks,
@@ -1081,17 +1110,21 @@ const Axes = ({
1081
1110
  fill: CURRENT_COLOR,
1082
1111
  fillOpacity: 0.75,
1083
1112
  children: [
1084
- /* @__PURE__ */ jsx(YAxis, {
1113
+ /* @__PURE__ */ jsx(YAxis$1, {
1085
1114
  ...sharedProps,
1115
+ className: yAxis?.className,
1116
+ tickFormatter: yAxis?.tickFormatter,
1086
1117
  yTicks,
1087
1118
  yMin,
1088
1119
  yMax,
1089
1120
  yTitle,
1090
1121
  axisWidth: yAxisWidth,
1091
1122
  }),
1092
- /* @__PURE__ */ jsx(XAxis, {
1123
+ /* @__PURE__ */ jsx(XAxis$1, {
1093
1124
  ...sharedProps,
1125
+ className: xAxis?.className,
1094
1126
  points,
1127
+ tickFormatter: xAxis?.tickFormatter,
1095
1128
  xTicks,
1096
1129
  xMin,
1097
1130
  xMax,
@@ -1278,12 +1311,21 @@ const CartesianChart = ({
1278
1311
  const barSeriesIdsRef = useRef([]);
1279
1312
  const [barSeriesIds, setBarSeriesIds] = useState([]);
1280
1313
  const [tooltipPoint, setTooltipPoint] = useState();
1314
+ const [chartChildren, xAxis, yAxis] = getParsedChildren(children);
1281
1315
  const xValues = domainState.xValues;
1282
- const dataBounds = domainState.bounds;
1283
- const axisKind =
1284
- domainState.continuousX || arrayIsEmpty(barSeriesIds) ? 'line' : 'bar';
1285
- const xTicks = getXTicks(axisKind, dataBounds, plotSize, labelSize);
1286
- const yTicks = getYTicks(dataBounds, plotSize, labelSize);
1316
+ const numericX =
1317
+ domainState.continuousX ||
1318
+ (arrayIsEmpty(xValues) && hasNumericXAxisDefinition(xAxis));
1319
+ const dataBounds = getAxisBounds(domainState.bounds, numericX, xAxis, yAxis);
1320
+ const axisKind = numericX || arrayIsEmpty(barSeriesIds) ? 'line' : 'bar';
1321
+ const xTicks =
1322
+ numericX && xAxis?.ticks != null
1323
+ ? getAxisTicks(xAxis.ticks)
1324
+ : getXTicks(axisKind, dataBounds, plotSize, labelSize, xAxis?.tickCount);
1325
+ const yTicks =
1326
+ yAxis?.ticks == null
1327
+ ? getYTicks(dataBounds, plotSize, labelSize, yAxis?.tickCount)
1328
+ : getAxisTicks(yAxis.ticks);
1287
1329
  const tickBounds = getTickBounds(dataBounds, xTicks, yTicks);
1288
1330
  const axisPoints = getScaledPoints(
1289
1331
  axisKind,
@@ -1469,21 +1511,20 @@ const CartesianChart = ({
1469
1511
  plotFrame,
1470
1512
  tickGap,
1471
1513
  tickSize,
1472
- titles: [xTitle, yTitle],
1514
+ titles: [xAxis?.title ?? xTitle, yAxis?.title ?? yTitle],
1515
+ xAxis,
1473
1516
  xAxisHeight,
1474
1517
  xTicks,
1518
+ yAxis,
1475
1519
  yAxisWidth,
1476
1520
  yTicks,
1477
1521
  }),
1478
- /* @__PURE__ */ jsx('g', {
1479
- className: 'plot',
1480
- children: getChartChildren(children),
1481
- }),
1522
+ /* @__PURE__ */ jsx('g', {className: 'plot', children: chartChildren}),
1482
1523
  /* @__PURE__ */ jsx(Tooltip, {
1483
1524
  height: plotSize[1],
1484
1525
  point: tooltipPoint,
1485
1526
  plotFrame,
1486
- titles: [xTitle, yTitle],
1527
+ titles: [xAxis?.title ?? xTitle, yAxis?.title ?? yTitle],
1487
1528
  width: plotSize[0],
1488
1529
  }),
1489
1530
  ],
@@ -1541,20 +1582,48 @@ const getTitle = (summaryById, cellIdType) => {
1541
1582
  });
1542
1583
  return arrayIsEmpty(titles) ? '' : titles.join(' & ');
1543
1584
  };
1544
- const getChartChildren = (children) => {
1585
+ const getAxisBounds = ([xMin, xMax, yMin, yMax], numericX, xAxis, yAxis) => [
1586
+ numericX ? getAxisBound(xAxis?.min, xMin) : xMin,
1587
+ numericX ? getAxisBound(xAxis?.max, xMax) : xMax,
1588
+ getNumberAxisBound(yAxis?.min, yMin),
1589
+ getNumberAxisBound(yAxis?.max, yMax),
1590
+ ];
1591
+ const getAxisBound = (value, bound) => (isFiniteNumber(value) ? value : bound);
1592
+ const getNumberAxisBound = (value, bound) =>
1593
+ isFiniteNumber(value) ? value : bound;
1594
+ const getAxisTicks = (ticks) =>
1595
+ arraySort(arrayFilter([...ticks], isFiniteNumber), (tick1, tick2) => {
1596
+ return tick1 - tick2;
1597
+ });
1598
+ const hasNumericXAxisDefinition = (xAxis) =>
1599
+ isFiniteNumber(xAxis?.min) ||
1600
+ isFiniteNumber(xAxis?.max) ||
1601
+ xAxis?.ticks != null;
1602
+ const getParsedChildren = (children) => {
1545
1603
  const chartChildren = [];
1604
+ let xAxis;
1605
+ let yAxis;
1546
1606
  Children.forEach(children, (child) => {
1547
1607
  if (isValidElement(child)) {
1548
1608
  if (child.type === Fragment) {
1549
- arrayForEach(getChartChildren(child.props.children), (chartChild) =>
1609
+ const [childChildren, childXAxis, childYAxis] = getParsedChildren(
1610
+ child.props.children,
1611
+ );
1612
+ arrayForEach(childChildren, (chartChild) =>
1550
1613
  arrayPush(chartChildren, chartChild),
1551
1614
  );
1552
- } else if (isChartSeriesComponent(child.type)) {
1615
+ xAxis ??= childXAxis;
1616
+ yAxis ??= childYAxis;
1617
+ } else if (isSeriesComponent(child.type)) {
1553
1618
  arrayPush(chartChildren, child);
1619
+ } else if (xAxis == null && isXAxisComponent(child.type)) {
1620
+ xAxis = child.props;
1621
+ } else if (yAxis == null && isYAxisComponent(child.type)) {
1622
+ yAxis = child.props;
1554
1623
  }
1555
1624
  }
1556
1625
  });
1557
- return chartChildren;
1626
+ return [chartChildren, xAxis, yAxis];
1558
1627
  };
1559
1628
 
1560
1629
  const useInitialSeriesSummary = (
@@ -1746,7 +1815,7 @@ const LineSeries = (props) => {
1746
1815
  }),
1747
1816
  });
1748
1817
  };
1749
- LineSeries[CHART_SERIES] = true;
1818
+ LineSeries[SERIES] = true;
1750
1819
 
1751
1820
  const LineChart = (props) => {
1752
1821
  const initialSummary = useInitialSeriesSummary('line', props);
@@ -1780,4 +1849,18 @@ const getSeriesProps = ({
1780
1849
  yCellId,
1781
1850
  });
1782
1851
 
1783
- export {BarChart, BarSeries, CartesianChart, LineChart, LineSeries};
1852
+ const XAxis = () => null;
1853
+ XAxis[X_AXIS] = true;
1854
+
1855
+ const YAxis = () => null;
1856
+ YAxis[Y_AXIS] = true;
1857
+
1858
+ export {
1859
+ BarChart,
1860
+ BarSeries,
1861
+ CartesianChart,
1862
+ LineChart,
1863
+ LineSeries,
1864
+ XAxis,
1865
+ YAxis,
1866
+ };
@@ -71,9 +71,15 @@ var SourceType = /* @__PURE__ */ ((SourceType2) => {
71
71
  SourceType2[(SourceType2['Table'] = 2)] = 'Table';
72
72
  return SourceType2;
73
73
  })(SourceType || {});
74
- const CHART_SERIES = '_tinybaseChartSeries';
75
- const isChartSeriesComponent = (component) =>
76
- typeof component == 'function' && component[CHART_SERIES] === true;
74
+ const SERIES = '_tinybaseChartSeries';
75
+ const X_AXIS = '_tinybaseChartXAxis';
76
+ const Y_AXIS = '_tinybaseChartYAxis';
77
+ const isSeriesComponent = (component) =>
78
+ typeof component == 'function' && component[SERIES] === true;
79
+ const isXAxisComponent = (component) =>
80
+ typeof component == 'function' && component[X_AXIS] === true;
81
+ const isYAxisComponent = (component) =>
82
+ typeof component == 'function' && component[Y_AXIS] === true;
77
83
  const CartesianChartContext = createContext(null);
78
84
  const useCartesianChartContext = () => {
79
85
  const context = useContext(CartesianChartContext);
@@ -95,6 +101,7 @@ const arrayOrValueEqual = (value1, value2) =>
95
101
  isArray(value1) && isArray(value2)
96
102
  ? arrayIsEqual(value1, value2)
97
103
  : value1 === value2;
104
+ const arraySort = (array, sorter) => array.sort(sorter);
98
105
  const arrayForEach = (array, cb) => array.forEach(cb);
99
106
  const arrayJoin = (array, sep = EMPTY_STRING) => array.join(sep);
100
107
  const arrayMap = (array, cb) => array.map(cb);
@@ -300,7 +307,7 @@ const getBounds = (kind, points) => {
300
307
  }
301
308
  return [points[0]?.[1], points[size(points) - 1]?.[1], yMin, yMax];
302
309
  };
303
- const getYTicks = ([, , yMin, yMax], [, height], labelSize) => {
310
+ const getYTicks = ([, , yMin, yMax], [, height], labelSize, tickCount) => {
304
311
  if (isUndefined(yMin) || isUndefined(yMax)) {
305
312
  return [];
306
313
  }
@@ -310,26 +317,26 @@ const getYTicks = ([, , yMin, yMax], [, height], labelSize) => {
310
317
  return getTicks(
311
318
  yMin,
312
319
  yMax,
313
- TARGET_TICKS,
320
+ getTickCount(tickCount),
314
321
  labelSize,
315
322
  height,
316
323
  isInteger(yMin) && isInteger(yMax),
317
324
  );
318
325
  };
319
- const getXTicks = (kind, [xMin, xMax], [width], labelSize) =>
326
+ const getXTicks = (kind, [xMin, xMax], [width], labelSize, tickCount) =>
320
327
  kind == 'line' && isNumber(xMin) && isNumber(xMax) && xMin != xMax
321
328
  ? getTicks(
322
329
  xMin,
323
330
  xMax,
324
- TARGET_TICKS,
331
+ getTickCount(tickCount),
325
332
  labelSize,
326
333
  width,
327
334
  isInteger(xMin) && isInteger(xMax),
328
335
  )
329
336
  : [];
330
337
  const getTickBounds = ([xMin, xMax, yMin, yMax], xTicks, yTicks) => [
331
- arrayIsEmpty(xTicks) ? xMin : mathMin(xMin, xTicks[0]),
332
- arrayIsEmpty(xTicks) ? xMax : mathMax(xMax, xTicks[size(xTicks) - 1]),
338
+ arrayIsEmpty(xTicks) ? xMin : getMinTickBound(xMin, xTicks[0]),
339
+ arrayIsEmpty(xTicks) ? xMax : getMaxTickBound(xMax, xTicks[size(xTicks) - 1]),
333
340
  arrayIsEmpty(yTicks) ? yMin : mathMin(yMin ?? infinity, yTicks[0]),
334
341
  arrayIsEmpty(yTicks)
335
342
  ? yMax
@@ -408,6 +415,12 @@ const getDomain = (values) => {
408
415
  const min = mathMin(...values);
409
416
  return min == infinity ? [0, 0] : [min, mathMax(...values)];
410
417
  };
418
+ const getMinTickBound = (bound, tick) =>
419
+ isNumber(bound) ? mathMin(bound, tick) : tick;
420
+ const getMaxTickBound = (bound, tick) =>
421
+ isNumber(bound) ? mathMax(bound, tick) : tick;
422
+ const getTickCount = (tickCount = TARGET_TICKS) =>
423
+ isFiniteNumber(tickCount) ? mathMax(mathRound(tickCount), 1) : TARGET_TICKS;
411
424
  const getRounded = (value) => mathRound(value * 1e6) / 1e6;
412
425
  const getXValue = (cell) =>
413
426
  isNumber(cell)
@@ -867,7 +880,7 @@ const BarSeries = (props) => {
867
880
  }),
868
881
  });
869
882
  };
870
- BarSeries[CHART_SERIES] = true;
883
+ BarSeries[SERIES] = true;
871
884
 
872
885
  const INTEGER = /^\d+$/;
873
886
  const getPoolFunctions = () => {
@@ -952,8 +965,10 @@ const isLayoutEqual = ([chartSize1, chartStyle1], [chartSize2, chartStyle2]) =>
952
965
  arrayIsEqual(chartSize1, chartSize2) &&
953
966
  arrayIsEqual(chartStyle1, chartStyle2);
954
967
 
955
- const XAxis = ({
968
+ const XAxis$1 = ({
969
+ className,
956
970
  points,
971
+ tickFormatter,
957
972
  xTicks,
958
973
  xMin,
959
974
  xMax,
@@ -967,7 +982,7 @@ const XAxis = ({
967
982
  const [plotX, plotY, plotWidth, plotHeight] = plotFrame;
968
983
  const titleGap = mathMax(axisHeight - tickSize - tickGap - 2 * fontSize, 0);
969
984
  return /* @__PURE__ */ jsxs('g', {
970
- className: 'x',
985
+ className: getAxisClassName$1('x', className),
971
986
  dominantBaseline: 'hanging',
972
987
  textAnchor: 'middle',
973
988
  children: [
@@ -989,7 +1004,7 @@ const XAxis = ({
989
1004
  {
990
1005
  x: plotX + x,
991
1006
  y: plotY + plotHeight + tickSize + tickGap,
992
- children: string(xValue),
1007
+ children: getTickLabel(xValue, tickFormatter),
993
1008
  },
994
1009
  rowId,
995
1010
  ),
@@ -1001,7 +1016,7 @@ const XAxis = ({
1001
1016
  {
1002
1017
  x: plotX + x,
1003
1018
  y: plotY + plotHeight + tickSize + tickGap,
1004
- children: tick,
1019
+ children: getTickLabel(tick, tickFormatter),
1005
1020
  },
1006
1021
  tick,
1007
1022
  );
@@ -1016,8 +1031,14 @@ const XAxis = ({
1016
1031
  ],
1017
1032
  });
1018
1033
  };
1034
+ const getAxisClassName$1 = (baseClassName, className) =>
1035
+ className == null ? baseClassName : `${baseClassName} ${className}`;
1036
+ const getTickLabel = (tick, tickFormatter) =>
1037
+ tickFormatter?.(tick) ?? string(tick);
1019
1038
 
1020
- const YAxis = ({
1039
+ const YAxis$1 = ({
1040
+ className,
1041
+ tickFormatter,
1021
1042
  yTicks,
1022
1043
  yMin,
1023
1044
  yMax,
@@ -1031,7 +1052,7 @@ const YAxis = ({
1031
1052
  return isNullish(yMin) || isNullish(yMax)
1032
1053
  ? null
1033
1054
  : /* @__PURE__ */ jsxs('g', {
1034
- className: 'y',
1055
+ className: getAxisClassName('y', className),
1035
1056
  children: [
1036
1057
  /* @__PURE__ */ jsx('path', {
1037
1058
  className: 'line',
@@ -1049,7 +1070,11 @@ const YAxis = ({
1049
1070
  const y = plotHeight - getScale(tick, yMin, yMax, plotHeight);
1050
1071
  return /* @__PURE__ */ jsx(
1051
1072
  'text',
1052
- {x: plotX - tickSize - tickGap, y: plotY + y, children: tick},
1073
+ {
1074
+ x: plotX - tickSize - tickGap,
1075
+ y: plotY + y,
1076
+ children: tickFormatter?.(tick) ?? string(tick),
1077
+ },
1053
1078
  tick,
1054
1079
  );
1055
1080
  }),
@@ -1064,8 +1089,12 @@ const YAxis = ({
1064
1089
  ],
1065
1090
  });
1066
1091
  };
1092
+ const getAxisClassName = (baseClassName, className) =>
1093
+ className == null ? baseClassName : `${baseClassName} ${className}`;
1067
1094
 
1068
1095
  const Axes = ({
1096
+ xAxis,
1097
+ yAxis,
1069
1098
  points,
1070
1099
  xTicks,
1071
1100
  yTicks,
@@ -1081,17 +1110,21 @@ const Axes = ({
1081
1110
  fill: CURRENT_COLOR,
1082
1111
  fillOpacity: 0.75,
1083
1112
  children: [
1084
- /* @__PURE__ */ jsx(YAxis, {
1113
+ /* @__PURE__ */ jsx(YAxis$1, {
1085
1114
  ...sharedProps,
1115
+ className: yAxis?.className,
1116
+ tickFormatter: yAxis?.tickFormatter,
1086
1117
  yTicks,
1087
1118
  yMin,
1088
1119
  yMax,
1089
1120
  yTitle,
1090
1121
  axisWidth: yAxisWidth,
1091
1122
  }),
1092
- /* @__PURE__ */ jsx(XAxis, {
1123
+ /* @__PURE__ */ jsx(XAxis$1, {
1093
1124
  ...sharedProps,
1125
+ className: xAxis?.className,
1094
1126
  points,
1127
+ tickFormatter: xAxis?.tickFormatter,
1095
1128
  xTicks,
1096
1129
  xMin,
1097
1130
  xMax,
@@ -1278,12 +1311,21 @@ const CartesianChart = ({
1278
1311
  const barSeriesIdsRef = useRef([]);
1279
1312
  const [barSeriesIds, setBarSeriesIds] = useState([]);
1280
1313
  const [tooltipPoint, setTooltipPoint] = useState();
1314
+ const [chartChildren, xAxis, yAxis] = getParsedChildren(children);
1281
1315
  const xValues = domainState.xValues;
1282
- const dataBounds = domainState.bounds;
1283
- const axisKind =
1284
- domainState.continuousX || arrayIsEmpty(barSeriesIds) ? 'line' : 'bar';
1285
- const xTicks = getXTicks(axisKind, dataBounds, plotSize, labelSize);
1286
- const yTicks = getYTicks(dataBounds, plotSize, labelSize);
1316
+ const numericX =
1317
+ domainState.continuousX ||
1318
+ (arrayIsEmpty(xValues) && hasNumericXAxisDefinition(xAxis));
1319
+ const dataBounds = getAxisBounds(domainState.bounds, numericX, xAxis, yAxis);
1320
+ const axisKind = numericX || arrayIsEmpty(barSeriesIds) ? 'line' : 'bar';
1321
+ const xTicks =
1322
+ numericX && xAxis?.ticks != null
1323
+ ? getAxisTicks(xAxis.ticks)
1324
+ : getXTicks(axisKind, dataBounds, plotSize, labelSize, xAxis?.tickCount);
1325
+ const yTicks =
1326
+ yAxis?.ticks == null
1327
+ ? getYTicks(dataBounds, plotSize, labelSize, yAxis?.tickCount)
1328
+ : getAxisTicks(yAxis.ticks);
1287
1329
  const tickBounds = getTickBounds(dataBounds, xTicks, yTicks);
1288
1330
  const axisPoints = getScaledPoints(
1289
1331
  axisKind,
@@ -1469,21 +1511,20 @@ const CartesianChart = ({
1469
1511
  plotFrame,
1470
1512
  tickGap,
1471
1513
  tickSize,
1472
- titles: [xTitle, yTitle],
1514
+ titles: [xAxis?.title ?? xTitle, yAxis?.title ?? yTitle],
1515
+ xAxis,
1473
1516
  xAxisHeight,
1474
1517
  xTicks,
1518
+ yAxis,
1475
1519
  yAxisWidth,
1476
1520
  yTicks,
1477
1521
  }),
1478
- /* @__PURE__ */ jsx('g', {
1479
- className: 'plot',
1480
- children: getChartChildren(children),
1481
- }),
1522
+ /* @__PURE__ */ jsx('g', {className: 'plot', children: chartChildren}),
1482
1523
  /* @__PURE__ */ jsx(Tooltip, {
1483
1524
  height: plotSize[1],
1484
1525
  point: tooltipPoint,
1485
1526
  plotFrame,
1486
- titles: [xTitle, yTitle],
1527
+ titles: [xAxis?.title ?? xTitle, yAxis?.title ?? yTitle],
1487
1528
  width: plotSize[0],
1488
1529
  }),
1489
1530
  ],
@@ -1541,20 +1582,48 @@ const getTitle = (summaryById, cellIdType) => {
1541
1582
  });
1542
1583
  return arrayIsEmpty(titles) ? '' : titles.join(' & ');
1543
1584
  };
1544
- const getChartChildren = (children) => {
1585
+ const getAxisBounds = ([xMin, xMax, yMin, yMax], numericX, xAxis, yAxis) => [
1586
+ numericX ? getAxisBound(xAxis?.min, xMin) : xMin,
1587
+ numericX ? getAxisBound(xAxis?.max, xMax) : xMax,
1588
+ getNumberAxisBound(yAxis?.min, yMin),
1589
+ getNumberAxisBound(yAxis?.max, yMax),
1590
+ ];
1591
+ const getAxisBound = (value, bound) => (isFiniteNumber(value) ? value : bound);
1592
+ const getNumberAxisBound = (value, bound) =>
1593
+ isFiniteNumber(value) ? value : bound;
1594
+ const getAxisTicks = (ticks) =>
1595
+ arraySort(arrayFilter([...ticks], isFiniteNumber), (tick1, tick2) => {
1596
+ return tick1 - tick2;
1597
+ });
1598
+ const hasNumericXAxisDefinition = (xAxis) =>
1599
+ isFiniteNumber(xAxis?.min) ||
1600
+ isFiniteNumber(xAxis?.max) ||
1601
+ xAxis?.ticks != null;
1602
+ const getParsedChildren = (children) => {
1545
1603
  const chartChildren = [];
1604
+ let xAxis;
1605
+ let yAxis;
1546
1606
  Children.forEach(children, (child) => {
1547
1607
  if (isValidElement(child)) {
1548
1608
  if (child.type === Fragment) {
1549
- arrayForEach(getChartChildren(child.props.children), (chartChild) =>
1609
+ const [childChildren, childXAxis, childYAxis] = getParsedChildren(
1610
+ child.props.children,
1611
+ );
1612
+ arrayForEach(childChildren, (chartChild) =>
1550
1613
  arrayPush(chartChildren, chartChild),
1551
1614
  );
1552
- } else if (isChartSeriesComponent(child.type)) {
1615
+ xAxis ??= childXAxis;
1616
+ yAxis ??= childYAxis;
1617
+ } else if (isSeriesComponent(child.type)) {
1553
1618
  arrayPush(chartChildren, child);
1619
+ } else if (xAxis == null && isXAxisComponent(child.type)) {
1620
+ xAxis = child.props;
1621
+ } else if (yAxis == null && isYAxisComponent(child.type)) {
1622
+ yAxis = child.props;
1554
1623
  }
1555
1624
  }
1556
1625
  });
1557
- return chartChildren;
1626
+ return [chartChildren, xAxis, yAxis];
1558
1627
  };
1559
1628
 
1560
1629
  const useInitialSeriesSummary = (
@@ -1746,7 +1815,7 @@ const LineSeries = (props) => {
1746
1815
  }),
1747
1816
  });
1748
1817
  };
1749
- LineSeries[CHART_SERIES] = true;
1818
+ LineSeries[SERIES] = true;
1750
1819
 
1751
1820
  const LineChart = (props) => {
1752
1821
  const initialSummary = useInitialSeriesSummary('line', props);
@@ -1780,4 +1849,18 @@ const getSeriesProps = ({
1780
1849
  yCellId,
1781
1850
  });
1782
1851
 
1783
- export {BarChart, BarSeries, CartesianChart, LineChart, LineSeries};
1852
+ const XAxis = () => null;
1853
+ XAxis[X_AXIS] = true;
1854
+
1855
+ const YAxis = () => null;
1856
+ YAxis[Y_AXIS] = true;
1857
+
1858
+ export {
1859
+ BarChart,
1860
+ BarSeries,
1861
+ CartesianChart,
1862
+ LineChart,
1863
+ LineSeries,
1864
+ XAxis,
1865
+ YAxis,
1866
+ };