@gravity-ui/chartkit 4.7.3 → 4.9.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 (86) hide show
  1. package/build/plugins/d3/examples/bar-x/GroupedColumns.js +4 -2
  2. package/build/plugins/d3/examples/bar-y/Basic.d.ts +2 -0
  3. package/build/plugins/d3/examples/bar-y/Basic.js +43 -0
  4. package/build/plugins/d3/examples/bar-y/GroupedColumns.d.ts +2 -0
  5. package/build/plugins/d3/examples/bar-y/GroupedColumns.js +48 -0
  6. package/build/plugins/d3/examples/bar-y/StackedColumns.d.ts +2 -0
  7. package/build/plugins/d3/examples/bar-y/StackedColumns.js +47 -0
  8. package/build/plugins/d3/examples/combined/LineAndBarX.d.ts +2 -0
  9. package/build/plugins/d3/examples/combined/LineAndBarX.js +61 -0
  10. package/build/plugins/d3/examples/line/Basic.d.ts +2 -0
  11. package/build/plugins/d3/examples/line/Basic.js +66 -0
  12. package/build/plugins/d3/examples/nintendoGames.d.ts +40 -10
  13. package/build/plugins/d3/examples/nintendoGames.js +2416 -2189
  14. package/build/plugins/d3/renderer/D3Widget.js +27 -11
  15. package/build/plugins/d3/renderer/components/Chart.d.ts +0 -2
  16. package/build/plugins/d3/renderer/components/Chart.js +4 -6
  17. package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.d.ts +2 -2
  18. package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.js +42 -35
  19. package/build/plugins/d3/renderer/components/Tooltip/TooltipTriggerArea.d.ts +0 -2
  20. package/build/plugins/d3/renderer/components/Tooltip/TooltipTriggerArea.js +118 -48
  21. package/build/plugins/d3/renderer/components/Tooltip/index.d.ts +1 -0
  22. package/build/plugins/d3/renderer/components/Tooltip/index.js +5 -4
  23. package/build/plugins/d3/renderer/components/styles.css +1 -0
  24. package/build/plugins/d3/renderer/constants/defaults/series-options.d.ts +9 -2
  25. package/build/plugins/d3/renderer/constants/defaults/series-options.js +27 -0
  26. package/build/plugins/d3/renderer/hooks/useAxisScales/index.js +15 -1
  27. package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.js +3 -3
  28. package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +3 -3
  29. package/build/plugins/d3/renderer/hooks/useSeries/constants.d.ts +3 -0
  30. package/build/plugins/d3/renderer/hooks/useSeries/constants.js +5 -0
  31. package/build/plugins/d3/renderer/hooks/useSeries/index.d.ts +1 -1
  32. package/build/plugins/d3/renderer/hooks/useSeries/index.js +2 -1
  33. package/build/plugins/d3/renderer/hooks/useSeries/prepare-bar-x.d.ts +10 -0
  34. package/build/plugins/d3/renderer/hooks/useSeries/prepare-bar-x.js +38 -0
  35. package/build/plugins/d3/renderer/hooks/useSeries/prepare-bar-y.d.ts +10 -0
  36. package/build/plugins/d3/renderer/hooks/useSeries/prepare-bar-y.js +50 -0
  37. package/build/plugins/d3/renderer/hooks/useSeries/prepare-line-series.d.ts +11 -0
  38. package/build/plugins/d3/renderer/hooks/useSeries/prepare-line-series.js +32 -0
  39. package/build/plugins/d3/renderer/hooks/useSeries/prepareSeries.d.ts +2 -1
  40. package/build/plugins/d3/renderer/hooks/useSeries/prepareSeries.js +21 -60
  41. package/build/plugins/d3/renderer/hooks/useSeries/types.d.ts +24 -2
  42. package/build/plugins/d3/renderer/hooks/useSeries/utils.d.ts +3 -1
  43. package/build/plugins/d3/renderer/hooks/useSeries/utils.js +13 -0
  44. package/build/plugins/d3/renderer/hooks/useShapes/bar-x/prepare-data.js +4 -6
  45. package/build/plugins/d3/renderer/hooks/useShapes/bar-y/index.d.ts +11 -0
  46. package/build/plugins/d3/renderer/hooks/useShapes/bar-y/index.js +87 -0
  47. package/build/plugins/d3/renderer/hooks/useShapes/bar-y/prepare-data.d.ts +12 -0
  48. package/build/plugins/d3/renderer/hooks/useShapes/bar-y/prepare-data.js +114 -0
  49. package/build/plugins/d3/renderer/hooks/useShapes/bar-y/types.d.ts +10 -0
  50. package/build/plugins/d3/renderer/hooks/useShapes/bar-y/types.js +1 -0
  51. package/build/plugins/d3/renderer/hooks/useShapes/constants.d.ts +3 -0
  52. package/build/plugins/d3/renderer/hooks/useShapes/constants.js +3 -0
  53. package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +4 -4
  54. package/build/plugins/d3/renderer/hooks/useShapes/index.js +35 -5
  55. package/build/plugins/d3/renderer/hooks/useShapes/line/index.d.ts +11 -0
  56. package/build/plugins/d3/renderer/hooks/useShapes/line/index.js +98 -0
  57. package/build/plugins/d3/renderer/hooks/useShapes/line/prepare-data.d.ts +11 -0
  58. package/build/plugins/d3/renderer/hooks/useShapes/line/prepare-data.js +21 -0
  59. package/build/plugins/d3/renderer/hooks/useShapes/line/types.d.ts +16 -0
  60. package/build/plugins/d3/renderer/hooks/useShapes/line/types.js +1 -0
  61. package/build/plugins/d3/renderer/hooks/useShapes/pie.d.ts +0 -2
  62. package/build/plugins/d3/renderer/hooks/useShapes/pie.js +3 -3
  63. package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.d.ts +0 -2
  64. package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.js +6 -6
  65. package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.d.ts +1 -1
  66. package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.js +3 -34
  67. package/build/plugins/d3/renderer/hooks/useShapes/styles.css +6 -0
  68. package/build/plugins/d3/renderer/hooks/useShapes/utils.d.ts +17 -0
  69. package/build/plugins/d3/renderer/hooks/useShapes/utils.js +25 -0
  70. package/build/plugins/d3/renderer/utils/axis-generators/bottom.js +3 -3
  71. package/build/plugins/d3/renderer/utils/text.d.ts +5 -7
  72. package/build/plugins/d3/renderer/utils/text.js +4 -15
  73. package/build/types/widget-data/bar-y.d.ts +55 -0
  74. package/build/types/widget-data/bar-y.js +1 -0
  75. package/build/types/widget-data/base.d.ts +4 -0
  76. package/build/types/widget-data/index.d.ts +2 -0
  77. package/build/types/widget-data/index.js +2 -0
  78. package/build/types/widget-data/line.d.ts +37 -0
  79. package/build/types/widget-data/line.js +1 -0
  80. package/build/types/widget-data/series.d.ts +53 -3
  81. package/build/types/widget-data/tooltip.d.ts +15 -1
  82. package/build/utils/index.d.ts +1 -1
  83. package/build/utils/index.js +1 -1
  84. package/build/utils/performance.d.ts +3 -0
  85. package/build/utils/performance.js +8 -0
  86. package/package.json +3 -2
@@ -3,7 +3,9 @@ import { ChartKit } from '../../../../components/ChartKit';
3
3
  import nintendoGames from '../nintendoGames';
4
4
  import { groups } from 'd3';
5
5
  function prepareData() {
6
- const grouped = groups(nintendoGames, (d) => d.platform, (d) => (d.date ? new Date(d.date).getFullYear() : 'unknown'));
6
+ const displayedYears = [2015, 2016, 2017, 2018, 2019];
7
+ const games = nintendoGames.filter((ng) => displayedYears.includes(new Date(ng.date).getFullYear()));
8
+ const grouped = groups(games, (d) => d.platform, (d) => (d.date ? new Date(d.date).getFullYear() : 'unknown'));
7
9
  const categories = [];
8
10
  const series = grouped.map(([platform, years]) => {
9
11
  return {
@@ -30,7 +32,7 @@ export const GroupedColumns = () => {
30
32
  });
31
33
  const widgetData = {
32
34
  series: {
33
- data: data,
35
+ data,
34
36
  },
35
37
  xAxis: {
36
38
  type: 'category',
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const Basic: () => React.JSX.Element;
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import nintendoGames from '../nintendoGames';
4
+ import { groups } from 'd3';
5
+ function prepareData(field = 'platform') {
6
+ const gamesByPlatform = groups(nintendoGames, (item) => item[field]);
7
+ const data = gamesByPlatform.map(([value, games]) => ({
8
+ y: value,
9
+ x: games.length,
10
+ }));
11
+ return {
12
+ categories: gamesByPlatform.map(([key]) => key),
13
+ series: [
14
+ {
15
+ data,
16
+ name: 'Games released',
17
+ },
18
+ ],
19
+ };
20
+ }
21
+ export const Basic = () => {
22
+ const { categories, series } = prepareData();
23
+ const widgetData = {
24
+ series: {
25
+ data: series.map((s) => ({
26
+ type: 'bar-y',
27
+ data: s.data,
28
+ name: s.name,
29
+ })),
30
+ },
31
+ xAxis: { title: { text: 'Number of games released' } },
32
+ yAxis: [
33
+ {
34
+ type: 'category',
35
+ categories: categories.map(String),
36
+ title: {
37
+ text: 'Game Platforms',
38
+ },
39
+ },
40
+ ],
41
+ };
42
+ return React.createElement(ChartKit, { type: "d3", data: widgetData });
43
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const GroupedColumns: () => React.JSX.Element;
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import nintendoGames from '../nintendoGames';
4
+ import { groups } from 'd3';
5
+ function prepareData() {
6
+ const displayedYears = [2015, 2016, 2017, 2018, 2019];
7
+ const games = nintendoGames.filter((ng) => displayedYears.includes(new Date(ng.date).getFullYear()));
8
+ const grouped = groups(games, (d) => d.platform, (d) => (d.date ? new Date(d.date).getFullYear() : 'unknown'));
9
+ const categories = [];
10
+ const series = grouped.map(([platform, years]) => {
11
+ return {
12
+ name: platform,
13
+ data: years.map(([year, list]) => {
14
+ categories.push(String(year));
15
+ return {
16
+ y: String(year),
17
+ x: list.length,
18
+ };
19
+ }),
20
+ };
21
+ });
22
+ return { categories, series };
23
+ }
24
+ export const GroupedColumns = () => {
25
+ const { series, categories } = prepareData();
26
+ const data = series.map((s) => {
27
+ return {
28
+ type: 'bar-y',
29
+ name: s.name,
30
+ data: s.data,
31
+ };
32
+ });
33
+ const widgetData = {
34
+ series: {
35
+ data: data,
36
+ },
37
+ yAxis: [
38
+ {
39
+ type: 'category',
40
+ categories: categories.sort(),
41
+ title: {
42
+ text: 'Release year',
43
+ },
44
+ },
45
+ ],
46
+ };
47
+ return React.createElement(ChartKit, { type: "d3", data: widgetData });
48
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const StackedColumns: () => React.JSX.Element;
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import nintendoGames from '../nintendoGames';
4
+ import { groups } from 'd3';
5
+ function prepareData() {
6
+ const grouped = groups(nintendoGames, (d) => d.platform, (d) => (d.date ? new Date(d.date).getFullYear() : 'unknown'));
7
+ const categories = [];
8
+ const series = grouped.map(([platform, years]) => {
9
+ return {
10
+ name: platform,
11
+ data: years.map(([year, list]) => {
12
+ categories.push(String(year));
13
+ return {
14
+ y: String(year),
15
+ x: list.length,
16
+ };
17
+ }),
18
+ };
19
+ });
20
+ return { categories, series };
21
+ }
22
+ export const StackedColumns = () => {
23
+ const { series, categories } = prepareData();
24
+ const data = series.map((s) => {
25
+ return {
26
+ type: 'bar-y',
27
+ stacking: 'normal',
28
+ name: s.name,
29
+ data: s.data,
30
+ };
31
+ });
32
+ const widgetData = {
33
+ series: {
34
+ data: data,
35
+ },
36
+ yAxis: [
37
+ {
38
+ type: 'category',
39
+ categories: categories.sort(),
40
+ title: {
41
+ text: 'Release year',
42
+ },
43
+ },
44
+ ],
45
+ };
46
+ return React.createElement(ChartKit, { type: "d3", data: widgetData });
47
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const LineAndBarXCombinedChart: () => React.JSX.Element;
@@ -0,0 +1,61 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import nintendoGames from '../../examples/nintendoGames';
4
+ import { groups, max, min, median } from 'd3';
5
+ export const LineAndBarXCombinedChart = () => {
6
+ const gamesByPlatform = groups(nintendoGames, (item) => item.platform || 'unknown');
7
+ const widgetData = {
8
+ series: {
9
+ options: {
10
+ line: {
11
+ lineWidth: 2,
12
+ },
13
+ },
14
+ data: [
15
+ {
16
+ type: 'bar-x',
17
+ data: gamesByPlatform.map(([value, games]) => ({
18
+ x: value,
19
+ y: median(games, (g) => g.user_score || 0),
20
+ })),
21
+ name: 'Median user score',
22
+ },
23
+ {
24
+ type: 'line',
25
+ data: gamesByPlatform.map(([value, games]) => ({
26
+ x: value,
27
+ y: max(games, (g) => g.user_score || 0),
28
+ })),
29
+ name: 'Max user score',
30
+ },
31
+ {
32
+ type: 'line',
33
+ data: gamesByPlatform.map(([value, games]) => ({
34
+ x: value,
35
+ y: min(games, (g) => g.user_score || 10),
36
+ })),
37
+ name: 'Min user score',
38
+ },
39
+ ],
40
+ },
41
+ xAxis: {
42
+ categories: gamesByPlatform.map(([key]) => key),
43
+ type: 'category',
44
+ title: {
45
+ text: 'Game Platforms',
46
+ },
47
+ },
48
+ yAxis: [
49
+ {
50
+ title: { text: 'User score' },
51
+ labels: {
52
+ enabled: true,
53
+ },
54
+ ticks: {
55
+ pixelInterval: 120,
56
+ },
57
+ },
58
+ ],
59
+ };
60
+ return React.createElement(ChartKit, { type: "d3", data: widgetData });
61
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const Basic: () => React.JSX.Element;
@@ -0,0 +1,66 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import nintendoGames from '../nintendoGames';
4
+ import { dateTime } from '@gravity-ui/date-utils';
5
+ function prepareData() {
6
+ const dataset = nintendoGames.filter((d) => d.date && d.user_score);
7
+ const data = dataset.map((d) => ({
8
+ x: d.date || undefined,
9
+ y: d.user_score || undefined,
10
+ custom: d,
11
+ }));
12
+ return {
13
+ series: [
14
+ {
15
+ data,
16
+ name: 'Nintendo games',
17
+ },
18
+ ],
19
+ };
20
+ }
21
+ export const Basic = () => {
22
+ const { series } = prepareData();
23
+ const widgetData = {
24
+ series: {
25
+ data: series.map((s) => ({
26
+ type: 'line',
27
+ data: s.data.filter((d) => d.x),
28
+ name: s.name,
29
+ })),
30
+ },
31
+ yAxis: [
32
+ {
33
+ title: {
34
+ text: 'User score',
35
+ },
36
+ },
37
+ ],
38
+ xAxis: {
39
+ type: 'datetime',
40
+ title: {
41
+ text: 'Release dates',
42
+ },
43
+ },
44
+ tooltip: {
45
+ renderer: (d) => {
46
+ var _a;
47
+ const point = (_a = d.hovered[0]) === null || _a === void 0 ? void 0 : _a.data;
48
+ if (!point) {
49
+ return null;
50
+ }
51
+ const title = point.custom.title;
52
+ const score = point.custom.user_score;
53
+ const date = dateTime({ input: point.custom.date }).format('DD MMM YYYY');
54
+ return (React.createElement(React.Fragment, null,
55
+ React.createElement("b", null, title),
56
+ React.createElement("br", null),
57
+ "Release date: ",
58
+ date,
59
+ React.createElement("br", null),
60
+ "User score: ",
61
+ score));
62
+ },
63
+ },
64
+ };
65
+ return React.createElement(ChartKit, { type: "d3", data: widgetData });
66
+ };
@@ -6,8 +6,8 @@ declare const _default: ({
6
6
  user_score: null;
7
7
  link: string;
8
8
  esrb_rating: string;
9
- developers: string;
10
- genres: string;
9
+ developers: string[];
10
+ genres: string[];
11
11
  } | {
12
12
  meta_score: number;
13
13
  title: string;
@@ -16,8 +16,8 @@ declare const _default: ({
16
16
  user_score: number;
17
17
  link: string;
18
18
  esrb_rating: string;
19
- developers: string;
20
- genres: string;
19
+ developers: string[];
20
+ genres: string[];
21
21
  } | {
22
22
  meta_score: null;
23
23
  title: string;
@@ -26,8 +26,18 @@ declare const _default: ({
26
26
  user_score: number;
27
27
  link: string;
28
28
  esrb_rating: string;
29
+ developers: string[];
30
+ genres: string[];
31
+ } | {
32
+ meta_score: number;
33
+ title: string;
34
+ platform: string;
35
+ date: number;
36
+ user_score: number;
37
+ link: string;
38
+ esrb_rating: string;
29
39
  developers: string;
30
- genres: string;
40
+ genres: string[];
31
41
  } | {
32
42
  meta_score: null;
33
43
  title: string;
@@ -36,8 +46,8 @@ declare const _default: ({
36
46
  user_score: null;
37
47
  link: string;
38
48
  esrb_rating: string;
39
- developers: string;
40
- genres: string;
49
+ developers: string[];
50
+ genres: string[];
41
51
  } | {
42
52
  meta_score: number;
43
53
  title: string;
@@ -46,8 +56,8 @@ declare const _default: ({
46
56
  user_score: null;
47
57
  link: string;
48
58
  esrb_rating: string;
49
- developers: string;
50
- genres: string;
59
+ developers: string[];
60
+ genres: string[];
51
61
  } | {
52
62
  meta_score: number;
53
63
  title: string;
@@ -56,7 +66,27 @@ declare const _default: ({
56
66
  user_score: number;
57
67
  link: string;
58
68
  esrb_rating: string;
69
+ developers: string[];
70
+ genres: string[];
71
+ } | {
72
+ meta_score: null;
73
+ title: string;
74
+ platform: string;
75
+ date: number;
76
+ user_score: null;
77
+ link: string;
78
+ esrb_rating: string;
79
+ developers: string;
80
+ genres: string[];
81
+ } | {
82
+ meta_score: null;
83
+ title: string;
84
+ platform: string;
85
+ date: null;
86
+ user_score: null;
87
+ link: string;
88
+ esrb_rating: string;
59
89
  developers: string;
60
- genres: string;
90
+ genres: string[];
61
91
  })[];
62
92
  export default _default;