@gravity-ui/chartkit 0.9.1 → 0.10.0
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 +13 -0
- package/build/components/ChartKit.css +23 -0
- package/build/components/ChartKit.d.ts +0 -1
- package/build/components/ChartKit.js +4 -5
- package/build/i18n/keysets/en.json +60 -0
- package/build/i18n/keysets/ru.json +62 -0
- package/build/libs/chartkit-error/chartkit-error.d.ts +1 -0
- package/build/libs/chartkit-error/chartkit-error.js +1 -0
- package/build/libs/settings/__tests__/settings.test.js +1 -1
- package/build/libs/settings/settings.d.ts +6 -3
- package/build/libs/settings/settings.js +4 -2
- package/build/plugins/highcharts/__stories__/AreaRange.stories.d.ts +4 -0
- package/build/plugins/highcharts/__stories__/AreaRange.stories.js +22 -0
- package/build/plugins/highcharts/__stories__/Line.stories.d.ts +4 -0
- package/build/plugins/highcharts/__stories__/Line.stories.js +21 -0
- package/build/plugins/highcharts/__stories__/mocks/area-range.d.ts +2 -0
- package/build/plugins/highcharts/__stories__/mocks/area-range.js +61 -0
- package/build/plugins/highcharts/__stories__/mocks/holidays.d.ts +7070 -0
- package/build/plugins/highcharts/__stories__/mocks/holidays.js +7065 -0
- package/build/plugins/highcharts/__stories__/mocks/line.d.ts +2 -0
- package/build/plugins/highcharts/__stories__/mocks/line.js +129 -0
- package/build/plugins/highcharts/index.d.ts +2 -0
- package/build/plugins/highcharts/index.js +5 -0
- package/build/plugins/highcharts/renderer/HighchartsWidget.d.ts +23 -0
- package/build/plugins/highcharts/renderer/HighchartsWidget.js +6 -0
- package/build/plugins/highcharts/renderer/components/HighchartsComponent.css +4 -0
- package/build/plugins/highcharts/renderer/components/HighchartsComponent.d.ts +575 -0
- package/build/plugins/highcharts/renderer/components/HighchartsComponent.js +115 -0
- package/build/plugins/highcharts/renderer/components/StyledSplitPane/StyledSplitPane.css +50 -0
- package/build/plugins/highcharts/renderer/components/StyledSplitPane/StyledSplitPane.d.ts +10 -0
- package/build/plugins/highcharts/renderer/components/StyledSplitPane/StyledSplitPane.js +32 -0
- package/build/plugins/highcharts/renderer/components/withSplitPane/WithSplitPane.css +4 -0
- package/build/plugins/highcharts/renderer/components/withSplitPane/withSplitPane.d.ts +10 -0
- package/build/plugins/highcharts/renderer/components/withSplitPane/withSplitPane.js +207 -0
- package/build/plugins/highcharts/renderer/helpers/add-holidays.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/add-holidays.js +43 -0
- package/build/plugins/highcharts/renderer/helpers/comments/drawing.d.ts +11 -0
- package/build/plugins/highcharts/renderer/helpers/comments/drawing.js +571 -0
- package/build/plugins/highcharts/renderer/helpers/config/config.d.ts +575 -0
- package/build/plugins/highcharts/renderer/helpers/config/config.js +1483 -0
- package/build/plugins/highcharts/renderer/helpers/config/handleLegendItemClick.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/handleLegendItemClick.js +57 -0
- package/build/plugins/highcharts/renderer/helpers/config/options.d.ts +465 -0
- package/build/plugins/highcharts/renderer/helpers/config/options.js +350 -0
- package/build/plugins/highcharts/renderer/helpers/config/types.d.ts +6 -0
- package/build/plugins/highcharts/renderer/helpers/config/types.js +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.d.ts +10 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.js +42 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.test.js +99 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.js +17 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.test.js +28 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.d.ts +5 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.test.js +27 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/concatStrings.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/concatStrings.js +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getChartKitFormattedValue.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getChartKitFormattedValue.js +15 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.d.ts +3 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.js +15 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.test.js +11 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.js +9 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.test.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/index.d.ts +13 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/index.js +13 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isNavigatorSeries.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isNavigatorSeries.js +3 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isSafari.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isSafari.js +12 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.js +8 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.test.js +31 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/localStorage.d.ts +5 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/localStorage.js +23 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/mergeArrayWithObject.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/mergeArrayWithObject.js +10 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.js +19 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.test.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.d.ts +13 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.js +27 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.test.js +45 -0
- package/build/plugins/highcharts/renderer/helpers/constants.d.ts +28 -0
- package/build/plugins/highcharts/renderer/helpers/constants.js +30 -0
- package/build/plugins/highcharts/renderer/helpers/graph.css +89 -0
- package/build/plugins/highcharts/renderer/helpers/graph.d.ts +552 -0
- package/build/plugins/highcharts/renderer/helpers/graph.js +85 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/colors.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/colors.js +17 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/highcharts.d.ts +4 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/highcharts.js +346 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calcucalteClosestPointManually.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calcucalteClosestPointManually.js +19 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calculateClosestPointManually.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calculateClosestPointManually.test.js +42 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/index.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/index.js +1 -0
- package/build/plugins/highcharts/renderer/helpers/init-highcharts-modules.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/init-highcharts-modules.js +49 -0
- package/build/plugins/highcharts/renderer/helpers/prepare-data.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/prepare-data.js +175 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/constants.d.ts +13 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/constants.js +14 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/helpers.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/helpers.js +5 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/index.d.ts +13 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/index.js +253 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/index.d.ts +6 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/index.js +22 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashDotLineIcon.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashLineIcon.js +25 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DotLineIcon.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotDotLineIcon.js +18 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotLineIcon.js +18 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashLineIcon.js +15 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotDotLineIcon.js +18 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotLineIcon.js +18 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashLineIcon.js +18 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDotLineIcon.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/SolidLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/SolidLineIcon.js +13 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/index.d.ts +11 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/index.js +11 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/types.d.ts +4 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/types.js +1 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/utils.d.ts +7 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/utils.js +5 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/tooltip.css +367 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/types.d.ts +85 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/types.js +1 -0
- package/build/plugins/highcharts/renderer/helpers/types.d.ts +22 -0
- package/build/plugins/highcharts/renderer/helpers/types.js +1 -0
- package/build/plugins/highcharts/types/comments.d.ts +51 -0
- package/build/plugins/highcharts/types/comments.js +1 -0
- package/build/plugins/highcharts/types/highcharts-extends.d.ts +38 -0
- package/build/plugins/highcharts/types/index.d.ts +4 -0
- package/build/plugins/highcharts/types/index.js +1 -0
- package/build/plugins/highcharts/types/lib.d.ts +1 -0
- package/build/plugins/highcharts/types/lib.js +1 -0
- package/build/plugins/highcharts/types/misc.d.ts +19 -0
- package/build/plugins/highcharts/types/misc.js +1 -0
- package/build/plugins/highcharts/types/widget.d.ts +47 -0
- package/build/plugins/highcharts/types/widget.js +1 -0
- package/build/plugins/index.d.ts +4 -2
- package/build/plugins/index.js +1 -0
- package/build/plugins/indicator/renderer/IndicatorItem.d.ts +3 -2
- package/build/plugins/indicator/renderer/IndicatorWidget.d.ts +10 -2
- package/build/plugins/indicator/renderer/IndicatorWidget.js +1 -1
- package/build/plugins/indicator/types.d.ts +0 -6
- package/build/plugins/shared/format-number/format-number.d.ts +4 -0
- package/build/plugins/shared/format-number/format-number.js +88 -0
- package/build/plugins/shared/format-number/format-number.test.d.ts +1 -0
- package/build/plugins/shared/format-number/format-number.test.js +14 -0
- package/build/plugins/shared/format-number/i18n/en.json +17 -0
- package/build/plugins/shared/format-number/i18n/i18n.d.ts +5 -0
- package/build/plugins/shared/format-number/i18n/i18n.js +8 -0
- package/build/plugins/shared/format-number/i18n/ru.json +17 -0
- package/build/plugins/shared/format-number/types.d.ts +14 -0
- package/build/plugins/shared/format-number/types.js +1 -0
- package/build/plugins/shared/index.d.ts +2 -0
- package/build/plugins/shared/index.js +1 -0
- package/build/plugins/yagr/renderer/YagrWidget.d.ts +11 -3
- package/build/plugins/yagr/renderer/YagrWidget.js +2 -1
- package/build/plugins/yagr/types.d.ts +0 -7
- package/build/types/index.d.ts +1 -2
- package/build/types/misc.d.ts +4 -0
- package/build/types/misc.js +1 -0
- package/build/types/widget.d.ts +17 -0
- package/package.json +4 -1
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ChartKitWidgetRef } from '../../../types';
|
|
3
|
-
import type { IndicatorWidgetProps } from '../types';
|
|
4
3
|
import './IndicatorWidget.css';
|
|
5
|
-
declare const IndicatorWidget: React.ForwardRefExoticComponent<
|
|
4
|
+
declare const IndicatorWidget: React.ForwardRefExoticComponent<{
|
|
5
|
+
type: "indicator";
|
|
6
|
+
data: import("../types").IndicatorWidgetData;
|
|
7
|
+
id?: string | undefined;
|
|
8
|
+
isMobile?: boolean | undefined;
|
|
9
|
+
onLoad?: ((data?: import("../../../types").ChartKitOnLoadData<"indicator"> | undefined) => void) | undefined;
|
|
10
|
+
onError?: import("../../../types").ChartKitOnError | undefined;
|
|
11
|
+
} & {
|
|
12
|
+
formatNumber?: (<T = any>(value: number, options?: T | undefined) => string) | undefined;
|
|
13
|
+
} & React.RefAttributes<ChartKitWidgetRef | undefined>>;
|
|
6
14
|
export default IndicatorWidget;
|
|
@@ -10,7 +10,7 @@ const b = block('chartkit-indicator');
|
|
|
10
10
|
const IndicatorWidget = React.forwardRef(
|
|
11
11
|
// _ref needs to avoid this React warning:
|
|
12
12
|
// "forwardRef render functions accept exactly two parameters: props and ref"
|
|
13
|
-
(props, _ref)
|
|
13
|
+
function IndicatorWidgetInner(props, _ref) {
|
|
14
14
|
const { onLoad, formatNumber, data: { data = [], defaultColor }, } = props;
|
|
15
15
|
React.useLayoutEffect(() => {
|
|
16
16
|
// TODO: swap to onRender after https://github.com/gravity-ui/chartkit/issues/33
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ChartKitFormatNumber } from '../../types';
|
|
2
1
|
export declare type IndicatorWidgetDataItem = {
|
|
3
2
|
content: {
|
|
4
3
|
current: {
|
|
@@ -14,8 +13,3 @@ export declare type IndicatorWidgetData = {
|
|
|
14
13
|
data?: IndicatorWidgetDataItem[];
|
|
15
14
|
defaultColor?: string;
|
|
16
15
|
};
|
|
17
|
-
export declare type IndicatorWidgetProps = {
|
|
18
|
-
data: IndicatorWidgetData;
|
|
19
|
-
onLoad?: () => void;
|
|
20
|
-
formatNumber?: ChartKitFormatNumber;
|
|
21
|
-
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FormatOptions, FormatNumberOptions } from './types';
|
|
2
|
+
export declare const formatBytes: (value: number, options?: FormatOptions) => string;
|
|
3
|
+
export declare const formatDuration: (value: number, options?: FormatOptions) => string;
|
|
4
|
+
export declare const formatNumber: (value: number | string, options?: FormatNumberOptions) => string;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import ru from './i18n/ru.json';
|
|
2
|
+
import en from './i18n/en.json';
|
|
3
|
+
import { i18nInstance, makeInstance } from './i18n/i18n';
|
|
4
|
+
const i18n = makeInstance('chartkit-units', { ru, en });
|
|
5
|
+
const unitFormatter = ({ exponent, unitsI18nKeys, unitDelimiterI18nKey, }) => {
|
|
6
|
+
return function formatUnit(value, options = {}) {
|
|
7
|
+
const { precision, unitRate, showRankDelimiter = true, lang } = options;
|
|
8
|
+
const i18nLang = i18nInstance.lang;
|
|
9
|
+
if (lang) {
|
|
10
|
+
i18nInstance.setLang(lang);
|
|
11
|
+
}
|
|
12
|
+
let resultUnitRate;
|
|
13
|
+
if (typeof unitRate === 'number') {
|
|
14
|
+
resultUnitRate = unitRate;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
resultUnitRate = 1;
|
|
18
|
+
while (Math.abs(value / Math.pow(exponent, resultUnitRate)) >= 1 &&
|
|
19
|
+
resultUnitRate < 10 &&
|
|
20
|
+
i18n(unitsI18nKeys[resultUnitRate])) {
|
|
21
|
+
resultUnitRate++;
|
|
22
|
+
}
|
|
23
|
+
resultUnitRate--;
|
|
24
|
+
}
|
|
25
|
+
let result = value / Math.pow(exponent, resultUnitRate);
|
|
26
|
+
if (typeof precision === 'number') {
|
|
27
|
+
result = Number(result.toFixed(precision));
|
|
28
|
+
}
|
|
29
|
+
else if (precision === 'auto' && result % 1 !== 0) {
|
|
30
|
+
result = Number(result.toFixed(Math.abs(result) > 1 ? 2 : 4));
|
|
31
|
+
}
|
|
32
|
+
result = new Intl.NumberFormat(lang !== null && lang !== void 0 ? lang : i18nLang, {
|
|
33
|
+
minimumFractionDigits: typeof precision === 'number' ? precision : 0,
|
|
34
|
+
maximumFractionDigits: 20,
|
|
35
|
+
useGrouping: showRankDelimiter,
|
|
36
|
+
}).format(result);
|
|
37
|
+
const unit = i18n(unitsI18nKeys[resultUnitRate]);
|
|
38
|
+
const delimiter = i18n(unitDelimiterI18nKey);
|
|
39
|
+
i18nInstance.setLang(i18nLang);
|
|
40
|
+
return `${result}${delimiter}${unit}`;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export const formatBytes = unitFormatter({
|
|
44
|
+
exponent: 1024,
|
|
45
|
+
unitDelimiterI18nKey: 'value_space-delimiter',
|
|
46
|
+
unitsI18nKeys: ['value_short-bytes', 'value_short-kilobytes', 'value_short-megabytes'],
|
|
47
|
+
});
|
|
48
|
+
export const formatDuration = unitFormatter({
|
|
49
|
+
exponent: 1000,
|
|
50
|
+
unitDelimiterI18nKey: 'value_space-delimiter',
|
|
51
|
+
unitsI18nKeys: ['value_short-milliseconds', 'value_short-seconds', 'value_short-minutes'],
|
|
52
|
+
});
|
|
53
|
+
const baseFormatNumber = unitFormatter({
|
|
54
|
+
exponent: 1000,
|
|
55
|
+
unitDelimiterI18nKey: 'value_number-delimiter',
|
|
56
|
+
unitsI18nKeys: [
|
|
57
|
+
'value_short-empty',
|
|
58
|
+
'value_short-k',
|
|
59
|
+
'value_short-m',
|
|
60
|
+
'value_short-b',
|
|
61
|
+
'value_short-t',
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
const NUMBER_UNIT_RATE_BY_UNIT = {
|
|
65
|
+
default: 0,
|
|
66
|
+
auto: undefined,
|
|
67
|
+
k: 1,
|
|
68
|
+
m: 2,
|
|
69
|
+
b: 3,
|
|
70
|
+
t: 4,
|
|
71
|
+
};
|
|
72
|
+
export const formatNumber = (value, options = {}) => {
|
|
73
|
+
if (Number.isNaN(value) || Number.isNaN(Number(value))) {
|
|
74
|
+
return new Intl.NumberFormat('en').format(Number(value));
|
|
75
|
+
}
|
|
76
|
+
const { format = 'number', multiplier = 1, prefix = '', postfix = '', unit, unitRate, labelMode, } = options;
|
|
77
|
+
let changedMultiplier = multiplier;
|
|
78
|
+
let prePostfix = '';
|
|
79
|
+
if (format === 'percent') {
|
|
80
|
+
changedMultiplier = 100;
|
|
81
|
+
prePostfix = '%';
|
|
82
|
+
}
|
|
83
|
+
if (labelMode === 'percent') {
|
|
84
|
+
prePostfix = '%';
|
|
85
|
+
}
|
|
86
|
+
const formattedValue = baseFormatNumber(Number(value) * changedMultiplier, Object.assign(Object.assign({}, options), { unitRate: unitRate !== null && unitRate !== void 0 ? unitRate : NUMBER_UNIT_RATE_BY_UNIT[unit !== null && unit !== void 0 ? unit : 'default'] }));
|
|
87
|
+
return `${prefix}${formattedValue}${prePostfix}${postfix}`;
|
|
88
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { i18nInstance } from './i18n/i18n';
|
|
2
|
+
import { formatNumber } from './format-number';
|
|
3
|
+
i18nInstance.setLang('en');
|
|
4
|
+
describe('plugins/shared', () => {
|
|
5
|
+
test.each([
|
|
6
|
+
['not-a-number', undefined, 'NaN'],
|
|
7
|
+
[NaN, undefined, 'NaN'],
|
|
8
|
+
['0.2211556', undefined, '0.2211556'],
|
|
9
|
+
['0.2211556', { precision: 4 }, '0.2212'],
|
|
10
|
+
])('formatNumber (args: {value: %p, options: %p})', (value, options, expected) => {
|
|
11
|
+
const result = formatNumber(value, options);
|
|
12
|
+
expect(result).toEqual(expected);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"chartkit-units": {
|
|
3
|
+
"value_short-bytes": "B",
|
|
4
|
+
"value_short-kilobytes": "KB",
|
|
5
|
+
"value_short-megabytes": "MB",
|
|
6
|
+
"value_short-milliseconds": "ms",
|
|
7
|
+
"value_short-seconds": "s",
|
|
8
|
+
"value_short-minutes": "m",
|
|
9
|
+
"value_short-empty": "",
|
|
10
|
+
"value_short-k": "K",
|
|
11
|
+
"value_short-m": "M",
|
|
12
|
+
"value_short-b": "B",
|
|
13
|
+
"value_short-t": "T",
|
|
14
|
+
"value_space-delimiter": " ",
|
|
15
|
+
"value_number-delimiter": ""
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { I18N } from '@gravity-ui/i18n';
|
|
2
|
+
declare type KeysetData = Parameters<InstanceType<typeof I18N>['registerKeysets']>[1];
|
|
3
|
+
declare const i18nInstance: I18N;
|
|
4
|
+
declare const makeInstance: (keysetName: string, keysetsData: Record<string, KeysetData>) => (key: string, params?: import("@gravity-ui/i18n").Params | undefined) => string;
|
|
5
|
+
export { i18nInstance, makeInstance };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { I18N } from '@gravity-ui/i18n';
|
|
2
|
+
const i18nInstance = new I18N();
|
|
3
|
+
i18nInstance.setLang('ru');
|
|
4
|
+
const makeInstance = (keysetName, keysetsData) => {
|
|
5
|
+
Object.entries(keysetsData).forEach(([key, value]) => i18nInstance.registerKeysets(key, value));
|
|
6
|
+
return i18nInstance.i18n.bind(i18nInstance, keysetName);
|
|
7
|
+
};
|
|
8
|
+
export { i18nInstance, makeInstance };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"chartkit-units": {
|
|
3
|
+
"value_short-bytes": "Б",
|
|
4
|
+
"value_short-kilobytes": "КБ",
|
|
5
|
+
"value_short-megabytes": "МБ",
|
|
6
|
+
"value_short-milliseconds": "мс",
|
|
7
|
+
"value_short-seconds": "с",
|
|
8
|
+
"value_short-minutes": "м",
|
|
9
|
+
"value_short-empty": "",
|
|
10
|
+
"value_short-k": "K",
|
|
11
|
+
"value_short-m": "M",
|
|
12
|
+
"value_short-b": "B",
|
|
13
|
+
"value_short-t": "T",
|
|
14
|
+
"value_space-delimiter": " ",
|
|
15
|
+
"value_number-delimiter": ""
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare type FormatOptions = {
|
|
2
|
+
precision?: number | 'auto';
|
|
3
|
+
unitRate?: number;
|
|
4
|
+
showRankDelimiter?: boolean;
|
|
5
|
+
lang?: string;
|
|
6
|
+
labelMode?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare type FormatNumberOptions = FormatOptions & {
|
|
9
|
+
format?: 'number' | 'percent';
|
|
10
|
+
multiplier?: number;
|
|
11
|
+
prefix?: string;
|
|
12
|
+
postfix?: string;
|
|
13
|
+
unit?: 'auto' | 'k' | 'm' | 'b' | 't' | null;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { formatNumber } from './format-number/format-number';
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ChartKitWidgetRef } from '../../../types';
|
|
3
|
-
import type { YagrWidgetProps } from '../types';
|
|
2
|
+
import type { ChartKitWidgetRef } from '../../../types';
|
|
4
3
|
import './polyfills';
|
|
5
4
|
import './YagrWidget.css';
|
|
6
|
-
declare const YagrWidget: React.ForwardRefExoticComponent<
|
|
5
|
+
declare const YagrWidget: React.ForwardRefExoticComponent<{
|
|
6
|
+
type: "yagr";
|
|
7
|
+
data: import("../types").YagrWidgetData;
|
|
8
|
+
id?: string | undefined;
|
|
9
|
+
isMobile?: boolean | undefined;
|
|
10
|
+
onLoad?: ((data?: import("../../../types").ChartKitOnLoadData<"yagr"> | undefined) => void) | undefined;
|
|
11
|
+
onError?: import("../../../types").ChartKitOnError | undefined;
|
|
12
|
+
} & {} & {
|
|
13
|
+
id: string;
|
|
14
|
+
} & React.RefAttributes<ChartKitWidgetRef | undefined>>;
|
|
7
15
|
export default YagrWidget;
|
|
@@ -4,6 +4,7 @@ import debounce from 'lodash/debounce';
|
|
|
4
4
|
import { useThemeType } from '@gravity-ui/uikit';
|
|
5
5
|
import YagrComponent from 'yagr/dist/react';
|
|
6
6
|
import { defaults, } from 'yagr';
|
|
7
|
+
import { settings } from '../../../libs';
|
|
7
8
|
import { formatTooltip } from './tooltip/tooltip';
|
|
8
9
|
import { synchronizeTooltipTablesCellsWidth } from './synchronizeTooltipTablesCellsWidth';
|
|
9
10
|
import './polyfills';
|
|
@@ -114,7 +115,7 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
|
|
|
114
115
|
}
|
|
115
116
|
};
|
|
116
117
|
const config = Object.assign(Object.assign({}, libraryConfig), { timeline: data.timeline, series: data.graphs });
|
|
117
|
-
config.settings = Object.assign({ locale:
|
|
118
|
+
config.settings = Object.assign({ locale: settings.get('lang'), theme }, (config.settings || {}));
|
|
118
119
|
if (((_a = config.tooltip) === null || _a === void 0 ? void 0 : _a.enabled) !== false) {
|
|
119
120
|
config.tooltip = config.tooltip || {};
|
|
120
121
|
config.tooltip.render = ((_b = config.tooltip) === null || _b === void 0 ? void 0 : _b.render) || renderTooltip;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { default as YagrLib, RawSerieData, YagrConfig } from 'yagr';
|
|
2
|
-
import type { ChartKitLang, ChartKitOnLoadData } from '../../types';
|
|
3
2
|
export declare type Yagr = YagrLib;
|
|
4
3
|
export declare type YagrWidgetData = {
|
|
5
4
|
data: {
|
|
@@ -13,9 +12,3 @@ export declare type YagrWidgetData = {
|
|
|
13
12
|
};
|
|
14
13
|
}>;
|
|
15
14
|
};
|
|
16
|
-
export declare type YagrWidgetProps = {
|
|
17
|
-
id: string;
|
|
18
|
-
data: YagrWidgetData;
|
|
19
|
-
lang?: ChartKitLang;
|
|
20
|
-
onLoad?: (data?: ChartKitOnLoadData<'yagr'>) => void;
|
|
21
|
-
};
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { ChartkitWidget } from './widget';
|
|
3
|
+
export type { ChartKitHolidays } from './misc';
|
|
3
4
|
export declare type ChartKitLang = 'ru' | 'en';
|
|
4
5
|
export declare type ChartkitType = keyof ChartkitWidget;
|
|
5
6
|
export declare type ChartKitRef = {
|
|
@@ -15,7 +16,6 @@ export declare type ChartKitOnLoadData<T extends ChartkitType> = {
|
|
|
15
16
|
export declare type ChartKitOnError = (data: {
|
|
16
17
|
error: any;
|
|
17
18
|
}) => void;
|
|
18
|
-
export declare type ChartKitFormatNumber = <T = any>(value: number, options?: T) => string;
|
|
19
19
|
export declare type ChartKitProps<T extends ChartkitType> = {
|
|
20
20
|
type: T;
|
|
21
21
|
data: ChartkitWidget[T]['data'];
|
|
@@ -23,7 +23,6 @@ export declare type ChartKitProps<T extends ChartkitType> = {
|
|
|
23
23
|
isMobile?: boolean;
|
|
24
24
|
onLoad?: (data?: ChartKitOnLoadData<T>) => void;
|
|
25
25
|
onError?: ChartKitOnError;
|
|
26
|
-
formatNumber?: ChartKitFormatNumber;
|
|
27
26
|
} & {
|
|
28
27
|
[key in keyof Omit<ChartkitWidget[T], 'data' | 'widget'>]: ChartkitWidget[T][key];
|
|
29
28
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/build/types/widget.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type Yagr from 'yagr';
|
|
2
2
|
import type { YagrWidgetData } from '../plugins/yagr/types';
|
|
3
3
|
import type { IndicatorWidgetData } from '../plugins/indicator/types';
|
|
4
|
+
import type { Highcharts, HighchartsWidgetData, StringParams } from '../plugins/highcharts/types';
|
|
4
5
|
export interface ChartkitWidget {
|
|
5
6
|
yagr: {
|
|
6
7
|
data: YagrWidgetData;
|
|
@@ -9,5 +10,21 @@ export interface ChartkitWidget {
|
|
|
9
10
|
indicator: {
|
|
10
11
|
data: IndicatorWidgetData;
|
|
11
12
|
widget: never;
|
|
13
|
+
formatNumber?: <T = any>(value: number, options?: T) => string;
|
|
14
|
+
};
|
|
15
|
+
highcharts: {
|
|
16
|
+
data: HighchartsWidgetData;
|
|
17
|
+
widget: Highcharts.Chart | null;
|
|
18
|
+
hoistConfigError?: boolean;
|
|
19
|
+
nonBodyScroll?: boolean;
|
|
20
|
+
splitTooltip?: boolean;
|
|
21
|
+
onChange?: (data: {
|
|
22
|
+
type: 'PARAMS_CHANGED';
|
|
23
|
+
data: {
|
|
24
|
+
params: StringParams;
|
|
25
|
+
};
|
|
26
|
+
}, state: {
|
|
27
|
+
forceUpdate: boolean;
|
|
28
|
+
}, callExternalOnChange?: boolean) => void;
|
|
12
29
|
};
|
|
13
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/chartkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
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",
|
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"bem-cn-lite": "^4.1.0",
|
|
17
|
+
"highcharts": "^8.2.2",
|
|
18
|
+
"highcharts-react-official": "^3.0.0",
|
|
17
19
|
"lodash": "^4.17.21",
|
|
20
|
+
"react-split-pane": "^0.1.92",
|
|
18
21
|
"yagr": "1.3.7"
|
|
19
22
|
},
|
|
20
23
|
"devDependencies": {
|