@gravity-ui/chartkit 4.14.0 → 4.16.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.
Files changed (71) hide show
  1. package/build/constants/index.d.ts +1 -0
  2. package/build/constants/index.js +1 -0
  3. package/build/constants/widget-data.d.ts +34 -0
  4. package/build/constants/widget-data.js +37 -0
  5. package/build/plugins/d3/examples/ExampleWrapper.d.ts +7 -0
  6. package/build/plugins/d3/examples/ExampleWrapper.js +5 -0
  7. package/build/plugins/d3/examples/area/Basic.js +3 -4
  8. package/build/plugins/d3/examples/area/StackedArea.js +3 -4
  9. package/build/plugins/d3/examples/bar-x/Basic.js +8 -4
  10. package/build/plugins/d3/examples/bar-x/DataLabels.js +4 -2
  11. package/build/plugins/d3/examples/bar-x/GroupedColumns.js +4 -2
  12. package/build/plugins/d3/examples/bar-x/StackedColumns.js +4 -2
  13. package/build/plugins/d3/examples/bar-y/Basic.js +4 -2
  14. package/build/plugins/d3/examples/bar-y/GroupedColumns.js +4 -2
  15. package/build/plugins/d3/examples/bar-y/StackedColumns.js +4 -2
  16. package/build/plugins/d3/examples/combined/LineAndBarX.js +5 -3
  17. package/build/plugins/d3/examples/line/Basic.js +4 -2
  18. package/build/plugins/d3/examples/line/DataLabels.js +4 -2
  19. package/build/plugins/d3/examples/line/LineWithMarkers.js +4 -2
  20. package/build/plugins/d3/examples/line/Shapes.d.ts +2 -0
  21. package/build/plugins/d3/examples/line/Shapes.js +93 -0
  22. package/build/plugins/d3/examples/pie/Basic.js +4 -2
  23. package/build/plugins/d3/examples/pie/Donut.js +4 -2
  24. package/build/plugins/d3/examples/scatter/Basic.js +4 -2
  25. package/build/plugins/d3/renderer/components/Legend.js +23 -1
  26. package/build/plugins/d3/renderer/components/styles.css +4 -0
  27. package/build/plugins/d3/renderer/hooks/useSeries/constants.d.ts +2 -3
  28. package/build/plugins/d3/renderer/hooks/useSeries/constants.js +1 -1
  29. package/build/plugins/d3/renderer/hooks/useSeries/prepare-line-series.d.ts +2 -0
  30. package/build/plugins/d3/renderer/hooks/useSeries/prepare-line-series.js +11 -0
  31. package/build/plugins/d3/renderer/hooks/useSeries/prepare-pie.d.ts +2 -1
  32. package/build/plugins/d3/renderer/hooks/useSeries/prepare-pie.js +11 -1
  33. package/build/plugins/d3/renderer/hooks/useSeries/prepareSeries.js +8 -5
  34. package/build/plugins/d3/renderer/hooks/useSeries/types.d.ts +23 -12
  35. package/build/plugins/d3/renderer/hooks/useSeries/utils.d.ts +2 -1
  36. package/build/plugins/d3/renderer/hooks/useSeries/utils.js +5 -6
  37. package/build/plugins/d3/renderer/hooks/useShapes/area/index.js +5 -62
  38. package/build/plugins/d3/renderer/hooks/useShapes/line/index.js +9 -65
  39. package/build/plugins/d3/renderer/hooks/useShapes/line/prepare-data.js +5 -2
  40. package/build/plugins/d3/renderer/hooks/useShapes/line/types.d.ts +3 -0
  41. package/build/plugins/d3/renderer/hooks/useShapes/marker.d.ts +12 -0
  42. package/build/plugins/d3/renderer/hooks/useShapes/marker.js +70 -0
  43. package/build/plugins/d3/renderer/hooks/useShapes/pie/index.d.ts +3 -2
  44. package/build/plugins/d3/renderer/hooks/useShapes/pie/index.js +28 -0
  45. package/build/plugins/d3/renderer/hooks/useShapes/pie/prepare-data.js +9 -3
  46. package/build/plugins/d3/renderer/hooks/useShapes/pie/types.d.ts +5 -0
  47. package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.js +16 -9
  48. package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.d.ts +1 -0
  49. package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.js +3 -0
  50. package/build/plugins/d3/renderer/hooks/useShapes/utils.d.ts +2 -0
  51. package/build/plugins/d3/renderer/hooks/useShapes/utils.js +17 -0
  52. package/build/plugins/d3/renderer/utils/index.d.ts +1 -0
  53. package/build/plugins/d3/renderer/utils/index.js +1 -0
  54. package/build/plugins/d3/renderer/utils/symbol.d.ts +5 -0
  55. package/build/plugins/d3/renderer/utils/symbol.js +36 -0
  56. package/build/plugins/d3/renderer/validation/index.js +2 -8
  57. package/build/plugins/highcharts/renderer/helpers/config/config.js +0 -3
  58. package/build/types/widget-data/area.d.ts +2 -1
  59. package/build/types/widget-data/bar-x.d.ts +2 -1
  60. package/build/types/widget-data/bar-y.d.ts +2 -1
  61. package/build/types/widget-data/halo.d.ts +9 -0
  62. package/build/types/widget-data/halo.js +1 -0
  63. package/build/types/widget-data/index.d.ts +1 -0
  64. package/build/types/widget-data/index.js +1 -0
  65. package/build/types/widget-data/legend.d.ts +8 -0
  66. package/build/types/widget-data/line.d.ts +6 -1
  67. package/build/types/widget-data/marker.d.ts +0 -8
  68. package/build/types/widget-data/pie.d.ts +2 -1
  69. package/build/types/widget-data/scatter.d.ts +3 -2
  70. package/build/types/widget-data/series.d.ts +19 -4
  71. package/package.json +8 -2
@@ -1 +1,2 @@
1
1
  export { CHARTKIT_SCROLLABLE_NODE_CLASSNAME } from './common';
2
+ export * from './widget-data';
@@ -1 +1,2 @@
1
1
  export { CHARTKIT_SCROLLABLE_NODE_CLASSNAME } from './common';
2
+ export * from './widget-data';
@@ -0,0 +1,34 @@
1
+ export declare const SeriesType: {
2
+ readonly Area: "area";
3
+ readonly BarX: "bar-x";
4
+ readonly BarY: "bar-y";
5
+ readonly Line: "line";
6
+ readonly Pie: "pie";
7
+ readonly Scatter: "scatter";
8
+ };
9
+ export declare enum DashStyle {
10
+ Dash = "Dash",
11
+ DashDot = "DashDot",
12
+ Dot = "Dot",
13
+ LongDash = "LongDash",
14
+ LongDashDot = "LongDashDot",
15
+ LongDashDotDot = "LongDashDotDot",
16
+ ShortDash = "ShortDash",
17
+ ShortDashDot = "ShortDashDot",
18
+ ShortDashDotDot = "ShortDashDotDot",
19
+ ShortDot = "ShortDot",
20
+ Solid = "Solid"
21
+ }
22
+ export declare enum SymbolType {
23
+ Circle = "circle",
24
+ Diamond = "diamond",
25
+ Square = "square",
26
+ Triangle = "triangle",
27
+ TriangleDown = "triangle-down"
28
+ }
29
+ export declare enum LineCap {
30
+ Butt = "butt",
31
+ Round = "round",
32
+ Square = "square",
33
+ None = "none"
34
+ }
@@ -0,0 +1,37 @@
1
+ export const SeriesType = {
2
+ Area: 'area',
3
+ BarX: 'bar-x',
4
+ BarY: 'bar-y',
5
+ Line: 'line',
6
+ Pie: 'pie',
7
+ Scatter: 'scatter',
8
+ };
9
+ export var DashStyle;
10
+ (function (DashStyle) {
11
+ DashStyle["Dash"] = "Dash";
12
+ DashStyle["DashDot"] = "DashDot";
13
+ DashStyle["Dot"] = "Dot";
14
+ DashStyle["LongDash"] = "LongDash";
15
+ DashStyle["LongDashDot"] = "LongDashDot";
16
+ DashStyle["LongDashDotDot"] = "LongDashDotDot";
17
+ DashStyle["ShortDash"] = "ShortDash";
18
+ DashStyle["ShortDashDot"] = "ShortDashDot";
19
+ DashStyle["ShortDashDotDot"] = "ShortDashDotDot";
20
+ DashStyle["ShortDot"] = "ShortDot";
21
+ DashStyle["Solid"] = "Solid";
22
+ })(DashStyle || (DashStyle = {}));
23
+ export var SymbolType;
24
+ (function (SymbolType) {
25
+ SymbolType["Circle"] = "circle";
26
+ SymbolType["Diamond"] = "diamond";
27
+ SymbolType["Square"] = "square";
28
+ SymbolType["Triangle"] = "triangle";
29
+ SymbolType["TriangleDown"] = "triangle-down";
30
+ })(SymbolType || (SymbolType = {}));
31
+ export var LineCap;
32
+ (function (LineCap) {
33
+ LineCap["Butt"] = "butt";
34
+ LineCap["Round"] = "round";
35
+ LineCap["Square"] = "square";
36
+ LineCap["None"] = "none";
37
+ })(LineCap || (LineCap = {}));
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ type Props = {
3
+ children?: React.ReactNode;
4
+ styles?: React.CSSProperties;
5
+ };
6
+ export declare const ExampleWrapper: (props: Props) => React.JSX.Element;
7
+ export {};
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export const ExampleWrapper = (props) => {
3
+ const styles = Object.assign({ height: 280 }, props.styles);
4
+ return React.createElement("div", { style: styles }, props.children);
5
+ };
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ChartKit } from '../../../../components/ChartKit';
3
+ import { ExampleWrapper } from '../ExampleWrapper';
3
4
  import nintendoGames from '../nintendoGames';
4
5
  function prepareData() {
5
6
  const games = nintendoGames.filter((d) => {
@@ -21,9 +22,6 @@ function prepareData() {
21
22
  export const Basic = () => {
22
23
  const series = prepareData();
23
24
  const widgetData = {
24
- title: {
25
- text: 'User score (puzzle genre)',
26
- },
27
25
  series: {
28
26
  data: series,
29
27
  },
@@ -31,5 +29,6 @@ export const Basic = () => {
31
29
  type: 'datetime',
32
30
  },
33
31
  };
34
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
32
+ return (React.createElement(ExampleWrapper, null,
33
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
35
34
  };
@@ -1,6 +1,7 @@
1
1
  import { groups } from 'd3';
2
2
  import React from 'react';
3
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
4
5
  import nintendoGames from '../nintendoGames';
5
6
  const years = Array.from(new Set(nintendoGames.map((d) => d.date ? String(new Date(d.date).getFullYear()) : 'unknown'))).sort();
6
7
  function prepareData() {
@@ -39,10 +40,8 @@ export const StackedArea = () => {
39
40
  xAxis: {
40
41
  type: 'category',
41
42
  categories: years,
42
- title: {
43
- text: 'Release year',
44
- },
45
43
  },
46
44
  };
47
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
45
+ return (React.createElement(ExampleWrapper, null,
46
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
48
47
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { groups } from 'd3';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { groups } from 'd3';
5
6
  function prepareData({ field, filterNulls } = {
6
7
  field: 'platform',
7
8
  }) {
@@ -43,7 +44,8 @@ export const BasicBarXChart = () => {
43
44
  },
44
45
  yAxis: [{ title: { text: 'Number of games released' } }],
45
46
  };
46
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
47
+ return (React.createElement(ExampleWrapper, null,
48
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
47
49
  };
48
50
  export const BasicLinearBarXChart = () => {
49
51
  const { series } = prepareData({ field: 'meta_score' });
@@ -61,7 +63,8 @@ export const BasicLinearBarXChart = () => {
61
63
  },
62
64
  },
63
65
  };
64
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
66
+ return (React.createElement(ExampleWrapper, null,
67
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
65
68
  };
66
69
  export const BasicDateTimeBarXChart = () => {
67
70
  const { series } = prepareData({ field: 'date', filterNulls: true });
@@ -80,5 +83,6 @@ export const BasicDateTimeBarXChart = () => {
80
83
  },
81
84
  },
82
85
  };
83
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
86
+ return (React.createElement(ExampleWrapper, null,
87
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
84
88
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { groups, sort } from 'd3';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { groups, sort } from 'd3';
5
6
  const years = Array.from(new Set(nintendoGames.map((g) => g.date ? new Date(g.date).getFullYear().toString() : 'unknown')));
6
7
  function prepareData() {
7
8
  const games = sort(nintendoGames.filter((d) => {
@@ -42,5 +43,6 @@ export const DataLabels = () => {
42
43
  ticks: { pixelInterval: 200 },
43
44
  },
44
45
  };
45
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
46
+ return (React.createElement(ExampleWrapper, null,
47
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
46
48
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { groups } from 'd3';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { groups } from 'd3';
5
6
  function prepareData() {
6
7
  const displayedYears = [2015, 2016, 2017, 2018, 2019];
7
8
  const games = nintendoGames.filter((ng) => displayedYears.includes(new Date(ng.date).getFullYear()));
@@ -42,5 +43,6 @@ export const GroupedColumns = () => {
42
43
  },
43
44
  },
44
45
  };
45
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
46
+ return (React.createElement(ExampleWrapper, null,
47
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
46
48
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { groups } from 'd3';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { groups } from 'd3';
5
6
  function prepareData() {
6
7
  const grouped = groups(nintendoGames, (d) => d.platform, (d) => (d.date ? new Date(d.date).getFullYear() : 'unknown'));
7
8
  const categories = [];
@@ -41,5 +42,6 @@ export const StackedColumns = () => {
41
42
  },
42
43
  },
43
44
  };
44
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
45
+ return (React.createElement(ExampleWrapper, null,
46
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
45
47
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { groups } from 'd3';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { groups } from 'd3';
5
6
  function prepareData(field = 'platform') {
6
7
  const gamesByPlatform = groups(nintendoGames, (item) => item[field]);
7
8
  const data = gamesByPlatform.map(([value, games]) => ({
@@ -39,5 +40,6 @@ export const Basic = () => {
39
40
  },
40
41
  ],
41
42
  };
42
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
43
+ return (React.createElement(ExampleWrapper, null,
44
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
43
45
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { groups } from 'd3';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { groups } from 'd3';
5
6
  function prepareData() {
6
7
  const displayedYears = [2015, 2016, 2017, 2018, 2019];
7
8
  const games = nintendoGames.filter((ng) => displayedYears.includes(new Date(ng.date).getFullYear()));
@@ -44,5 +45,6 @@ export const GroupedColumns = () => {
44
45
  },
45
46
  ],
46
47
  };
47
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
48
+ return (React.createElement(ExampleWrapper, null,
49
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
48
50
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { groups } from 'd3';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { groups } from 'd3';
5
6
  function prepareData() {
6
7
  const grouped = groups(nintendoGames, (d) => d.platform, (d) => (d.date ? new Date(d.date).getFullYear() : 'unknown'));
7
8
  const categories = [];
@@ -43,5 +44,6 @@ export const StackedColumns = () => {
43
44
  },
44
45
  ],
45
46
  };
46
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
47
+ return (React.createElement(ExampleWrapper, null,
48
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
47
49
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
- import { ChartKit } from '../../../../components/ChartKit';
3
- import nintendoGames from '../../examples/nintendoGames';
4
2
  import { groups, max, min, median } from 'd3';
3
+ import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
5
+ import nintendoGames from '../nintendoGames';
5
6
  export const LineAndBarXCombinedChart = () => {
6
7
  const gamesByPlatform = groups(nintendoGames, (item) => item.platform || 'unknown');
7
8
  const widgetData = {
@@ -57,5 +58,6 @@ export const LineAndBarXCombinedChart = () => {
57
58
  },
58
59
  ],
59
60
  };
60
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
61
+ return (React.createElement(ExampleWrapper, null,
62
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
61
63
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { dateTime } from '@gravity-ui/date-utils';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { dateTime } from '@gravity-ui/date-utils';
5
6
  function prepareData() {
6
7
  const dataset = nintendoGames.filter((d) => d.date && d.user_score);
7
8
  const data = dataset.map((d) => ({
@@ -62,5 +63,6 @@ export const Basic = () => {
62
63
  },
63
64
  },
64
65
  };
65
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
66
+ return (React.createElement(ExampleWrapper, null,
67
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
66
68
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { dateTime } from '@gravity-ui/date-utils';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { dateTime } from '@gravity-ui/date-utils';
5
6
  function prepareData() {
6
7
  const games = nintendoGames.filter((d) => {
7
8
  return d.date && d.user_score;
@@ -85,5 +86,6 @@ export const DataLabels = () => {
85
86
  },
86
87
  },
87
88
  };
88
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
89
+ return (React.createElement(ExampleWrapper, null,
90
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
89
91
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { dateTime } from '@gravity-ui/date-utils';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { dateTime } from '@gravity-ui/date-utils';
5
6
  function prepareData() {
6
7
  const dataset = nintendoGames.filter((d) => d.date && d.user_score && new Date(d.date) > new Date(2022, 0, 1));
7
8
  const data = dataset.map((d) => ({
@@ -63,5 +64,6 @@ export const LineWithMarkers = () => {
63
64
  },
64
65
  },
65
66
  };
66
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
67
+ return (React.createElement(ExampleWrapper, null,
68
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
67
69
  };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const LinesWithShapes: () => React.JSX.Element;
@@ -0,0 +1,93 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import { DashStyle } from '../../../../constants';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
5
+ import nintendoGames from '../nintendoGames';
6
+ const SHAPES = {
7
+ [DashStyle.Solid]: 1,
8
+ [DashStyle.Dash]: 2,
9
+ [DashStyle.Dot]: 3,
10
+ [DashStyle.ShortDashDot]: 4,
11
+ [DashStyle.LongDash]: 5,
12
+ [DashStyle.LongDashDot]: 6,
13
+ [DashStyle.ShortDot]: 7,
14
+ [DashStyle.LongDashDotDot]: 8,
15
+ [DashStyle.ShortDash]: 9,
16
+ [DashStyle.DashDot]: 10,
17
+ [DashStyle.ShortDashDotDot]: 11,
18
+ };
19
+ const selectShapes = () => Object.values(DashStyle);
20
+ const getShapesOrder = () => selectShapes().sort((a, b) => SHAPES[a] - SHAPES[b]);
21
+ const SHAPES_IN_ORDER = getShapesOrder();
22
+ function prepareData() {
23
+ const games = nintendoGames.filter((d) => {
24
+ return d.date && d.user_score;
25
+ });
26
+ const byGenre = (genre) => {
27
+ return games
28
+ .filter((d) => d.genres.includes(genre))
29
+ .map((d) => {
30
+ return {
31
+ x: d.date,
32
+ y: d.user_score,
33
+ label: d.title,
34
+ };
35
+ });
36
+ };
37
+ return {
38
+ series: {
39
+ options: {
40
+ line: {
41
+ lineWidth: 2,
42
+ },
43
+ },
44
+ data: [
45
+ {
46
+ name: '3D',
47
+ type: 'line',
48
+ data: byGenre('3D'),
49
+ },
50
+ {
51
+ name: '2D',
52
+ type: 'line',
53
+ data: byGenre('2D'),
54
+ },
55
+ {
56
+ name: 'Strategy',
57
+ type: 'line',
58
+ data: byGenre('Strategy'),
59
+ },
60
+ {
61
+ name: 'Shooter',
62
+ type: 'line',
63
+ data: byGenre('Shooter'),
64
+ },
65
+ ],
66
+ },
67
+ xAxis: {
68
+ type: 'datetime',
69
+ title: {
70
+ text: 'Release date',
71
+ },
72
+ },
73
+ yAxis: [
74
+ {
75
+ title: { text: 'User score' },
76
+ labels: {
77
+ enabled: true,
78
+ },
79
+ ticks: {
80
+ pixelInterval: 120,
81
+ },
82
+ },
83
+ ],
84
+ };
85
+ }
86
+ export const LinesWithShapes = () => {
87
+ const data = prepareData();
88
+ data.series.data.forEach((graph, i) => {
89
+ graph.dashStyle = SHAPES_IN_ORDER[i % SHAPES_IN_ORDER.length];
90
+ });
91
+ return (React.createElement(ExampleWrapper, null,
92
+ React.createElement(ChartKit, { type: "d3", data: data })));
93
+ };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { groups } from 'd3';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { groups } from 'd3';
5
6
  function prepareData() {
6
7
  const gamesByPlatform = groups(nintendoGames, (item) => item.platform);
7
8
  return gamesByPlatform.map(([platform, games]) => ({
@@ -26,5 +27,6 @@ export const BasicPie = () => {
26
27
  style: { fontSize: '12px', fontWeight: 'normal' },
27
28
  },
28
29
  };
29
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
30
+ return (React.createElement(ExampleWrapper, null,
31
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
30
32
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { groups } from 'd3';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { groups } from 'd3';
5
6
  function prepareData() {
6
7
  const gamesByPlatform = groups(nintendoGames, (d) => d.esrb_rating || 'unknown');
7
8
  return gamesByPlatform.map(([value, games]) => ({
@@ -27,5 +28,6 @@ export const Donut = () => {
27
28
  style: { fontSize: '12px', fontWeight: 'normal' },
28
29
  },
29
30
  };
30
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
31
+ return (React.createElement(ExampleWrapper, null,
32
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
31
33
  };
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
+ import { dateTime } from '@gravity-ui/date-utils';
2
3
  import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
3
5
  import nintendoGames from '../nintendoGames';
4
- import { dateTime } from '@gravity-ui/date-utils';
5
6
  function prepareData() {
6
7
  const dataset = nintendoGames.filter((d) => d.date && d.user_score);
7
8
  const data = dataset.map((d) => ({
@@ -62,5 +63,6 @@ export const Basic = () => {
62
63
  },
63
64
  },
64
65
  };
65
- return React.createElement(ChartKit, { type: "d3", data: widgetData });
66
+ return (React.createElement(ExampleWrapper, null,
67
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
66
68
  };
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
- import { select, line as lineGenerator } from 'd3';
2
+ import { symbol, select, line as lineGenerator } from 'd3';
3
+ import { getSymbol } from '../utils';
3
4
  import { block } from '../../../../utils/cn';
5
+ import { getLineDashArray } from '../hooks/useShapes/utils';
4
6
  const b = block('d3-legend');
5
7
  const getLegendPosition = (args) => {
6
8
  const { align, offsetWidth, width, contentWidth } = args;
@@ -90,6 +92,9 @@ function renderLegendSymbol(args) {
90
92
  .attr('stroke-width', d.symbol.strokeWidth)
91
93
  .attr('class', className)
92
94
  .style('stroke', color);
95
+ if (d.dashStyle) {
96
+ element.attr('stroke-dasharray', getLineDashArray(d.dashStyle, d.symbol.strokeWidth));
97
+ }
93
98
  break;
94
99
  }
95
100
  case 'rect': {
@@ -105,6 +110,23 @@ function renderLegendSymbol(args) {
105
110
  .style('fill', color);
106
111
  break;
107
112
  }
113
+ case 'symbol': {
114
+ const y = legend.lineHeight / 2;
115
+ element
116
+ .append('svg:path')
117
+ .attr('d', () => {
118
+ const scatterSymbol = getSymbol(d.symbol.symbolType);
119
+ // D3 takes size as square pixels, so we need to make square pixels size by multiplying
120
+ // https://d3js.org/d3-shape/symbol#symbol
121
+ return symbol(scatterSymbol, d.symbol.width * d.symbol.width)();
122
+ })
123
+ .attr('transform', () => {
124
+ return 'translate(' + x + ',' + y + ')';
125
+ })
126
+ .attr('class', className)
127
+ .style('fill', color);
128
+ break;
129
+ }
108
130
  }
109
131
  });
110
132
  }
@@ -29,6 +29,10 @@
29
29
  stroke: var(--g-color-text-hint);
30
30
  }
31
31
 
32
+ .chartkit-d3-legend__item-symbol_shape_symbol.chartkit-d3-legend__item-symbol_unselected {
33
+ fill: var(--g-color-text-hint);
34
+ }
35
+
32
36
  .chartkit-d3-legend__item-text {
33
37
  fill: var(--g-color-text-secondary);
34
38
  alignment-baseline: before-edge;
@@ -1,7 +1,6 @@
1
- import type { BaseTextStyle } from '../../../../../types';
2
- import type { PointMarkerHalo } from '../../../../../types/widget-data/marker';
1
+ import type { BaseTextStyle, Halo } from '../../../../../types';
3
2
  export declare const DEFAULT_LEGEND_SYMBOL_SIZE = 8;
4
3
  export declare const DEFAULT_LEGEND_SYMBOL_PADDING = 5;
5
4
  export declare const DEFAULT_DATALABELS_PADDING = 5;
6
5
  export declare const DEFAULT_DATALABELS_STYLE: BaseTextStyle;
7
- export declare const DEFAULT_HALO_OPTIONS: Required<PointMarkerHalo>;
6
+ export declare const DEFAULT_HALO_OPTIONS: Required<Halo>;
@@ -9,5 +9,5 @@ export const DEFAULT_DATALABELS_STYLE = {
9
9
  export const DEFAULT_HALO_OPTIONS = {
10
10
  enabled: true,
11
11
  opacity: 0.25,
12
- radius: 10,
12
+ size: 10,
13
13
  };
@@ -1,8 +1,10 @@
1
1
  import { ScaleOrdinal } from 'd3';
2
+ import { DashStyle } from '../../../../../constants';
2
3
  import { ChartKitWidgetSeriesOptions, LineSeries } from '../../../../../types';
3
4
  import { PreparedLineSeries, PreparedLegend } from './types';
4
5
  export declare const DEFAULT_LEGEND_SYMBOL_SIZE = 16;
5
6
  export declare const DEFAULT_LINE_WIDTH = 1;
7
+ export declare const DEFAULT_DASH_STYLE = DashStyle.Solid;
6
8
  export declare const DEFAULT_MARKER: {
7
9
  enabled: boolean;
8
10
  symbol: string;
@@ -1,9 +1,11 @@
1
1
  import get from 'lodash/get';
2
2
  import merge from 'lodash/merge';
3
+ import { DashStyle, LineCap } from '../../../../../constants';
3
4
  import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_HALO_OPTIONS, DEFAULT_LEGEND_SYMBOL_PADDING, } from './constants';
4
5
  import { getRandomCKId } from '../../../../../utils';
5
6
  export const DEFAULT_LEGEND_SYMBOL_SIZE = 16;
6
7
  export const DEFAULT_LINE_WIDTH = 1;
8
+ export const DEFAULT_DASH_STYLE = DashStyle.Solid;
7
9
  export const DEFAULT_MARKER = {
8
10
  enabled: false,
9
11
  symbol: 'circle',
@@ -11,6 +13,11 @@ export const DEFAULT_MARKER = {
11
13
  borderWidth: 0,
12
14
  borderColor: '',
13
15
  };
16
+ function prepareLinecap(dashStyle, series, seriesOptions) {
17
+ const defaultLineCap = dashStyle === DashStyle.Solid ? LineCap.Round : LineCap.None;
18
+ const lineCapFromSeriesOptions = get(seriesOptions, 'line.linecap', defaultLineCap);
19
+ return get(series, 'linecap', lineCapFromSeriesOptions);
20
+ }
14
21
  function prepareLineLegendSymbol(series, seriesOptions) {
15
22
  var _a;
16
23
  const symbolOptions = ((_a = series.legend) === null || _a === void 0 ? void 0 : _a.symbol) || {};
@@ -43,11 +50,13 @@ function prepareMarker(series, seriesOptions) {
43
50
  export function prepareLineSeries(args) {
44
51
  const { colorScale, series: seriesList, seriesOptions, legend } = args;
45
52
  const defaultLineWidth = get(seriesOptions, 'line.lineWidth', DEFAULT_LINE_WIDTH);
53
+ const defaultDashStyle = get(seriesOptions, 'line.dashStyle', DEFAULT_DASH_STYLE);
46
54
  return seriesList.map((series) => {
47
55
  var _a, _b;
48
56
  const id = getRandomCKId();
49
57
  const name = series.name || '';
50
58
  const color = series.color || colorScale(name);
59
+ const dashStyle = get(series, 'dashStyle', defaultDashStyle);
51
60
  const prepared = {
52
61
  type: series.type,
53
62
  color,
@@ -67,6 +76,8 @@ export function prepareLineSeries(args) {
67
76
  allowOverlap: get(series, 'dataLabels.allowOverlap', false),
68
77
  },
69
78
  marker: prepareMarker(series, seriesOptions),
79
+ dashStyle: dashStyle,
80
+ linecap: prepareLinecap(dashStyle, series, seriesOptions),
70
81
  };
71
82
  return prepared;
72
83
  }, []);