@gravity-ui/chartkit 4.19.0 → 4.19.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.
@@ -1,4 +1,4 @@
1
- import type { Yagr, YagrWidgetData, YagrTheme, MinimalValidConfig } from '../types';
1
+ import type { Yagr, YagrWidgetData, YagrTheme, YagrChartOptions, MinimalValidConfig } from '../types';
2
2
  type ShapeYagrConfigArgs = {
3
3
  data: YagrWidgetData['data'];
4
4
  libraryConfig: YagrWidgetData['libraryConfig'];
@@ -18,5 +18,12 @@ export declare const detectClickOutside: (args: {
18
18
  };
19
19
  yagr?: Yagr<MinimalValidConfig> | undefined;
20
20
  }) => (event: MouseEvent) => void;
21
+ /**
22
+ * This function needs to align timezone that uplot is processing.
23
+ * Uplot uses simple new Date() when [processing ticks](https://github.com/leeoniya/uPlot/blob/master/src/opts.js#L177) on axis.
24
+ * It leads that timestamp will be converted to user browser timezone.
25
+ * In this function we artificially add shift diff between browser timezone and user timeozne to reset new Date() affects.
26
+ */
27
+ export declare const getUplotTimezoneAligner: (chart?: YagrChartOptions, timeZone?: string) => (ts: number) => Date;
21
28
  export declare const shapeYagrConfig: (args: ShapeYagrConfigArgs) => MinimalValidConfig;
22
29
  export {};
@@ -82,6 +82,20 @@ const getXAxisFormatter = (msm = 1, timeZone) => (_, ticks) => {
82
82
  return d.format(range < 300 ? 'HH:mm:ss' : 'HH:mm');
83
83
  });
84
84
  };
85
+ /**
86
+ * This function needs to align timezone that uplot is processing.
87
+ * Uplot uses simple new Date() when [processing ticks](https://github.com/leeoniya/uPlot/blob/master/src/opts.js#L177) on axis.
88
+ * It leads that timestamp will be converted to user browser timezone.
89
+ * In this function we artificially add shift diff between browser timezone and user timeozne to reset new Date() affects.
90
+ */
91
+ export const getUplotTimezoneAligner = (chart, timeZone) => (ts) => {
92
+ const dt = ts / ((chart === null || chart === void 0 ? void 0 : chart.timeMultiplier) || 1);
93
+ const browserDate = dateTime({ input: dt });
94
+ const browserTimezone = browserDate.utcOffset();
95
+ const timestampRealTimezone = dateTime({ input: dt, timeZone }).utcOffset();
96
+ const uPlotOffset = (browserTimezone - timestampRealTimezone) * 60 * 1000;
97
+ return new Date(browserDate.valueOf() + uPlotOffset);
98
+ };
85
99
  export const shapeYagrConfig = (args) => {
86
100
  var _a, _b;
87
101
  const { data, libraryConfig, theme } = args;
@@ -114,6 +128,7 @@ export const shapeYagrConfig = (args) => {
114
128
  }
115
129
  config.axes = config.axes || {};
116
130
  const xAxis = config.axes[defaults.DEFAULT_X_SCALE];
131
+ config.editUplotOptions = (opts) => (Object.assign(Object.assign({}, opts), { tzDate: timeZone ? getUplotTimezoneAligner(config.chart, timeZone) : undefined }));
117
132
  if (xAxis && !xAxis.values) {
118
133
  xAxis.values = getXAxisFormatter(config.chart.timeMultiplier, timeZone);
119
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "4.19.0",
3
+ "version": "4.19.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",
@@ -47,7 +47,7 @@
47
47
  ],
48
48
  "dependencies": {
49
49
  "@bem-react/classname": "^1.6.0",
50
- "@gravity-ui/date-utils": "^1.4.1",
50
+ "@gravity-ui/date-utils": "^1.4.2",
51
51
  "@gravity-ui/yagr": "^4.2.3",
52
52
  "afterframe": "^1.0.2",
53
53
  "d3": "^7.8.5",