@oliasoft-open-source/charts-library 9.1.0-beta-1 → 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 CHANGED
@@ -34108,10 +34108,10 @@ var validateAxes = (axes) => {
34108
34108
  };
34109
34109
  // src/components/line-chart/state/helpers.ts
34110
34110
  var RANGE_GAP = 1;
34111
- var getInitAxes = ({ chartRef, state }) => {
34111
+ var getInitAxes = ({ chartRef, state, useCurrentBounds = false }) => {
34112
34112
  const chart = chartRef.current;
34113
34113
  if (!chart) return [];
34114
- const initScales = chart?.getInitialScaleBounds() ?? {};
34114
+ const initScales = useCurrentBounds ? chart.scales : chart.getInitialScaleBounds() ?? {};
34115
34115
  return Object.entries(initScales).map(([id, { min = "", max = "" }]) => {
34116
34116
  let adjustedMin = Number(min);
34117
34117
  let adjustedMax = Number(max);
@@ -34129,7 +34129,9 @@ var getInitAxes = ({ chartRef, state }) => {
34129
34129
  };
34130
34130
  // src/components/line-chart/controls/axes-options/axes-options.tsx
34131
34131
  var AxesOptionsPopover = (optionsPopover) => {
34132
- const { state, controlsAxesLabels, onUpdateAxes, onResetAxes, onUpdateEdited, depthType, translations, close, chartRef, onToggleEqualScale } = 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;
34133
34135
  const [formState, setFormState] = useState({
34134
34136
  localAxes: getInitAxes({
34135
34137
  chartRef,
@@ -34138,6 +34140,29 @@ var AxesOptionsPopover = (optionsPopover) => {
34138
34140
  depthType: depthType?.selectedDepthType,
34139
34141
  edited: state.edited
34140
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
+ ]);
34141
34166
  const { errors, valid } = validateAxes(formState.localAxes);
34142
34167
  const onEditValue = ({ name, value, id }) => {
34143
34168
  setFormState((prevState) => ({
@@ -34164,6 +34189,10 @@ var AxesOptionsPopover = (optionsPopover) => {
34164
34189
  };
34165
34190
  const onDone = (e) => {
34166
34191
  e.preventDefault();
34192
+ if (equalScaleEnabled) {
34193
+ close?.();
34194
+ return;
34195
+ }
34167
34196
  if (valid) {
34168
34197
  onUpdateAxes({ axes: formState.localAxes });
34169
34198
  close?.();
@@ -34197,6 +34226,11 @@ var AxesOptionsPopover = (optionsPopover) => {
34197
34226
  onChange: onToggleEqualScale
34198
34227
  })
34199
34228
  }),
34229
+ equalScaleEnabled && /* @__PURE__ */ jsx(Text, {
34230
+ small: true,
34231
+ muted: true,
34232
+ children: translations.equalAxisScaleReadOnly
34233
+ }),
34200
34234
  formState.localAxes.map((axis) => {
34201
34235
  const axisLabel = controlsAxesLabels.find((el) => el.id === axis.id)?.label || startCase(axis.id);
34202
34236
  const axisErrors = errors.find((err) => err.id === axis.id);
@@ -34209,6 +34243,7 @@ var AxesOptionsPopover = (optionsPopover) => {
34209
34243
  /* @__PURE__ */ jsx(NumberInput, {
34210
34244
  name: "min",
34211
34245
  value: axis.min,
34246
+ disabled: equalScaleEnabled,
34212
34247
  error: axisErrors?.min?.[0] ? translations[axisErrors.min[0]] : null,
34213
34248
  width: "100%",
34214
34249
  onChange: (evt) => onEditValue({
@@ -34222,6 +34257,7 @@ var AxesOptionsPopover = (optionsPopover) => {
34222
34257
  /* @__PURE__ */ jsx(NumberInput, {
34223
34258
  name: "max",
34224
34259
  value: axis.max,
34260
+ disabled: equalScaleEnabled,
34225
34261
  error: axisErrors?.max?.[0] ? translations[axisErrors.max[0]] : null,
34226
34262
  width: "100%",
34227
34263
  onChange: (evt) => onEditValue({
@@ -34233,6 +34269,7 @@ var AxesOptionsPopover = (optionsPopover) => {
34233
34269
  }),
34234
34270
  axis.unit ? /* @__PURE__ */ jsx(Select, {
34235
34271
  name: "selectedUnit",
34272
+ disabled: equalScaleEnabled,
34236
34273
  options: typeof axis.unit !== "string" ? axis.unit.options : [],
34237
34274
  value: typeof axis.unit !== "string" ? axis.unit.selectedUnit : void 0,
34238
34275
  onChange: (e) => onEditUnit({
@@ -34271,7 +34308,7 @@ var AxesOptionsPopover = (optionsPopover) => {
34271
34308
  small: true,
34272
34309
  colored: true,
34273
34310
  label: translations.done,
34274
- disabled: !valid || !formState.edited
34311
+ disabled: !equalScaleEnabled && (!valid || !formState.edited)
34275
34312
  }),
34276
34313
  /* @__PURE__ */ jsx(Button, {
34277
34314
  small: true,
@@ -34314,9 +34351,9 @@ var AxesOptions = (optionsPopover) => {
34314
34351
  });
34315
34352
  };
34316
34353
  // src/components/line-chart/controls/controls.tsx
34317
- var Controls = ({ table, headerComponent, subheaderComponent, chartRef, state, options, dispatch, translations, controlsPortalId }) => {
34354
+ var Controls = ({ table, headerComponent, subheaderComponent, chartRef, onAxesUpdate, state, options, dispatch, translations, controlsPortalId }) => {
34318
34355
  const { enableDragPoints, lineEnabled, panEnabled, pointsEnabled, showTable, zoomEnabled, enableDragAnnotation } = state;
34319
- const { dragData, depthType, annotations } = options;
34356
+ const { dragData, depthType, annotations, additionalAxesOptions, axes, scales } = options;
34320
34357
  const { onToggleLine, onTogglePan, onTogglePoints, onToggleTable, onToggleZoom, onToggleDragPoints, onToggleDragAnnotation, onDisableDragOptions } = useToggleHandlers(dispatch);
34321
34358
  const { handleDownload, controlsAxesLabels, onResetAxes, onUpdateAxes, onUpdateEdited } = useChartFunctions({
34322
34359
  chartRef,
@@ -34366,6 +34403,10 @@ var Controls = ({ table, headerComponent, subheaderComponent, chartRef, state, o
34366
34403
  translations,
34367
34404
  zoomEnabled
34368
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
+ };
34369
34410
  return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
34370
34411
  className: controls_module_default.controls,
34371
34412
  children: [
@@ -34381,6 +34422,7 @@ var Controls = ({ table, headerComponent, subheaderComponent, chartRef, state, o
34381
34422
  ref: measureRef,
34382
34423
  children: [!showTable && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(AxesOptions, {
34383
34424
  chartRef,
34425
+ onAxesUpdate,
34384
34426
  state,
34385
34427
  controlsAxesLabels,
34386
34428
  onUpdateAxes,
@@ -34388,9 +34430,7 @@ var Controls = ({ table, headerComponent, subheaderComponent, chartRef, state, o
34388
34430
  onUpdateEdited,
34389
34431
  depthType,
34390
34432
  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
34433
+ onToggleEqualScale: canToggleEqualScale ? handleToggleEqualScale : void 0
34394
34434
  }), isNarrow ? /* @__PURE__ */ jsx(Menu, { menu: {
34395
34435
  placement: "bottom-end",
34396
34436
  sections: [
@@ -36629,13 +36669,17 @@ var getEqualScaleRanges = (x, y, width, height) => {
36629
36669
  * Fits the requested viewport after layout, when the actual plot dimensions are available.
36630
36670
  * Temporary bounds are restored so resizing and toggling do not accumulate extra padding.
36631
36671
  */
36632
- var createEqualScalePlugin = () => {
36672
+ var createEqualScalePlugin = (onAxesUpdate) => {
36633
36673
  let fitting = false;
36634
36674
  return {
36635
36675
  id: "equalAxisScale",
36636
36676
  afterUpdate(chart, _args, { enabled }) {
36677
+ if (fitting) return;
36637
36678
  const { x, y } = chart.scales;
36638
- if (!enabled || fitting || Object.keys(chart.scales).length !== 2 || x?.type !== "linear" || y?.type !== "linear") return;
36679
+ if (!enabled || Object.keys(chart.scales).length !== 2 || x?.type !== "linear" || y?.type !== "linear") {
36680
+ onAxesUpdate();
36681
+ return;
36682
+ }
36639
36683
  const baseX = {
36640
36684
  min: x.min,
36641
36685
  max: x.max
@@ -36676,11 +36720,12 @@ var createEqualScalePlugin = () => {
36676
36720
  Object.assign(chart.scales.y.options, originalY);
36677
36721
  fitting = false;
36678
36722
  }
36723
+ onAxesUpdate();
36679
36724
  }
36680
36725
  };
36681
36726
  };
36682
36727
  // src/components/line-chart/hooks/use-chart-plugins.ts
36683
- var useChartPlugins = ({ options, resetZoom }) => {
36728
+ var useChartPlugins = ({ options, resetZoom, onAxesUpdate }) => {
36684
36729
  const { graph, legend } = options;
36685
36730
  const handleDoubleClick = useCallback((_, args) => {
36686
36731
  const { event } = args;
@@ -36693,7 +36738,9 @@ var useChartPlugins = ({ options, resetZoom }) => {
36693
36738
  return useMemo(() => {
36694
36739
  return [
36695
36740
  ...getPlugins(graph, legend),
36696
- createEqualScalePlugin(),
36741
+ createEqualScalePlugin(() => {
36742
+ onAxesUpdate.current?.();
36743
+ }),
36697
36744
  {
36698
36745
  id: "customEventCatcher",
36699
36746
  beforeEvent: handleDoubleClick
@@ -36702,7 +36749,8 @@ var useChartPlugins = ({ options, resetZoom }) => {
36702
36749
  }, [
36703
36750
  graph,
36704
36751
  handleDoubleClick,
36705
- legend
36752
+ legend,
36753
+ onAxesUpdate
36706
36754
  ]);
36707
36755
  };
36708
36756
  // src/components/line-chart/hooks/use-chart-state.ts
@@ -38198,6 +38246,7 @@ var defaultTranslations = /* @__PURE__ */ function(defaultTranslations) {
38198
38246
  defaultTranslations["axesOptions"] = "Axes options";
38199
38247
  defaultTranslations["resetAxes"] = "Reset Axes";
38200
38248
  defaultTranslations["equalAxisScale"] = "Equal X/Y scale (1:1)";
38249
+ defaultTranslations["equalAxisScaleReadOnly"] = "Turn off equal scaling to edit axis limits.";
38201
38250
  defaultTranslations["done"] = "Done";
38202
38251
  defaultTranslations["downloadAsPNG"] = "Download as PNG";
38203
38252
  defaultTranslations["showChart"] = "Show chart";
@@ -38690,6 +38739,7 @@ var Legend = ({ chartRef, legendConfig, persistenceId }) => {
38690
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);
38691
38740
  var LineChart = (props) => {
38692
38741
  setDefaultTheme();
38742
+ const onAxesUpdate = useRef(null);
38693
38743
  const chartRef = useRef(null);
38694
38744
  const setChartRef = useCallback((chartInstance) => {
38695
38745
  chartRef.current = chartInstance ?? null;
@@ -38732,7 +38782,8 @@ var LineChart = (props) => {
38732
38782
  });
38733
38783
  const usePlugins = useChartPlugins({
38734
38784
  options,
38735
- resetZoom
38785
+ resetZoom,
38786
+ onAxesUpdate
38736
38787
  });
38737
38788
  return /* @__PURE__ */ jsxs("div", {
38738
38789
  className: getClassName(chartStyling, line_chart_module_default),
@@ -38749,6 +38800,7 @@ var LineChart = (props) => {
38749
38800
  headerComponent,
38750
38801
  subheaderComponent,
38751
38802
  chartRef,
38803
+ onAxesUpdate,
38752
38804
  state,
38753
38805
  options,
38754
38806
  dispatch,
@@ -6,6 +6,7 @@ export declare enum defaultTranslations {
6
6
  axesOptions = "Axes options",
7
7
  resetAxes = "Reset Axes",
8
8
  equalAxisScale = "Equal X/Y scale (1:1)",
9
+ equalAxisScaleReadOnly = "Turn off equal scaling to edit axis limits.",
9
10
  done = "Done",
10
11
  downloadAsPNG = "Download as PNG",
11
12
  showChart = "Show chart",
@@ -23,6 +23,7 @@ export interface IAxesOptions {
23
23
  depthType?: IDepthType | object;
24
24
  close?: () => void;
25
25
  onToggleEqualScale?: () => void;
26
+ onAxesUpdate: RefObject<(() => void) | null>;
26
27
  }
27
28
  export interface IOnEdit {
28
29
  name?: string;
@@ -7,6 +7,7 @@ export interface IControls {
7
7
  subheaderComponent?: ReactNode;
8
8
  table?: ReactNode;
9
9
  chartRef: RefObject<TChart | null>;
10
+ onAxesUpdate: RefObject<(() => void) | null>;
10
11
  state: IState;
11
12
  options: ILineChartOptions;
12
13
  dispatch: Dispatch<any>;
@@ -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 {};
@@ -3,6 +3,6 @@ import type { Plugin } from 'chart.js';
3
3
  * Fits the requested viewport after layout, when the actual plot dimensions are available.
4
4
  * Temporary bounds are restored so resizing and toggling do not accumulate extra padding.
5
5
  */
6
- export declare const createEqualScalePlugin: () => Plugin<'line', {
6
+ export declare const createEqualScalePlugin: (onAxesUpdate: () => void) => Plugin<'line', {
7
7
  enabled: boolean;
8
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/charts-library",
3
- "version": "9.1.0-beta-1",
3
+ "version": "9.1.0-beta-2",
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": {