@gravity-ui/charts 1.39.0 → 1.39.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.
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { line, select } from 'd3';
3
3
  import { getAxisPlotsPosition, getLineDashArray } from '../../utils';
4
+ import { getXValue, getYValue } from '../useShapes/utils';
4
5
  import { useCrosshairHover } from './useCrosshairHover';
5
6
  export const useCrosshair = (props) => {
6
7
  var _a, _b;
@@ -29,15 +30,18 @@ export const useCrosshair = (props) => {
29
30
  crosshairSelection
30
31
  .append('path')
31
32
  .attr('d', (hoveredElement) => {
32
- var _a, _b, _c;
33
33
  let lineValue = 0;
34
- if (xAxis.crosshair.snap) {
35
- const offset = ((_b = (_a = xAxisScale.bandwidth) === null || _a === void 0 ? void 0 : _a.call(xAxisScale)) !== null && _b !== void 0 ? _b : 0) / 2;
36
- if (typeof hoveredElement.data === 'object' && 'x' in hoveredElement.data) {
37
- lineValue = Number(xAxisScale((_c = hoveredElement.data.x) !== null && _c !== void 0 ? _c : 0)) + offset;
38
- }
34
+ if (xAxis.crosshair.snap &&
35
+ typeof hoveredElement.data === 'object' &&
36
+ 'x' in hoveredElement.data) {
37
+ const xVal = getXValue({
38
+ point: hoveredElement.data,
39
+ xAxis,
40
+ xScale: xAxisScale,
41
+ });
42
+ lineValue = xVal !== null && !Number.isNaN(xVal) ? xVal : lineValue;
39
43
  }
40
- else {
44
+ else if (!xAxis.crosshair.snap) {
41
45
  lineValue = pointerXPos - boundsOffsetLeft;
42
46
  }
43
47
  const points = [
@@ -89,16 +93,18 @@ export const useCrosshair = (props) => {
89
93
  crosshairSelection
90
94
  .append('path')
91
95
  .attr('d', (hoveredElement) => {
92
- var _a, _b, _c;
93
96
  let lineValue = 0;
94
- if (yAxis.crosshair.snap) {
95
- const offset = ((_b = (_a = yAxisScale.bandwidth) === null || _a === void 0 ? void 0 : _a.call(yAxisScale)) !== null && _b !== void 0 ? _b : 0) / 2;
96
- if (typeof hoveredElement.data === 'object' &&
97
- 'y' in hoveredElement.data) {
98
- lineValue = Number(yAxisScale((_c = hoveredElement.data.y) !== null && _c !== void 0 ? _c : 0)) + offset;
99
- }
97
+ if (yAxis.crosshair.snap &&
98
+ typeof hoveredElement.data === 'object' &&
99
+ 'y' in hoveredElement.data) {
100
+ const yVal = getYValue({
101
+ point: hoveredElement.data,
102
+ yAxis,
103
+ yScale: yAxisScale,
104
+ });
105
+ lineValue = yVal !== null && !Number.isNaN(yVal) ? yVal : lineValue;
100
106
  }
101
- else {
107
+ else if (!yAxis.crosshair.snap) {
102
108
  lineValue = pointerYPos - boundsOffsetTop;
103
109
  }
104
110
  const points = [
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { line, select } from 'd3';
3
3
  import { getAxisPlotsPosition, getLineDashArray } from '../../utils';
4
+ import { getXValue, getYValue } from '../useShapes/utils';
4
5
  import { useCrosshairHover } from './useCrosshairHover';
5
6
  export const useCrosshair = (props) => {
6
7
  var _a, _b;
@@ -29,15 +30,18 @@ export const useCrosshair = (props) => {
29
30
  crosshairSelection
30
31
  .append('path')
31
32
  .attr('d', (hoveredElement) => {
32
- var _a, _b, _c;
33
33
  let lineValue = 0;
34
- if (xAxis.crosshair.snap) {
35
- const offset = ((_b = (_a = xAxisScale.bandwidth) === null || _a === void 0 ? void 0 : _a.call(xAxisScale)) !== null && _b !== void 0 ? _b : 0) / 2;
36
- if (typeof hoveredElement.data === 'object' && 'x' in hoveredElement.data) {
37
- lineValue = Number(xAxisScale((_c = hoveredElement.data.x) !== null && _c !== void 0 ? _c : 0)) + offset;
38
- }
34
+ if (xAxis.crosshair.snap &&
35
+ typeof hoveredElement.data === 'object' &&
36
+ 'x' in hoveredElement.data) {
37
+ const xVal = getXValue({
38
+ point: hoveredElement.data,
39
+ xAxis,
40
+ xScale: xAxisScale,
41
+ });
42
+ lineValue = xVal !== null && !Number.isNaN(xVal) ? xVal : lineValue;
39
43
  }
40
- else {
44
+ else if (!xAxis.crosshair.snap) {
41
45
  lineValue = pointerXPos - boundsOffsetLeft;
42
46
  }
43
47
  const points = [
@@ -89,16 +93,18 @@ export const useCrosshair = (props) => {
89
93
  crosshairSelection
90
94
  .append('path')
91
95
  .attr('d', (hoveredElement) => {
92
- var _a, _b, _c;
93
96
  let lineValue = 0;
94
- if (yAxis.crosshair.snap) {
95
- const offset = ((_b = (_a = yAxisScale.bandwidth) === null || _a === void 0 ? void 0 : _a.call(yAxisScale)) !== null && _b !== void 0 ? _b : 0) / 2;
96
- if (typeof hoveredElement.data === 'object' &&
97
- 'y' in hoveredElement.data) {
98
- lineValue = Number(yAxisScale((_c = hoveredElement.data.y) !== null && _c !== void 0 ? _c : 0)) + offset;
99
- }
97
+ if (yAxis.crosshair.snap &&
98
+ typeof hoveredElement.data === 'object' &&
99
+ 'y' in hoveredElement.data) {
100
+ const yVal = getYValue({
101
+ point: hoveredElement.data,
102
+ yAxis,
103
+ yScale: yAxisScale,
104
+ });
105
+ lineValue = yVal !== null && !Number.isNaN(yVal) ? yVal : lineValue;
100
106
  }
101
- else {
107
+ else if (!yAxis.crosshair.snap) {
102
108
  lineValue = pointerYPos - boundsOffsetTop;
103
109
  }
104
110
  const points = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.39.0",
3
+ "version": "1.39.1",
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",