@pushwoosh/kit-charts 0.4.1 → 0.4.3

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.
Files changed (2) hide show
  1. package/core/Chart/Chart.js +12 -12
  2. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useCallback, useEffect, useMemo, useState } from 'react';
3
3
  import { Grid, XAxis, XAxisLine, YAxis } from './Axes';
4
4
  import { ChartErrorBoundary } from './ChartErrorBoundary';
5
5
  import { Legend } from './Legend';
@@ -158,11 +158,13 @@ function ChartBody({
158
158
  const identity = seriesIdentity(options);
159
159
  // A different set of series is a different chart: start from its own options
160
160
  // again rather than carrying the previous chart's switched-off indices over.
161
- useEffect(() => {
161
+ const identityDeps = [identity];
162
+ const [prevIdentityDeps, setPrevIdentityDeps] = useState(null);
163
+ if (prevIdentityDeps === null || identityDeps.some((dep, index) => dep !== prevIdentityDeps[index])) {
164
+ setPrevIdentityDeps(identityDeps);
162
165
  setHidden(hiddenByOptions(options));
163
166
  setZoom(null);
164
- // eslint-disable-next-line react-hooks/exhaustive-deps
165
- }, [identity]);
167
+ }
166
168
  const toggle = useCallback(item => {
167
169
  // A tooltip captured before the toggle would keep quoting what just went away.
168
170
  setHover(null);
@@ -209,12 +211,10 @@ function ChartBody({
209
211
  hidden
210
212
  }) : null, [zoomed, canvas, registry, hidden]);
211
213
  const anyShown = built?.series.some(series => !series.hidden) ?? false;
212
- const lastShown = useRef(null);
213
- useEffect(() => {
214
- if (built && anyShown) {
215
- lastShown.current = built;
216
- }
217
- }, [built, anyShown]);
214
+ const [lastShown, setLastShown] = useState(null);
215
+ if (built && anyShown && built !== lastShown) {
216
+ setLastShown(built);
217
+ }
218
218
  // Switching off the last series must not reshape the axes under it: the plot
219
219
  // holds the geometry of the last state that had something on show, so the series
220
220
  // fades out where it stood instead of jumping to a rescaled axis first.
@@ -222,7 +222,7 @@ function ChartBody({
222
222
  if (anyShown || !built) {
223
223
  return built;
224
224
  }
225
- const frozen = lastShown.current;
225
+ const frozen = lastShown;
226
226
  if (!frozen) {
227
227
  return built;
228
228
  }
@@ -235,7 +235,7 @@ function ChartBody({
235
235
  legend: built.legend,
236
236
  titles: built.titles
237
237
  };
238
- }, [built, anyShown]);
238
+ }, [built, anyShown, lastShown]);
239
239
  const contextFor = useCallback(series => {
240
240
  if (!model) {
241
241
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/kit-charts",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Small React chart library on SVG, with a Highcharts-shaped configuration model",
5
5
  "license": "MIT",
6
6
  "repository": {