@gravity-ui/chartkit 2.1.0 → 2.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.1](https://github.com/gravity-ui/chartkit/compare/v2.2.0...v2.2.1) (2023-03-27)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **Highcharts plugin:** proper message for empty data ([#140](https://github.com/gravity-ui/chartkit/issues/140)) ([ee41ace](https://github.com/gravity-ui/chartkit/commit/ee41ace81ddaa88601b584273a7759dfe1dbe1c9))
9
+
10
+ ## [2.2.0](https://github.com/gravity-ui/chartkit/compare/v2.1.0...v2.2.0) (2023-03-21)
11
+
12
+
13
+ ### Features
14
+
15
+ * **Higcharts plugin:** add type for manageTooltipConfig ([#139](https://github.com/gravity-ui/chartkit/issues/139)) ([f781cca](https://github.com/gravity-ui/chartkit/commit/f781cca112bb1e87607d24916aa38bf44fe2abf6))
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **Highcharts:** fix resetZoomButton styles ([#137](https://github.com/gravity-ui/chartkit/issues/137)) ([07f610e](https://github.com/gravity-ui/chartkit/commit/07f610e443f2c9a2543ac68bbff443112a1d650a))
21
+
3
22
  ## [2.1.0](https://github.com/gravity-ui/chartkit/compare/v2.0.0...v2.1.0) (2023-03-13)
4
23
 
5
24
 
@@ -89,6 +89,12 @@ export const data = {
89
89
  hideHolidays: false,
90
90
  normalizeDiv: false,
91
91
  normalizeSub: false,
92
+ manageTooltipConfig: (config) => {
93
+ config.lines.forEach((line, index) => {
94
+ line.commentText = `Some comment ${index + 1}`;
95
+ });
96
+ return config;
97
+ },
92
98
  },
93
99
  libraryConfig: {
94
100
  chart: {
@@ -487,6 +487,9 @@ export declare class HighchartsComponent extends React.PureComponent<Props, Stat
487
487
  labels: {
488
488
  formatter: () => any;
489
489
  };
490
+ events: {
491
+ setExtremes: () => void;
492
+ };
490
493
  };
491
494
  yAxis: {
492
495
  gridLineColor: string;
@@ -565,6 +565,9 @@ export function prepareConfig(data: any, options: any, isMobile: any, holidays:
565
565
  labels: {
566
566
  formatter: () => any;
567
567
  };
568
+ events: {
569
+ setExtremes: () => void;
570
+ };
568
571
  };
569
572
  yAxis: {
570
573
  crosshair: boolean | {
@@ -924,7 +924,7 @@ function fixTooltip(tooltip, options, event) {
924
924
  top = tooltipRect.top;
925
925
  tooltip.preFixationHeight = height;
926
926
  }
927
- tooltip.lastVisibleRowIndex = null;
927
+ tooltip.lastVisibleRowIndex = undefined;
928
928
  tooltip.update({
929
929
  style: Object.assign(Object.assign({}, tooltip.style), { pointerEvents: 'auto' }),
930
930
  });
@@ -1324,6 +1324,20 @@ export function prepareConfig(data, options, isMobile, holidays) {
1324
1324
  return Highcharts.Axis.prototype.defaultLabelFormatter.call(this);
1325
1325
  },
1326
1326
  },
1327
+ events: {
1328
+ setExtremes: function () {
1329
+ // There is no better way to align zoom button text
1330
+ // Callback setExtremes used because of it obligatory invocation on every zoom event
1331
+ // setTimeout used because of absence resetZoomButton node in dom on first zoom event
1332
+ setTimeout(() => {
1333
+ var _a;
1334
+ const text = (_a = this.chart.resetZoomButton) === null || _a === void 0 ? void 0 : _a.text;
1335
+ if (text) {
1336
+ text.translate(0, -6);
1337
+ }
1338
+ }, 0);
1339
+ },
1340
+ },
1327
1341
  }, yAxis: {
1328
1342
  crosshair: options.splitTooltip
1329
1343
  ? getCrosshairConfig(hasScatterSeries ? 'scatter' : chartType, true)
@@ -481,6 +481,9 @@ declare function getGraph({ options, data, comments, isMobile, holidays }: GetGr
481
481
  labels: {
482
482
  formatter: () => any;
483
483
  };
484
+ events: {
485
+ setExtremes: () => void;
486
+ };
484
487
  };
485
488
  yAxis: {
486
489
  gridLineColor: string;
@@ -31,11 +31,15 @@ Highcharts.setOptions({
31
31
  resetZoomButton: {
32
32
  relativeTo: 'chart',
33
33
  theme: {
34
- width: 16,
35
- height: 16,
34
+ r: 6,
35
+ width: 12,
36
+ height: 12,
36
37
  'text-align': 'center',
37
38
  opacity: '0.8',
38
39
  cursor: 'pointer',
40
+ style: {
41
+ fontSize: '20px',
42
+ },
39
43
  },
40
44
  position: {
41
45
  y: 30,
@@ -223,7 +227,7 @@ function initHighcharts({ isMobile }) {
223
227
  });
224
228
  Highcharts.wrap(Highcharts.Tooltip.prototype, 'hide', function (proceed, ...rest) {
225
229
  if (this.lastVisibleRowIndex) {
226
- this.lastVisibleRowIndex = null;
230
+ this.lastVisibleRowIndex = undefined;
227
231
  }
228
232
  if (this.scrollHandler && !this.fixed) {
229
233
  window.removeEventListener('scroll', this.scrollHandler);
@@ -257,7 +261,7 @@ function initHighcharts({ isMobile }) {
257
261
  const isFixation = rest[1];
258
262
  if ((!this.fixed || isFixation) && points) {
259
263
  if (isFixation) {
260
- this.lastVisibleRowIndex = null;
264
+ this.lastVisibleRowIndex = undefined;
261
265
  }
262
266
  proceed.apply(this, [points, ...rest]);
263
267
  if (chartType === 'timeline') {
@@ -292,7 +296,7 @@ function initHighcharts({ isMobile }) {
292
296
  const bottomPadding = parseFloat(window.getComputedStyle(tooltipNode, null).getPropertyValue('padding-bottom'), 10);
293
297
  const containerBottomEdge = top + height;
294
298
  const rows = tooltipNode.querySelectorAll(`.${TOOLTIP_LIST_CLASS_NAME} .${TOOLTIP_ROW_CLASS_NAME}`);
295
- let lastVisibleRowIndex = null;
299
+ let lastVisibleRowIndex;
296
300
  const selectedSeriesIndex = this.chart.hoverPoints.indexOf(this.chart.hoverPoint);
297
301
  const rowForSelectedSeriesHeight = selectedSeriesIndex >= 0
298
302
  ? rows[selectedSeriesIndex].getBoundingClientRect().height
@@ -1,5 +1,6 @@
1
1
  import moment from 'moment';
2
2
  import lodashMin from 'lodash/min';
3
+ import { i18n } from '../../../../i18n';
3
4
  import { ChartKitError, CHARTKIT_ERROR_CODE } from '../../../../libs';
4
5
  import { DEFAULT_LINES_LIMIT } from './constants';
5
6
  function prepareValue(value, firstValue, options) {
@@ -90,7 +91,10 @@ export function prepareData(data, options, holidays) {
90
91
  (data.graphs &&
91
92
  !(data.graphs.length && data.graphs.some((graph) => graph.data && graph.data.length))) ||
92
93
  (Array.isArray(data) && !data.length)) {
93
- throw new ChartKitError({ code: CHARTKIT_ERROR_CODE.NO_DATA });
94
+ throw new ChartKitError({
95
+ code: CHARTKIT_ERROR_CODE.NO_DATA,
96
+ message: i18n('error', 'label_no-data'),
97
+ });
94
98
  }
95
99
  if (data.graphs) {
96
100
  if (data.graphs.length > limit && !options.withoutLineLimit) {
@@ -160,7 +160,8 @@ export const formatTooltip = (data, tooltip, isMobile) => {
160
160
  cellsRenderers,
161
161
  useCompareFrom: data.useCompareFrom,
162
162
  isSelectedLine: true,
163
- allowComment: selectedLineIndex > tooltip.lastVisibleRowIndex,
163
+ allowComment: typeof tooltip.lastVisibleRowIndex === 'number' &&
164
+ selectedLineIndex > tooltip.lastVisibleRowIndex,
164
165
  };
165
166
  // @ts-ignore
166
167
  const windowHeight = document.body.clientHeight / ((window.visualViewport && window.visualViewport.scale) || 1);
@@ -1,11 +1,32 @@
1
1
  import type { Highcharts } from './lib';
2
2
  import type { HighchartsComment } from './comments';
3
3
  import type { DrillDownConfig, StringParams } from './misc';
4
+ import type { TooltipData, TooltipLine } from '../renderer/helpers/tooltip/types';
4
5
  export declare type CkHighchartsSeriesOptionsType = Highcharts.SeriesOptionsType & {
5
6
  title?: string;
6
7
  sname?: string;
7
8
  fname?: string;
8
9
  };
10
+ export declare type HighchartsManageTooltipConfigOptions = {
11
+ count: number;
12
+ lines: TooltipLine[];
13
+ shared: boolean;
14
+ this: {
15
+ x: string;
16
+ y: number;
17
+ points: Highcharts.Point[];
18
+ };
19
+ activeRowAlwaysFirstInTooltip?: boolean;
20
+ hiddenRowsNumber?: number;
21
+ hiddenRowsSum?: string;
22
+ splitTooltip?: boolean;
23
+ tooltipHeader?: string;
24
+ unsafe?: boolean;
25
+ useCompareFrom?: boolean;
26
+ withPercent?: boolean;
27
+ xComments?: TooltipData['xComments'];
28
+ };
29
+ export declare type HighchartsManageTooltipConfig = (options: HighchartsManageTooltipConfigOptions, chart: Highcharts.Chart) => HighchartsManageTooltipConfigOptions;
9
30
  export declare type HighchartsWidgetData = {
10
31
  data: (CkHighchartsSeriesOptionsType[] | {
11
32
  graphs: CkHighchartsSeriesOptionsType[];
@@ -58,6 +79,10 @@ export declare type HighchartsWidgetData = {
58
79
  drillDown?: DrillDownConfig;
59
80
  enableSum?: boolean;
60
81
  unsafe?: boolean;
82
+ /**
83
+ * Used to modify tooltip data
84
+ */
85
+ manageTooltipConfig?: HighchartsManageTooltipConfig;
61
86
  };
62
87
  libraryConfig: Highcharts.Options;
63
88
  params?: StringParams;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
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",