@gravity-ui/charts 1.34.9 → 1.34.10

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.
@@ -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'), dangerouslySetInnerHTML: { __html: formattedHeadValue } })),
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;
@@ -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
- let textWidth = Math.floor(await getTextWidth(originalText));
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 text = originalText + '…';
214
- while (textWidth > textMaxWidth && text.length > 2) {
215
- text = text.slice(0, -2) + '…';
216
- textWidth = Math.floor(await getTextWidth(text));
217
- }
218
- if (textWidth > textMaxWidth) {
219
- text = '';
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 text;
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'), dangerouslySetInnerHTML: { __html: formattedHeadValue } })),
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;
@@ -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
- let textWidth = Math.floor(await getTextWidth(originalText));
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 text = originalText + '…';
214
- while (textWidth > textMaxWidth && text.length > 2) {
215
- text = text.slice(0, -2) + '…';
216
- textWidth = Math.floor(await getTextWidth(text));
217
- }
218
- if (textWidth > textMaxWidth) {
219
- text = '';
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 text;
226
+ return low > 0 ? originalText.slice(0, low) + '…' : '';
222
227
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.34.9",
3
+ "version": "1.34.10",
4
4
  "description": "A flexible JavaScript library for data visualization and chart rendering using React",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",