@gravity-ui/chartkit 4.2.0 → 4.3.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.
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
- import type { ChartOptions, ChartScale } from '../hooks';
2
+ import type { ChartScale, PreparedAxis } from '../hooks';
3
3
  type Props = {
4
- axis: ChartOptions['xAxis'];
4
+ axis: PreparedAxis;
5
5
  width: number;
6
6
  height: number;
7
7
  scale: ChartScale;
@@ -51,7 +51,10 @@ export const AxisX = ({ axis, width, height, scale }) => {
51
51
  xAxisGenerator = xAxisGenerator.ticks(ticksCount);
52
52
  }
53
53
  svgElement.call(xAxisGenerator).attr('class', b());
54
- svgElement.select('.domain').attr('d', `M0,0V0H${width}`);
54
+ svgElement
55
+ .select('.domain')
56
+ .attr('d', `M0,0V0H${width}`)
57
+ .style('stroke', axis.lineColor || '');
55
58
  if (axis.labels.enabled) {
56
59
  svgElement.selectAll('.tick text').style('font-size', axis.labels.style.fontSize);
57
60
  }
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
- import type { ChartOptions, ChartScale } from '../hooks';
2
+ import type { ChartScale, PreparedAxis } from '../hooks';
3
3
  type Props = {
4
- axises: ChartOptions['yAxis'];
4
+ axises: PreparedAxis[];
5
5
  width: number;
6
6
  height: number;
7
7
  scale: ChartScale;
@@ -52,7 +52,10 @@ export const AxisY = ({ axises, width, height, scale }) => {
52
52
  yAxisGenerator = yAxisGenerator.ticks(ticksCount);
53
53
  }
54
54
  svgElement.call(yAxisGenerator).attr('class', b());
55
- svgElement.select('.domain').attr('d', `M0,${height}H0V0`);
55
+ svgElement
56
+ .select('.domain')
57
+ .attr('d', `M0,${height}H0V0`)
58
+ .style('stroke', axis.lineColor || '');
56
59
  if (axis.labels.enabled) {
57
60
  svgElement
58
61
  .selectAll('.tick text')
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import isNil from 'lodash/isNil';
2
3
  import { block } from '../../../../../utils/cn';
3
4
  import { DefaultContent } from './DefaultContent';
4
5
  const b = block('d3-tooltip');
@@ -32,13 +33,12 @@ export const Tooltip = (props) => {
32
33
  return undefined;
33
34
  }, [hovered, pointerPosition, size]);
34
35
  const content = React.useMemo(() => {
35
- if (tooltip.renderer && hovered) {
36
- return tooltip.renderer({ hovered });
36
+ var _a;
37
+ if (!hovered) {
38
+ return null;
37
39
  }
38
- else if (hovered) {
39
- return React.createElement(DefaultContent, { hovered: hovered, xAxis: xAxis, yAxis: yAxis });
40
- }
41
- return null;
40
+ const customTooltip = (_a = tooltip.renderer) === null || _a === void 0 ? void 0 : _a.call(tooltip, { hovered });
41
+ return isNil(customTooltip) ? (React.createElement(DefaultContent, { hovered: hovered, xAxis: xAxis, yAxis: yAxis })) : (customTooltip);
42
42
  }, [hovered, tooltip, xAxis, yAxis]);
43
43
  if (!position || !hovered) {
44
44
  return null;
@@ -15,6 +15,7 @@ export const getPreparedXAxis = ({ xAxis }) => {
15
15
  numberFormat: get(xAxis, 'labels.numberFormat'),
16
16
  style: { fontSize: get(xAxis, 'labels.style.fontSize', DEFAULT_AXIS_LABEL_FONT_SIZE) },
17
17
  },
18
+ lineColor: get(xAxis, 'lineColor'),
18
19
  categories: get(xAxis, 'categories'),
19
20
  timestamps: get(xAxis, 'timestamps'),
20
21
  title: {
@@ -20,6 +20,7 @@ export const getPreparedYAxis = ({ yAxis }) => {
20
20
  numberFormat: get(yAxis1, 'labels.numberFormat'),
21
21
  style: y1LabelsStyle,
22
22
  },
23
+ lineColor: get(yAxis1, 'lineColor'),
23
24
  categories: get(yAxis1, 'categories'),
24
25
  timestamps: get(yAxis1, 'timestamps'),
25
26
  title: {
@@ -2,9 +2,9 @@ import type { FormatNumberOptions } from '../../plugins/shared';
2
2
  import type { BaseTextStyle } from './base';
3
3
  export type ChartKitWidgetAxisType = 'category' | 'datetime' | 'linear';
4
4
  export type ChartKitWidgetAxisLabels = {
5
- /** Enable or disable the axis labels */
5
+ /** Enable or disable the axis labels. */
6
6
  enabled?: boolean;
7
- /** The pixel padding for axis labels */
7
+ /** The pixel padding for axis labels. */
8
8
  padding?: number;
9
9
  dateFormat?: string;
10
10
  numberFormat?: FormatNumberOptions;
@@ -14,13 +14,16 @@ export type ChartKitWidgetAxis = {
14
14
  categories?: string[];
15
15
  timestamps?: number[];
16
16
  type?: ChartKitWidgetAxisType;
17
- /** The axis labels show the number or category for each tick */
17
+ /** The axis labels show the number or category for each tick. */
18
18
  labels?: ChartKitWidgetAxisLabels;
19
+ /** The color of the line marking the axis itself. */
20
+ lineColor?: string;
19
21
  title?: {
20
22
  text?: string;
21
23
  };
22
- /** The minimum value of the axis. If undefined the min value is automatically calculate */
24
+ /** The minimum value of the axis. If undefined the min value is automatically calculate. */
23
25
  min?: number;
26
+ /** The grid lines settings. */
24
27
  grid?: {
25
28
  /** Enable or disable the grid lines.
26
29
  *
@@ -36,7 +39,7 @@ export type ChartKitWidgetAxis = {
36
39
  /** Padding of the max value relative to the length of the axis.
37
40
  * A padding of 0.05 will make a 100px axis 5px longer.
38
41
  *
39
- * Defaults to 0.05 for Y axis and to 0.01 for X axis
42
+ * Defaults to 0.05 for Y axis and to 0.01 for X axis.
40
43
  * */
41
44
  maxPadding?: number;
42
45
  };
@@ -6,6 +6,7 @@ export type TooltipHoveredData<T = any> = {
6
6
  };
7
7
  export type ChartKitWidgetTooltip<T = any> = {
8
8
  enabled?: boolean;
9
+ /** Specifies the renderer for the tooltip. If returned null default tooltip renderer will be used. */
9
10
  renderer?: (data: {
10
11
  hovered: TooltipHoveredData<T>;
11
12
  }) => React.ReactElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "description": "React component used to render charts based on any sources you need",
5
5
  "license": "MIT",
6
6
  "repository": "git@github.com:gravity-ui/ChartKit.git",