@gravity-ui/chartkit 5.3.1 → 5.3.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.
@@ -0,0 +1 @@
1
+ export declare function mergeSettingStrategy(objValue: any, srcValue: any, key: string): any;
@@ -0,0 +1,31 @@
1
+ import isObject from 'lodash/isObject';
2
+ import mergeWith from 'lodash/mergeWith';
3
+ // @ts-ignore
4
+ export function mergeSettingStrategy(objValue, srcValue, key) {
5
+ if (key === 'plugins') {
6
+ const currentPlugins = [...objValue];
7
+ const newPlugins = [...srcValue];
8
+ // modify existing plugins
9
+ let newSettingsPlugins = currentPlugins.map((currentPlugin) => {
10
+ const newPluginIndex = newPlugins.findIndex(({ type }) => type === currentPlugin.type);
11
+ if (newPluginIndex !== -1) {
12
+ const newPlugin = newPlugins[newPluginIndex];
13
+ newPlugins.splice(newPluginIndex, 1);
14
+ return {
15
+ type: currentPlugin.type,
16
+ renderer: newPlugin.renderer,
17
+ };
18
+ }
19
+ return currentPlugin;
20
+ });
21
+ // add new plugins if it exist after modified
22
+ if (newPlugins.length > 0) {
23
+ newSettingsPlugins = [...newSettingsPlugins, ...newPlugins];
24
+ }
25
+ return newSettingsPlugins;
26
+ }
27
+ if (isObject(objValue)) {
28
+ return mergeWith(objValue, srcValue, mergeSettingStrategy);
29
+ }
30
+ return srcValue;
31
+ }
@@ -1,8 +1,9 @@
1
1
  import { configure } from '@gravity-ui/uikit';
2
2
  import get from 'lodash/get';
3
- import merge from 'lodash/merge';
3
+ import mergeWith from 'lodash/mergeWith';
4
4
  import { i18nFactory } from '../../i18n';
5
5
  import { EventEmitter } from './eventEmitter';
6
+ import { mergeSettingStrategy } from './mergeSettingStrategy';
6
7
  export const settingsEventEmitter = new EventEmitter();
7
8
  const removeUndefinedValues = (data) => {
8
9
  return Object.entries(data).reduce((acc, [key, value]) => {
@@ -29,7 +30,7 @@ class ChartKitSettings {
29
30
  }
30
31
  set(updates) {
31
32
  const filteredUpdates = removeUndefinedValues(updates);
32
- this.settings = merge(this.settings, filteredUpdates);
33
+ this.settings = mergeWith(this.settings, filteredUpdates, mergeSettingStrategy);
33
34
  if (filteredUpdates.lang) {
34
35
  const lang = filteredUpdates.lang || this.get('lang');
35
36
  updateLang(lang);
@@ -2,7 +2,6 @@
2
2
  import { dateTime } from '@gravity-ui/date-utils';
3
3
  import Highcharts from 'highcharts';
4
4
  import clamp from 'lodash/clamp';
5
- import debounce from 'lodash/debounce';
6
5
  import get from 'lodash/get';
7
6
  import isEmpty from 'lodash/isEmpty';
8
7
  import isNumber from 'lodash/isNumber';
@@ -1152,7 +1151,6 @@ export function prepareConfig(data, options, isMobile, holidays) {
1152
1151
  const chartType = get(options, 'highcharts.chart.type') || 'line';
1153
1152
  const { entryId } = options;
1154
1153
  const testClassName = `data-qa-chartkit-tooltip-entry-${entryId}`;
1155
- const debouncedAdjustDonutFontSize = debounce(adjustDonutFontSize, 100);
1156
1154
  const params = merge(getParamsByCustomType(options.type, options), defaultOptions, Object.assign({ _config: options, chart: {
1157
1155
  events: Object.assign({ load: function () {
1158
1156
  var _a;
@@ -1231,7 +1229,7 @@ export function prepareConfig(data, options, isMobile, holidays) {
1231
1229
  const chartSeries = chart.series[0];
1232
1230
  const innerWidth = chartSeries === null || chartSeries === void 0 ? void 0 : chartSeries.center[3];
1233
1231
  if (innerWidth) {
1234
- debouncedAdjustDonutFontSize(chart, chartSeries, innerWidth, totals);
1232
+ adjustDonutFontSize(chart, chartSeries, innerWidth, totals);
1235
1233
  }
1236
1234
  },
1237
1235
  })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "5.3.1",
3
+ "version": "5.3.3",
4
4
  "description": "React component used to render charts based on any sources you need",
5
5
  "license": "MIT",
6
6
  "repository": "git@github.com:gravity-ui/ChartKit.git",