@gravity-ui/charts 1.18.1 → 1.18.2

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.
@@ -226,7 +226,7 @@ export async function prepareAxisData({ axis, split, scale, top: topOffset, widt
226
226
  content: titleContent,
227
227
  style: axis.title.style,
228
228
  size: rotatedTitleSize,
229
- x: x,
229
+ x,
230
230
  y: axisPlotTopPosition + y,
231
231
  rotate: rotateAngle,
232
232
  offset: -(originalTextSize.height / titleContent.length) * (titleContent.length - 1),
@@ -85,7 +85,7 @@ function renderLegendSymbol(args) {
85
85
  case 'path': {
86
86
  const y = legendLineHeight / 2;
87
87
  const points = [
88
- { x: x, y },
88
+ { x, y },
89
89
  { x: x + d.symbol.width, y },
90
90
  ];
91
91
  element
@@ -113,9 +113,6 @@ export async function prepareBarYData(args) {
113
113
  if (dataLabels.enabled) {
114
114
  const data = prepared.data;
115
115
  const content = getFormattedValue(Object.assign({ value: data.label || data.x }, dataLabels));
116
- const x = dataLabels.inside
117
- ? prepared.x + prepared.width / 2
118
- : prepared.x + prepared.width + DEFAULT_LABEL_PADDING;
119
116
  const y = prepared.y + prepared.height / 2;
120
117
  if (dataLabels.html) {
121
118
  const { maxHeight: height, maxWidth: width } = await getLabelsSize({
@@ -123,6 +120,9 @@ export async function prepareBarYData(args) {
123
120
  style: dataLabels.style,
124
121
  html: dataLabels.html,
125
122
  });
123
+ const x = dataLabels.inside
124
+ ? prepared.x + prepared.width / 2 - width / 2
125
+ : prepared.x + prepared.width + DEFAULT_LABEL_PADDING;
126
126
  const constrainedPosition = getHtmlLabelConstraintedPosition({
127
127
  boundsHeight,
128
128
  boundsWidth,
@@ -145,6 +145,9 @@ export async function prepareBarYData(args) {
145
145
  }
146
146
  const getTextSize = map.get(dataLabels.style);
147
147
  const { width, height } = await getTextSize(content);
148
+ const x = dataLabels.inside
149
+ ? prepared.x + prepared.width / 2 - width / 2
150
+ : prepared.x + prepared.width + DEFAULT_LABEL_PADDING;
148
151
  const constrainedPosition = getSvgLabelConstraintedPosition({
149
152
  boundsHeight,
150
153
  boundsWidth,
@@ -158,7 +161,7 @@ export async function prepareBarYData(args) {
158
161
  series: prepared.series,
159
162
  style: dataLabels.style,
160
163
  text: content,
161
- textAnchor: dataLabels.inside ? 'middle' : 'right',
164
+ textAnchor: 'start',
162
165
  x: constrainedPosition.x,
163
166
  y: constrainedPosition.y,
164
167
  });
@@ -368,7 +368,10 @@ function validateTooltip({ tooltip }) {
368
368
  }
369
369
  }
370
370
  export function validateData(data) {
371
- if (isEmpty(data) || isEmpty(data.series) || isEmpty(data.series.data)) {
371
+ if (isEmpty(data) ||
372
+ isEmpty(data.series) ||
373
+ isEmpty(data.series.data) ||
374
+ data.series.data.every((s) => isEmpty(s.data))) {
372
375
  throw new ChartError({
373
376
  code: CHART_ERROR_CODE.NO_DATA,
374
377
  message: i18n('error', 'label_no-data'),
@@ -226,7 +226,7 @@ export async function prepareAxisData({ axis, split, scale, top: topOffset, widt
226
226
  content: titleContent,
227
227
  style: axis.title.style,
228
228
  size: rotatedTitleSize,
229
- x: x,
229
+ x,
230
230
  y: axisPlotTopPosition + y,
231
231
  rotate: rotateAngle,
232
232
  offset: -(originalTextSize.height / titleContent.length) * (titleContent.length - 1),
@@ -85,7 +85,7 @@ function renderLegendSymbol(args) {
85
85
  case 'path': {
86
86
  const y = legendLineHeight / 2;
87
87
  const points = [
88
- { x: x, y },
88
+ { x, y },
89
89
  { x: x + d.symbol.width, y },
90
90
  ];
91
91
  element
@@ -113,9 +113,6 @@ export async function prepareBarYData(args) {
113
113
  if (dataLabels.enabled) {
114
114
  const data = prepared.data;
115
115
  const content = getFormattedValue(Object.assign({ value: data.label || data.x }, dataLabels));
116
- const x = dataLabels.inside
117
- ? prepared.x + prepared.width / 2
118
- : prepared.x + prepared.width + DEFAULT_LABEL_PADDING;
119
116
  const y = prepared.y + prepared.height / 2;
120
117
  if (dataLabels.html) {
121
118
  const { maxHeight: height, maxWidth: width } = await getLabelsSize({
@@ -123,6 +120,9 @@ export async function prepareBarYData(args) {
123
120
  style: dataLabels.style,
124
121
  html: dataLabels.html,
125
122
  });
123
+ const x = dataLabels.inside
124
+ ? prepared.x + prepared.width / 2 - width / 2
125
+ : prepared.x + prepared.width + DEFAULT_LABEL_PADDING;
126
126
  const constrainedPosition = getHtmlLabelConstraintedPosition({
127
127
  boundsHeight,
128
128
  boundsWidth,
@@ -145,6 +145,9 @@ export async function prepareBarYData(args) {
145
145
  }
146
146
  const getTextSize = map.get(dataLabels.style);
147
147
  const { width, height } = await getTextSize(content);
148
+ const x = dataLabels.inside
149
+ ? prepared.x + prepared.width / 2 - width / 2
150
+ : prepared.x + prepared.width + DEFAULT_LABEL_PADDING;
148
151
  const constrainedPosition = getSvgLabelConstraintedPosition({
149
152
  boundsHeight,
150
153
  boundsWidth,
@@ -158,7 +161,7 @@ export async function prepareBarYData(args) {
158
161
  series: prepared.series,
159
162
  style: dataLabels.style,
160
163
  text: content,
161
- textAnchor: dataLabels.inside ? 'middle' : 'right',
164
+ textAnchor: 'start',
162
165
  x: constrainedPosition.x,
163
166
  y: constrainedPosition.y,
164
167
  });
@@ -368,7 +368,10 @@ function validateTooltip({ tooltip }) {
368
368
  }
369
369
  }
370
370
  export function validateData(data) {
371
- if (isEmpty(data) || isEmpty(data.series) || isEmpty(data.series.data)) {
371
+ if (isEmpty(data) ||
372
+ isEmpty(data.series) ||
373
+ isEmpty(data.series.data) ||
374
+ data.series.data.every((s) => isEmpty(s.data))) {
372
375
  throw new ChartError({
373
376
  code: CHART_ERROR_CODE.NO_DATA,
374
377
  message: i18n('error', 'label_no-data'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.18.1",
3
+ "version": "1.18.2",
4
4
  "description": "React component used to render charts",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",