@gravity-ui/charts 1.15.0 → 1.16.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/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +4 -2
- package/dist/cjs/components/Tooltip/ChartTooltipContent.js +2 -2
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/Row.d.ts +2 -1
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/Row.js +3 -3
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/{RowTotals.d.ts → RowWithAggregation.d.ts} +2 -1
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/{RowTotals.js → RowWithAggregation.js} +3 -3
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.d.ts +4 -2
- package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +171 -114
- package/dist/cjs/components/Tooltip/index.js +1 -1
- package/dist/cjs/components/Tooltip/styles.css +11 -1
- package/dist/cjs/hooks/useSeries/prepare-area.js +1 -0
- package/dist/cjs/hooks/useSeries/prepare-bar-x.js +1 -0
- package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +1 -0
- package/dist/cjs/hooks/useSeries/prepare-bar-y.js +1 -0
- package/dist/cjs/hooks/useSeries/prepare-line.js +1 -0
- package/dist/cjs/hooks/useSeries/prepare-pie.js +1 -0
- package/dist/cjs/hooks/useSeries/prepare-radar.js +1 -0
- package/dist/cjs/hooks/useSeries/prepare-sankey.js +1 -0
- package/dist/cjs/hooks/useSeries/prepare-scatter.js +1 -0
- package/dist/cjs/hooks/useSeries/prepare-treemap.js +1 -0
- package/dist/cjs/hooks/useSeries/prepare-waterfall.js +1 -0
- package/dist/cjs/hooks/useSeries/types.d.ts +2 -1
- package/dist/cjs/i18n/keysets/en.json +2 -1
- package/dist/cjs/i18n/keysets/ru.json +2 -1
- package/dist/cjs/types/chart/base.d.ts +13 -0
- package/dist/cjs/types/chart/tooltip.d.ts +5 -1
- package/dist/cjs/utils/chart/format.d.ts +9 -2
- package/dist/cjs/utils/chart/format.js +39 -5
- package/dist/cjs/utils/chart/index.d.ts +6 -10
- package/dist/cjs/utils/chart/index.js +6 -26
- package/dist/cjs/utils/misc.d.ts +1 -0
- package/dist/cjs/utils/misc.js +6 -0
- package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +4 -2
- package/dist/esm/components/Tooltip/ChartTooltipContent.js +2 -2
- package/dist/esm/components/Tooltip/DefaultTooltipContent/Row.d.ts +2 -1
- package/dist/esm/components/Tooltip/DefaultTooltipContent/Row.js +3 -3
- package/dist/esm/components/Tooltip/DefaultTooltipContent/{RowTotals.d.ts → RowWithAggregation.d.ts} +2 -1
- package/dist/esm/components/Tooltip/DefaultTooltipContent/{RowTotals.js → RowWithAggregation.js} +3 -3
- package/dist/esm/components/Tooltip/DefaultTooltipContent/index.d.ts +4 -2
- package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +171 -114
- package/dist/esm/components/Tooltip/index.js +1 -1
- package/dist/esm/components/Tooltip/styles.css +11 -1
- package/dist/esm/hooks/useSeries/prepare-area.js +1 -0
- package/dist/esm/hooks/useSeries/prepare-bar-x.js +1 -0
- package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +1 -0
- package/dist/esm/hooks/useSeries/prepare-bar-y.js +1 -0
- package/dist/esm/hooks/useSeries/prepare-line.js +1 -0
- package/dist/esm/hooks/useSeries/prepare-pie.js +1 -0
- package/dist/esm/hooks/useSeries/prepare-radar.js +1 -0
- package/dist/esm/hooks/useSeries/prepare-sankey.js +1 -0
- package/dist/esm/hooks/useSeries/prepare-scatter.js +1 -0
- package/dist/esm/hooks/useSeries/prepare-treemap.js +1 -0
- package/dist/esm/hooks/useSeries/prepare-waterfall.js +1 -0
- package/dist/esm/hooks/useSeries/types.d.ts +2 -1
- package/dist/esm/i18n/keysets/en.json +2 -1
- package/dist/esm/i18n/keysets/ru.json +2 -1
- package/dist/esm/types/chart/base.d.ts +13 -0
- package/dist/esm/types/chart/tooltip.d.ts +5 -1
- package/dist/esm/utils/chart/format.d.ts +9 -2
- package/dist/esm/utils/chart/format.js +39 -5
- package/dist/esm/utils/chart/index.d.ts +6 -10
- package/dist/esm/utils/chart/index.js +6 -26
- package/dist/esm/utils/misc.d.ts +1 -0
- package/dist/esm/utils/misc.js +6 -0
- package/package.json +1 -1
|
@@ -52,6 +52,7 @@ export function prepareBarYSeries(args) {
|
|
|
52
52
|
borderRadius: (_c = (_a = series.borderRadius) !== null && _a !== void 0 ? _a : (_b = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _b === void 0 ? void 0 : _b.borderRadius) !== null && _c !== void 0 ? _c : 0,
|
|
53
53
|
borderWidth: (_f = (_d = series.borderWidth) !== null && _d !== void 0 ? _d : (_e = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _e === void 0 ? void 0 : _e.borderWidth) !== null && _f !== void 0 ? _f : 0,
|
|
54
54
|
borderColor: (_j = (_g = series.borderColor) !== null && _g !== void 0 ? _g : (_h = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _h === void 0 ? void 0 : _h.borderColor) !== null && _j !== void 0 ? _j : 'var(--gcharts-shape-border-color)',
|
|
55
|
+
tooltip: series.tooltip,
|
|
55
56
|
};
|
|
56
57
|
}));
|
|
57
58
|
}
|
|
@@ -34,6 +34,7 @@ export function prepareTreemap(args) {
|
|
|
34
34
|
layoutAlgorithm: get(s, 'layoutAlgorithm', LayoutAlgorithm.Binary),
|
|
35
35
|
cursor: get(s, 'cursor', null),
|
|
36
36
|
sorting: Object.assign({ enabled: false, direction: 'desc' }, s.sorting),
|
|
37
|
+
tooltip: s.tooltip,
|
|
37
38
|
};
|
|
38
39
|
return preparedSeries;
|
|
39
40
|
});
|
|
@@ -28,6 +28,7 @@ export function prepareWaterfallSeries(args) {
|
|
|
28
28
|
},
|
|
29
29
|
cursor: get(series, 'cursor', null),
|
|
30
30
|
data: [],
|
|
31
|
+
tooltip: series.tooltip,
|
|
31
32
|
};
|
|
32
33
|
const positive = Object.assign(Object.assign({}, common), { name: (_g = (_f = (_e = series.legend) === null || _e === void 0 ? void 0 : _e.itemText) === null || _f === void 0 ? void 0 : _f.positive) !== null && _g !== void 0 ? _g : `${series.name} ↑`, id: getUniqId(), color: series.positiveColor || positiveColor, data: [] });
|
|
33
34
|
const negative = Object.assign(Object.assign({}, common), { name: (_k = (_j = (_h = series.legend) === null || _h === void 0 ? void 0 : _h.itemText) === null || _j === void 0 ? void 0 : _j.negative) !== null && _k !== void 0 ? _k : `${series.name} ↓`, id: getUniqId(), color: series.negativeColor || negativeColor, data: [] });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DashStyle, LayoutAlgorithm, LineCap, SeriesOptionsDefaults, SymbolType } from '../../constants';
|
|
2
|
-
import type { AreaSeries, AreaSeriesData, BarXSeries, BarXSeriesData, BarYSeries, BarYSeriesData, BaseTextStyle, ChartLegend, ConnectorCurve, ConnectorShape, LineSeries, LineSeriesData, PathLegendSymbolOptions, PieSeries, PieSeriesData, RadarSeries, RadarSeriesCategory, RadarSeriesData, RectLegendSymbolOptions, SankeySeries, SankeySeriesData, ScatterSeries, ScatterSeriesData, SymbolLegendSymbolOptions, TreemapSeries, TreemapSeriesData, ValueFormat, WaterfallSeries, WaterfallSeriesData } from '../../types';
|
|
2
|
+
import type { AreaSeries, AreaSeriesData, BarXSeries, BarXSeriesData, BarYSeries, BarYSeriesData, BaseTextStyle, ChartLegend, ChartSeries, ConnectorCurve, ConnectorShape, LineSeries, LineSeriesData, PathLegendSymbolOptions, PieSeries, PieSeriesData, RadarSeries, RadarSeriesCategory, RadarSeriesData, RectLegendSymbolOptions, SankeySeries, SankeySeriesData, ScatterSeries, ScatterSeriesData, SymbolLegendSymbolOptions, TreemapSeries, TreemapSeriesData, ValueFormat, WaterfallSeries, WaterfallSeriesData } from '../../types';
|
|
3
3
|
export type RectLegendSymbol = {
|
|
4
4
|
shape: 'rect';
|
|
5
5
|
} & Required<RectLegendSymbolOptions>;
|
|
@@ -76,6 +76,7 @@ type BasePreparedSeries = {
|
|
|
76
76
|
symbol: PreparedLegendSymbol;
|
|
77
77
|
};
|
|
78
78
|
cursor: string | null;
|
|
79
|
+
tooltip: ChartSeries['tooltip'];
|
|
79
80
|
};
|
|
80
81
|
export type PreparedScatterSeries = {
|
|
81
82
|
type: ScatterSeries['type'];
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"label_invalid-axis-labels-html-not-supported-axis-type": "It seems you are trying to use \"labels.html\" property for an axis with an unsupported type. This property is supported only for \"category\" axis."
|
|
22
22
|
},
|
|
23
23
|
"tooltip": {
|
|
24
|
-
"label_totals_sum": "Sum"
|
|
24
|
+
"label_totals_sum": "Sum",
|
|
25
|
+
"label_more": "{{count}} more"
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"label_invalid-axis-labels-html-not-supported-axis-type": "Похоже, что вы пытаетесь использовать свойство \"labels.html\" для оси с неподдерживаемым типом. Это свойство поддерживается только для оси типа \"category\"."
|
|
22
22
|
},
|
|
23
23
|
"tooltip": {
|
|
24
|
-
"label_totals_sum": "Сумма"
|
|
24
|
+
"label_totals_sum": "Сумма",
|
|
25
|
+
"label_more": "Еще {{count}}"
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -7,6 +7,12 @@ type DateFormat = {
|
|
|
7
7
|
type: 'date';
|
|
8
8
|
format?: string;
|
|
9
9
|
};
|
|
10
|
+
export type CustomFormat = {
|
|
11
|
+
type: 'custom';
|
|
12
|
+
formatter: (args: {
|
|
13
|
+
value: unknown;
|
|
14
|
+
}) => string;
|
|
15
|
+
};
|
|
10
16
|
export type ValueFormat = NumberFormat | DateFormat;
|
|
11
17
|
export interface BaseSeries {
|
|
12
18
|
/** Initial visibility of the series */
|
|
@@ -41,6 +47,13 @@ export interface BaseSeries {
|
|
|
41
47
|
};
|
|
42
48
|
/** You can set the cursor to "pointer" if you have click events attached to the series, to signal to the user that the points and lines can be clicked. */
|
|
43
49
|
cursor?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Options for the tooltip that appears when the user hovers over a series or point.
|
|
52
|
+
*/
|
|
53
|
+
tooltip?: {
|
|
54
|
+
/** Formatting settings for tooltip value. */
|
|
55
|
+
valueFormat?: ValueFormat;
|
|
56
|
+
};
|
|
44
57
|
}
|
|
45
58
|
export interface BaseSeriesData<T = MeaningfulAny> {
|
|
46
59
|
/**
|
|
@@ -4,7 +4,7 @@ import type { AreaSeries, AreaSeriesData } from './area';
|
|
|
4
4
|
import type { ChartXAxis, ChartYAxis } from './axis';
|
|
5
5
|
import type { BarXSeries, BarXSeriesData } from './bar-x';
|
|
6
6
|
import type { BarYSeries, BarYSeriesData } from './bar-y';
|
|
7
|
-
import type { ValueFormat } from './base';
|
|
7
|
+
import type { CustomFormat, ValueFormat } from './base';
|
|
8
8
|
import type { LineSeries, LineSeriesData } from './line';
|
|
9
9
|
import type { PieSeries, PieSeriesData } from './pie';
|
|
10
10
|
import type { RadarSeries, RadarSeriesCategory, RadarSeriesData } from './radar';
|
|
@@ -110,6 +110,8 @@ export interface ChartTooltip<T = MeaningfulAny> {
|
|
|
110
110
|
throttle?: number;
|
|
111
111
|
/** Formatting settings for tooltip value. */
|
|
112
112
|
valueFormat?: ValueFormat;
|
|
113
|
+
/** Formatting settings for tooltip header row. */
|
|
114
|
+
headerFormat?: ValueFormat | CustomFormat;
|
|
113
115
|
/** Settings for totals block in tooltip */
|
|
114
116
|
totals?: {
|
|
115
117
|
/**
|
|
@@ -125,5 +127,7 @@ export interface ChartTooltip<T = MeaningfulAny> {
|
|
|
125
127
|
enabled?: boolean;
|
|
126
128
|
/** The label text for the totals. For built-in aggregations, the label can be omitted. */
|
|
127
129
|
label?: string;
|
|
130
|
+
/** Formatting settings for totals tooltip value. */
|
|
131
|
+
valueFormat?: ValueFormat;
|
|
128
132
|
};
|
|
129
133
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AxisDomain } from 'd3';
|
|
2
|
+
import type { PreparedAxis } from '../../hooks';
|
|
3
|
+
import type { CustomFormat, ValueFormat } from '../../types';
|
|
2
4
|
export declare function getFormattedValue(args: {
|
|
3
5
|
value: string | number | undefined | null;
|
|
4
|
-
format?: ValueFormat;
|
|
6
|
+
format?: ValueFormat | CustomFormat;
|
|
7
|
+
}): string;
|
|
8
|
+
export declare function formatAxisTickLabel(args: {
|
|
9
|
+
axis: PreparedAxis;
|
|
10
|
+
value: AxisDomain;
|
|
11
|
+
step?: number;
|
|
5
12
|
}): string;
|
|
@@ -1,17 +1,51 @@
|
|
|
1
1
|
import { dateTime } from '@gravity-ui/date-utils';
|
|
2
|
-
import
|
|
2
|
+
import capitalize from 'lodash/capitalize';
|
|
3
|
+
import { formatNumber, getDefaultUnit } from '../../libs';
|
|
4
|
+
import { getDefaultDateFormat } from './time';
|
|
5
|
+
const LETTER_MOUNTH_AT_START_FORMAT_REGEXP = /^M{3,}/;
|
|
6
|
+
function getFormattedDate(args) {
|
|
7
|
+
const { value, format = '' } = args;
|
|
8
|
+
const date = dateTime({ input: value });
|
|
9
|
+
if (date === null || date === void 0 ? void 0 : date.isValid()) {
|
|
10
|
+
const formattedDate = date.format(format);
|
|
11
|
+
if (LETTER_MOUNTH_AT_START_FORMAT_REGEXP.test(format)) {
|
|
12
|
+
return capitalize(formattedDate);
|
|
13
|
+
}
|
|
14
|
+
return formattedDate;
|
|
15
|
+
}
|
|
16
|
+
return String(value);
|
|
17
|
+
}
|
|
3
18
|
export function getFormattedValue(args) {
|
|
19
|
+
var _a;
|
|
4
20
|
const { value, format } = args;
|
|
5
21
|
switch (format === null || format === void 0 ? void 0 : format.type) {
|
|
6
22
|
case 'number': {
|
|
7
23
|
return formatNumber(Number(value), format);
|
|
8
24
|
}
|
|
9
25
|
case 'date': {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
26
|
+
return getFormattedDate({ value, format: format.format });
|
|
27
|
+
}
|
|
28
|
+
case 'custom': {
|
|
29
|
+
return (_a = format.formatter) === null || _a === void 0 ? void 0 : _a.call(format, { value });
|
|
14
30
|
}
|
|
15
31
|
}
|
|
16
32
|
return String(value);
|
|
17
33
|
}
|
|
34
|
+
export function formatAxisTickLabel(args) {
|
|
35
|
+
const { axis, value, step } = args;
|
|
36
|
+
switch (axis.type) {
|
|
37
|
+
case 'category': {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
case 'datetime': {
|
|
41
|
+
const date = value;
|
|
42
|
+
const format = axis.labels.dateFormat || getDefaultDateFormat(step);
|
|
43
|
+
return getFormattedDate({ value: date, format });
|
|
44
|
+
}
|
|
45
|
+
case 'linear':
|
|
46
|
+
default: {
|
|
47
|
+
const numberFormat = Object.assign({ unit: value && step ? getDefaultUnit(step) : undefined }, axis.labels.numberFormat);
|
|
48
|
+
return formatNumber(value, numberFormat);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -2,15 +2,16 @@ import type { AxisDomain } from 'd3';
|
|
|
2
2
|
import type { PreparedAxis } from '../../hooks';
|
|
3
3
|
import type { BaseTextStyle, ChartSeries, ChartSeriesData } from '../../types';
|
|
4
4
|
import type { AxisDirection } from './types';
|
|
5
|
-
export * from './math';
|
|
6
|
-
export * from './text';
|
|
7
|
-
export * from './time';
|
|
8
5
|
export * from './axis';
|
|
6
|
+
export * from './color';
|
|
7
|
+
export * from './format';
|
|
9
8
|
export * from './labels';
|
|
10
9
|
export * from './legend';
|
|
11
|
-
export * from './
|
|
10
|
+
export * from './math';
|
|
12
11
|
export * from './series';
|
|
13
|
-
export * from './
|
|
12
|
+
export * from './symbol';
|
|
13
|
+
export * from './text';
|
|
14
|
+
export * from './time';
|
|
14
15
|
export * from './zoom';
|
|
15
16
|
export declare const CHART_SERIES_WITH_VOLUME_ON_Y_AXIS: ChartSeries['type'][];
|
|
16
17
|
export declare const CHART_SERIES_WITH_VOLUME_ON_X_AXIS: ChartSeries['type'][];
|
|
@@ -56,11 +57,6 @@ export declare const parseTransformStyle: (style: string | null) => {
|
|
|
56
57
|
x?: number;
|
|
57
58
|
y?: number;
|
|
58
59
|
};
|
|
59
|
-
export declare const formatAxisTickLabel: (args: {
|
|
60
|
-
axis: PreparedAxis;
|
|
61
|
-
value: AxisDomain;
|
|
62
|
-
step?: number;
|
|
63
|
-
}) => string;
|
|
64
60
|
export declare const getHorizontalHtmlTextHeight: (args: {
|
|
65
61
|
text: string;
|
|
66
62
|
style?: Partial<BaseTextStyle>;
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import { dateTime } from '@gravity-ui/date-utils';
|
|
2
1
|
import { group, select } from 'd3';
|
|
3
2
|
import get from 'lodash/get';
|
|
4
3
|
import isNil from 'lodash/isNil';
|
|
5
4
|
import sortBy from 'lodash/sortBy';
|
|
6
5
|
import { DEFAULT_AXIS_LABEL_FONT_SIZE } from '../../constants';
|
|
7
6
|
import { getSeriesStackId } from '../../hooks/useSeries/utils';
|
|
8
|
-
import { formatNumber, getDefaultUnit } from '../../libs/format-number';
|
|
9
7
|
import { getWaterfallPointSubtotal } from './series/waterfall';
|
|
10
|
-
import { getDefaultDateFormat } from './time';
|
|
11
|
-
export * from './math';
|
|
12
|
-
export * from './text';
|
|
13
|
-
export * from './time';
|
|
14
8
|
export * from './axis';
|
|
9
|
+
export * from './color';
|
|
10
|
+
export * from './format';
|
|
15
11
|
export * from './labels';
|
|
16
12
|
export * from './legend';
|
|
17
|
-
export * from './
|
|
13
|
+
export * from './math';
|
|
18
14
|
export * from './series';
|
|
19
|
-
export * from './
|
|
15
|
+
export * from './symbol';
|
|
16
|
+
export * from './text';
|
|
17
|
+
export * from './time';
|
|
20
18
|
export * from './zoom';
|
|
21
19
|
const CHARTS_WITHOUT_AXIS = ['pie', 'treemap', 'sankey', 'radar'];
|
|
22
20
|
export const CHART_SERIES_WITH_VOLUME_ON_Y_AXIS = [
|
|
@@ -177,24 +175,6 @@ export const parseTransformStyle = (style) => {
|
|
|
177
175
|
const y = Number.isNaN(Number(yString)) ? undefined : Number(yString);
|
|
178
176
|
return { x, y };
|
|
179
177
|
};
|
|
180
|
-
export const formatAxisTickLabel = (args) => {
|
|
181
|
-
const { axis, value, step } = args;
|
|
182
|
-
switch (axis.type) {
|
|
183
|
-
case 'category': {
|
|
184
|
-
return value;
|
|
185
|
-
}
|
|
186
|
-
case 'datetime': {
|
|
187
|
-
const date = value;
|
|
188
|
-
const format = axis.labels.dateFormat || getDefaultDateFormat(step);
|
|
189
|
-
return dateTime({ input: date }).format(format);
|
|
190
|
-
}
|
|
191
|
-
case 'linear':
|
|
192
|
-
default: {
|
|
193
|
-
const numberFormat = Object.assign({ unit: value && step ? getDefaultUnit(step) : undefined }, axis.labels.numberFormat);
|
|
194
|
-
return formatNumber(value, numberFormat);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
178
|
export const getHorizontalHtmlTextHeight = (args) => {
|
|
199
179
|
var _a;
|
|
200
180
|
const { text, style } = args;
|
package/dist/esm/utils/misc.d.ts
CHANGED
package/dist/esm/utils/misc.js
CHANGED