@gravity-ui/charts 1.6.3 → 1.6.5
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/Axis/styles.css +3 -3
- package/dist/cjs/components/ChartInner/styles.css +1 -0
- package/dist/cjs/components/Legend/index.js +1 -1
- package/dist/cjs/components/Legend/styles.css +2 -2
- package/dist/cjs/hooks/useShapes/pie/index.js +1 -1
- package/dist/cjs/hooks/useShapes/styles.css +4 -4
- package/dist/cjs/utils/chart/axis-generators/bottom.js +1 -1
- package/dist/cjs/utils/chart/index.js +1 -1
- package/dist/cjs/utils/chart/text.js +1 -1
- package/dist/cjs/utils/chart-ui/pie-center-text.d.ts +3 -2
- package/dist/cjs/utils/chart-ui/pie-center-text.js +23 -10
- package/dist/esm/components/Axis/styles.css +3 -3
- package/dist/esm/components/ChartInner/styles.css +1 -0
- package/dist/esm/components/Legend/index.js +1 -1
- package/dist/esm/components/Legend/styles.css +2 -2
- package/dist/esm/hooks/useShapes/pie/index.js +1 -1
- package/dist/esm/hooks/useShapes/styles.css +4 -4
- package/dist/esm/utils/chart/axis-generators/bottom.js +1 -1
- package/dist/esm/utils/chart/index.js +1 -1
- package/dist/esm/utils/chart/text.js +1 -1
- package/dist/esm/utils/chart-ui/pie-center-text.d.ts +3 -2
- package/dist/esm/utils/chart-ui/pie-center-text.js +23 -10
- package/package.json +1 -1
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
}
|
|
4
4
|
.gcharts-axis .tick text {
|
|
5
5
|
color: var(--g-color-text-secondary);
|
|
6
|
-
|
|
6
|
+
dominant-baseline: text-after-edge;
|
|
7
7
|
}
|
|
8
8
|
.gcharts-axis .tick line, .gcharts-axis .tick path {
|
|
9
9
|
stroke: var(--g-color-line-generic);
|
|
10
10
|
}
|
|
11
11
|
.gcharts-axis__title {
|
|
12
|
-
|
|
12
|
+
dominant-baseline: text-after-edge;
|
|
13
13
|
fill: var(--g-color-text-secondary);
|
|
14
14
|
}
|
|
15
15
|
.gcharts-axis__title tspan {
|
|
16
|
-
|
|
16
|
+
dominant-baseline: text-after-edge;
|
|
17
17
|
}
|
|
@@ -294,7 +294,7 @@ export const Legend = (props) => {
|
|
|
294
294
|
.attr('font-weight', (_c = legend.title.style.fontWeight) !== null && _c !== void 0 ? _c : null)
|
|
295
295
|
.attr('font-size', (_d = legend.title.style.fontSize) !== null && _d !== void 0 ? _d : null)
|
|
296
296
|
.attr('fill', (_e = legend.title.style.fontColor) !== null && _e !== void 0 ? _e : null)
|
|
297
|
-
.style('
|
|
297
|
+
.style('dominant-baseline', 'text-before-edge')
|
|
298
298
|
.html(legend.title.text);
|
|
299
299
|
}
|
|
300
300
|
const { left } = getLegendPosition({
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
}
|
|
20
20
|
.gcharts-legend__item-text {
|
|
21
21
|
fill: var(--g-color-text-secondary);
|
|
22
|
-
|
|
22
|
+
dominant-baseline: text-before-edge;
|
|
23
23
|
}
|
|
24
24
|
.gcharts-legend__item-text_unselected {
|
|
25
25
|
fill: var(--g-color-text-hint);
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
fill: var(--g-color-text-primary);
|
|
33
33
|
}
|
|
34
34
|
.gcharts-legend__pagination-counter, .gcharts-legend__pagination-arrow {
|
|
35
|
-
|
|
35
|
+
dominant-baseline: middle;
|
|
36
36
|
}
|
|
37
37
|
.gcharts-legend__pagination-arrow {
|
|
38
38
|
cursor: pointer;
|
|
@@ -147,7 +147,7 @@ export function PieSeriesShapes(args) {
|
|
|
147
147
|
});
|
|
148
148
|
return d;
|
|
149
149
|
});
|
|
150
|
-
const labelSelection = pieSelection.selectAll('
|
|
150
|
+
const labelSelection = pieSelection.selectAll(`.${b('label')} tspan`);
|
|
151
151
|
const connectorSelection = pieSelection.selectAll(connectorSelector);
|
|
152
152
|
labelSelection.merge(connectorSelection).datum((d, i, elements) => {
|
|
153
153
|
return setActiveState({
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
font-size: 11px;
|
|
10
10
|
font-weight: bold;
|
|
11
11
|
fill: var(--g-color-text-complementary);
|
|
12
|
-
|
|
12
|
+
dominant-baseline: text-before-edge;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
.gcharts-radar__label {
|
|
16
|
-
|
|
16
|
+
dominant-baseline: text-before-edge;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
.gcharts-bar-x__label {
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
.gcharts-bar-y__label {
|
|
25
25
|
user-select: none;
|
|
26
26
|
fill: var(--g-color-text-complementary);
|
|
27
|
-
|
|
27
|
+
dominant-baseline: text-after-edge;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
.gcharts-treemap__label {
|
|
31
31
|
user-select: none;
|
|
32
32
|
pointer-events: none;
|
|
33
33
|
fill: var(--g-color-text-complementary);
|
|
34
|
-
|
|
34
|
+
dominant-baseline: text-before-edge;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
.gcharts-waterfall__connector {
|
|
@@ -173,7 +173,7 @@ export const getHorisontalSvgTextHeight = (args) => {
|
|
|
173
173
|
const textSelection = container.append('text').text(text);
|
|
174
174
|
const fontSize = get(style, 'fontSize', DEFAULT_AXIS_LABEL_FONT_SIZE);
|
|
175
175
|
if (fontSize) {
|
|
176
|
-
textSelection.style('font-size', fontSize).style('
|
|
176
|
+
textSelection.style('font-size', fontSize).style('dominant-baseline', 'text-after-edge');
|
|
177
177
|
}
|
|
178
178
|
const height = ((_a = textSelection.node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height) || 0;
|
|
179
179
|
container.remove();
|
|
@@ -30,7 +30,7 @@ export function handleOverflowingText(tSpan, maxWidth) {
|
|
|
30
30
|
export function setEllipsisForOverflowText(selection, maxWidth) {
|
|
31
31
|
const text = selection.text();
|
|
32
32
|
selection.text(null).append('title').text(text);
|
|
33
|
-
const tSpan = selection.append('tspan').text(text).style('
|
|
33
|
+
const tSpan = selection.append('tspan').text(text).style('dominant-baseline', 'inherit');
|
|
34
34
|
handleOverflowingText(tSpan.node(), maxWidth);
|
|
35
35
|
}
|
|
36
36
|
export function setEllipsisForOverflowTexts(selection, maxWidth) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export declare function pieCenterText(text: string, options?: {
|
|
2
|
-
padding?: number;
|
|
2
|
+
padding?: string | number;
|
|
3
3
|
color?: string;
|
|
4
|
+
minFontSize?: number;
|
|
4
5
|
}): ((args: {
|
|
5
6
|
series: {
|
|
6
7
|
innerRadius: number;
|
|
7
8
|
};
|
|
8
|
-
}) =>
|
|
9
|
+
}) => SVGGElement | null) | undefined;
|
|
@@ -1,29 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { select } from 'd3-selection';
|
|
2
2
|
import get from 'lodash/get';
|
|
3
|
-
import {
|
|
3
|
+
import { calculateNumericProperty } from '../chart/math';
|
|
4
|
+
import { getLabelsSize, handleOverflowingText } from '../chart/text';
|
|
4
5
|
const MAX_FONT_SIZE = 64;
|
|
6
|
+
const MIN_FONT_SIZE = 8;
|
|
5
7
|
export function pieCenterText(text, options) {
|
|
6
8
|
if (!text) {
|
|
7
9
|
return undefined;
|
|
8
10
|
}
|
|
9
|
-
const padding = get(options, 'padding', 12);
|
|
10
11
|
const color = get(options, 'color', 'currentColor');
|
|
11
12
|
return function (args) {
|
|
13
|
+
var _a, _b;
|
|
12
14
|
let fontSize = MAX_FONT_SIZE;
|
|
13
15
|
const textSize = getLabelsSize({ labels: [text], style: { fontSize: `${fontSize}px` } });
|
|
14
16
|
let availableSpace = args.series.innerRadius * 2;
|
|
17
|
+
const padding = (_a = calculateNumericProperty({
|
|
18
|
+
base: availableSpace,
|
|
19
|
+
value: options === null || options === void 0 ? void 0 : options.padding,
|
|
20
|
+
})) !== null && _a !== void 0 ? _a : 12;
|
|
15
21
|
if (padding < args.series.innerRadius) {
|
|
16
22
|
availableSpace -= padding * 2;
|
|
17
23
|
}
|
|
18
|
-
fontSize = (fontSize * availableSpace) / textSize.maxWidth;
|
|
19
|
-
const
|
|
20
|
-
container
|
|
24
|
+
fontSize = Math.max((_b = options === null || options === void 0 ? void 0 : options.minFontSize) !== null && _b !== void 0 ? _b : MIN_FONT_SIZE, (fontSize * availableSpace) / Math.max(textSize.maxWidth, textSize.maxHeight));
|
|
25
|
+
const tempWrapper = select(document.body).append('svg');
|
|
26
|
+
const container = tempWrapper.append('g');
|
|
27
|
+
const textSelection = container
|
|
21
28
|
.append('text')
|
|
22
|
-
.text(text)
|
|
23
|
-
.attr('text-anchor', 'middle')
|
|
24
|
-
.attr('alignment-baseline', 'middle')
|
|
25
29
|
.style('font-size', `${fontSize}px`)
|
|
26
30
|
.style('fill', color);
|
|
27
|
-
|
|
31
|
+
textSelection.append('title').text(text);
|
|
32
|
+
const tspan = textSelection
|
|
33
|
+
.append('tspan')
|
|
34
|
+
.attr('text-anchor', 'middle')
|
|
35
|
+
.attr('dominant-baseline', 'middle')
|
|
36
|
+
.text(text);
|
|
37
|
+
handleOverflowingText(tspan.node(), availableSpace);
|
|
38
|
+
const result = container.node();
|
|
39
|
+
tempWrapper.remove();
|
|
40
|
+
return result;
|
|
28
41
|
};
|
|
29
42
|
}
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
}
|
|
4
4
|
.gcharts-axis .tick text {
|
|
5
5
|
color: var(--g-color-text-secondary);
|
|
6
|
-
|
|
6
|
+
dominant-baseline: text-after-edge;
|
|
7
7
|
}
|
|
8
8
|
.gcharts-axis .tick line, .gcharts-axis .tick path {
|
|
9
9
|
stroke: var(--g-color-line-generic);
|
|
10
10
|
}
|
|
11
11
|
.gcharts-axis__title {
|
|
12
|
-
|
|
12
|
+
dominant-baseline: text-after-edge;
|
|
13
13
|
fill: var(--g-color-text-secondary);
|
|
14
14
|
}
|
|
15
15
|
.gcharts-axis__title tspan {
|
|
16
|
-
|
|
16
|
+
dominant-baseline: text-after-edge;
|
|
17
17
|
}
|
|
@@ -294,7 +294,7 @@ export const Legend = (props) => {
|
|
|
294
294
|
.attr('font-weight', (_c = legend.title.style.fontWeight) !== null && _c !== void 0 ? _c : null)
|
|
295
295
|
.attr('font-size', (_d = legend.title.style.fontSize) !== null && _d !== void 0 ? _d : null)
|
|
296
296
|
.attr('fill', (_e = legend.title.style.fontColor) !== null && _e !== void 0 ? _e : null)
|
|
297
|
-
.style('
|
|
297
|
+
.style('dominant-baseline', 'text-before-edge')
|
|
298
298
|
.html(legend.title.text);
|
|
299
299
|
}
|
|
300
300
|
const { left } = getLegendPosition({
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
}
|
|
20
20
|
.gcharts-legend__item-text {
|
|
21
21
|
fill: var(--g-color-text-secondary);
|
|
22
|
-
|
|
22
|
+
dominant-baseline: text-before-edge;
|
|
23
23
|
}
|
|
24
24
|
.gcharts-legend__item-text_unselected {
|
|
25
25
|
fill: var(--g-color-text-hint);
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
fill: var(--g-color-text-primary);
|
|
33
33
|
}
|
|
34
34
|
.gcharts-legend__pagination-counter, .gcharts-legend__pagination-arrow {
|
|
35
|
-
|
|
35
|
+
dominant-baseline: middle;
|
|
36
36
|
}
|
|
37
37
|
.gcharts-legend__pagination-arrow {
|
|
38
38
|
cursor: pointer;
|
|
@@ -147,7 +147,7 @@ export function PieSeriesShapes(args) {
|
|
|
147
147
|
});
|
|
148
148
|
return d;
|
|
149
149
|
});
|
|
150
|
-
const labelSelection = pieSelection.selectAll('
|
|
150
|
+
const labelSelection = pieSelection.selectAll(`.${b('label')} tspan`);
|
|
151
151
|
const connectorSelection = pieSelection.selectAll(connectorSelector);
|
|
152
152
|
labelSelection.merge(connectorSelection).datum((d, i, elements) => {
|
|
153
153
|
return setActiveState({
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
font-size: 11px;
|
|
10
10
|
font-weight: bold;
|
|
11
11
|
fill: var(--g-color-text-complementary);
|
|
12
|
-
|
|
12
|
+
dominant-baseline: text-before-edge;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
.gcharts-radar__label {
|
|
16
|
-
|
|
16
|
+
dominant-baseline: text-before-edge;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
.gcharts-bar-x__label {
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
.gcharts-bar-y__label {
|
|
25
25
|
user-select: none;
|
|
26
26
|
fill: var(--g-color-text-complementary);
|
|
27
|
-
|
|
27
|
+
dominant-baseline: text-after-edge;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
.gcharts-treemap__label {
|
|
31
31
|
user-select: none;
|
|
32
32
|
pointer-events: none;
|
|
33
33
|
fill: var(--g-color-text-complementary);
|
|
34
|
-
|
|
34
|
+
dominant-baseline: text-before-edge;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
.gcharts-waterfall__connector {
|
|
@@ -173,7 +173,7 @@ export const getHorisontalSvgTextHeight = (args) => {
|
|
|
173
173
|
const textSelection = container.append('text').text(text);
|
|
174
174
|
const fontSize = get(style, 'fontSize', DEFAULT_AXIS_LABEL_FONT_SIZE);
|
|
175
175
|
if (fontSize) {
|
|
176
|
-
textSelection.style('font-size', fontSize).style('
|
|
176
|
+
textSelection.style('font-size', fontSize).style('dominant-baseline', 'text-after-edge');
|
|
177
177
|
}
|
|
178
178
|
const height = ((_a = textSelection.node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height) || 0;
|
|
179
179
|
container.remove();
|
|
@@ -30,7 +30,7 @@ export function handleOverflowingText(tSpan, maxWidth) {
|
|
|
30
30
|
export function setEllipsisForOverflowText(selection, maxWidth) {
|
|
31
31
|
const text = selection.text();
|
|
32
32
|
selection.text(null).append('title').text(text);
|
|
33
|
-
const tSpan = selection.append('tspan').text(text).style('
|
|
33
|
+
const tSpan = selection.append('tspan').text(text).style('dominant-baseline', 'inherit');
|
|
34
34
|
handleOverflowingText(tSpan.node(), maxWidth);
|
|
35
35
|
}
|
|
36
36
|
export function setEllipsisForOverflowTexts(selection, maxWidth) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export declare function pieCenterText(text: string, options?: {
|
|
2
|
-
padding?: number;
|
|
2
|
+
padding?: string | number;
|
|
3
3
|
color?: string;
|
|
4
|
+
minFontSize?: number;
|
|
4
5
|
}): ((args: {
|
|
5
6
|
series: {
|
|
6
7
|
innerRadius: number;
|
|
7
8
|
};
|
|
8
|
-
}) =>
|
|
9
|
+
}) => SVGGElement | null) | undefined;
|
|
@@ -1,29 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { select } from 'd3-selection';
|
|
2
2
|
import get from 'lodash/get';
|
|
3
|
-
import {
|
|
3
|
+
import { calculateNumericProperty } from '../chart/math';
|
|
4
|
+
import { getLabelsSize, handleOverflowingText } from '../chart/text';
|
|
4
5
|
const MAX_FONT_SIZE = 64;
|
|
6
|
+
const MIN_FONT_SIZE = 8;
|
|
5
7
|
export function pieCenterText(text, options) {
|
|
6
8
|
if (!text) {
|
|
7
9
|
return undefined;
|
|
8
10
|
}
|
|
9
|
-
const padding = get(options, 'padding', 12);
|
|
10
11
|
const color = get(options, 'color', 'currentColor');
|
|
11
12
|
return function (args) {
|
|
13
|
+
var _a, _b;
|
|
12
14
|
let fontSize = MAX_FONT_SIZE;
|
|
13
15
|
const textSize = getLabelsSize({ labels: [text], style: { fontSize: `${fontSize}px` } });
|
|
14
16
|
let availableSpace = args.series.innerRadius * 2;
|
|
17
|
+
const padding = (_a = calculateNumericProperty({
|
|
18
|
+
base: availableSpace,
|
|
19
|
+
value: options === null || options === void 0 ? void 0 : options.padding,
|
|
20
|
+
})) !== null && _a !== void 0 ? _a : 12;
|
|
15
21
|
if (padding < args.series.innerRadius) {
|
|
16
22
|
availableSpace -= padding * 2;
|
|
17
23
|
}
|
|
18
|
-
fontSize = (fontSize * availableSpace) / textSize.maxWidth;
|
|
19
|
-
const
|
|
20
|
-
container
|
|
24
|
+
fontSize = Math.max((_b = options === null || options === void 0 ? void 0 : options.minFontSize) !== null && _b !== void 0 ? _b : MIN_FONT_SIZE, (fontSize * availableSpace) / Math.max(textSize.maxWidth, textSize.maxHeight));
|
|
25
|
+
const tempWrapper = select(document.body).append('svg');
|
|
26
|
+
const container = tempWrapper.append('g');
|
|
27
|
+
const textSelection = container
|
|
21
28
|
.append('text')
|
|
22
|
-
.text(text)
|
|
23
|
-
.attr('text-anchor', 'middle')
|
|
24
|
-
.attr('alignment-baseline', 'middle')
|
|
25
29
|
.style('font-size', `${fontSize}px`)
|
|
26
30
|
.style('fill', color);
|
|
27
|
-
|
|
31
|
+
textSelection.append('title').text(text);
|
|
32
|
+
const tspan = textSelection
|
|
33
|
+
.append('tspan')
|
|
34
|
+
.attr('text-anchor', 'middle')
|
|
35
|
+
.attr('dominant-baseline', 'middle')
|
|
36
|
+
.text(text);
|
|
37
|
+
handleOverflowingText(tspan.node(), availableSpace);
|
|
38
|
+
const result = container.node();
|
|
39
|
+
tempWrapper.remove();
|
|
40
|
+
return result;
|
|
28
41
|
};
|
|
29
42
|
}
|