@gravity-ui/charts 1.34.9 → 1.35.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/DefaultTooltipContent/index.js +2 -1
- package/dist/cjs/components/Tooltip/styles.css +7 -0
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +8 -5
- package/dist/cjs/utils/chart/text.js +14 -9
- package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +2 -1
- package/dist/esm/components/Tooltip/styles.css +7 -0
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +8 -5
- package/dist/esm/utils/chart/text.js +14 -9
- package/package.json +1 -1
|
@@ -89,7 +89,8 @@ export const DefaultTooltipContent = ({ hovered, pinned, rowRenderer, totals, va
|
|
|
89
89
|
}
|
|
90
90
|
}, [pinned]);
|
|
91
91
|
return (React.createElement("div", { className: b('content'), "data-qa": qa },
|
|
92
|
-
formattedHeadValue && (React.createElement("div", { className: b('series-name')
|
|
92
|
+
formattedHeadValue && (React.createElement("div", { className: b('series-name') },
|
|
93
|
+
React.createElement("div", { className: b('series-name-text'), dangerouslySetInnerHTML: { __html: formattedHeadValue } }))),
|
|
93
94
|
React.createElement("div", { className: b('content-rows', { pinned }), ref: contentRowsRef, style: { maxHeight: maxContentRowsHeight } },
|
|
94
95
|
visibleHovered.map((seriesItem, i) => {
|
|
95
96
|
var _a;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
box-shadow: 0 2px 12px var(--g-color-sfx-shadow);
|
|
4
4
|
}
|
|
5
5
|
.gcharts-tooltip__popup-content {
|
|
6
|
+
max-width: 450px;
|
|
6
7
|
text-wrap: nowrap;
|
|
7
8
|
border-radius: 4px;
|
|
8
9
|
background-color: var(--g-color-infographics-tooltip-bg);
|
|
@@ -24,6 +25,12 @@
|
|
|
24
25
|
font-size: 13px;
|
|
25
26
|
font-weight: 600;
|
|
26
27
|
}
|
|
28
|
+
.gcharts-tooltip__series-name-text {
|
|
29
|
+
display: block;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
text-overflow: ellipsis;
|
|
33
|
+
}
|
|
27
34
|
.gcharts-tooltip__content-row {
|
|
28
35
|
display: flex;
|
|
29
36
|
align-items: center;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ascending, descending, sort } from 'd3';
|
|
1
|
+
import { ascending, descending, reverse, sort } from 'd3';
|
|
2
2
|
import get from 'lodash/get';
|
|
3
3
|
import { getDataCategoryValue, getLabelsSize } from '../../../utils';
|
|
4
4
|
import { getFormattedValue } from '../../../utils/chart/format';
|
|
@@ -103,9 +103,13 @@ export const prepareBarXData = async (args) => {
|
|
|
103
103
|
let positiveStackHeight = 0;
|
|
104
104
|
let negativeStackHeight = 0;
|
|
105
105
|
const stackItems = [];
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
let sortedData = yValues;
|
|
107
|
+
if (sortKey) {
|
|
108
|
+
sortedData = sort(yValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)));
|
|
109
|
+
}
|
|
110
|
+
else if ((sortingOptions === null || sortingOptions === void 0 ? void 0 : sortingOptions.direction) === 'desc') {
|
|
111
|
+
sortedData = reverse(yValues);
|
|
112
|
+
}
|
|
109
113
|
for (let yValueIndex = 0; yValueIndex < sortedData.length; yValueIndex++) {
|
|
110
114
|
const yValue = sortedData[yValueIndex];
|
|
111
115
|
const yAxisIndex = yValue.series.yAxis;
|
|
@@ -119,7 +123,6 @@ export const prepareBarXData = async (args) => {
|
|
|
119
123
|
if (xAxis.type === 'category') {
|
|
120
124
|
const xBandScale = xScale;
|
|
121
125
|
const xBandScaleDomain = xBandScale.domain();
|
|
122
|
-
// eslint-disable-next-line max-depth
|
|
123
126
|
if (xBandScaleDomain.indexOf(xValue) === -1) {
|
|
124
127
|
continue;
|
|
125
128
|
}
|
|
@@ -205,18 +205,23 @@ export function getTextSizeFn({ style }) {
|
|
|
205
205
|
// We ignore an inaccuracy of less than a pixel.
|
|
206
206
|
// To do this, we round the font size down when comparing it, and the size of the allowed space up.
|
|
207
207
|
export async function getTextWithElipsis({ text: originalText, getTextWidth, maxWidth, }) {
|
|
208
|
-
|
|
208
|
+
const textWidth = Math.floor(await getTextWidth(originalText));
|
|
209
209
|
const textMaxWidth = Math.ceil(maxWidth);
|
|
210
210
|
if (textWidth <= textMaxWidth) {
|
|
211
211
|
return originalText;
|
|
212
212
|
}
|
|
213
|
-
let
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
213
|
+
let low = 0;
|
|
214
|
+
let high = originalText.length;
|
|
215
|
+
while (low < high) {
|
|
216
|
+
const mid = Math.floor((low + high + 1) / 2);
|
|
217
|
+
const candidate = originalText.slice(0, mid) + '…';
|
|
218
|
+
const candidateWidth = Math.floor(await getTextWidth(candidate));
|
|
219
|
+
if (candidateWidth <= textMaxWidth) {
|
|
220
|
+
low = mid;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
high = mid - 1;
|
|
224
|
+
}
|
|
220
225
|
}
|
|
221
|
-
return
|
|
226
|
+
return low > 0 ? originalText.slice(0, low) + '…' : '';
|
|
222
227
|
}
|
|
@@ -89,7 +89,8 @@ export const DefaultTooltipContent = ({ hovered, pinned, rowRenderer, totals, va
|
|
|
89
89
|
}
|
|
90
90
|
}, [pinned]);
|
|
91
91
|
return (React.createElement("div", { className: b('content'), "data-qa": qa },
|
|
92
|
-
formattedHeadValue && (React.createElement("div", { className: b('series-name')
|
|
92
|
+
formattedHeadValue && (React.createElement("div", { className: b('series-name') },
|
|
93
|
+
React.createElement("div", { className: b('series-name-text'), dangerouslySetInnerHTML: { __html: formattedHeadValue } }))),
|
|
93
94
|
React.createElement("div", { className: b('content-rows', { pinned }), ref: contentRowsRef, style: { maxHeight: maxContentRowsHeight } },
|
|
94
95
|
visibleHovered.map((seriesItem, i) => {
|
|
95
96
|
var _a;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
box-shadow: 0 2px 12px var(--g-color-sfx-shadow);
|
|
4
4
|
}
|
|
5
5
|
.gcharts-tooltip__popup-content {
|
|
6
|
+
max-width: 450px;
|
|
6
7
|
text-wrap: nowrap;
|
|
7
8
|
border-radius: 4px;
|
|
8
9
|
background-color: var(--g-color-infographics-tooltip-bg);
|
|
@@ -24,6 +25,12 @@
|
|
|
24
25
|
font-size: 13px;
|
|
25
26
|
font-weight: 600;
|
|
26
27
|
}
|
|
28
|
+
.gcharts-tooltip__series-name-text {
|
|
29
|
+
display: block;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
text-overflow: ellipsis;
|
|
33
|
+
}
|
|
27
34
|
.gcharts-tooltip__content-row {
|
|
28
35
|
display: flex;
|
|
29
36
|
align-items: center;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ascending, descending, sort } from 'd3';
|
|
1
|
+
import { ascending, descending, reverse, sort } from 'd3';
|
|
2
2
|
import get from 'lodash/get';
|
|
3
3
|
import { getDataCategoryValue, getLabelsSize } from '../../../utils';
|
|
4
4
|
import { getFormattedValue } from '../../../utils/chart/format';
|
|
@@ -103,9 +103,13 @@ export const prepareBarXData = async (args) => {
|
|
|
103
103
|
let positiveStackHeight = 0;
|
|
104
104
|
let negativeStackHeight = 0;
|
|
105
105
|
const stackItems = [];
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
let sortedData = yValues;
|
|
107
|
+
if (sortKey) {
|
|
108
|
+
sortedData = sort(yValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)));
|
|
109
|
+
}
|
|
110
|
+
else if ((sortingOptions === null || sortingOptions === void 0 ? void 0 : sortingOptions.direction) === 'desc') {
|
|
111
|
+
sortedData = reverse(yValues);
|
|
112
|
+
}
|
|
109
113
|
for (let yValueIndex = 0; yValueIndex < sortedData.length; yValueIndex++) {
|
|
110
114
|
const yValue = sortedData[yValueIndex];
|
|
111
115
|
const yAxisIndex = yValue.series.yAxis;
|
|
@@ -119,7 +123,6 @@ export const prepareBarXData = async (args) => {
|
|
|
119
123
|
if (xAxis.type === 'category') {
|
|
120
124
|
const xBandScale = xScale;
|
|
121
125
|
const xBandScaleDomain = xBandScale.domain();
|
|
122
|
-
// eslint-disable-next-line max-depth
|
|
123
126
|
if (xBandScaleDomain.indexOf(xValue) === -1) {
|
|
124
127
|
continue;
|
|
125
128
|
}
|
|
@@ -205,18 +205,23 @@ export function getTextSizeFn({ style }) {
|
|
|
205
205
|
// We ignore an inaccuracy of less than a pixel.
|
|
206
206
|
// To do this, we round the font size down when comparing it, and the size of the allowed space up.
|
|
207
207
|
export async function getTextWithElipsis({ text: originalText, getTextWidth, maxWidth, }) {
|
|
208
|
-
|
|
208
|
+
const textWidth = Math.floor(await getTextWidth(originalText));
|
|
209
209
|
const textMaxWidth = Math.ceil(maxWidth);
|
|
210
210
|
if (textWidth <= textMaxWidth) {
|
|
211
211
|
return originalText;
|
|
212
212
|
}
|
|
213
|
-
let
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
213
|
+
let low = 0;
|
|
214
|
+
let high = originalText.length;
|
|
215
|
+
while (low < high) {
|
|
216
|
+
const mid = Math.floor((low + high + 1) / 2);
|
|
217
|
+
const candidate = originalText.slice(0, mid) + '…';
|
|
218
|
+
const candidateWidth = Math.floor(await getTextWidth(candidate));
|
|
219
|
+
if (candidateWidth <= textMaxWidth) {
|
|
220
|
+
low = mid;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
high = mid - 1;
|
|
224
|
+
}
|
|
220
225
|
}
|
|
221
|
-
return
|
|
226
|
+
return low > 0 ? originalText.slice(0, low) + '…' : '';
|
|
222
227
|
}
|