@gravity-ui/charts 1.26.0 → 1.26.1

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.
@@ -6,17 +6,15 @@ import { block, createGradientRect, getContinuesColorFn, getLabelsSize, getLineD
6
6
  import { axisBottom } from '../../utils/chart/axis-generators';
7
7
  import './styles.css';
8
8
  const b = block('legend');
9
- const getLegendItemPosition = (args) => {
9
+ const getLegendItemLeftPosition = (args) => {
10
10
  const { align, width, contentWidth } = args;
11
11
  if (align === 'right') {
12
- return { left: width - contentWidth };
12
+ return width - contentWidth;
13
13
  }
14
- else if (align === 'left') {
15
- return { left: 0 };
16
- }
17
- else {
18
- return { left: width / 2 - contentWidth / 2 };
14
+ if (align === 'left') {
15
+ return 0;
19
16
  }
17
+ return width / 2 - contentWidth / 2;
20
18
  };
21
19
  const getLegendPosition = (args) => {
22
20
  const { offsetLeft, offsetTop, contentWidth, width } = args;
@@ -256,12 +254,11 @@ export const Legend = (props) => {
256
254
  let left = 0;
257
255
  switch (legend.justifyContent) {
258
256
  case 'center': {
259
- const legendLinePostion = getLegendItemPosition({
257
+ left = getLegendItemLeftPosition({
260
258
  align: legend.align,
261
259
  width: config.maxWidth,
262
260
  contentWidth,
263
261
  });
264
- left = legendLinePostion.left;
265
262
  legendWidth = config.maxWidth;
266
263
  break;
267
264
  }
@@ -296,11 +293,21 @@ export const Legend = (props) => {
296
293
  legendTop = top;
297
294
  }
298
295
  else {
299
- const { left } = getLegendItemPosition({
300
- align: legend.align,
301
- width: config.maxWidth,
302
- contentWidth: legend.width,
303
- });
296
+ let left = 0;
297
+ switch (legend.align) {
298
+ case 'right': {
299
+ left = config.offset.left + config.maxWidth - legend.width;
300
+ break;
301
+ }
302
+ case 'left': {
303
+ left = config.offset.left;
304
+ break;
305
+ }
306
+ case 'center': {
307
+ left = config.offset.left + config.maxWidth / 2 - legend.width / 2;
308
+ break;
309
+ }
310
+ }
304
311
  const { top } = getLegendPosition({
305
312
  width: config.maxWidth,
306
313
  contentWidth: legendWidth,
@@ -6,17 +6,15 @@ import { block, createGradientRect, getContinuesColorFn, getLabelsSize, getLineD
6
6
  import { axisBottom } from '../../utils/chart/axis-generators';
7
7
  import './styles.css';
8
8
  const b = block('legend');
9
- const getLegendItemPosition = (args) => {
9
+ const getLegendItemLeftPosition = (args) => {
10
10
  const { align, width, contentWidth } = args;
11
11
  if (align === 'right') {
12
- return { left: width - contentWidth };
12
+ return width - contentWidth;
13
13
  }
14
- else if (align === 'left') {
15
- return { left: 0 };
16
- }
17
- else {
18
- return { left: width / 2 - contentWidth / 2 };
14
+ if (align === 'left') {
15
+ return 0;
19
16
  }
17
+ return width / 2 - contentWidth / 2;
20
18
  };
21
19
  const getLegendPosition = (args) => {
22
20
  const { offsetLeft, offsetTop, contentWidth, width } = args;
@@ -256,12 +254,11 @@ export const Legend = (props) => {
256
254
  let left = 0;
257
255
  switch (legend.justifyContent) {
258
256
  case 'center': {
259
- const legendLinePostion = getLegendItemPosition({
257
+ left = getLegendItemLeftPosition({
260
258
  align: legend.align,
261
259
  width: config.maxWidth,
262
260
  contentWidth,
263
261
  });
264
- left = legendLinePostion.left;
265
262
  legendWidth = config.maxWidth;
266
263
  break;
267
264
  }
@@ -296,11 +293,21 @@ export const Legend = (props) => {
296
293
  legendTop = top;
297
294
  }
298
295
  else {
299
- const { left } = getLegendItemPosition({
300
- align: legend.align,
301
- width: config.maxWidth,
302
- contentWidth: legend.width,
303
- });
296
+ let left = 0;
297
+ switch (legend.align) {
298
+ case 'right': {
299
+ left = config.offset.left + config.maxWidth - legend.width;
300
+ break;
301
+ }
302
+ case 'left': {
303
+ left = config.offset.left;
304
+ break;
305
+ }
306
+ case 'center': {
307
+ left = config.offset.left + config.maxWidth / 2 - legend.width / 2;
308
+ break;
309
+ }
310
+ }
304
311
  const { top } = getLegendPosition({
305
312
  width: config.maxWidth,
306
313
  contentWidth: legendWidth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.26.0",
3
+ "version": "1.26.1",
4
4
  "description": "React component used to render charts",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",