@oliasoft-open-source/charts-library 5.14.1-beta-1 → 5.15.0-beta-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/dist/index.js +40 -20
- package/dist/src/components/common/common.interface.d.ts +5 -7
- package/dist/src/components/common/enums.d.ts +3 -1
- package/dist/src/components/line-chart/line-chart.interface.d.ts +3 -3
- package/dist/src/components/line-chart/utils/get-line-chart-scales.d.ts +2 -586
- package/dist/src/components/scatter-chart/hooks/use-scatter-chart-config.d.ts +348 -46
- package/dist/src/components/scatter-chart/utils/get-scales-config.d.ts +348 -46
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createContext, forwardRef, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState } from "react";
|
|
2
|
+
import "chartjs-adapter-date-fns";
|
|
2
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
4
|
import { DndProvider, useDrag, useDrop } from "react-dnd";
|
|
4
5
|
import { HTML5Backend } from "react-dnd-html5-backend";
|
|
5
|
-
import { displayNumber, isCloseTo, round, roundByMagnitude } from "@oliasoft-open-source/units";
|
|
6
|
+
import { displayNumber, isCloseTo, round, roundByMagnitude, toNum } from "@oliasoft-open-source/units";
|
|
6
7
|
import cx from "classnames";
|
|
7
|
-
import { cloneDeep, debounce, defaultTo, find, findIndex, get, has, isArray, isEmpty, isNil, isNumber, isObject, map, noop, set, some, startCase } from "es-toolkit/compat";
|
|
8
|
+
import { cloneDeep, debounce, defaultTo, find, findIndex, get, has, isArray, isEmpty, isFinite as isFinite$1, isNil, isNumber, isObject, isString, map, noop, set, some, startCase } from "es-toolkit/compat";
|
|
8
9
|
import { produce } from "immer";
|
|
9
10
|
import { Button, ButtonGroup, Field, Flex, Icon, InputGroup, InputGroupAddon, Menu, NumberInput, Popover, Portal, Select, Spacer, Text, Tooltip } from "@oliasoft-open-source/react-ui-library";
|
|
10
11
|
import { useMeasure } from "react-use";
|
|
@@ -12094,7 +12095,7 @@ function interpolate(table, val, reverse) {
|
|
|
12094
12095
|
const span = nextSource - prevSource;
|
|
12095
12096
|
return span ? prevTarget + (nextTarget - prevTarget) * (val - prevSource) / span : prevTarget;
|
|
12096
12097
|
}
|
|
12097
|
-
|
|
12098
|
+
var TimeSeriesScale = class extends TimeScale {
|
|
12098
12099
|
static id = "timeseries";
|
|
12099
12100
|
static defaults = TimeScale.defaults;
|
|
12100
12101
|
constructor(props) {
|
|
@@ -12163,7 +12164,7 @@ function interpolate(table, val, reverse) {
|
|
|
12163
12164
|
const decimal = this.getDecimalForPixel(pixel) / offsets.factor - offsets.end;
|
|
12164
12165
|
return interpolate(this._table, decimal * this._tableRange + this._minPos, true);
|
|
12165
12166
|
}
|
|
12166
|
-
}
|
|
12167
|
+
};
|
|
12167
12168
|
//#endregion
|
|
12168
12169
|
//#region node_modules/.pnpm/react-chartjs-2@5.3.1_chart.js@4.5.1_react@18.3.1/node_modules/react-chartjs-2/dist/index.js
|
|
12169
12170
|
var defaultDatasetIdKey = "label";
|
|
@@ -19069,6 +19070,8 @@ var ScaleType = /* @__PURE__ */ function(ScaleType) {
|
|
|
19069
19070
|
ScaleType["Category"] = "category";
|
|
19070
19071
|
ScaleType["Linear"] = "linear";
|
|
19071
19072
|
ScaleType["Logarithmic"] = "logarithmic";
|
|
19073
|
+
ScaleType["Time"] = "time";
|
|
19074
|
+
ScaleType["TimeSeries"] = "timeseries";
|
|
19072
19075
|
return ScaleType;
|
|
19073
19076
|
}({});
|
|
19074
19077
|
var ChartDirection = /* @__PURE__ */ function(ChartDirection) {
|
|
@@ -20802,18 +20805,22 @@ var formatAxisLabelNumbers = (tickValue, ticks) => {
|
|
|
20802
20805
|
var getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
|
|
20803
20806
|
const axisData = currentScales || options.axes[axisType][0] || {};
|
|
20804
20807
|
const stateAxis = state?.axes.filter((axis) => axis?.id?.startsWith(axisType))[i];
|
|
20805
|
-
const axisKey =
|
|
20806
|
-
const
|
|
20807
|
-
const
|
|
20808
|
+
const axisKey = generateAxisId(axisType, i, true);
|
|
20809
|
+
const scaleConfigFromProps = options?.scales?.[axisKey];
|
|
20810
|
+
const ticksConfigFromProps = scaleConfigFromProps?.ticks;
|
|
20811
|
+
const titleConfigFromProps = scaleConfigFromProps?.title;
|
|
20808
20812
|
const { additionalAxesOptions } = options;
|
|
20813
|
+
const scaleType = scaleConfigFromProps?.type ?? additionalAxesOptions.chartScaleType;
|
|
20809
20814
|
const getTicks = () => {
|
|
20810
|
-
const isLogarithmic =
|
|
20815
|
+
const isLogarithmic = scaleType === ScaleType.Logarithmic;
|
|
20816
|
+
const isNumericScale = scaleType === ScaleType.Linear || scaleType === ScaleType.Logarithmic;
|
|
20811
20817
|
const ticksFormattingCallback = (tick, _, ticks) => {
|
|
20812
|
-
|
|
20818
|
+
const tickValue = Number(tick);
|
|
20819
|
+
return isLogarithmic ? LOGARITHMIC_STEPS.includes(tickValue) ? formatAxisLabelNumbers(tickValue, ticks) : "" : formatAxisLabelNumbers(tickValue, ticks);
|
|
20813
20820
|
};
|
|
20814
20821
|
return {
|
|
20815
|
-
|
|
20816
|
-
callback: ticksFormattingCallback,
|
|
20822
|
+
...isNumericScale && !isLogarithmic ? { stepSize: axisData.stepSize ?? (axisType === AxisType.Y ? additionalAxesOptions.stepSize : null) } : {},
|
|
20823
|
+
...isNumericScale ? { callback: ticksFormattingCallback } : {},
|
|
20817
20824
|
includeBounds: false,
|
|
20818
20825
|
...ticksConfigFromProps,
|
|
20819
20826
|
font: {
|
|
@@ -20824,7 +20831,7 @@ var getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
|
|
|
20824
20831
|
};
|
|
20825
20832
|
return {
|
|
20826
20833
|
display: true,
|
|
20827
|
-
type:
|
|
20834
|
+
type: scaleType,
|
|
20828
20835
|
position: axisData.position,
|
|
20829
20836
|
beginAtZero: additionalAxesOptions.beginAtZero,
|
|
20830
20837
|
reverse: axisType === AxisType.Y ? additionalAxesOptions.reverse : false,
|
|
@@ -20832,8 +20839,9 @@ var getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
|
|
|
20832
20839
|
suggestedMin: additionalAxesOptions.suggestedMin,
|
|
20833
20840
|
min: stateAxis?.min ?? additionalAxesOptions?.range?.[axisType]?.min,
|
|
20834
20841
|
max: stateAxis?.max ?? additionalAxesOptions?.range?.[axisType]?.max,
|
|
20842
|
+
...scaleConfigFromProps,
|
|
20835
20843
|
title: {
|
|
20836
|
-
display: axisData.label?.length,
|
|
20844
|
+
display: Boolean(axisData.label?.length),
|
|
20837
20845
|
text: axisData.label,
|
|
20838
20846
|
padding: 0,
|
|
20839
20847
|
...titleConfigFromProps,
|
|
@@ -20843,7 +20851,10 @@ var getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
|
|
|
20843
20851
|
}
|
|
20844
20852
|
},
|
|
20845
20853
|
ticks: getTicks(),
|
|
20846
|
-
grid: {
|
|
20854
|
+
grid: {
|
|
20855
|
+
...axisData.gridLines,
|
|
20856
|
+
...scaleConfigFromProps?.grid
|
|
20857
|
+
}
|
|
20847
20858
|
};
|
|
20848
20859
|
};
|
|
20849
20860
|
var getLineChartAxes = (options, axisType, state) => {
|
|
@@ -20871,6 +20882,11 @@ var getLineChartScales = (options, state) => {
|
|
|
20871
20882
|
};
|
|
20872
20883
|
//#endregion
|
|
20873
20884
|
//#region src/components/common/helpers/range/estimate-data-series-have-close-values.ts
|
|
20885
|
+
var getFiniteNumber = (value) => {
|
|
20886
|
+
if (!isNumber(value) && !isString(value)) return;
|
|
20887
|
+
const numericValue = toNum(value);
|
|
20888
|
+
return isFinite$1(numericValue) ? numericValue : void 0;
|
|
20889
|
+
};
|
|
20874
20890
|
/**
|
|
20875
20891
|
* Estimates whether any of the data series has values that are all close together
|
|
20876
20892
|
* - checks only the first and last values in each series (i.e. assumes they are ordered)
|
|
@@ -20884,8 +20900,13 @@ var estimateDataSeriesHaveCloseValues = (generatedDatasets) => {
|
|
|
20884
20900
|
const yAxisId = dataset?.yAxisID ?? "y";
|
|
20885
20901
|
const data = dataset?.data ?? [];
|
|
20886
20902
|
if (data && data?.length) {
|
|
20887
|
-
const { x:
|
|
20888
|
-
const { x:
|
|
20903
|
+
const { x: rawXFirstCurrent, y: rawYFirstCurrent } = data?.[0] ?? {};
|
|
20904
|
+
const { x: rawXLastCurrent, y: rawYLastCurrent } = data?.at(-1) ?? {};
|
|
20905
|
+
const xFirstCurrent = getFiniteNumber(rawXFirstCurrent);
|
|
20906
|
+
const yFirstCurrent = getFiniteNumber(rawYFirstCurrent);
|
|
20907
|
+
const xLastCurrent = getFiniteNumber(rawXLastCurrent);
|
|
20908
|
+
const yLastCurrent = getFiniteNumber(rawYLastCurrent);
|
|
20909
|
+
if (xFirstCurrent === void 0 || yFirstCurrent === void 0 || xLastCurrent === void 0 || yLastCurrent === void 0) return acc;
|
|
20889
20910
|
const xFirstAcc = acc?.[xAxisId]?.xFirst ?? xFirstCurrent;
|
|
20890
20911
|
const xLastAcc = acc?.[xAxisId]?.xLast ?? xLastCurrent;
|
|
20891
20912
|
const yFirstAcc = acc?.[yAxisId]?.yFirst ?? yFirstCurrent;
|
|
@@ -24506,7 +24527,7 @@ var Legend = ({ chartRef, legendConfig }) => {
|
|
|
24506
24527
|
};
|
|
24507
24528
|
//#endregion
|
|
24508
24529
|
//#region src/components/line-chart/line-chart.tsx
|
|
24509
|
-
Chart$1.register(LinearScale, PointElement, LineElement, CategoryScale, LogarithmicScale, plugin_legend, plugin_tooltip, plugin_title, index, plugin$1, plugin, annotation, chartAreaTextPlugin, annotationDraggerPlugin, ellipsisAnnotationPlugin, calloutConnectorPlugin, lineMarkersPlugin);
|
|
24530
|
+
Chart$1.register(LinearScale, PointElement, LineElement, CategoryScale, LogarithmicScale, TimeScale, TimeSeriesScale, plugin_legend, plugin_tooltip, plugin_title, index, plugin$1, plugin, annotation, chartAreaTextPlugin, annotationDraggerPlugin, ellipsisAnnotationPlugin, calloutConnectorPlugin, lineMarkersPlugin);
|
|
24510
24531
|
var LineChart = (props) => {
|
|
24511
24532
|
setDefaultTheme();
|
|
24512
24533
|
const chartRef = useRef(null);
|
|
@@ -38852,8 +38873,9 @@ var getBarChartAxis = ({ chart, axisType = AxisType.X, currentScale, i }) => {
|
|
|
38852
38873
|
const ticksFormattingCallback = (tick, _, ticks) => {
|
|
38853
38874
|
return isLogarithmic ? LOGARITHMIC_STEPS.includes(Number(tick)) ? formatAxisLabelNumbers(tick, ticks) : "" : formatAxisLabelNumbers(tick, ticks);
|
|
38854
38875
|
};
|
|
38855
|
-
|
|
38876
|
+
return {
|
|
38856
38877
|
...!isLogarithmic ? { stepSize: axisData.stepSize ?? (axisType === AxisType.Y ? additionalAxesOptions?.stepSize : null) } : {},
|
|
38878
|
+
...additionalAxesOptions?.chartScaleType === ScaleType.Logarithmic ? { callback: ticksFormattingCallback } : {},
|
|
38857
38879
|
includeBounds: false,
|
|
38858
38880
|
...ticksConfigFromProps,
|
|
38859
38881
|
font: {
|
|
@@ -38861,8 +38883,6 @@ var getBarChartAxis = ({ chart, axisType = AxisType.X, currentScale, i }) => {
|
|
|
38861
38883
|
...ticksConfigFromProps?.font
|
|
38862
38884
|
}
|
|
38863
38885
|
};
|
|
38864
|
-
if (additionalAxesOptions?.chartScaleType === ScaleType.Logarithmic) ticks.callback = ticksFormattingCallback;
|
|
38865
|
-
return ticks;
|
|
38866
38886
|
};
|
|
38867
38887
|
return {
|
|
38868
38888
|
type: getScaleType(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChartEvent, ChartTypeRegistry,
|
|
1
|
+
import { ChartEvent, ChartTypeRegistry, Plugin, ScaleOptions } from 'chart.js';
|
|
2
2
|
import { LabelOptions } from 'chartjs-plugin-annotation';
|
|
3
3
|
import { GradientDirection } from './plugins/gradient-background-plugin/enums';
|
|
4
4
|
import { AnnotationType as DraggableAnnotationType, DragAxis } from './plugins/annotation-dragger-plugin/enums';
|
|
@@ -9,8 +9,8 @@ export type DeepPartial<T> = T extends (...args: unknown[]) => unknown ? T : T e
|
|
|
9
9
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
10
10
|
} : T;
|
|
11
11
|
export interface ICommonDataValue {
|
|
12
|
-
x: number;
|
|
13
|
-
y: number;
|
|
12
|
+
x: number | string;
|
|
13
|
+
y: number | string;
|
|
14
14
|
label?: string;
|
|
15
15
|
}
|
|
16
16
|
export interface ICommonDataset {
|
|
@@ -21,10 +21,8 @@ export interface ICommonDataset {
|
|
|
21
21
|
data: ICommonDataValue[];
|
|
22
22
|
hidden?: boolean;
|
|
23
23
|
}
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
y: LinearScaleOptions;
|
|
27
|
-
}
|
|
24
|
+
export type ICommonScaleOptions = ScaleOptions<'category'> | ScaleOptions<'linear'> | ScaleOptions<'logarithmic'> | ScaleOptions<'time'> | ScaleOptions<'timeseries'>;
|
|
25
|
+
export type ICommonScales = Partial<Record<string, ICommonScaleOptions>>;
|
|
28
26
|
export interface ICommonAnnotationElement {
|
|
29
27
|
id?: string;
|
|
30
28
|
display: boolean;
|
|
@@ -30,7 +30,9 @@ export declare enum CursorStyle {
|
|
|
30
30
|
export declare enum ScaleType {
|
|
31
31
|
Category = "category",
|
|
32
32
|
Linear = "linear",
|
|
33
|
-
Logarithmic = "logarithmic"
|
|
33
|
+
Logarithmic = "logarithmic",
|
|
34
|
+
Time = "time",
|
|
35
|
+
TimeSeries = "timeseries"
|
|
34
36
|
}
|
|
35
37
|
export declare enum ChartDirection {
|
|
36
38
|
VERTICAL = "vertical",
|
|
@@ -19,14 +19,14 @@ export interface ILineChartTooltip extends ICommonTooltip {
|
|
|
19
19
|
scientificNotation?: boolean;
|
|
20
20
|
}
|
|
21
21
|
export interface ILineChartRange {
|
|
22
|
-
min?: number;
|
|
23
|
-
max?: number;
|
|
22
|
+
min?: number | string;
|
|
23
|
+
max?: number | string;
|
|
24
24
|
}
|
|
25
25
|
export interface ILineRange {
|
|
26
26
|
[key: string]: ILineChartRange;
|
|
27
27
|
}
|
|
28
28
|
export interface ILineChartAdditionalAxesOptions {
|
|
29
|
-
chartScaleType?: 'linear' | 'logarithmic';
|
|
29
|
+
chartScaleType?: 'linear' | 'logarithmic' | 'time' | 'timeseries';
|
|
30
30
|
reverse?: boolean;
|
|
31
31
|
beginAtZero?: boolean;
|
|
32
32
|
stepSize?: number;
|