@oliasoft-open-source/charts-library 9.0.0-beta-1 → 9.1.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 +120 -8
- package/dist/src/components/line-chart/constants/default-translations.d.ts +1 -0
- package/dist/src/components/line-chart/controls/axes-options/axes-options-interfaces.d.ts +1 -0
- package/dist/src/components/line-chart/line-chart.interface.d.ts +6 -0
- package/dist/src/components/line-chart/plugins/equal-scale-plugin.d.ts +8 -0
- package/dist/src/components/line-chart/state/action-types.d.ts +1 -0
- package/dist/src/components/line-chart/state/state.interfaces.d.ts +1 -0
- package/dist/src/components/line-chart/utils/get-equal-scale-ranges.d.ts +16 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,12 +7,13 @@ import { displayNumber, isCloseTo, round, roundByMagnitude, toNum } from "@olias
|
|
|
7
7
|
import cx from "classnames";
|
|
8
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";
|
|
9
9
|
import { produce } from "immer";
|
|
10
|
-
import { Button, ButtonGroup, Color, Field, Flex, Icon, InputGroup, InputGroupAddon, Menu, NumberInput, Popover, Portal, Select, Spacer, Text, Tooltip } from "@oliasoft-open-source/react-ui-library";
|
|
10
|
+
import { Button, ButtonGroup, Color, Field, Flex, Icon, InputGroup, InputGroupAddon, Menu, NumberInput, Popover, Portal, Select, Spacer, Text, Toggle, Tooltip } from "@oliasoft-open-source/react-ui-library";
|
|
11
11
|
import { useMeasure } from "react-use";
|
|
12
12
|
import { TbArrowsMove, TbBan, TbCircleFilled, TbHandStop, TbList, TbRuler, TbSquareFilled, TbX, TbZoomIn } from "react-icons/tb";
|
|
13
13
|
import { toPng } from "html-to-image";
|
|
14
14
|
import { triggerBase64Download } from "react-base64-downloader";
|
|
15
15
|
import hash from "object-hash";
|
|
16
|
+
import { omit } from "es-toolkit";
|
|
16
17
|
import isEqual from "fast-deep-equal";
|
|
17
18
|
import { colord, extend } from "colord";
|
|
18
19
|
import namesPlugin from "colord/plugins/names";
|
|
@@ -33498,6 +33499,7 @@ var line_chart_module_default = {
|
|
|
33498
33499
|
table: "_table_e3qdd_62"
|
|
33499
33500
|
};
|
|
33500
33501
|
// src/components/line-chart/state/action-types.ts
|
|
33502
|
+
var TOGGLE_EQUAL_SCALE = "TOGGLE_EQUAL_SCALE";
|
|
33501
33503
|
var TOGGLE_ZOOM = "TOGGLE_ZOOM";
|
|
33502
33504
|
var TOGGLE_PAN = "TOGGLE_PAN";
|
|
33503
33505
|
var TOGGLE_POINTS = "TOGGLE_POINTS";
|
|
@@ -33514,6 +33516,9 @@ var UPDATE_EDITED = "UPDATE_EDITED";
|
|
|
33514
33516
|
var reducer = (state, action) => {
|
|
33515
33517
|
return produce(state, (draft) => {
|
|
33516
33518
|
switch (action.type) {
|
|
33519
|
+
case TOGGLE_EQUAL_SCALE:
|
|
33520
|
+
draft.equalScaleEnabled = !draft.equalScaleEnabled;
|
|
33521
|
+
break;
|
|
33517
33522
|
case TOGGLE_ZOOM:
|
|
33518
33523
|
draft.zoomEnabled = !draft.zoomEnabled;
|
|
33519
33524
|
if (draft.panEnabled) draft.panEnabled = false;
|
|
@@ -33910,7 +33915,7 @@ var getAxisTypeFromKey = (string) => {
|
|
|
33910
33915
|
var isPrimitiveValue = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null;
|
|
33911
33916
|
var getChartKey = (state, languageKey) => {
|
|
33912
33917
|
return hash({
|
|
33913
|
-
state,
|
|
33918
|
+
state: omit(state, ["equalScaleEnabled"]),
|
|
33914
33919
|
languageKey
|
|
33915
33920
|
}, { unorderedObjects: true });
|
|
33916
33921
|
};
|
|
@@ -34124,7 +34129,7 @@ var getInitAxes = ({ chartRef, state }) => {
|
|
|
34124
34129
|
};
|
|
34125
34130
|
// src/components/line-chart/controls/axes-options/axes-options.tsx
|
|
34126
34131
|
var AxesOptionsPopover = (optionsPopover) => {
|
|
34127
|
-
const { state, controlsAxesLabels, onUpdateAxes, onResetAxes, onUpdateEdited, depthType, translations, close, chartRef } = optionsPopover ?? {};
|
|
34132
|
+
const { state, controlsAxesLabels, onUpdateAxes, onResetAxes, onUpdateEdited, depthType, translations, close, chartRef, onToggleEqualScale } = optionsPopover ?? {};
|
|
34128
34133
|
const [formState, setFormState] = useState({
|
|
34129
34134
|
localAxes: getInitAxes({
|
|
34130
34135
|
chartRef,
|
|
@@ -34183,6 +34188,15 @@ var AxesOptionsPopover = (optionsPopover) => {
|
|
|
34183
34188
|
return /* @__PURE__ */ jsxs("form", {
|
|
34184
34189
|
onSubmit: onDone,
|
|
34185
34190
|
children: [
|
|
34191
|
+
onToggleEqualScale && /* @__PURE__ */ jsx(Field, {
|
|
34192
|
+
label: translations.equalAxisScale,
|
|
34193
|
+
children: /* @__PURE__ */ jsx(Toggle, {
|
|
34194
|
+
small: true,
|
|
34195
|
+
noMargin: true,
|
|
34196
|
+
checked: !!state.equalScaleEnabled,
|
|
34197
|
+
onChange: onToggleEqualScale
|
|
34198
|
+
})
|
|
34199
|
+
}),
|
|
34186
34200
|
formState.localAxes.map((axis) => {
|
|
34187
34201
|
const axisLabel = controlsAxesLabels.find((el) => el.id === axis.id)?.label || startCase(axis.id);
|
|
34188
34202
|
const axisErrors = errors.find((err) => err.id === axis.id);
|
|
@@ -34373,7 +34387,10 @@ var Controls = ({ table, headerComponent, subheaderComponent, chartRef, state, o
|
|
|
34373
34387
|
onResetAxes,
|
|
34374
34388
|
onUpdateEdited,
|
|
34375
34389
|
depthType,
|
|
34376
|
-
translations
|
|
34390
|
+
translations,
|
|
34391
|
+
onToggleEqualScale: options.additionalAxesOptions.allowEqualScale && options.axes.x.length === 1 && options.axes.y.length === 1 && (options.scales?.x?.type ?? options.additionalAxesOptions.chartScaleType) === "linear" && (options.scales?.y?.type ?? options.additionalAxesOptions.chartScaleType) === "linear" ? () => {
|
|
34392
|
+
dispatch({ type: "TOGGLE_EQUAL_SCALE" });
|
|
34393
|
+
} : void 0
|
|
34377
34394
|
}), isNarrow ? /* @__PURE__ */ jsx(Menu, { menu: {
|
|
34378
34395
|
placement: "bottom-end",
|
|
34379
34396
|
sections: [
|
|
@@ -34509,6 +34526,7 @@ var defaultAxes$2 = (axes) => {
|
|
|
34509
34526
|
};
|
|
34510
34527
|
};
|
|
34511
34528
|
var defaultAdditionalAxesOptions$2 = (options) => ({
|
|
34529
|
+
allowEqualScale: options?.allowEqualScale ?? false,
|
|
34512
34530
|
chartScaleType: options?.chartScaleType || "linear",
|
|
34513
34531
|
reverse: options?.reverse || false,
|
|
34514
34532
|
beginAtZero: options?.beginAtZero ?? false,
|
|
@@ -36486,6 +36504,7 @@ var useChartOptions = ({ chartRef, state, options, dispatch, generatedDatasets,
|
|
|
36486
36504
|
const lineMarkersAnnotation = options?.annotations?.lineMarkersAnnotation ?? {};
|
|
36487
36505
|
const lineMarkersPluginEnabled = Boolean(options?.plugins?.lineMarkersPlugin?.enabled ?? lineMarkersAnnotation?.enabled);
|
|
36488
36506
|
const plugins = useMemo(() => ({
|
|
36507
|
+
equalAxisScale: { enabled: !!options.additionalAxesOptions.allowEqualScale && !!state.equalScaleEnabled },
|
|
36489
36508
|
datalabels,
|
|
36490
36509
|
annotationDraggerPlugin: { enabled: state?.enableDragAnnotation },
|
|
36491
36510
|
calloutConnectorPlugin: { enableCalloutAnnotation: options?.annotations.enableCalloutAnnotation },
|
|
@@ -36515,6 +36534,8 @@ var useChartOptions = ({ chartRef, state, options, dispatch, generatedDatasets,
|
|
|
36515
36534
|
},
|
|
36516
36535
|
...dragData
|
|
36517
36536
|
}), [
|
|
36537
|
+
options.additionalAxesOptions.allowEqualScale,
|
|
36538
|
+
state.equalScaleEnabled,
|
|
36518
36539
|
annotation,
|
|
36519
36540
|
customLegendPlugin,
|
|
36520
36541
|
datalabels,
|
|
@@ -36572,6 +36593,92 @@ var useChartOptions = ({ chartRef, state, options, dispatch, generatedDatasets,
|
|
|
36572
36593
|
scales
|
|
36573
36594
|
]);
|
|
36574
36595
|
};
|
|
36596
|
+
// src/components/line-chart/utils/get-equal-scale-ranges.ts
|
|
36597
|
+
/** Expands the smaller units-per-pixel range without moving either range's centre or clipping it. */
|
|
36598
|
+
var getEqualScaleRanges = (x, y, width, height) => {
|
|
36599
|
+
const xSpan = x.max - x.min;
|
|
36600
|
+
const ySpan = y.max - y.min;
|
|
36601
|
+
if (![
|
|
36602
|
+
x.min,
|
|
36603
|
+
x.max,
|
|
36604
|
+
y.min,
|
|
36605
|
+
y.max,
|
|
36606
|
+
xSpan,
|
|
36607
|
+
ySpan,
|
|
36608
|
+
width,
|
|
36609
|
+
height
|
|
36610
|
+
].every(Number.isFinite) || Math.min(xSpan, ySpan, width, height) <= 0) return null;
|
|
36611
|
+
const unitsPerPixel = Math.max(xSpan / width, ySpan / height);
|
|
36612
|
+
const xPadding = Math.max(0, (unitsPerPixel * width - xSpan) / 2);
|
|
36613
|
+
const yPadding = Math.max(0, (unitsPerPixel * height - ySpan) / 2);
|
|
36614
|
+
const ranges = {
|
|
36615
|
+
x: {
|
|
36616
|
+
min: x.min - xPadding,
|
|
36617
|
+
max: x.max + xPadding
|
|
36618
|
+
},
|
|
36619
|
+
y: {
|
|
36620
|
+
min: y.min - yPadding,
|
|
36621
|
+
max: y.max + yPadding
|
|
36622
|
+
}
|
|
36623
|
+
};
|
|
36624
|
+
if (!Object.values(ranges).every((range) => Number.isFinite(range.min) && Number.isFinite(range.max))) return null;
|
|
36625
|
+
return ranges;
|
|
36626
|
+
};
|
|
36627
|
+
// src/components/line-chart/plugins/equal-scale-plugin.ts
|
|
36628
|
+
/**
|
|
36629
|
+
* Fits the requested viewport after layout, when the actual plot dimensions are available.
|
|
36630
|
+
* Temporary bounds are restored so resizing and toggling do not accumulate extra padding.
|
|
36631
|
+
*/
|
|
36632
|
+
var createEqualScalePlugin = () => {
|
|
36633
|
+
let fitting = false;
|
|
36634
|
+
return {
|
|
36635
|
+
id: "equalAxisScale",
|
|
36636
|
+
afterUpdate(chart, _args, { enabled }) {
|
|
36637
|
+
const { x, y } = chart.scales;
|
|
36638
|
+
if (!enabled || fitting || Object.keys(chart.scales).length !== 2 || x?.type !== "linear" || y?.type !== "linear") return;
|
|
36639
|
+
const baseX = {
|
|
36640
|
+
min: x.min,
|
|
36641
|
+
max: x.max
|
|
36642
|
+
};
|
|
36643
|
+
const baseY = {
|
|
36644
|
+
min: y.min,
|
|
36645
|
+
max: y.max
|
|
36646
|
+
};
|
|
36647
|
+
const originalX = {
|
|
36648
|
+
min: x.options.min,
|
|
36649
|
+
max: x.options.max
|
|
36650
|
+
};
|
|
36651
|
+
const originalY = {
|
|
36652
|
+
min: y.options.min,
|
|
36653
|
+
max: y.options.max
|
|
36654
|
+
};
|
|
36655
|
+
fitting = true;
|
|
36656
|
+
try {
|
|
36657
|
+
for (let pass = 0; pass < 4; pass++) {
|
|
36658
|
+
const { width, height } = chart.chartArea;
|
|
36659
|
+
const ranges = getEqualScaleRanges(baseX, baseY, width, height);
|
|
36660
|
+
if (!ranges) break;
|
|
36661
|
+
const currentX = chart.scales.x;
|
|
36662
|
+
const currentY = chart.scales.y;
|
|
36663
|
+
const tolerance = Math.max(ranges.x.max - ranges.x.min, ranges.y.max - ranges.y.min) * 1e-8;
|
|
36664
|
+
if ([
|
|
36665
|
+
currentX.min - ranges.x.min,
|
|
36666
|
+
currentX.max - ranges.x.max,
|
|
36667
|
+
currentY.min - ranges.y.min,
|
|
36668
|
+
currentY.max - ranges.y.max
|
|
36669
|
+
].every((difference) => Math.abs(difference) <= tolerance)) break;
|
|
36670
|
+
Object.assign(currentX.options, ranges.x);
|
|
36671
|
+
Object.assign(currentY.options, ranges.y);
|
|
36672
|
+
chart.update("none");
|
|
36673
|
+
}
|
|
36674
|
+
} finally {
|
|
36675
|
+
Object.assign(chart.scales.x.options, originalX);
|
|
36676
|
+
Object.assign(chart.scales.y.options, originalY);
|
|
36677
|
+
fitting = false;
|
|
36678
|
+
}
|
|
36679
|
+
}
|
|
36680
|
+
};
|
|
36681
|
+
};
|
|
36575
36682
|
// src/components/line-chart/hooks/use-chart-plugins.ts
|
|
36576
36683
|
var useChartPlugins = ({ options, resetZoom }) => {
|
|
36577
36684
|
const { graph, legend } = options;
|
|
@@ -36584,10 +36691,14 @@ var useChartPlugins = ({ options, resetZoom }) => {
|
|
|
36584
36691
|
return true;
|
|
36585
36692
|
}, [resetZoom]);
|
|
36586
36693
|
return useMemo(() => {
|
|
36587
|
-
return [
|
|
36588
|
-
|
|
36589
|
-
|
|
36590
|
-
|
|
36694
|
+
return [
|
|
36695
|
+
...getPlugins(graph, legend),
|
|
36696
|
+
createEqualScalePlugin(),
|
|
36697
|
+
{
|
|
36698
|
+
id: "customEventCatcher",
|
|
36699
|
+
beforeEvent: handleDoubleClick
|
|
36700
|
+
}
|
|
36701
|
+
];
|
|
36591
36702
|
}, [
|
|
36592
36703
|
graph,
|
|
36593
36704
|
handleDoubleClick,
|
|
@@ -38086,6 +38197,7 @@ var defaultTranslations = /* @__PURE__ */ function(defaultTranslations) {
|
|
|
38086
38197
|
defaultTranslations["pointsOnly"] = "Points only";
|
|
38087
38198
|
defaultTranslations["axesOptions"] = "Axes options";
|
|
38088
38199
|
defaultTranslations["resetAxes"] = "Reset Axes";
|
|
38200
|
+
defaultTranslations["equalAxisScale"] = "Equal X/Y scale (1:1)";
|
|
38089
38201
|
defaultTranslations["done"] = "Done";
|
|
38090
38202
|
defaultTranslations["downloadAsPNG"] = "Download as PNG";
|
|
38091
38203
|
defaultTranslations["showChart"] = "Show chart";
|
|
@@ -66,6 +66,12 @@ export interface ILineRange {
|
|
|
66
66
|
}
|
|
67
67
|
/** LineChart scale defaults and per-axis range overrides. */
|
|
68
68
|
export interface ILineChartAdditionalAxesOptions {
|
|
69
|
+
/**
|
|
70
|
+
* Offers a toggle for equal units per pixel on one pair of linear X/Y axes. Defaults to false.
|
|
71
|
+
* Both axes must use the same physical units; no unit conversion is performed.
|
|
72
|
+
* The toggle starts off and expands the requested viewport without changing the canvas shape.
|
|
73
|
+
*/
|
|
74
|
+
allowEqualScale?: boolean;
|
|
69
75
|
/** Scale family used when constructing axes. */
|
|
70
76
|
chartScaleType?: 'linear' | 'logarithmic' | 'time' | 'timeseries';
|
|
71
77
|
/** Reverses the Y scale direction. Does not change tooltip axis selection. */
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Plugin } from 'chart.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fits the requested viewport after layout, when the actual plot dimensions are available.
|
|
4
|
+
* Temporary bounds are restored so resizing and toggling do not accumulate extra padding.
|
|
5
|
+
*/
|
|
6
|
+
export declare const createEqualScalePlugin: () => Plugin<'line', {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface IRange {
|
|
2
|
+
min: number;
|
|
3
|
+
max: number;
|
|
4
|
+
}
|
|
5
|
+
/** Expands the smaller units-per-pixel range without moving either range's centre or clipping it. */
|
|
6
|
+
export declare const getEqualScaleRanges: (x: IRange, y: IRange, width: number, height: number) => {
|
|
7
|
+
x: {
|
|
8
|
+
min: number;
|
|
9
|
+
max: number;
|
|
10
|
+
};
|
|
11
|
+
y: {
|
|
12
|
+
min: number;
|
|
13
|
+
max: number;
|
|
14
|
+
};
|
|
15
|
+
} | null;
|
|
16
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oliasoft-open-source/charts-library",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.1.0-beta-1",
|
|
4
4
|
"description": "React Chart Library (based on Chart.js and react-chart-js-2)",
|
|
5
5
|
"homepage": "https://gitlab.com/oliasoft-open-source/charts-library",
|
|
6
6
|
"bugs": {
|