@oliasoft-open-source/charts-library 9.0.0 → 9.1.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 +180 -16
- package/dist/src/components/line-chart/constants/default-translations.d.ts +2 -0
- package/dist/src/components/line-chart/controls/axes-options/axes-options-interfaces.d.ts +2 -0
- package/dist/src/components/line-chart/controls/controls-interfaces.d.ts +1 -0
- package/dist/src/components/line-chart/controls/controls.d.ts +1 -1
- package/dist/src/components/line-chart/hooks/use-chart-plugins.d.ts +3 -1
- 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/helpers.d.ts +2 -1
- 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
|
};
|
|
@@ -34103,10 +34108,10 @@ var validateAxes = (axes) => {
|
|
|
34103
34108
|
};
|
|
34104
34109
|
// src/components/line-chart/state/helpers.ts
|
|
34105
34110
|
var RANGE_GAP = 1;
|
|
34106
|
-
var getInitAxes = ({ chartRef, state }) => {
|
|
34111
|
+
var getInitAxes = ({ chartRef, state, useCurrentBounds = false }) => {
|
|
34107
34112
|
const chart = chartRef.current;
|
|
34108
34113
|
if (!chart) return [];
|
|
34109
|
-
const initScales = chart
|
|
34114
|
+
const initScales = useCurrentBounds ? chart.scales : chart.getInitialScaleBounds() ?? {};
|
|
34110
34115
|
return Object.entries(initScales).map(([id, { min = "", max = "" }]) => {
|
|
34111
34116
|
let adjustedMin = Number(min);
|
|
34112
34117
|
let adjustedMax = Number(max);
|
|
@@ -34124,7 +34129,9 @@ 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, onAxesUpdate } = optionsPopover ?? {};
|
|
34133
|
+
const canToggleEqualScale = !!onToggleEqualScale;
|
|
34134
|
+
const equalScaleEnabled = canToggleEqualScale && !!state.equalScaleEnabled;
|
|
34128
34135
|
const [formState, setFormState] = useState({
|
|
34129
34136
|
localAxes: getInitAxes({
|
|
34130
34137
|
chartRef,
|
|
@@ -34133,6 +34140,29 @@ var AxesOptionsPopover = (optionsPopover) => {
|
|
|
34133
34140
|
depthType: depthType?.selectedDepthType,
|
|
34134
34141
|
edited: state.edited
|
|
34135
34142
|
});
|
|
34143
|
+
useEffect(() => {
|
|
34144
|
+
if (!canToggleEqualScale) return;
|
|
34145
|
+
const updateBounds = () => {
|
|
34146
|
+
setFormState((previous) => ({
|
|
34147
|
+
...previous,
|
|
34148
|
+
localAxes: getInitAxes({
|
|
34149
|
+
chartRef,
|
|
34150
|
+
state,
|
|
34151
|
+
useCurrentBounds: true
|
|
34152
|
+
})
|
|
34153
|
+
}));
|
|
34154
|
+
};
|
|
34155
|
+
onAxesUpdate.current = updateBounds;
|
|
34156
|
+
updateBounds();
|
|
34157
|
+
return () => {
|
|
34158
|
+
onAxesUpdate.current = null;
|
|
34159
|
+
};
|
|
34160
|
+
}, [
|
|
34161
|
+
canToggleEqualScale,
|
|
34162
|
+
chartRef,
|
|
34163
|
+
state,
|
|
34164
|
+
onAxesUpdate
|
|
34165
|
+
]);
|
|
34136
34166
|
const { errors, valid } = validateAxes(formState.localAxes);
|
|
34137
34167
|
const onEditValue = ({ name, value, id }) => {
|
|
34138
34168
|
setFormState((prevState) => ({
|
|
@@ -34159,6 +34189,10 @@ var AxesOptionsPopover = (optionsPopover) => {
|
|
|
34159
34189
|
};
|
|
34160
34190
|
const onDone = (e) => {
|
|
34161
34191
|
e.preventDefault();
|
|
34192
|
+
if (equalScaleEnabled) {
|
|
34193
|
+
close?.();
|
|
34194
|
+
return;
|
|
34195
|
+
}
|
|
34162
34196
|
if (valid) {
|
|
34163
34197
|
onUpdateAxes({ axes: formState.localAxes });
|
|
34164
34198
|
close?.();
|
|
@@ -34183,6 +34217,20 @@ var AxesOptionsPopover = (optionsPopover) => {
|
|
|
34183
34217
|
return /* @__PURE__ */ jsxs("form", {
|
|
34184
34218
|
onSubmit: onDone,
|
|
34185
34219
|
children: [
|
|
34220
|
+
onToggleEqualScale && /* @__PURE__ */ jsx(Field, {
|
|
34221
|
+
label: translations.equalAxisScale,
|
|
34222
|
+
children: /* @__PURE__ */ jsx(Toggle, {
|
|
34223
|
+
small: true,
|
|
34224
|
+
noMargin: true,
|
|
34225
|
+
checked: !!state.equalScaleEnabled,
|
|
34226
|
+
onChange: onToggleEqualScale
|
|
34227
|
+
})
|
|
34228
|
+
}),
|
|
34229
|
+
equalScaleEnabled && /* @__PURE__ */ jsx(Text, {
|
|
34230
|
+
small: true,
|
|
34231
|
+
muted: true,
|
|
34232
|
+
children: translations.equalAxisScaleReadOnly
|
|
34233
|
+
}),
|
|
34186
34234
|
formState.localAxes.map((axis) => {
|
|
34187
34235
|
const axisLabel = controlsAxesLabels.find((el) => el.id === axis.id)?.label || startCase(axis.id);
|
|
34188
34236
|
const axisErrors = errors.find((err) => err.id === axis.id);
|
|
@@ -34195,6 +34243,7 @@ var AxesOptionsPopover = (optionsPopover) => {
|
|
|
34195
34243
|
/* @__PURE__ */ jsx(NumberInput, {
|
|
34196
34244
|
name: "min",
|
|
34197
34245
|
value: axis.min,
|
|
34246
|
+
disabled: equalScaleEnabled,
|
|
34198
34247
|
error: axisErrors?.min?.[0] ? translations[axisErrors.min[0]] : null,
|
|
34199
34248
|
width: "100%",
|
|
34200
34249
|
onChange: (evt) => onEditValue({
|
|
@@ -34208,6 +34257,7 @@ var AxesOptionsPopover = (optionsPopover) => {
|
|
|
34208
34257
|
/* @__PURE__ */ jsx(NumberInput, {
|
|
34209
34258
|
name: "max",
|
|
34210
34259
|
value: axis.max,
|
|
34260
|
+
disabled: equalScaleEnabled,
|
|
34211
34261
|
error: axisErrors?.max?.[0] ? translations[axisErrors.max[0]] : null,
|
|
34212
34262
|
width: "100%",
|
|
34213
34263
|
onChange: (evt) => onEditValue({
|
|
@@ -34219,6 +34269,7 @@ var AxesOptionsPopover = (optionsPopover) => {
|
|
|
34219
34269
|
}),
|
|
34220
34270
|
axis.unit ? /* @__PURE__ */ jsx(Select, {
|
|
34221
34271
|
name: "selectedUnit",
|
|
34272
|
+
disabled: equalScaleEnabled,
|
|
34222
34273
|
options: typeof axis.unit !== "string" ? axis.unit.options : [],
|
|
34223
34274
|
value: typeof axis.unit !== "string" ? axis.unit.selectedUnit : void 0,
|
|
34224
34275
|
onChange: (e) => onEditUnit({
|
|
@@ -34257,7 +34308,7 @@ var AxesOptionsPopover = (optionsPopover) => {
|
|
|
34257
34308
|
small: true,
|
|
34258
34309
|
colored: true,
|
|
34259
34310
|
label: translations.done,
|
|
34260
|
-
disabled: !valid || !formState.edited
|
|
34311
|
+
disabled: !equalScaleEnabled && (!valid || !formState.edited)
|
|
34261
34312
|
}),
|
|
34262
34313
|
/* @__PURE__ */ jsx(Button, {
|
|
34263
34314
|
small: true,
|
|
@@ -34300,9 +34351,9 @@ var AxesOptions = (optionsPopover) => {
|
|
|
34300
34351
|
});
|
|
34301
34352
|
};
|
|
34302
34353
|
// src/components/line-chart/controls/controls.tsx
|
|
34303
|
-
var Controls = ({ table, headerComponent, subheaderComponent, chartRef, state, options, dispatch, translations, controlsPortalId }) => {
|
|
34354
|
+
var Controls = ({ table, headerComponent, subheaderComponent, chartRef, onAxesUpdate, state, options, dispatch, translations, controlsPortalId }) => {
|
|
34304
34355
|
const { enableDragPoints, lineEnabled, panEnabled, pointsEnabled, showTable, zoomEnabled, enableDragAnnotation } = state;
|
|
34305
|
-
const { dragData, depthType, annotations } = options;
|
|
34356
|
+
const { dragData, depthType, annotations, additionalAxesOptions, axes, scales } = options;
|
|
34306
34357
|
const { onToggleLine, onTogglePan, onTogglePoints, onToggleTable, onToggleZoom, onToggleDragPoints, onToggleDragAnnotation, onDisableDragOptions } = useToggleHandlers(dispatch);
|
|
34307
34358
|
const { handleDownload, controlsAxesLabels, onResetAxes, onUpdateAxes, onUpdateEdited } = useChartFunctions({
|
|
34308
34359
|
chartRef,
|
|
@@ -34352,6 +34403,10 @@ var Controls = ({ table, headerComponent, subheaderComponent, chartRef, state, o
|
|
|
34352
34403
|
translations,
|
|
34353
34404
|
zoomEnabled
|
|
34354
34405
|
]);
|
|
34406
|
+
const canToggleEqualScale = additionalAxesOptions.allowEqualScale && axes.x.length === 1 && axes.y.length === 1 && (scales?.x?.type ?? additionalAxesOptions.chartScaleType) === "linear" && (scales?.y?.type ?? additionalAxesOptions.chartScaleType) === "linear";
|
|
34407
|
+
const handleToggleEqualScale = () => {
|
|
34408
|
+
dispatch({ type: TOGGLE_EQUAL_SCALE });
|
|
34409
|
+
};
|
|
34355
34410
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
34356
34411
|
className: controls_module_default.controls,
|
|
34357
34412
|
children: [
|
|
@@ -34367,13 +34422,15 @@ var Controls = ({ table, headerComponent, subheaderComponent, chartRef, state, o
|
|
|
34367
34422
|
ref: measureRef,
|
|
34368
34423
|
children: [!showTable && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(AxesOptions, {
|
|
34369
34424
|
chartRef,
|
|
34425
|
+
onAxesUpdate,
|
|
34370
34426
|
state,
|
|
34371
34427
|
controlsAxesLabels,
|
|
34372
34428
|
onUpdateAxes,
|
|
34373
34429
|
onResetAxes,
|
|
34374
34430
|
onUpdateEdited,
|
|
34375
34431
|
depthType,
|
|
34376
|
-
translations
|
|
34432
|
+
translations,
|
|
34433
|
+
onToggleEqualScale: canToggleEqualScale ? handleToggleEqualScale : void 0
|
|
34377
34434
|
}), isNarrow ? /* @__PURE__ */ jsx(Menu, { menu: {
|
|
34378
34435
|
placement: "bottom-end",
|
|
34379
34436
|
sections: [
|
|
@@ -34509,6 +34566,7 @@ var defaultAxes$2 = (axes) => {
|
|
|
34509
34566
|
};
|
|
34510
34567
|
};
|
|
34511
34568
|
var defaultAdditionalAxesOptions$2 = (options) => ({
|
|
34569
|
+
allowEqualScale: options?.allowEqualScale ?? false,
|
|
34512
34570
|
chartScaleType: options?.chartScaleType || "linear",
|
|
34513
34571
|
reverse: options?.reverse || false,
|
|
34514
34572
|
beginAtZero: options?.beginAtZero ?? false,
|
|
@@ -36486,6 +36544,7 @@ var useChartOptions = ({ chartRef, state, options, dispatch, generatedDatasets,
|
|
|
36486
36544
|
const lineMarkersAnnotation = options?.annotations?.lineMarkersAnnotation ?? {};
|
|
36487
36545
|
const lineMarkersPluginEnabled = Boolean(options?.plugins?.lineMarkersPlugin?.enabled ?? lineMarkersAnnotation?.enabled);
|
|
36488
36546
|
const plugins = useMemo(() => ({
|
|
36547
|
+
equalAxisScale: { enabled: !!options.additionalAxesOptions.allowEqualScale && !!state.equalScaleEnabled },
|
|
36489
36548
|
datalabels,
|
|
36490
36549
|
annotationDraggerPlugin: { enabled: state?.enableDragAnnotation },
|
|
36491
36550
|
calloutConnectorPlugin: { enableCalloutAnnotation: options?.annotations.enableCalloutAnnotation },
|
|
@@ -36515,6 +36574,8 @@ var useChartOptions = ({ chartRef, state, options, dispatch, generatedDatasets,
|
|
|
36515
36574
|
},
|
|
36516
36575
|
...dragData
|
|
36517
36576
|
}), [
|
|
36577
|
+
options.additionalAxesOptions.allowEqualScale,
|
|
36578
|
+
state.equalScaleEnabled,
|
|
36518
36579
|
annotation,
|
|
36519
36580
|
customLegendPlugin,
|
|
36520
36581
|
datalabels,
|
|
@@ -36572,8 +36633,99 @@ var useChartOptions = ({ chartRef, state, options, dispatch, generatedDatasets,
|
|
|
36572
36633
|
scales
|
|
36573
36634
|
]);
|
|
36574
36635
|
};
|
|
36636
|
+
// src/components/line-chart/utils/get-equal-scale-ranges.ts
|
|
36637
|
+
/** Expands the smaller units-per-pixel range without moving either range's centre or clipping it. */
|
|
36638
|
+
var getEqualScaleRanges = (x, y, width, height) => {
|
|
36639
|
+
const xSpan = x.max - x.min;
|
|
36640
|
+
const ySpan = y.max - y.min;
|
|
36641
|
+
if (![
|
|
36642
|
+
x.min,
|
|
36643
|
+
x.max,
|
|
36644
|
+
y.min,
|
|
36645
|
+
y.max,
|
|
36646
|
+
xSpan,
|
|
36647
|
+
ySpan,
|
|
36648
|
+
width,
|
|
36649
|
+
height
|
|
36650
|
+
].every(Number.isFinite) || Math.min(xSpan, ySpan, width, height) <= 0) return null;
|
|
36651
|
+
const unitsPerPixel = Math.max(xSpan / width, ySpan / height);
|
|
36652
|
+
const xPadding = Math.max(0, (unitsPerPixel * width - xSpan) / 2);
|
|
36653
|
+
const yPadding = Math.max(0, (unitsPerPixel * height - ySpan) / 2);
|
|
36654
|
+
const ranges = {
|
|
36655
|
+
x: {
|
|
36656
|
+
min: x.min - xPadding,
|
|
36657
|
+
max: x.max + xPadding
|
|
36658
|
+
},
|
|
36659
|
+
y: {
|
|
36660
|
+
min: y.min - yPadding,
|
|
36661
|
+
max: y.max + yPadding
|
|
36662
|
+
}
|
|
36663
|
+
};
|
|
36664
|
+
if (!Object.values(ranges).every((range) => Number.isFinite(range.min) && Number.isFinite(range.max))) return null;
|
|
36665
|
+
return ranges;
|
|
36666
|
+
};
|
|
36667
|
+
// src/components/line-chart/plugins/equal-scale-plugin.ts
|
|
36668
|
+
/**
|
|
36669
|
+
* Fits the requested viewport after layout, when the actual plot dimensions are available.
|
|
36670
|
+
* Temporary bounds are restored so resizing and toggling do not accumulate extra padding.
|
|
36671
|
+
*/
|
|
36672
|
+
var createEqualScalePlugin = (onAxesUpdate) => {
|
|
36673
|
+
let fitting = false;
|
|
36674
|
+
return {
|
|
36675
|
+
id: "equalAxisScale",
|
|
36676
|
+
afterUpdate(chart, _args, { enabled }) {
|
|
36677
|
+
if (fitting) return;
|
|
36678
|
+
const { x, y } = chart.scales;
|
|
36679
|
+
if (!enabled || Object.keys(chart.scales).length !== 2 || x?.type !== "linear" || y?.type !== "linear") {
|
|
36680
|
+
onAxesUpdate();
|
|
36681
|
+
return;
|
|
36682
|
+
}
|
|
36683
|
+
const baseX = {
|
|
36684
|
+
min: x.min,
|
|
36685
|
+
max: x.max
|
|
36686
|
+
};
|
|
36687
|
+
const baseY = {
|
|
36688
|
+
min: y.min,
|
|
36689
|
+
max: y.max
|
|
36690
|
+
};
|
|
36691
|
+
const originalX = {
|
|
36692
|
+
min: x.options.min,
|
|
36693
|
+
max: x.options.max
|
|
36694
|
+
};
|
|
36695
|
+
const originalY = {
|
|
36696
|
+
min: y.options.min,
|
|
36697
|
+
max: y.options.max
|
|
36698
|
+
};
|
|
36699
|
+
fitting = true;
|
|
36700
|
+
try {
|
|
36701
|
+
for (let pass = 0; pass < 4; pass++) {
|
|
36702
|
+
const { width, height } = chart.chartArea;
|
|
36703
|
+
const ranges = getEqualScaleRanges(baseX, baseY, width, height);
|
|
36704
|
+
if (!ranges) break;
|
|
36705
|
+
const currentX = chart.scales.x;
|
|
36706
|
+
const currentY = chart.scales.y;
|
|
36707
|
+
const tolerance = Math.max(ranges.x.max - ranges.x.min, ranges.y.max - ranges.y.min) * 1e-8;
|
|
36708
|
+
if ([
|
|
36709
|
+
currentX.min - ranges.x.min,
|
|
36710
|
+
currentX.max - ranges.x.max,
|
|
36711
|
+
currentY.min - ranges.y.min,
|
|
36712
|
+
currentY.max - ranges.y.max
|
|
36713
|
+
].every((difference) => Math.abs(difference) <= tolerance)) break;
|
|
36714
|
+
Object.assign(currentX.options, ranges.x);
|
|
36715
|
+
Object.assign(currentY.options, ranges.y);
|
|
36716
|
+
chart.update("none");
|
|
36717
|
+
}
|
|
36718
|
+
} finally {
|
|
36719
|
+
Object.assign(chart.scales.x.options, originalX);
|
|
36720
|
+
Object.assign(chart.scales.y.options, originalY);
|
|
36721
|
+
fitting = false;
|
|
36722
|
+
}
|
|
36723
|
+
onAxesUpdate();
|
|
36724
|
+
}
|
|
36725
|
+
};
|
|
36726
|
+
};
|
|
36575
36727
|
// src/components/line-chart/hooks/use-chart-plugins.ts
|
|
36576
|
-
var useChartPlugins = ({ options, resetZoom }) => {
|
|
36728
|
+
var useChartPlugins = ({ options, resetZoom, onAxesUpdate }) => {
|
|
36577
36729
|
const { graph, legend } = options;
|
|
36578
36730
|
const handleDoubleClick = useCallback((_, args) => {
|
|
36579
36731
|
const { event } = args;
|
|
@@ -36584,14 +36736,21 @@ var useChartPlugins = ({ options, resetZoom }) => {
|
|
|
36584
36736
|
return true;
|
|
36585
36737
|
}, [resetZoom]);
|
|
36586
36738
|
return useMemo(() => {
|
|
36587
|
-
return [
|
|
36588
|
-
|
|
36589
|
-
|
|
36590
|
-
|
|
36739
|
+
return [
|
|
36740
|
+
...getPlugins(graph, legend),
|
|
36741
|
+
createEqualScalePlugin(() => {
|
|
36742
|
+
onAxesUpdate.current?.();
|
|
36743
|
+
}),
|
|
36744
|
+
{
|
|
36745
|
+
id: "customEventCatcher",
|
|
36746
|
+
beforeEvent: handleDoubleClick
|
|
36747
|
+
}
|
|
36748
|
+
];
|
|
36591
36749
|
}, [
|
|
36592
36750
|
graph,
|
|
36593
36751
|
handleDoubleClick,
|
|
36594
|
-
legend
|
|
36752
|
+
legend,
|
|
36753
|
+
onAxesUpdate
|
|
36595
36754
|
]);
|
|
36596
36755
|
};
|
|
36597
36756
|
// src/components/line-chart/hooks/use-chart-state.ts
|
|
@@ -38086,6 +38245,8 @@ var defaultTranslations = /* @__PURE__ */ function(defaultTranslations) {
|
|
|
38086
38245
|
defaultTranslations["pointsOnly"] = "Points only";
|
|
38087
38246
|
defaultTranslations["axesOptions"] = "Axes options";
|
|
38088
38247
|
defaultTranslations["resetAxes"] = "Reset Axes";
|
|
38248
|
+
defaultTranslations["equalAxisScale"] = "Equal X/Y scale (1:1)";
|
|
38249
|
+
defaultTranslations["equalAxisScaleReadOnly"] = "Turn off equal scaling to edit axis limits.";
|
|
38089
38250
|
defaultTranslations["done"] = "Done";
|
|
38090
38251
|
defaultTranslations["downloadAsPNG"] = "Download as PNG";
|
|
38091
38252
|
defaultTranslations["showChart"] = "Show chart";
|
|
@@ -38578,6 +38739,7 @@ var Legend = ({ chartRef, legendConfig, persistenceId }) => {
|
|
|
38578
38739
|
Chart$1.register(LinearScale, PointElement, LineElement, CategoryScale, LogarithmicScale, TimeScale, TimeSeriesScale, plugin_legend, plugin_tooltip, plugin_title, index, plugin$1, import_chartjs_plugin_dragdata_min.default, plugin, annotation, chartAreaTextPlugin, annotationDraggerPlugin, ellipsisAnnotationPlugin, calloutConnectorPlugin, lineMarkersPlugin);
|
|
38579
38740
|
var LineChart = (props) => {
|
|
38580
38741
|
setDefaultTheme();
|
|
38742
|
+
const onAxesUpdate = useRef(null);
|
|
38581
38743
|
const chartRef = useRef(null);
|
|
38582
38744
|
const setChartRef = useCallback((chartInstance) => {
|
|
38583
38745
|
chartRef.current = chartInstance ?? null;
|
|
@@ -38620,7 +38782,8 @@ var LineChart = (props) => {
|
|
|
38620
38782
|
});
|
|
38621
38783
|
const usePlugins = useChartPlugins({
|
|
38622
38784
|
options,
|
|
38623
|
-
resetZoom
|
|
38785
|
+
resetZoom,
|
|
38786
|
+
onAxesUpdate
|
|
38624
38787
|
});
|
|
38625
38788
|
return /* @__PURE__ */ jsxs("div", {
|
|
38626
38789
|
className: getClassName(chartStyling, line_chart_module_default),
|
|
@@ -38637,6 +38800,7 @@ var LineChart = (props) => {
|
|
|
38637
38800
|
headerComponent,
|
|
38638
38801
|
subheaderComponent,
|
|
38639
38802
|
chartRef,
|
|
38803
|
+
onAxesUpdate,
|
|
38640
38804
|
state,
|
|
38641
38805
|
options,
|
|
38642
38806
|
dispatch,
|
|
@@ -5,6 +5,8 @@ export declare enum defaultTranslations {
|
|
|
5
5
|
pointsOnly = "Points only",
|
|
6
6
|
axesOptions = "Axes options",
|
|
7
7
|
resetAxes = "Reset Axes",
|
|
8
|
+
equalAxisScale = "Equal X/Y scale (1:1)",
|
|
9
|
+
equalAxisScaleReadOnly = "Turn off equal scaling to edit axis limits.",
|
|
8
10
|
done = "Done",
|
|
9
11
|
downloadAsPNG = "Download as PNG",
|
|
10
12
|
showChart = "Show chart",
|
|
@@ -22,6 +22,8 @@ export interface IAxesOptions {
|
|
|
22
22
|
onUpdateEdited: (edited: boolean) => void;
|
|
23
23
|
depthType?: IDepthType | object;
|
|
24
24
|
close?: () => void;
|
|
25
|
+
onToggleEqualScale?: () => void;
|
|
26
|
+
onAxesUpdate: RefObject<(() => void) | null>;
|
|
25
27
|
}
|
|
26
28
|
export interface IOnEdit {
|
|
27
29
|
name?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { IControls } from './controls-interfaces';
|
|
3
|
-
declare const Controls: ({ table, headerComponent, subheaderComponent, chartRef, state, options, dispatch, translations, controlsPortalId, }: IControls) => React.JSX.Element;
|
|
3
|
+
declare const Controls: ({ table, headerComponent, subheaderComponent, chartRef, onAxesUpdate, state, options, dispatch, translations, controlsPortalId, }: IControls) => React.JSX.Element;
|
|
4
4
|
export default Controls;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
1
2
|
import { ILineChartOptions } from '../line-chart.interface';
|
|
2
3
|
interface IUseChartPlugins {
|
|
3
4
|
options: ILineChartOptions;
|
|
4
5
|
resetZoom: () => void;
|
|
6
|
+
onAxesUpdate: RefObject<(() => void) | null>;
|
|
5
7
|
}
|
|
6
|
-
export declare const useChartPlugins: ({ options, resetZoom }: IUseChartPlugins) => any[];
|
|
8
|
+
export declare const useChartPlugins: ({ options, resetZoom, onAxesUpdate }: IUseChartPlugins) => any[];
|
|
7
9
|
export {};
|
|
@@ -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: (onAxesUpdate: () => void) => Plugin<'line', {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
}>;
|
|
@@ -4,8 +4,9 @@ import { TChart } from '../../common/common.interface.js';
|
|
|
4
4
|
export interface IGetInitAxes {
|
|
5
5
|
chartRef: RefObject<TChart | null>;
|
|
6
6
|
state: IState;
|
|
7
|
+
useCurrentBounds?: boolean;
|
|
7
8
|
}
|
|
8
|
-
export declare const getInitAxes: ({ chartRef, state }: IGetInitAxes) => {
|
|
9
|
+
export declare const getInitAxes: ({ chartRef, state, useCurrentBounds }: IGetInitAxes) => {
|
|
9
10
|
id: string;
|
|
10
11
|
min: number;
|
|
11
12
|
max: number;
|
|
@@ -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