@oliasoft-open-source/charts-library 5.15.0-beta-1 → 5.15.0-beta-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/dist/index.js CHANGED
@@ -19877,7 +19877,7 @@ var isGreaterThanMin = (value, min) => {
19877
19877
  * @param {boolean} [hasMultiAxes] - optional, false by default
19878
19878
  * @return {string} - e.g. x if chart has singular axes; x, x2 - in case of multiple axes
19879
19879
  */
19880
- var generateAxisId = (axisType, index = 0, hasMultiAxes = false) => {
19880
+ var generateAxisId$1 = (axisType, index = 0, hasMultiAxes = false) => {
19881
19881
  return `${axisType}${hasMultiAxes && index !== 0 ? index + 1 : ""}`;
19882
19882
  };
19883
19883
  /**
@@ -19987,7 +19987,7 @@ var useChartFunctions = ({ chartRef, state, options, dispatch }) => {
19987
19987
  if (!axes[axisType] || !axes[axisType]?.length) return [];
19988
19988
  else return axes[axisType].map((axisObj, index) => {
19989
19989
  return {
19990
- id: generateAxisId(axisType, index, axes[axisType].length > 1),
19990
+ id: generateAxisId$1(axisType, index, axes[axisType].length > 1),
19991
19991
  label: axisObj?.label || ""
19992
19992
  };
19993
19993
  });
@@ -20801,48 +20801,33 @@ var formatAxisLabelNumbers = (tickValue, ticks) => {
20801
20801
  });
20802
20802
  };
20803
20803
  //#endregion
20804
- //#region src/components/line-chart/utils/get-line-chart-scales.ts
20805
- var getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
20806
- const axisData = currentScales || options.axes[axisType][0] || {};
20807
- const stateAxis = state?.axes.filter((axis) => axis?.id?.startsWith(axisType))[i];
20808
- const axisKey = generateAxisId(axisType, i, true);
20809
- const scaleConfigFromProps = options?.scales?.[axisKey];
20804
+ //#region src/components/common/helpers/get-cartesian-scale-options.ts
20805
+ var isNumericScale = (scaleType) => {
20806
+ return scaleType === ScaleType.Linear || scaleType === ScaleType.Logarithmic;
20807
+ };
20808
+ var getGridLines = (gridLines) => {
20809
+ return gridLines && typeof gridLines === "object" ? gridLines : {};
20810
+ };
20811
+ var getCartesianScaleOptions = ({ axisData, scaleType, scaleConfigFromProps, display, beginAtZero, reverse, suggestedMax, suggestedMin, min, max, additionalStepSize, useStepSize = true, stacked, numericTickCallback }) => {
20810
20812
  const ticksConfigFromProps = scaleConfigFromProps?.ticks;
20811
20813
  const titleConfigFromProps = scaleConfigFromProps?.title;
20812
- const { additionalAxesOptions } = options;
20813
- const scaleType = scaleConfigFromProps?.type ?? additionalAxesOptions.chartScaleType;
20814
- const getTicks = () => {
20815
- const isLogarithmic = scaleType === ScaleType.Logarithmic;
20816
- const isNumericScale = scaleType === ScaleType.Linear || scaleType === ScaleType.Logarithmic;
20817
- const ticksFormattingCallback = (tick, _, ticks) => {
20818
- const tickValue = Number(tick);
20819
- return isLogarithmic ? LOGARITHMIC_STEPS.includes(tickValue) ? formatAxisLabelNumbers(tickValue, ticks) : "" : formatAxisLabelNumbers(tickValue, ticks);
20820
- };
20821
- return {
20822
- ...isNumericScale && !isLogarithmic ? { stepSize: axisData.stepSize ?? (axisType === AxisType.Y ? additionalAxesOptions.stepSize : null) } : {},
20823
- ...isNumericScale ? { callback: ticksFormattingCallback } : {},
20824
- includeBounds: false,
20825
- ...ticksConfigFromProps,
20826
- font: {
20827
- size: 12,
20828
- ...ticksConfigFromProps?.font
20829
- }
20830
- };
20831
- };
20814
+ const titleText = axisData?.label || (typeof axisData?.unit === "string" ? axisData.unit : void 0);
20815
+ const stepSize = useStepSize && isNumericScale(scaleType) && scaleType !== ScaleType.Logarithmic ? { stepSize: axisData?.stepSize ?? additionalStepSize } : {};
20832
20816
  return {
20833
- display: true,
20817
+ ...display !== void 0 ? { display } : {},
20834
20818
  type: scaleType,
20835
- position: axisData.position,
20836
- beginAtZero: additionalAxesOptions.beginAtZero,
20837
- reverse: axisType === AxisType.Y ? additionalAxesOptions.reverse : false,
20838
- suggestedMax: additionalAxesOptions.suggestedMax,
20839
- suggestedMin: additionalAxesOptions.suggestedMin,
20840
- min: stateAxis?.min ?? additionalAxesOptions?.range?.[axisType]?.min,
20841
- max: stateAxis?.max ?? additionalAxesOptions?.range?.[axisType]?.max,
20819
+ position: axisData?.position,
20820
+ beginAtZero,
20821
+ reverse,
20822
+ suggestedMax,
20823
+ suggestedMin,
20824
+ min,
20825
+ max,
20826
+ ...stacked !== void 0 ? { stacked } : {},
20842
20827
  ...scaleConfigFromProps,
20843
20828
  title: {
20844
- display: Boolean(axisData.label?.length),
20845
- text: axisData.label,
20829
+ display: Boolean(titleText?.length),
20830
+ text: titleText,
20846
20831
  padding: 0,
20847
20832
  ...titleConfigFromProps,
20848
20833
  font: {
@@ -20850,20 +20835,57 @@ var getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
20850
20835
  ...titleConfigFromProps?.font
20851
20836
  }
20852
20837
  },
20853
- ticks: getTicks(),
20838
+ ticks: {
20839
+ ...stepSize,
20840
+ ...isNumericScale(scaleType) && numericTickCallback ? { callback: numericTickCallback } : {},
20841
+ includeBounds: false,
20842
+ ...ticksConfigFromProps,
20843
+ font: {
20844
+ size: 12,
20845
+ ...ticksConfigFromProps?.font
20846
+ }
20847
+ },
20854
20848
  grid: {
20855
- ...axisData.gridLines,
20849
+ ...getGridLines(axisData?.gridLines),
20856
20850
  ...scaleConfigFromProps?.grid
20857
20851
  }
20858
20852
  };
20859
20853
  };
20854
+ //#endregion
20855
+ //#region src/components/line-chart/utils/get-line-chart-scales.ts
20856
+ var getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
20857
+ const axisData = currentScales || options.axes[axisType][0] || {};
20858
+ const stateAxis = state?.axes.filter((axis) => axis?.id?.startsWith(axisType))[i];
20859
+ const axisKey = generateAxisId$1(axisType, i, true);
20860
+ const scaleConfigFromProps = options?.scales?.[axisKey];
20861
+ const { additionalAxesOptions } = options;
20862
+ const scaleType = scaleConfigFromProps?.type ?? additionalAxesOptions.chartScaleType;
20863
+ const ticksFormattingCallback = (tick, _, ticks) => {
20864
+ const tickValue = Number(tick);
20865
+ return scaleType === ScaleType.Logarithmic ? LOGARITHMIC_STEPS.includes(tickValue) ? formatAxisLabelNumbers(tickValue, ticks) : "" : formatAxisLabelNumbers(tickValue, ticks);
20866
+ };
20867
+ return getCartesianScaleOptions({
20868
+ axisData,
20869
+ scaleType,
20870
+ scaleConfigFromProps,
20871
+ display: true,
20872
+ beginAtZero: additionalAxesOptions.beginAtZero,
20873
+ reverse: axisType === AxisType.Y ? additionalAxesOptions.reverse : false,
20874
+ suggestedMax: additionalAxesOptions.suggestedMax,
20875
+ suggestedMin: additionalAxesOptions.suggestedMin,
20876
+ min: stateAxis?.min ?? additionalAxesOptions?.range?.[axisType]?.min,
20877
+ max: stateAxis?.max ?? additionalAxesOptions?.range?.[axisType]?.max,
20878
+ additionalStepSize: axisType === AxisType.Y ? additionalAxesOptions.stepSize : null,
20879
+ numericTickCallback: ticksFormattingCallback
20880
+ });
20881
+ };
20860
20882
  var getLineChartAxes = (options, axisType, state) => {
20861
20883
  return options.axes[axisType].reduce((acc, curr, i) => {
20862
20884
  const axisData = curr;
20863
20885
  axisData.color = curr.color || COLORS[i] || generateRandomColor(COLORS);
20864
20886
  axisData.position = curr.position || getAxisPosition(axisType, i);
20865
20887
  const axis = getLineChartAxis(options, axisType, state, axisData, i);
20866
- const axisId = generateAxisId(axisType, i, true);
20888
+ const axisId = generateAxisId$1(axisType, i, true);
20867
20889
  return {
20868
20890
  ...acc,
20869
20891
  [axisId]: axis
@@ -38851,67 +38873,42 @@ var getStackedOptions = (axisType, { stacked, stackedX, stackedY }) => {
38851
38873
  else if (axisType === AxisType.Y) return stackedY ?? stacked;
38852
38874
  return stacked;
38853
38875
  };
38854
- var getBarChartAxis = ({ chart, axisType = AxisType.X, currentScale, i }) => {
38876
+ var generateAxisId = (axisType, index = 0) => {
38877
+ return index === 0 ? axisType : `${axisType}${index + 1}`;
38878
+ };
38879
+ var getBarChartAxis = ({ chart, axisType = AxisType.X, currentScale, i = 0 }) => {
38855
38880
  const { data, options } = chart ?? {};
38856
38881
  const isDirectionVertical = isVertical(options.direction);
38857
38882
  const axisData = currentScale || options?.axes?.[axisType]?.[0];
38858
38883
  const isDirectionCompatibleWithAxisType = isDirectionVertical && axisType === AxisType.Y || !isDirectionVertical && axisType === AxisType.X;
38859
- const grid = axisData?.gridLines || {};
38860
- const getScaleType = () => {
38884
+ const axisKey = generateAxisId(axisType, i);
38885
+ const scaleConfigFromProps = options?.scales?.[axisKey];
38886
+ const getDefaultScaleType = () => {
38861
38887
  const scaleType = data.labels ? ScaleType.Category : ScaleType.Linear;
38862
38888
  return axisType === (isDirectionVertical ? AxisType.X : AxisType.Y) ? scaleType : options?.additionalAxesOptions?.chartScaleType;
38863
38889
  };
38890
+ const scaleType = scaleConfigFromProps?.type ?? getDefaultScaleType();
38864
38891
  const getReverse = () => {
38865
38892
  return axisType === (isDirectionVertical ? AxisType.Y : AxisType.X) ? options?.additionalAxesOptions?.reverse : false;
38866
38893
  };
38867
- const axisKey = `${i === 0 ? axisType : axisType + i}`;
38868
- const titleConfigFromProps = options?.scales?.[axisKey]?.title;
38869
- const getTicks = () => {
38870
- const additionalAxesOptions = options?.additionalAxesOptions;
38871
- const ticksConfigFromProps = options?.scales?.[axisKey]?.ticks;
38872
- const isLogarithmic = isDirectionCompatibleWithAxisType && additionalAxesOptions?.chartScaleType === ScaleType.Logarithmic;
38873
- const ticksFormattingCallback = (tick, _, ticks) => {
38874
- return isLogarithmic ? LOGARITHMIC_STEPS.includes(Number(tick)) ? formatAxisLabelNumbers(tick, ticks) : "" : formatAxisLabelNumbers(tick, ticks);
38875
- };
38876
- return {
38877
- ...!isLogarithmic ? { stepSize: axisData.stepSize ?? (axisType === AxisType.Y ? additionalAxesOptions?.stepSize : null) } : {},
38878
- ...additionalAxesOptions?.chartScaleType === ScaleType.Logarithmic ? { callback: ticksFormattingCallback } : {},
38879
- includeBounds: false,
38880
- ...ticksConfigFromProps,
38881
- font: {
38882
- size: 12,
38883
- ...ticksConfigFromProps?.font
38884
- }
38885
- };
38894
+ const ticksFormattingCallback = (tick, _, ticks) => {
38895
+ return isDirectionCompatibleWithAxisType && scaleType === ScaleType.Logarithmic ? LOGARITHMIC_STEPS.includes(Number(tick)) ? formatAxisLabelNumbers(tick, ticks) : "" : formatAxisLabelNumbers(tick, ticks);
38886
38896
  };
38887
- return {
38888
- type: getScaleType(),
38889
- position: axisData?.position,
38897
+ return getCartesianScaleOptions({
38898
+ axisData,
38899
+ scaleType,
38900
+ scaleConfigFromProps,
38890
38901
  beginAtZero: options?.additionalAxesOptions?.beginAtZero,
38891
38902
  reverse: getReverse(),
38892
38903
  suggestedMax: options?.additionalAxesOptions?.suggestedMax,
38893
38904
  suggestedMin: options?.additionalAxesOptions?.suggestedMin,
38894
38905
  min: isDirectionCompatibleWithAxisType ? options?.additionalAxesOptions?.min : void 0,
38895
38906
  max: isDirectionCompatibleWithAxisType ? options?.additionalAxesOptions?.max : void 0,
38896
- title: {
38897
- display: axisData?.label?.length || axisData?.unit?.length,
38898
- text: axisData?.label || axisData?.unit,
38899
- padding: 0,
38900
- ...titleConfigFromProps,
38901
- font: {
38902
- size: 12,
38903
- ...titleConfigFromProps?.font
38904
- }
38905
- },
38906
- ticks: getTicks(),
38907
- grid: { ...grid },
38908
- stacked: getStackedOptions(axisType, options?.additionalAxesOptions)
38909
- };
38907
+ additionalStepSize: axisType === AxisType.Y ? options?.additionalAxesOptions?.stepSize : null,
38908
+ stacked: getStackedOptions(axisType, options?.additionalAxesOptions),
38909
+ numericTickCallback: ticksFormattingCallback
38910
+ });
38910
38911
  };
38911
- /**
38912
- * @param {IBarChartData} chart - chart data
38913
- * @param {'x'|'y'} axisType
38914
- */
38915
38912
  var getBarChartAxes = (chart, axisType) => {
38916
38913
  return (chart?.options?.axes?.[axisType] || []).reduce((acc, curr, i) => {
38917
38914
  const axisData = curr;
@@ -38920,9 +38917,10 @@ var getBarChartAxes = (chart, axisType) => {
38920
38917
  const axis = getBarChartAxis({
38921
38918
  chart,
38922
38919
  axisType,
38923
- currentScale: axisData
38920
+ currentScale: axisData,
38921
+ i
38924
38922
  });
38925
- const axisId = i === 0 ? axisType : `${axisType}${i + 1}`;
38923
+ const axisId = generateAxisId(axisType, i);
38926
38924
  return {
38927
38925
  ...acc,
38928
38926
  [axisId]: axis
@@ -39186,6 +39184,7 @@ var normalizeBarOptions = (options = {}) => ({
39186
39184
  chartStyling: defaultChartStyling$1(options?.chartStyling),
39187
39185
  tooltip: defaultTooltip$1(options?.tooltip),
39188
39186
  graph: defaultGraph$1(options?.graph),
39187
+ scales: options?.scales ?? {},
39189
39188
  annotations: defaultAnnotations$1(options?.annotations),
39190
39189
  legend: defaultLegend$1(options?.legend),
39191
39190
  chartOptions: defaultChartOptions$1(options?.chartOptions),
@@ -39214,7 +39213,7 @@ var getDefaultProps$1 = (props) => {
39214
39213
  };
39215
39214
  //#endregion
39216
39215
  //#region src/components/bar-chart/bar-chart.tsx
39217
- Chart$1.register(LinearScale, PointElement, LineElement, CategoryScale, LogarithmicScale, BarElement, plugin_legend, plugin_tooltip, plugin_title, index, plugin$1, plugin, annotation, import_chartjs_plugin_dragdata_min.default);
39216
+ Chart$1.register(LinearScale, PointElement, LineElement, CategoryScale, LogarithmicScale, TimeScale, TimeSeriesScale, BarElement, plugin_legend, plugin_tooltip, plugin_title, index, plugin$1, plugin, annotation, import_chartjs_plugin_dragdata_min.default);
39218
39217
  var BarChart = (props) => {
39219
39218
  setDefaultTheme();
39220
39219
  const chartRef = useRef(null);
@@ -39325,46 +39324,23 @@ var getScatterChartAxis = ({ options, axisType = AxisType.X, currentScale }) =>
39325
39324
  const isDirectionVertical = isVertical(options.direction);
39326
39325
  const axisData = currentScale || options?.axes?.[axisType]?.[0];
39327
39326
  const isDirectionCompatibleWithAxisType = isDirectionVertical && axisType === AxisType.Y || !isDirectionVertical && axisType === AxisType.X;
39328
- const grid = axisData?.gridLines || {};
39329
- const ticksConfigFromProps = options?.scales?.[axisType]?.ticks;
39330
- const titleConfigFromProps = options?.scales?.[axisType]?.title;
39327
+ const scaleConfigFromProps = options?.scales?.[axisType];
39328
+ const scaleType = scaleConfigFromProps?.type ?? options?.additionalAxesOptions?.chartScaleType ?? ScaleType.Linear;
39331
39329
  const getReverse = () => {
39332
39330
  return axisType === (isDirectionVertical ? AxisType.Y : AxisType.X) ? options?.additionalAxesOptions?.reverse : false;
39333
39331
  };
39334
- const getTicks = () => {
39335
- const additionalAxesOptions = options?.additionalAxesOptions;
39336
- return {
39337
- stepSize: axisData?.stepSize ?? (axisType === AxisType.Y ? additionalAxesOptions?.stepSize : void 0),
39338
- includeBounds: false,
39339
- ...ticksConfigFromProps,
39340
- font: {
39341
- size: 12,
39342
- ...ticksConfigFromProps?.font
39343
- }
39344
- };
39345
- };
39346
- return {
39347
- type: ScaleType.Linear,
39348
- position: axisData?.position,
39332
+ return getCartesianScaleOptions({
39333
+ axisData,
39334
+ scaleType,
39335
+ scaleConfigFromProps,
39349
39336
  beginAtZero: options?.additionalAxesOptions?.beginAtZero,
39350
39337
  reverse: getReverse(),
39351
39338
  suggestedMax: options?.additionalAxesOptions?.suggestedMax,
39352
39339
  suggestedMin: options?.additionalAxesOptions?.suggestedMin,
39353
39340
  min: isDirectionCompatibleWithAxisType ? options?.additionalAxesOptions?.min : void 0,
39354
39341
  max: isDirectionCompatibleWithAxisType ? options?.additionalAxesOptions?.max : void 0,
39355
- title: {
39356
- display: !!axisData?.label?.length || !!axisData?.unit?.length,
39357
- text: axisData?.label || axisData?.unit,
39358
- padding: 0,
39359
- ...titleConfigFromProps,
39360
- font: {
39361
- size: 12,
39362
- ...titleConfigFromProps?.font
39363
- }
39364
- },
39365
- ticks: getTicks(),
39366
- grid: { ...grid }
39367
- };
39342
+ additionalStepSize: axisType === AxisType.Y ? options?.additionalAxesOptions?.stepSize : null
39343
+ });
39368
39344
  };
39369
39345
  var getScatterChartScales = (options) => {
39370
39346
  return {
@@ -39528,6 +39504,7 @@ var defaultAxes = (axes) => ({
39528
39504
  y: axes?.y ?? [{}]
39529
39505
  });
39530
39506
  var defaultAdditionalAxesOptions = (options) => ({
39507
+ chartScaleType: options?.chartScaleType || "linear",
39531
39508
  reverse: options?.reverse ?? false,
39532
39509
  stacked: options?.stacked ?? false,
39533
39510
  beginAtZero: options?.beginAtZero ?? true,
@@ -39545,6 +39522,7 @@ var normalizeScatterOptions = (options = {}) => ({
39545
39522
  chartStyling: defaultChartStyling(options?.chartStyling),
39546
39523
  tooltip: defaultTooltip(options?.tooltip),
39547
39524
  graph: defaultGraph(options?.graph),
39525
+ scales: options?.scales ?? {},
39548
39526
  legend: defaultLegend(options?.legend),
39549
39527
  annotations: defaultAnnotations(options?.annotations),
39550
39528
  chartOptions: defaultChartOptions(options?.chartOptions),
@@ -39651,7 +39629,7 @@ var scatter_chart_module_default = {
39651
39629
  };
39652
39630
  //#endregion
39653
39631
  //#region src/components/scatter-chart/scatter-chart.tsx
39654
- Chart$1.register(LinearScale, PointElement, CategoryScale, plugin_legend, plugin_tooltip, plugin_title, plugin$1, plugin, annotation, gradientBackgroundPlugin);
39632
+ Chart$1.register(LinearScale, PointElement, CategoryScale, TimeScale, TimeSeriesScale, plugin_legend, plugin_tooltip, plugin_title, plugin$1, plugin, annotation, gradientBackgroundPlugin);
39655
39633
  var ScatterChart = (props) => {
39656
39634
  setDefaultTheme();
39657
39635
  const chartRef = useRef(null);
@@ -1,3 +1,4 @@
1
1
  import { IBarDefaultProps } from '../bar-chart.interface';
2
- declare const getBarChartScales: (chart: IBarDefaultProps) => any;
2
+ import { ICommonScaleOptions } from '../../common/common.interface';
3
+ declare const getBarChartScales: (chart: IBarDefaultProps) => Record<string, ICommonScaleOptions>;
3
4
  export default getBarChartScales;
@@ -17,7 +17,7 @@ export declare const useBarChartOptions: ({ chart, chartRef, }: IUseBarChartOpti
17
17
  mode: ChartHoverMode;
18
18
  intersect: boolean;
19
19
  };
20
- scales: any;
20
+ scales: Record<string, import('../../common/common.interface').ICommonScaleOptions>;
21
21
  plugins: {
22
22
  title: {
23
23
  display: boolean;
@@ -150,15 +150,15 @@ export interface ICommonTooltip {
150
150
  callbacks?: ICommonTooltipCallbacks;
151
151
  }
152
152
  export interface ICommonAdditionalAxesOptions {
153
- chartScaleType?: 'linear' | 'logarithmic';
153
+ chartScaleType?: 'linear' | 'logarithmic' | 'time' | 'timeseries';
154
154
  reverse?: boolean;
155
155
  beginAtZero?: boolean;
156
156
  stepSize?: number;
157
157
  stacked?: boolean;
158
158
  suggestedMin?: number;
159
159
  suggestedMax?: number;
160
- min?: number;
161
- max?: number;
160
+ min?: number | string;
161
+ max?: number | string;
162
162
  }
163
163
  export interface ICommonAnnotation {
164
164
  showLabel?: boolean;
@@ -0,0 +1,27 @@
1
+ import { Tick } from 'chart.js';
2
+ import { ICommonScaleOptions, UnusedParameter } from '../common.interface';
3
+ type TScaleType = NonNullable<ICommonScaleOptions['type']>;
4
+ interface IGetCartesianScaleOptionsParams {
5
+ axisData?: {
6
+ gridLines?: unknown;
7
+ label?: string;
8
+ position?: unknown;
9
+ stepSize?: number;
10
+ unit?: unknown;
11
+ };
12
+ scaleType?: TScaleType;
13
+ scaleConfigFromProps?: ICommonScaleOptions;
14
+ display?: boolean;
15
+ beginAtZero?: boolean;
16
+ reverse?: boolean;
17
+ suggestedMax?: number | string;
18
+ suggestedMin?: number | string;
19
+ min?: number | string;
20
+ max?: number | string;
21
+ additionalStepSize?: number | null;
22
+ useStepSize?: boolean;
23
+ stacked?: boolean;
24
+ numericTickCallback?: (tick: string | number, unused: UnusedParameter, ticks: Tick[]) => unknown;
25
+ }
26
+ export declare const getCartesianScaleOptions: ({ axisData, scaleType, scaleConfigFromProps, display, beginAtZero, reverse, suggestedMax, suggestedMin, min, max, additionalStepSize, useStepSize, stacked, numericTickCallback, }: IGetCartesianScaleOptionsParams) => ICommonScaleOptions;
27
+ export {};