@topkit/analytics-charts 1.1.4 → 1.1.5-alpha-fix-alpha-packages.2603

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 (161) hide show
  1. package/{dist-package/AnalyticsChart → AnalyticsChart}/AnalyticsChart.d.ts +0 -0
  2. package/{dist-package/AnalyticsChart → AnalyticsChart}/AnalyticsChart.js +0 -0
  3. package/{dist-package/AnalyticsChart → AnalyticsChart}/AnalyticsChart.js.map +0 -0
  4. package/{dist-package/AnalyticsChart → AnalyticsChart}/index.d.ts +0 -0
  5. package/{dist-package/AnalyticsChart → AnalyticsChart}/index.js +0 -0
  6. package/{dist-package/AnalyticsChart → AnalyticsChart}/index.js.map +0 -0
  7. package/{dist-package/CategoriesChart → CategoriesChart}/CategoriesChart.d.ts +0 -0
  8. package/{dist-package/CategoriesChart → CategoriesChart}/CategoriesChart.js +0 -0
  9. package/{dist-package/CategoriesChart → CategoriesChart}/CategoriesChart.js.map +0 -0
  10. package/{dist-package/CategoriesChart → CategoriesChart}/index.d.ts +0 -0
  11. package/{dist-package/CategoriesChart → CategoriesChart}/index.js +0 -0
  12. package/{dist-package/CategoriesChart → CategoriesChart}/index.js.map +0 -0
  13. package/{dist-package/CategoriesChart → CategoriesChart}/types.d.ts +0 -0
  14. package/{dist-package/CategoriesChart → CategoriesChart}/types.js +0 -0
  15. package/{dist-package/CategoriesChart → CategoriesChart}/types.js.map +0 -0
  16. package/{dist-package/CategoriesChart → CategoriesChart}/utils/format-data/format-data.d.ts +0 -0
  17. package/{dist-package/CategoriesChart → CategoriesChart}/utils/format-data/format-data.js +0 -0
  18. package/{dist-package/CategoriesChart → CategoriesChart}/utils/format-data/format-data.js.map +0 -0
  19. package/{dist-package/CategoriesChart → CategoriesChart}/utils/format-data/index.d.ts +0 -0
  20. package/{dist-package/CategoriesChart → CategoriesChart}/utils/format-data/index.js +0 -0
  21. package/{dist-package/CategoriesChart → CategoriesChart}/utils/format-data/index.js.map +0 -0
  22. package/{dist-package/CategoriesChart → CategoriesChart}/utils/get-color/get-color.d.ts +0 -0
  23. package/{dist-package/CategoriesChart → CategoriesChart}/utils/get-color/get-color.js +0 -0
  24. package/{dist-package/CategoriesChart → CategoriesChart}/utils/get-color/get-color.js.map +0 -0
  25. package/{dist-package/CategoriesChart → CategoriesChart}/utils/get-color/index.d.ts +0 -0
  26. package/{dist-package/CategoriesChart → CategoriesChart}/utils/get-color/index.js +0 -0
  27. package/{dist-package/CategoriesChart → CategoriesChart}/utils/get-color/index.js.map +0 -0
  28. package/{dist-package/CategoriesChart → CategoriesChart}/utils/index.d.ts +0 -0
  29. package/{dist-package/CategoriesChart → CategoriesChart}/utils/index.js +0 -0
  30. package/{dist-package/CategoriesChart → CategoriesChart}/utils/index.js.map +0 -0
  31. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/CategoriesChartTooltip.d.ts +0 -0
  32. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/CategoriesChartTooltip.js +0 -0
  33. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/CategoriesChartTooltip.js.map +0 -0
  34. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/index.d.ts +0 -0
  35. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/index.js +0 -0
  36. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/index.js.map +0 -0
  37. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/utils/get-display-texts/get-display-texts.d.ts +0 -0
  38. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/utils/get-display-texts/get-display-texts.js +0 -0
  39. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/utils/get-display-texts/get-display-texts.js.map +0 -0
  40. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/utils/get-display-texts/index.d.ts +0 -0
  41. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/utils/get-display-texts/index.js +0 -0
  42. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/utils/get-display-texts/index.js.map +0 -0
  43. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/utils/index.d.ts +0 -0
  44. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/utils/index.js +0 -0
  45. package/{dist-package/CategoriesChartTooltip → CategoriesChartTooltip}/utils/index.js.map +0 -0
  46. package/{dist-package/config.d.ts → config.d.ts} +0 -0
  47. package/{dist-package/config.js → config.js} +0 -0
  48. package/{dist-package/config.js.map → config.js.map} +0 -0
  49. package/{dist-package/index.d.ts → index.d.ts} +0 -0
  50. package/{dist-package/index.js → index.js} +0 -0
  51. package/{dist-package/index.js.map → index.js.map} +0 -0
  52. package/package.json +6 -4
  53. package/{dist-package/utils → utils}/format-y-axis-tick/format-y-axis-tick.d.ts +0 -0
  54. package/{dist-package/utils → utils}/format-y-axis-tick/format-y-axis-tick.js +0 -0
  55. package/{dist-package/utils → utils}/format-y-axis-tick/format-y-axis-tick.js.map +0 -0
  56. package/{dist-package/utils → utils}/format-y-axis-tick/index.d.ts +0 -0
  57. package/{dist-package/utils → utils}/format-y-axis-tick/index.js +0 -0
  58. package/{dist-package/utils → utils}/format-y-axis-tick/index.js.map +0 -0
  59. package/{dist-package/utils → utils}/generate-reference-key/generate-reference-key.d.ts +0 -0
  60. package/{dist-package/utils → utils}/generate-reference-key/generate-reference-key.js +0 -0
  61. package/{dist-package/utils → utils}/generate-reference-key/generate-reference-key.js.map +0 -0
  62. package/{dist-package/utils → utils}/generate-reference-key/index.d.ts +0 -0
  63. package/{dist-package/utils → utils}/generate-reference-key/index.js +0 -0
  64. package/{dist-package/utils → utils}/generate-reference-key/index.js.map +0 -0
  65. package/{dist-package/utils → utils}/get-x-axis-ticks/get-x-axis-ticks.d.ts +0 -0
  66. package/{dist-package/utils → utils}/get-x-axis-ticks/get-x-axis-ticks.js +0 -0
  67. package/{dist-package/utils → utils}/get-x-axis-ticks/get-x-axis-ticks.js.map +0 -0
  68. package/{dist-package/utils → utils}/get-x-axis-ticks/index.d.ts +0 -0
  69. package/{dist-package/utils → utils}/get-x-axis-ticks/index.js +0 -0
  70. package/{dist-package/utils → utils}/get-x-axis-ticks/index.js.map +0 -0
  71. package/{dist-package/utils → utils}/get-y-axis-ticks/get-y-axis-ticks.d.ts +0 -0
  72. package/{dist-package/utils → utils}/get-y-axis-ticks/get-y-axis-ticks.js +0 -0
  73. package/{dist-package/utils → utils}/get-y-axis-ticks/get-y-axis-ticks.js.map +0 -0
  74. package/{dist-package/utils → utils}/get-y-axis-ticks/index.d.ts +0 -0
  75. package/{dist-package/utils → utils}/get-y-axis-ticks/index.js +0 -0
  76. package/{dist-package/utils → utils}/get-y-axis-ticks/index.js.map +0 -0
  77. package/{dist-package/utils → utils}/index.d.ts +0 -0
  78. package/{dist-package/utils → utils}/index.js +0 -0
  79. package/{dist-package/utils → utils}/index.js.map +0 -0
  80. package/{dist-package/utils → utils}/to-chart-format/index.d.ts +0 -0
  81. package/{dist-package/utils → utils}/to-chart-format/index.js +0 -0
  82. package/{dist-package/utils → utils}/to-chart-format/index.js.map +0 -0
  83. package/{dist-package/utils → utils}/to-chart-format/to-chart-format.d.ts +0 -0
  84. package/{dist-package/utils → utils}/to-chart-format/to-chart-format.js +0 -0
  85. package/{dist-package/utils → utils}/to-chart-format/to-chart-format.js.map +0 -0
  86. package/{dist-package/utils → utils}/to-highlight-format/index.d.ts +0 -0
  87. package/{dist-package/utils → utils}/to-highlight-format/index.js +0 -0
  88. package/{dist-package/utils → utils}/to-highlight-format/index.js.map +0 -0
  89. package/{dist-package/utils → utils}/to-highlight-format/to-highlight-format.d.ts +0 -0
  90. package/{dist-package/utils → utils}/to-highlight-format/to-highlight-format.js +0 -0
  91. package/{dist-package/utils → utils}/to-highlight-format/to-highlight-format.js.map +0 -0
  92. package/{dist-package/utils → utils}/to-line-config-format/index.d.ts +0 -0
  93. package/{dist-package/utils → utils}/to-line-config-format/index.js +0 -0
  94. package/{dist-package/utils → utils}/to-line-config-format/index.js.map +0 -0
  95. package/{dist-package/utils → utils}/to-line-config-format/to-line-config-format.d.ts +0 -0
  96. package/{dist-package/utils → utils}/to-line-config-format/to-line-config-format.js +0 -0
  97. package/{dist-package/utils → utils}/to-line-config-format/to-line-config-format.js.map +0 -0
  98. package/CHANGELOG.md +0 -189
  99. package/dist-package/README.md +0 -5
  100. package/dist-package/package.json +0 -36
  101. package/src/AnalyticsChart/AnalyticsChart.tsx +0 -85
  102. package/src/AnalyticsChart/__image_snapshots__/analyticschart-custom-format-xaxis-label-snap.png +0 -0
  103. package/src/AnalyticsChart/__image_snapshots__/analyticschart-default-snap.png +0 -0
  104. package/src/AnalyticsChart/__image_snapshots__/analyticschart-granularity-snap.png +0 -0
  105. package/src/AnalyticsChart/__image_snapshots__/analyticschart-highlights-snap.png +0 -0
  106. package/src/AnalyticsChart/__image_snapshots__/analyticschart-multiple-snap.png +0 -0
  107. package/src/AnalyticsChart/__image_snapshots__/analyticschart-null-values-snap.png +0 -0
  108. package/src/AnalyticsChart/__image_snapshots__/analyticschart-reference-lines-snap.png +0 -0
  109. package/src/AnalyticsChart/index.ts +0 -2
  110. package/src/AnalyticsChart/story/Default.example.tsx +0 -44
  111. package/src/AnalyticsChart/story/FormatLabel.example.tsx +0 -46
  112. package/src/AnalyticsChart/story/Granularity.example.tsx +0 -104
  113. package/src/AnalyticsChart/story/Highlights.example.tsx +0 -54
  114. package/src/AnalyticsChart/story/Multiple.example.tsx +0 -72
  115. package/src/AnalyticsChart/story/NullValues.example.tsx +0 -103
  116. package/src/AnalyticsChart/story/ReferenceLines.example.tsx +0 -105
  117. package/src/AnalyticsChart/story/index.jsx +0 -74
  118. package/src/CategoriesChart/CategoriesChart.tsx +0 -51
  119. package/src/CategoriesChart/__image_snapshots__/categorieschart-default-snap.png +0 -0
  120. package/src/CategoriesChart/index.ts +0 -2
  121. package/src/CategoriesChart/story/Default.example.tsx +0 -234
  122. package/src/CategoriesChart/story/index.jsx +0 -61
  123. package/src/CategoriesChart/types.ts +0 -22
  124. package/src/CategoriesChart/utils/format-data/format-data.ts +0 -23
  125. package/src/CategoriesChart/utils/format-data/index.ts +0 -1
  126. package/src/CategoriesChart/utils/format-data/test.ts +0 -99
  127. package/src/CategoriesChart/utils/get-color/get-color.ts +0 -37
  128. package/src/CategoriesChart/utils/get-color/index.ts +0 -1
  129. package/src/CategoriesChart/utils/get-color/test.ts +0 -65
  130. package/src/CategoriesChart/utils/index.ts +0 -2
  131. package/src/CategoriesChartTooltip/CategoriesChartTooltip.tsx +0 -57
  132. package/src/CategoriesChartTooltip/index.ts +0 -1
  133. package/src/CategoriesChartTooltip/test.tsx +0 -27
  134. package/src/CategoriesChartTooltip/utils/get-display-texts/get-display-texts.ts +0 -61
  135. package/src/CategoriesChartTooltip/utils/get-display-texts/index.ts +0 -1
  136. package/src/CategoriesChartTooltip/utils/get-display-texts/test.ts +0 -81
  137. package/src/CategoriesChartTooltip/utils/index.ts +0 -1
  138. package/src/config.ts +0 -3
  139. package/src/index.ts +0 -3
  140. package/src/utils/format-y-axis-tick/format-y-axis-tick.ts +0 -23
  141. package/src/utils/format-y-axis-tick/index.ts +0 -1
  142. package/src/utils/format-y-axis-tick/test.ts +0 -13
  143. package/src/utils/generate-reference-key/generate-reference-key.ts +0 -4
  144. package/src/utils/generate-reference-key/index.ts +0 -1
  145. package/src/utils/get-x-axis-ticks/get-x-axis-ticks.ts +0 -24
  146. package/src/utils/get-x-axis-ticks/index.ts +0 -1
  147. package/src/utils/get-x-axis-ticks/test.ts +0 -37
  148. package/src/utils/get-y-axis-ticks/get-y-axis-ticks.ts +0 -25
  149. package/src/utils/get-y-axis-ticks/index.ts +0 -1
  150. package/src/utils/get-y-axis-ticks/test.ts +0 -22
  151. package/src/utils/index.ts +0 -7
  152. package/src/utils/to-chart-format/index.ts +0 -1
  153. package/src/utils/to-chart-format/test.ts +0 -200
  154. package/src/utils/to-chart-format/to-chart-format.ts +0 -60
  155. package/src/utils/to-highlight-format/index.ts +0 -1
  156. package/src/utils/to-highlight-format/test.ts +0 -56
  157. package/src/utils/to-highlight-format/to-highlight-format.ts +0 -26
  158. package/src/utils/to-line-config-format/index.ts +0 -1
  159. package/src/utils/to-line-config-format/test.ts +0 -50
  160. package/src/utils/to-line-config-format/to-line-config-format.ts +0 -19
  161. package/tsconfig.build.json +0 -7
@@ -1,81 +0,0 @@
1
- import getDisplayTexts, { GetDisplayTextsParams } from './get-display-texts'
2
-
3
- describe('getDisplayTexts', () => {
4
- it('returns correct data', () => {
5
- const INPUT: GetDisplayTextsParams = {
6
- currentData: {
7
- id: 'claimed',
8
- values: [
9
- {
10
- id: 'team',
11
- values: [
12
- { id: 'viable', value: 252 },
13
- { id: 'bad_leads', value: 0 },
14
- { id: 'rejected', value: 11 }
15
- ]
16
- },
17
- {
18
- id: 'user',
19
- values: [
20
- { id: 'viable', value: 595 },
21
- { id: 'bad_leads', value: 0 },
22
- { id: 'rejected', value: 24 }
23
- ]
24
- }
25
- ]
26
- },
27
- tooltips: {
28
- claimed: {
29
- team: {
30
- viable: 'Team Viable Average',
31
- bad_leads: 'Team Bad Leads (Unresponsive) Average',
32
- rejected: 'Team Removed Average'
33
- },
34
- user: {
35
- viable: 'Your Viable',
36
- bad_leads: 'Your Bad Leads (Unresponsive)',
37
- rejected: 'Your Removed'
38
- }
39
- }
40
- },
41
- currentPayload: {
42
- team: 263,
43
- user: 619,
44
- name: 'claimed'
45
- }
46
- }
47
-
48
- const OUTPUT = {
49
- teamTexts: [
50
- {
51
- key: 'team-viable',
52
- label: 'Team Viable Average',
53
- value: 252,
54
- color: '#204ecf'
55
- },
56
- {
57
- key: 'team-rejected',
58
- label: 'Team Removed Average',
59
- value: 11,
60
- color: '#204ecf'
61
- }
62
- ],
63
- userTexts: [
64
- {
65
- key: 'user-viable',
66
- label: 'Your Viable',
67
- value: 595,
68
- color: '#0f256e'
69
- },
70
- {
71
- key: 'user-rejected',
72
- label: 'Your Removed',
73
- value: 24,
74
- color: '#0f256e'
75
- }
76
- ]
77
- }
78
-
79
- expect(getDisplayTexts(INPUT)).toStrictEqual(OUTPUT)
80
- })
81
- })
@@ -1 +0,0 @@
1
- export { default as getDisplayTexts } from './get-display-texts'
package/src/config.ts DELETED
@@ -1,3 +0,0 @@
1
- export const HOUR = 60
2
- export const DAY = HOUR * 24
3
- export const NUMBER_OF_Y_AXIS_TICKS = 4
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export { default as AnalyticsChart } from './AnalyticsChart'
2
- export { default as CategoriesChart } from './CategoriesChart'
3
- export type { DataItem } from './CategoriesChart'
@@ -1,23 +0,0 @@
1
- import { HOUR, DAY } from '../../config'
2
-
3
- const formatYAxisTick = (
4
- value: number,
5
- domain: [number, number],
6
- unit?: string
7
- ) => {
8
- if (unit === 'minutes') {
9
- if (domain[1] >= DAY * 2) {
10
- return Math.floor(value / DAY) + 'd'
11
- }
12
-
13
- if (domain[1] >= HOUR) {
14
- return Math.floor(value / HOUR) + 'h'
15
- }
16
-
17
- return Math.floor(value) + 'm'
18
- }
19
-
20
- return `${value}`
21
- }
22
-
23
- export default formatYAxisTick
@@ -1 +0,0 @@
1
- export { default } from './format-y-axis-tick'
@@ -1,13 +0,0 @@
1
- import formatYAxisTick from './format-y-axis-tick'
2
-
3
- describe('formatYAxisTick', () => {
4
- it('formats y axis ticks', () => {
5
- expect(formatYAxisTick(3, [0, 1])).toBe('3')
6
- })
7
-
8
- it('formats y axis ticks with minutes unit', () => {
9
- expect(formatYAxisTick(20, [0, 37], 'minutes')).toBe('20m')
10
- expect(formatYAxisTick(120, [0, 140], 'minutes')).toBe('2h')
11
- expect(formatYAxisTick(2880, [0, 5444], 'minutes')).toBe('2d')
12
- })
13
- })
@@ -1,4 +0,0 @@
1
- const generateReferenceKey = (postfix: string | number) =>
2
- `reference-${postfix}`
3
-
4
- export default generateReferenceKey
@@ -1 +0,0 @@
1
- export { default } from './generate-reference-key'
@@ -1,24 +0,0 @@
1
- import { OrderedChartDataPoint } from '@toptal/picasso-charts'
2
-
3
- import { ChartGranularity } from '../../AnalyticsChart'
4
-
5
- const getXAxisTicks = (
6
- orderedData: OrderedChartDataPoint[],
7
- granularity?: ChartGranularity
8
- ) => {
9
- if (granularity === 'day') {
10
- return orderedData
11
- .filter(({ order }) => order % 2 === 0)
12
- .map(({ order }) => order)
13
- }
14
-
15
- if (granularity === 'hour') {
16
- return orderedData
17
- .filter(({ order }) => order % 2 !== 0)
18
- .map(({ order }) => order)
19
- }
20
-
21
- return orderedData.map(({ order }) => order)
22
- }
23
-
24
- export default getXAxisTicks
@@ -1 +0,0 @@
1
- export { default } from './get-x-axis-ticks'
@@ -1,37 +0,0 @@
1
- import getXAxisTicks from './get-x-axis-ticks'
2
-
3
- const ORDERED_DATA = [
4
- {
5
- order: 0
6
- },
7
- {
8
- order: 1
9
- },
10
- {
11
- order: 2
12
- },
13
- {
14
- order: 3
15
- }
16
- ]
17
-
18
- describe('getXAxisTicks', () => {
19
- it('gets x axis ticks', () => {
20
- const EXPECTED_TICKS = [0, 1, 2, 3]
21
-
22
- expect(getXAxisTicks(ORDERED_DATA, 'week')).toEqual(EXPECTED_TICKS)
23
- expect(getXAxisTicks(ORDERED_DATA)).toEqual(EXPECTED_TICKS)
24
- })
25
-
26
- it('gets x axis ticks for day granularity', () => {
27
- const EXPECTED_TICKS = [0, 2]
28
-
29
- expect(getXAxisTicks(ORDERED_DATA, 'day')).toEqual(EXPECTED_TICKS)
30
- })
31
-
32
- it('gets x axis ticks for hour granularity', () => {
33
- const EXPECTED_TICKS = [1, 3]
34
-
35
- expect(getXAxisTicks(ORDERED_DATA, 'hour')).toEqual(EXPECTED_TICKS)
36
- })
37
- })
@@ -1,25 +0,0 @@
1
- import { scaleLinear } from 'd3'
2
- import { ticks } from 'd3-array'
3
-
4
- import { HOUR, DAY, NUMBER_OF_Y_AXIS_TICKS } from '../../config'
5
-
6
- const uniqBy = <T>(array: T[]) =>
7
- array.filter((value, index, self) => self.indexOf(value) === index)
8
-
9
- const getYAxisTicks = (domain: [number, number], unit?: string) => {
10
- if (unit === 'minutes') {
11
- if (domain[1] >= HOUR) {
12
- const interval = domain[1] >= DAY * 2 ? DAY : HOUR
13
-
14
- const yAxisTicks = scaleLinear()
15
- .domain([0, domain[1] / interval])
16
- .ticks(4)
17
-
18
- return uniqBy(yAxisTicks.map(Math.floor)).map(tick => tick * interval)
19
- }
20
- }
21
-
22
- return ticks(domain[0], domain[1], NUMBER_OF_Y_AXIS_TICKS)
23
- }
24
-
25
- export default getYAxisTicks
@@ -1 +0,0 @@
1
- export { default } from './get-y-axis-ticks'
@@ -1,22 +0,0 @@
1
- import getYAxisTicks from './get-y-axis-ticks'
2
-
3
- const DOMAIN: [number, number] = [0, 37]
4
-
5
- describe('getYAxisTicks', () => {
6
- it('gets y axis ticks', () => {
7
- expect(getYAxisTicks(DOMAIN)).toStrictEqual([0, 10, 20, 30])
8
- })
9
-
10
- it('gets y axis ticks for minutes unit', () => {
11
- expect(getYAxisTicks(DOMAIN, 'minutes')).toStrictEqual([0, 10, 20, 30])
12
- })
13
-
14
- it('gets y axis ticks for minutes unit that exceeds 1 hour', () => {
15
- expect(getYAxisTicks([0, 5444], 'minutes')).toStrictEqual([
16
- 0,
17
- 1440,
18
- 2880,
19
- 4320
20
- ])
21
- })
22
- })
@@ -1,7 +0,0 @@
1
- export { default as toChartFormat } from './to-chart-format'
2
- export { default as toHighlightFormat } from './to-highlight-format'
3
- export { default as generateReferenceKey } from './generate-reference-key'
4
- export { default as toLineConfigFormat } from './to-line-config-format'
5
- export { default as getXAxisTicks } from './get-x-axis-ticks'
6
- export { default as getYAxisTicks } from './get-y-axis-ticks'
7
- export { default as formatYAxisTick } from './format-y-axis-tick'
@@ -1 +0,0 @@
1
- export { default } from './to-chart-format'
@@ -1,200 +0,0 @@
1
- import { format, parseISO } from 'date-fns'
2
-
3
- import toChartFormat from './'
4
- import generateReferenceKey from './../generate-reference-key'
5
-
6
- const RAW_CHART_DATA = [
7
- {
8
- id: 'projects',
9
- values: {
10
- '2020-10-20': 1.7,
11
- '2020-10-21': 2,
12
- '2020-10-22': 1.7,
13
- '2020-10-23': 2,
14
- '2020-10-24': 1.5,
15
- '2020-10-25': 1.3
16
- }
17
- },
18
- {
19
- id: 'team',
20
- values: {
21
- '2020-10-20': 1.7,
22
- '2020-10-21': 2,
23
- '2020-10-22': 1.7,
24
- '2020-10-23': 2,
25
- '2020-10-24': 1.5,
26
- '2020-10-25': 1.3
27
- }
28
- }
29
- ]
30
- const X_AXIS_KEY = 'x'
31
-
32
- describe('toChartFormat', () => {
33
- it('converts chart data', () => {
34
- const EXPECTED_CHART_DATA = [
35
- { x: '2020-10-20', projects: 1.7, team: 1.7 },
36
- { x: '2020-10-21', projects: 2, team: 2 },
37
- { x: '2020-10-22', projects: 1.7, team: 1.7 },
38
- { x: '2020-10-23', projects: 2, team: 2 },
39
- { x: '2020-10-24', projects: 1.5, team: 1.5 },
40
- { x: '2020-10-25', projects: 1.3, team: 1.3 }
41
- ]
42
- const convertedChartData = toChartFormat(
43
- RAW_CHART_DATA,
44
- undefined,
45
- X_AXIS_KEY,
46
- label => label
47
- )
48
-
49
- expect(convertedChartData).toEqual(EXPECTED_CHART_DATA)
50
- })
51
-
52
- it('converts chart data with custom label format', () => {
53
- const EXPECTED_CHART_DATA = [
54
- { x: 'Oct 20', projects: 1.7, team: 1.7 },
55
- { x: 'Oct 21', projects: 2, team: 2 },
56
- { x: 'Oct 22', projects: 1.7, team: 1.7 },
57
- { x: 'Oct 23', projects: 2, team: 2 },
58
- { x: 'Oct 24', projects: 1.5, team: 1.5 },
59
- { x: 'Oct 25', projects: 1.3, team: 1.3 }
60
- ]
61
- const convertedChartData = toChartFormat(
62
- RAW_CHART_DATA,
63
- undefined,
64
- X_AXIS_KEY,
65
- label => format(parseISO(label), 'MMM dd')
66
- )
67
-
68
- expect(convertedChartData).toEqual(EXPECTED_CHART_DATA)
69
- })
70
-
71
- it('converts chart data with null values', () => {
72
- const CHART_DATA_WITH_NULLS = [
73
- {
74
- id: 'projects',
75
- values: {
76
- '2020-10-20': 1.7,
77
- '2020-10-21': null,
78
- '2020-10-22': null,
79
- '2020-10-23': 2,
80
- '2020-10-24': 1.5,
81
- '2020-10-25': 1.3
82
- }
83
- },
84
- {
85
- id: 'team',
86
- values: {
87
- '2020-10-20': 1.7,
88
- '2020-10-21': 2,
89
- '2020-10-22': null,
90
- '2020-10-23': 2,
91
- '2020-10-24': null,
92
- '2020-10-25': 1.3
93
- }
94
- }
95
- ]
96
-
97
- const EXPECTED_CHART_DATA = [
98
- { x: '2020-10-20', projects: 1.7, team: 1.7 },
99
- { x: '2020-10-21', projects: 0, team: 2, projectsIsEmpty: true },
100
- {
101
- x: '2020-10-22',
102
- projects: 0,
103
- team: 0,
104
- projectsIsEmpty: true,
105
- teamIsEmpty: true
106
- },
107
- { x: '2020-10-23', projects: 2, team: 2 },
108
- { x: '2020-10-24', projects: 1.5, team: 0, teamIsEmpty: true },
109
- { x: '2020-10-25', projects: 1.3, team: 1.3 }
110
- ]
111
-
112
- const convertedChartData = toChartFormat(
113
- CHART_DATA_WITH_NULLS,
114
- undefined,
115
- X_AXIS_KEY,
116
- label => label
117
- )
118
-
119
- expect(convertedChartData).toEqual(EXPECTED_CHART_DATA)
120
- })
121
-
122
- it('convertschart data with ref data', () => {
123
- const REF_DATA = [
124
- {
125
- data: {
126
- '2020-10-20': 1.7,
127
- '2020-10-21': 2,
128
- '2020-10-22': 1.7,
129
- '2020-10-23': 2,
130
- '2020-10-24': 1.5,
131
- '2020-10-25': 1.3
132
- },
133
- color: 'red'
134
- },
135
- {
136
- data: {
137
- '2020-10-20': 1.7,
138
- '2020-10-21': 2,
139
- '2020-10-22': 1.7,
140
- '2020-10-23': 2,
141
- '2020-10-24': 1.5,
142
- '2020-10-25': 1.3
143
- },
144
- color: 'blue'
145
- }
146
- ]
147
- const EXPECTED_CHART_DATA = [
148
- {
149
- x: '2020-10-20',
150
- [generateReferenceKey(0)]: 1.7,
151
- [generateReferenceKey(1)]: 1.7,
152
- projects: 1.7,
153
- team: 1.7
154
- },
155
- {
156
- x: '2020-10-21',
157
- [generateReferenceKey(0)]: 2,
158
- [generateReferenceKey(1)]: 2,
159
- projects: 2,
160
- team: 2
161
- },
162
- {
163
- x: '2020-10-22',
164
- [generateReferenceKey(0)]: 1.7,
165
- [generateReferenceKey(1)]: 1.7,
166
- projects: 1.7,
167
- team: 1.7
168
- },
169
- {
170
- x: '2020-10-23',
171
- [generateReferenceKey(0)]: 2,
172
- [generateReferenceKey(1)]: 2,
173
- projects: 2,
174
- team: 2
175
- },
176
- {
177
- x: '2020-10-24',
178
- [generateReferenceKey(0)]: 1.5,
179
- [generateReferenceKey(1)]: 1.5,
180
- projects: 1.5,
181
- team: 1.5
182
- },
183
- {
184
- x: '2020-10-25',
185
- [generateReferenceKey(0)]: 1.3,
186
- [generateReferenceKey(1)]: 1.3,
187
- projects: 1.3,
188
- team: 1.3
189
- }
190
- ]
191
- const convertedChartData = toChartFormat(
192
- RAW_CHART_DATA,
193
- REF_DATA,
194
- X_AXIS_KEY,
195
- label => label
196
- )
197
-
198
- expect(convertedChartData).toEqual(EXPECTED_CHART_DATA)
199
- })
200
- })
@@ -1,60 +0,0 @@
1
- import { ChartDataPoint } from '@toptal/picasso-charts'
2
-
3
- import { Point, ReferenceLine } from './../../AnalyticsChart'
4
- import generateReferenceKey from '../generate-reference-key'
5
-
6
- const toChartFormat = (
7
- data: Point[],
8
- referenceLines: ReferenceLine[] | undefined,
9
- xAxisKey: string,
10
- formatLabel: (label: string) => string
11
- ) => {
12
- const formattedData: ChartDataPoint[] = []
13
- const decoratePointWithRefData = (point: ChartDataPoint, dataKey: string) =>
14
- referenceLines?.reduce((point, { data }, index) => {
15
- point[generateReferenceKey(index)] = data[dataKey]
16
-
17
- return point
18
- }, point) || point
19
-
20
- data.forEach(({ id, values }) => {
21
- Object.entries(values).forEach(([key, value]) => {
22
- const label = formatLabel(key)
23
- const isEmptyValue = value === null
24
- const nonNullValue = value === null ? 0 : value
25
-
26
- const existingItem = formattedData.find(
27
- ({ [xAxisKey]: existingLabel }) => existingLabel === label
28
- )
29
-
30
- if (existingItem) {
31
- existingItem[id] = nonNullValue
32
- if (isEmptyValue) {
33
- existingItem[`${id}IsEmpty`] = true
34
- }
35
-
36
- return
37
- }
38
-
39
- const dataPoint: ChartDataPoint = {
40
- [xAxisKey]: label,
41
- [id]: nonNullValue
42
- }
43
-
44
- // We indicate that value is empty for particular data set with the special flag.
45
- // Since single ChartDataPoint may contain values from multiple data sets, we'll may also have multiple number of flags.
46
- // Setting those flags will make this information available inside tooltips and other custom elements.
47
- // Please refer to this example for more details:
48
- // http://picasso.toptal.net/?path=/story/charts-folder--analyticschart#null-values
49
- if (isEmptyValue) {
50
- dataPoint[`${id}IsEmpty`] = true
51
- }
52
-
53
- formattedData.push(decoratePointWithRefData(dataPoint, key))
54
- })
55
- })
56
-
57
- return formattedData
58
- }
59
-
60
- export default toChartFormat
@@ -1 +0,0 @@
1
- export { default } from './to-highlight-format'
@@ -1,56 +0,0 @@
1
- import { format, parseISO } from 'date-fns'
2
-
3
- import toHighlightFormat from './'
4
-
5
- const HIGHLIGHTS = [
6
- {
7
- data: ['2020-11-01', '2020-11-04'],
8
- color: 'red'
9
- }
10
- ]
11
-
12
- const X_AXIS_KEY = 'x'
13
-
14
- describe('toHighlightFormat', () => {
15
- it('converts highlight data', () => {
16
- const CHART_DATA = [
17
- { x: '2020-11-01', test: 2 },
18
- { x: '2020-11-02', test: 1.5 },
19
- { x: '2020-11-03', test: 1.3 },
20
- { x: '2020-11-04', test: 1.5 },
21
- { x: '2020-11-05', test: 1.5 }
22
- ]
23
- const convertedHighlightsData = toHighlightFormat(
24
- CHART_DATA,
25
- HIGHLIGHTS,
26
- X_AXIS_KEY,
27
- label => label
28
- )
29
-
30
- expect(convertedHighlightsData).toEqual([
31
- { color: 'red', from: 0, to: 1 },
32
- { color: 'red', from: 3, to: 4 }
33
- ])
34
- })
35
-
36
- it('converts highlight data with label format', () => {
37
- const CHART_DATA = [
38
- { x: 'Nov 01', test: 2 },
39
- { x: 'Nov 02', test: 1.5 },
40
- { x: 'Nov 03', test: 1.3 },
41
- { x: 'Nov 04', test: 1.5 },
42
- { x: 'Nov 05', test: 1.5 }
43
- ]
44
- const convertedHighlightsData = toHighlightFormat(
45
- CHART_DATA,
46
- HIGHLIGHTS,
47
- X_AXIS_KEY,
48
- (label: string) => format(parseISO(label), 'MMM dd')
49
- )
50
-
51
- expect(convertedHighlightsData).toEqual([
52
- { color: 'red', from: 0, to: 1 },
53
- { color: 'red', from: 3, to: 4 }
54
- ])
55
- })
56
- })
@@ -1,26 +0,0 @@
1
- import { ChartDataPoint, HighlightConfig } from '@toptal/picasso-charts'
2
-
3
- import { Highlight } from './../../AnalyticsChart'
4
-
5
- const HIGHLIGHT_LENGTH = 1
6
-
7
- const toHighlightFormat = (
8
- chartData: ChartDataPoint[],
9
- highlights: Highlight[],
10
- xAxisKey: string,
11
- formatLabel: (label: string) => string
12
- ): HighlightConfig[] =>
13
- highlights
14
- .map(({ data, color }) => data.map(section => ({ section, color })))
15
- .flat()
16
- .map(({ section, color }) => {
17
- const formattedSection = formatLabel(section)
18
- const from = chartData.findIndex(
19
- point => point[xAxisKey] === formattedSection
20
- )
21
- const to = from + HIGHLIGHT_LENGTH
22
-
23
- return { from, to, color }
24
- })
25
-
26
- export default toHighlightFormat
@@ -1 +0,0 @@
1
- export { default } from './to-line-config-format'
@@ -1,50 +0,0 @@
1
- import { LineConfig } from '@toptal/picasso-charts'
2
-
3
- import generateReferenceKey from './../generate-reference-key'
4
- import toLineConfigFormat from './'
5
-
6
- const LINE_CONFIG: LineConfig = {
7
- team: {
8
- color: 'orange',
9
- variant: 'solid'
10
- }
11
- }
12
-
13
- const REF_DATA = [
14
- {
15
- data: {
16
- '2020-10-20': 1.7,
17
- '2020-10-21': 2,
18
- '2020-10-22': 1.7,
19
- '2020-10-23': 2,
20
- '2020-10-24': 1.5,
21
- '2020-10-25': 1.3
22
- },
23
- color: 'red'
24
- },
25
- {
26
- data: {
27
- '2020-10-20': 1.7,
28
- '2020-10-21': 2,
29
- '2020-10-22': 1.7,
30
- '2020-10-23': 2,
31
- '2020-10-24': 1.5,
32
- '2020-10-25': 1.3
33
- },
34
- color: 'blue'
35
- }
36
- ]
37
-
38
- describe('Name of the group', () => {
39
- it('convertsline config', () => {
40
- const EXPECTED_LINE_CONFIG = {
41
- ...LINE_CONFIG,
42
- [generateReferenceKey(0)]: { color: 'red', variant: 'reference' },
43
- [generateReferenceKey(1)]: { color: 'blue', variant: 'reference' }
44
- }
45
-
46
- const convertedLineConfig = toLineConfigFormat(LINE_CONFIG, REF_DATA)
47
-
48
- expect(convertedLineConfig).toEqual(EXPECTED_LINE_CONFIG)
49
- })
50
- })