@orbcharts/core 3.0.7 → 4.0.0-alpha.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 (196) hide show
  1. package/dist/orbcharts-core.es.js +2826 -6582
  2. package/dist/orbcharts-core.umd.js +6 -6
  3. package/dist/src/OrbCharts.d.ts +18 -0
  4. package/dist/src/chart/createChart.d.ts +3 -0
  5. package/dist/src/chart/createGraphData.d.ts +3 -0
  6. package/dist/src/chart/createGridData.d.ts +3 -0
  7. package/dist/src/chart/createMultivariateData.d.ts +3 -0
  8. package/dist/src/chart/createSeriesData.d.ts +3 -0
  9. package/dist/src/chart/createTreeData.d.ts +3 -0
  10. package/dist/src/chart/defaults.d.ts +5 -0
  11. package/dist/src/defineCanvasLayer.d.ts +16 -0
  12. package/dist/src/defineCanvasPlugin.d.ts +22 -0
  13. package/dist/src/defineSVGLayer.d.ts +16 -0
  14. package/dist/src/defineSVGPlugin.d.ts +22 -0
  15. package/dist/src/index.d.ts +6 -14
  16. package/dist/src/layer/createLayer.d.ts +3 -0
  17. package/dist/src/plugin/createPlugin.d.ts +3 -0
  18. package/dist/src/test/createGraphData.test.d.ts +1 -0
  19. package/dist/src/test/createTreeData.test.d.ts +1 -0
  20. package/dist/src/test/simple-graph-test.d.ts +74 -0
  21. package/dist/src/test/simple-tree-test.d.ts +13 -0
  22. package/dist/src/types/Chart.d.ts +39 -0
  23. package/dist/src/types/ChartContext.d.ts +27 -0
  24. package/dist/src/types/Common.d.ts +3 -0
  25. package/dist/src/types/Encoding.d.ts +33 -0
  26. package/dist/src/types/Event.d.ts +12 -0
  27. package/dist/src/types/Layers.d.ts +55 -0
  28. package/dist/src/types/ModelData.d.ts +70 -0
  29. package/dist/src/types/Plugin.d.ts +39 -0
  30. package/dist/src/types/RawData.d.ts +18 -0
  31. package/dist/src/types/RenderData.d.ts +4 -0
  32. package/dist/src/types/Theme.d.ts +17 -0
  33. package/dist/src/types/Validator.d.ts +20 -0
  34. package/dist/src/types/index.d.ts +12 -0
  35. package/dist/src/utils/aggregateUtils.d.ts +37 -0
  36. package/dist/src/utils/colorUtils.d.ts +22 -0
  37. package/dist/src/utils/commonUtils.d.ts +3 -5
  38. package/dist/src/utils/dom-lifecycle.d.ts +37 -0
  39. package/dist/src/utils/dom.d.ts +6 -0
  40. package/dist/src/utils/index.d.ts +5 -1
  41. package/dist/src/utils/observables.d.ts +1 -25
  42. package/dist/src/utils/orbchartsUtils.d.ts +2 -53
  43. package/dist/src/utils/validator.d.ts +2 -2
  44. package/dist/test/aggregateTest.d.ts +1 -0
  45. package/package.json +24 -13
  46. package/src/OrbCharts.ts +35 -0
  47. package/src/chart/createChart.ts +997 -0
  48. package/src/chart/createGraphData.ts +391 -0
  49. package/src/chart/createGridData.ts +247 -0
  50. package/src/chart/createMultivariateData.ts +181 -0
  51. package/src/chart/createSeriesData.ts +297 -0
  52. package/src/chart/createTreeData.ts +344 -0
  53. package/src/chart/defaults.ts +120 -0
  54. package/src/defineCanvasLayer.ts +24 -0
  55. package/src/defineCanvasPlugin.ts +39 -0
  56. package/src/defineSVGLayer.ts +24 -0
  57. package/src/defineSVGPlugin.ts +39 -0
  58. package/src/index.ts +6 -18
  59. package/src/layer/createLayer.ts +138 -0
  60. package/src/plugin/createPlugin.ts +470 -0
  61. package/src/test/createGraphData.test.ts +103 -0
  62. package/src/test/createTreeData.test.ts +97 -0
  63. package/src/test/simple-graph-test.js +51 -0
  64. package/src/test/simple-tree-test.js +58 -0
  65. package/src/types/Chart.ts +62 -0
  66. package/src/types/ChartContext.ts +42 -0
  67. package/src/types/Common.ts +5 -0
  68. package/src/types/Encoding.ts +43 -0
  69. package/src/types/Event.ts +26 -0
  70. package/src/types/Layers.ts +93 -0
  71. package/src/types/ModelData.ts +95 -0
  72. package/src/types/Plugin.ts +98 -0
  73. package/src/types/RawData.ts +67 -0
  74. package/src/types/RenderData.ts +16 -0
  75. package/src/types/Theme.ts +21 -0
  76. package/src/types/Validator.ts +36 -0
  77. package/src/types/index.ts +12 -0
  78. package/src/utils/aggregateUtils.ts +99 -0
  79. package/src/utils/colorUtils.ts +63 -0
  80. package/src/utils/commonUtils.ts +12 -11
  81. package/src/utils/dom-lifecycle.ts +164 -0
  82. package/src/utils/dom.ts +55 -0
  83. package/src/utils/index.ts +6 -2
  84. package/src/utils/observables.ts +1 -292
  85. package/src/utils/orbchartsUtils.ts +6 -393
  86. package/src/utils/validator.ts +15 -14
  87. package/dist/lib/core-types.d.ts +0 -1
  88. package/dist/src/AbstractChart.d.ts +0 -19
  89. package/dist/src/GridChart.d.ts +0 -6
  90. package/dist/src/MultiGridChart.d.ts +0 -6
  91. package/dist/src/MultiValueChart.d.ts +0 -6
  92. package/dist/src/RelationshipChart.d.ts +0 -6
  93. package/dist/src/SeriesChart.d.ts +0 -6
  94. package/dist/src/TreeChart.d.ts +0 -6
  95. package/dist/src/base/createBaseChart.d.ts +0 -3
  96. package/dist/src/base/createBasePlugin.d.ts +0 -3
  97. package/dist/src/base/validators/chartOptionsValidator.d.ts +0 -3
  98. package/dist/src/base/validators/chartParamsValidator.d.ts +0 -3
  99. package/dist/src/base/validators/elementValidator.d.ts +0 -3
  100. package/dist/src/base/validators/pluginsValidator.d.ts +0 -3
  101. package/dist/src/defaults.d.ts +0 -25
  102. package/dist/src/defineGridPlugin.d.ts +0 -1
  103. package/dist/src/defineMultiGridPlugin.d.ts +0 -1
  104. package/dist/src/defineMultiValuePlugin.d.ts +0 -1
  105. package/dist/src/defineNoneDataPlugin.d.ts +0 -1
  106. package/dist/src/defineRelationshipPlugin.d.ts +0 -1
  107. package/dist/src/defineSeriesPlugin.d.ts +0 -1
  108. package/dist/src/defineTreePlugin.d.ts +0 -1
  109. package/dist/src/grid/computedDataFn.d.ts +0 -4
  110. package/dist/src/grid/contextObserverCallback.d.ts +0 -3
  111. package/dist/src/grid/dataFormatterValidator.d.ts +0 -3
  112. package/dist/src/grid/dataValidator.d.ts +0 -3
  113. package/dist/src/grid/gridObservables.d.ts +0 -64
  114. package/dist/src/multiGrid/computedDataFn.d.ts +0 -3
  115. package/dist/src/multiGrid/contextObserverCallback.d.ts +0 -3
  116. package/dist/src/multiGrid/dataFormatterValidator.d.ts +0 -3
  117. package/dist/src/multiGrid/dataValidator.d.ts +0 -3
  118. package/dist/src/multiGrid/multiGridObservables.d.ts +0 -16
  119. package/dist/src/multiValue/computedDataFn.d.ts +0 -3
  120. package/dist/src/multiValue/contextObserverCallback.d.ts +0 -3
  121. package/dist/src/multiValue/dataFormatterValidator.d.ts +0 -3
  122. package/dist/src/multiValue/dataValidator.d.ts +0 -3
  123. package/dist/src/multiValue/multiValueObservables.d.ts +0 -130
  124. package/dist/src/relationship/computedDataFn.d.ts +0 -3
  125. package/dist/src/relationship/contextObserverCallback.d.ts +0 -3
  126. package/dist/src/relationship/dataFormatterValidator.d.ts +0 -3
  127. package/dist/src/relationship/dataValidator.d.ts +0 -3
  128. package/dist/src/relationship/relationshipObservables.d.ts +0 -13
  129. package/dist/src/series/computedDataFn.d.ts +0 -3
  130. package/dist/src/series/contextObserverCallback.d.ts +0 -3
  131. package/dist/src/series/dataFormatterValidator.d.ts +0 -3
  132. package/dist/src/series/dataValidator.d.ts +0 -3
  133. package/dist/src/series/seriesObservables.d.ts +0 -37
  134. package/dist/src/tree/computedDataFn.d.ts +0 -3
  135. package/dist/src/tree/contextObserverCallback.d.ts +0 -3
  136. package/dist/src/tree/dataFormatterValidator.d.ts +0 -3
  137. package/dist/src/tree/dataValidator.d.ts +0 -3
  138. package/dist/src/tree/treeObservables.d.ts +0 -10
  139. package/dist/src/utils/d3Scale.d.ts +0 -28
  140. package/lib/core-types.ts +0 -7
  141. package/src/AbstractChart.ts +0 -57
  142. package/src/GridChart.ts +0 -25
  143. package/src/MultiGridChart.ts +0 -25
  144. package/src/MultiValueChart.ts +0 -25
  145. package/src/RelationshipChart.ts +0 -25
  146. package/src/SeriesChart.ts +0 -25
  147. package/src/TreeChart.ts +0 -25
  148. package/src/base/createBaseChart.ts +0 -524
  149. package/src/base/createBasePlugin.ts +0 -154
  150. package/src/base/validators/chartOptionsValidator.ts +0 -24
  151. package/src/base/validators/chartParamsValidator.ts +0 -134
  152. package/src/base/validators/elementValidator.ts +0 -14
  153. package/src/base/validators/pluginsValidator.ts +0 -15
  154. package/src/defaults.ts +0 -284
  155. package/src/defineGridPlugin.ts +0 -3
  156. package/src/defineMultiGridPlugin.ts +0 -3
  157. package/src/defineMultiValuePlugin.ts +0 -3
  158. package/src/defineNoneDataPlugin.ts +0 -4
  159. package/src/defineRelationshipPlugin.ts +0 -3
  160. package/src/defineSeriesPlugin.ts +0 -3
  161. package/src/defineTreePlugin.ts +0 -3
  162. package/src/grid/computedDataFn.ts +0 -129
  163. package/src/grid/contextObserverCallback.ts +0 -209
  164. package/src/grid/dataFormatterValidator.ts +0 -126
  165. package/src/grid/dataValidator.ts +0 -13
  166. package/src/grid/gridObservables.ts +0 -699
  167. package/src/multiGrid/computedDataFn.ts +0 -123
  168. package/src/multiGrid/contextObserverCallback.ts +0 -109
  169. package/src/multiGrid/dataFormatterValidator.ts +0 -121
  170. package/src/multiGrid/dataValidator.ts +0 -13
  171. package/src/multiGrid/multiGridObservables.ts +0 -367
  172. package/src/multiValue/computedDataFn.ts +0 -113
  173. package/src/multiValue/contextObserverCallback.ts +0 -328
  174. package/src/multiValue/dataFormatterValidator.ts +0 -95
  175. package/src/multiValue/dataValidator.ts +0 -13
  176. package/src/multiValue/multiValueObservables.ts +0 -865
  177. package/src/relationship/computedDataFn.ts +0 -159
  178. package/src/relationship/contextObserverCallback.ts +0 -80
  179. package/src/relationship/dataFormatterValidator.ts +0 -14
  180. package/src/relationship/dataValidator.ts +0 -14
  181. package/src/relationship/relationshipObservables.ts +0 -85
  182. package/src/series/computedDataFn.ts +0 -88
  183. package/src/series/contextObserverCallback.ts +0 -132
  184. package/src/series/dataFormatterValidator.ts +0 -47
  185. package/src/series/dataValidator.ts +0 -13
  186. package/src/series/seriesObservables.ts +0 -210
  187. package/src/tree/computedDataFn.ts +0 -129
  188. package/src/tree/contextObserverCallback.ts +0 -58
  189. package/src/tree/dataFormatterValidator.ts +0 -14
  190. package/src/tree/dataValidator.ts +0 -14
  191. package/src/tree/treeObservables.ts +0 -106
  192. package/src/utils/d3Scale.ts +0 -198
  193. package/tsconfig.base.json +0 -14
  194. package/tsconfig.json +0 -3
  195. package/vite-env.d.ts +0 -7
  196. package/vite.config.js +0 -23
@@ -1,134 +0,0 @@
1
- import type { ChartParamsPartial, ChartType, ValidatorResult } from '../../../lib/core-types'
2
- import { validateColumns } from '../../utils/validator'
3
-
4
- export function chartParamsValidator (chartType: ChartType, chartParamsPartial: ChartParamsPartial | undefined): ValidatorResult {
5
- const highlightTargetToBe: {[key in ChartType]: string[]} = {
6
- series: ['series', 'datum', 'none'],
7
- grid: ['series', 'group', 'datum', 'none'],
8
- multiGrid: ['series', 'group', 'datum', 'none'],
9
- multiValue: ['category', 'datum', 'none'],
10
- relationship: ['category', 'datum', 'none'],
11
- tree: ['category', 'datum', 'none'],
12
- noneData: ['none']
13
- }
14
-
15
- const result = validateColumns(chartParamsPartial, {
16
- padding: {
17
- toBeTypes: ['object'],
18
- },
19
- highlightTarget: {
20
- toBe: highlightTargetToBe[chartType].map(d => `"${d}"`).join(' | '),
21
- test: (value: any) => {
22
- return highlightTargetToBe[chartType].includes(value)
23
- }
24
- },
25
- highlightDefault: {
26
- toBeTypes: ['string', 'null']
27
- },
28
- colorScheme: {
29
- toBe: '"dark" | "light"',
30
- test: (value: any) => value === 'dark' || value === 'light'
31
- },
32
- colors: {
33
- toBeTypes: ['object'],
34
- test: (value: any) => {
35
- return value.light && value.dark
36
- }
37
- },
38
- styles: {
39
- toBeTypes: ['object'],
40
- },
41
- transitionDuration: {
42
- toBeTypes: ['number'],
43
- },
44
- transitionEase: {
45
- toBeTypes: ['string'],
46
- }
47
- })
48
-
49
- if (chartParamsPartial && chartParamsPartial.padding) {
50
- const paddingResult = validateColumns(chartParamsPartial.padding, {
51
- top: {
52
- toBeTypes: ['number'],
53
- },
54
- right: {
55
- toBeTypes: ['number'],
56
- },
57
- bottom: {
58
- toBeTypes: ['number'],
59
- },
60
- left: {
61
- toBeTypes: ['number'],
62
- },
63
- })
64
-
65
- if (paddingResult.status === 'error') {
66
- return paddingResult
67
- }
68
- }
69
-
70
- if (chartParamsPartial && chartParamsPartial.colors) {
71
- const colorsResult = validateColumns(chartParamsPartial.colors, {
72
- light: {
73
- toBeTypes: ['object'],
74
- },
75
- dark: {
76
- toBeTypes: ['object'],
77
- },
78
- })
79
-
80
- if (colorsResult.status === 'error') {
81
- return colorsResult
82
- }
83
-
84
- if (chartParamsPartial.colors.light) {
85
- const lightResult = validateColumns(chartParamsPartial.colors.light, {
86
- label: {
87
- toBeTypes: ['string[]'],
88
- },
89
- primary: {
90
- toBeTypes: ['string'],
91
- },
92
- secondary: {
93
- toBeTypes: ['string'],
94
- },
95
- labelContrast: {
96
- toBeTypes: ['string[]'],
97
- },
98
- background: {
99
- toBeTypes: ['string'],
100
- },
101
- })
102
-
103
- if (lightResult.status === 'error') {
104
- return lightResult
105
- }
106
- }
107
-
108
- if (chartParamsPartial.colors.dark) {
109
- const darkResult = validateColumns(chartParamsPartial.colors.dark, {
110
- label: {
111
- toBeTypes: ['string[]'],
112
- },
113
- primary: {
114
- toBeTypes: ['string'],
115
- },
116
- secondary: {
117
- toBeTypes: ['string'],
118
- },
119
- labelContrast: {
120
- toBeTypes: ['string[]'],
121
- },
122
- background: {
123
- toBeTypes: ['string'],
124
- },
125
- })
126
-
127
- if (darkResult.status === 'error') {
128
- return darkResult
129
- }
130
- }
131
- }
132
-
133
- return result
134
- }
@@ -1,14 +0,0 @@
1
- import type { ValidatorResult } from '../../../lib/core-types'
2
- import { validateColumns } from '../../utils/validator'
3
- import { isDom } from '../../utils/commonUtils'
4
-
5
- export function elementValidator (element: HTMLElement | Element): ValidatorResult {
6
- const result = validateColumns({ element }, {
7
- element: {
8
- toBe: 'Dom',
9
- test: (value: any) => isDom(value)
10
- },
11
- })
12
-
13
- return result
14
- }
@@ -1,15 +0,0 @@
1
- import type { ChartType, PluginEntity, ValidatorResult } from '../../../lib/core-types'
2
- import { validateColumns } from '../../utils/validator'
3
-
4
- export function pluginsValidator (chartType: ChartType, pluginEntities: PluginEntity<any, any, any>[]): ValidatorResult {
5
- const result = validateColumns({ pluginEntities }, {
6
- pluginEntities: {
7
- toBe: `PluginEntity<'${chartType}'>[]`,
8
- test: (value: PluginEntity<any, any, any>[]) => {
9
- return Array.isArray(value) && value.every((v) => v.chartType === chartType || v.chartType === 'noneData')
10
- }
11
- }
12
- })
13
-
14
- return result
15
- }
package/src/defaults.ts DELETED
@@ -1,284 +0,0 @@
1
- import type {
2
- ChartOptionsPartial,
3
- DataSeries,
4
- DataGrid,
5
- DataMultiGrid,
6
- DataMultiValue,
7
- DataTree,
8
- DataRelationship,
9
- DataFormatterValueAxis,
10
- DataFormatterGroupAxis,
11
- DataFormatterXYAxis,
12
- DataFormatterContainer,
13
- DataFormatterSeries,
14
- DataFormatterGrid,
15
- DataFormatterGridGrid,
16
- DataFormatterMultiGrid,
17
- DataFormatterMultiGridGrid,
18
- DataFormatterMultiValue,
19
- DataFormatterTree,
20
- DataFormatterRelationship,
21
- ChartParams,
22
- Padding
23
- } from '../lib/core-types'
24
-
25
- export const DEFAULT_CHART_OPTIONS: ChartOptionsPartial<any> = {
26
- // preset: {} // 預設為空
27
- width: 'auto',
28
- height: 'auto'
29
- }
30
-
31
- // export const GLOBAL_DEFAULT: ChartGlobalDefault = {
32
- // colors: ['#67B7DC', '#6794DC', '#6771DC', '#8067DC', '#A367DC', '#C767DC', '#DC67CE', '#DC67AB', '#DC6788', '#DC6967', '#DC8C67', '#DCAF67'],
33
- // padding: {
34
- // top: 50,
35
- // right: 70,
36
- // bottom: 50,
37
- // left: 70
38
- // },
39
- // // chartWidth: '100%',
40
- // // chartHeight: 500
41
- // }
42
-
43
- // export const COLORS_DEFAULT = ['#67B7DC', '#6794DC', '#6771DC', '#8067DC', '#A367DC', '#C767DC', '#DC67CE', '#DC67AB', '#DC6788', '#DC6967', '#DC8C67', '#DCAF67']
44
- // ['#ff7ab9', '#66dec8', '#84c8ff', '#30ad1b', '#f8c43e', '#fa5640', '#9d79d7', '#ea4f98']
45
-
46
- export const DEFAULT_PADDING: Padding = {
47
- top: 60,
48
- right: 60,
49
- bottom: 60,
50
- left: 60
51
- }
52
-
53
- export const DEFAULT_CHART_PARAMS: ChartParams = {
54
- padding: DEFAULT_PADDING,
55
- highlightTarget: 'datum',
56
- highlightDefault: null,
57
- colorScheme: 'light',
58
- colors: {
59
- light: {
60
- label: [
61
- "#0088FF",
62
- "#FF3232",
63
- "#38BEA8",
64
- "#6F3BD5",
65
- "#314285",
66
- "#42C724",
67
- "#D52580",
68
- "#F4721B",
69
- "#D117EA",
70
- "#7E7D7D"
71
- ],
72
- // label: ['#67B7DC', '#6794DC', '#6771DC', '#8067DC', '#A367DC', '#C767DC', '#DC67CE', '#DC67AB', '#DC6788', '#DC6967', '#DC8C67', '#DCAF67'],
73
- // label: ['#F3A356', '#7A60F0', '#38B1AF', '#60A2F0', '#F06062', '#FF383C', '#6580EA', '#079F9C', '#9F65EA', '#EA7465', '#EA7465', '#8657D2', '#59B757', '#2797FF', '#D25786', '#F54BA6', '#4BECF5', '#74FD72', '#CA4BF5', '#EFE26E'],
74
- // label: ['#60A2F0', '#F3A356', '#7A60F0', '#38B1AF', '#F06062', '#FF383C', '#6580EA', '#079F9C', '#9F65EA', '#EA7465', '#EA7465', '#8657D2', '#59B757', '#2797FF', '#D25786', '#F54BA6', '#4BECF5', '#74FD72', '#CA4BF5', '#EFE26E'],
75
- // primary: '#454545',
76
- // primary: '#1b1e23',
77
- primary: '#000000',
78
- secondary: '#e0e0e0',
79
- // white: '#ffffff',
80
- labelContrast: ['#ffffff', '#000000'],
81
- background: '#ffffff'
82
- },
83
- dark: {
84
- label: [
85
- "#4BABFF",
86
- "#FF6C6C",
87
- "#7DD3C4",
88
- "#8E6BC9",
89
- "#5366AC",
90
- "#86DC72",
91
- "#FF72BB",
92
- "#F9B052",
93
- "#EF76FF",
94
- "#C4C4C4"
95
- ],
96
- // label: ['#67B7DC', '#6794DC', '#6771DC', '#8067DC', '#A367DC', '#C767DC', '#DC67CE', '#DC67AB', '#DC6788', '#DC6967', '#DC8C67', '#DCAF67'],
97
- // label: ['#67B7DC', '#6794DC', '#38B1AF', '#6771DC', '#8067DC', '#A367DC', '#C767DC', '#DC67CE', '#DC67AB', '#DC6788', '#DC6967', '#DC8C67', '#DCAF67'],
98
- // label: ['#60A2F0', '#F3A356', '#7A60F0', '#38B1AF', '#F06062', '#FF383C', '#6580EA', '#079F9C', '#9F65EA', '#EA7465', '#EA7465', '#8657D2', '#59B757', '#2797FF', '#D25786', '#F54BA6', '#4BECF5', '#74FD72', '#CA4BF5', '#EFE26E'],
99
- // primary: '#f0f0f0',
100
- primary: '#ffffff',
101
- secondary: '#e0e0e0',
102
- // white: '#ffffff',
103
- labelContrast: ['#ffffff', '#000000'],
104
- background: '#000000'
105
- }
106
- },
107
- styles: {
108
- // textSize: 14,
109
- textSize: '0.875rem',
110
- unhighlightedOpacity: 0.3
111
- },
112
- transitionDuration: 800,
113
- transitionEase: 'easeCubic'
114
- }
115
-
116
- export const DEFAULT_CHART_WIDTH = 800
117
-
118
- export const DEFAULT_CHART_HEIGHT = 500
119
-
120
- // -- Data --
121
-
122
- export const DEFAULT_DATA_SERIES: DataSeries = []
123
-
124
- export const DEFAULT_DATA_GRID: DataGrid = []
125
-
126
- export const DEFAULT_DATA_MULTI_GRID: DataMultiGrid = []
127
-
128
- export const DEFAULT_DATA_MULTI_VALUE: DataMultiValue = []
129
-
130
- export const DEFAULT_DATA_TREE: DataTree = []
131
-
132
- export const DEFAULTL_DATA_RELATIONA: DataRelationship = {
133
- nodes: [],
134
- edges: []
135
- }
136
-
137
- // -- Data Formatter --
138
-
139
- export const DEFAULT_DATA_FORMATTER_VALUE_AXIS: DataFormatterValueAxis = {
140
- position: 'left',
141
- scaleDomain: ['auto', 'auto'],
142
- scaleRange: [0, 0.9],
143
- label: '',
144
- }
145
-
146
- export const DEFAULT_DATA_FORMATTER_GROUP_AXIS: DataFormatterGroupAxis = {
147
- position: 'bottom',
148
- scaleDomain: [0, 'max'],
149
- scalePadding: 0.5,
150
- label: ''
151
- }
152
-
153
- export const DEFAULT_DATA_FORMATTER_X_Y_AXIS: DataFormatterXYAxis = {
154
- scaleDomain: ['auto', 'auto'],
155
- scaleRange: [0, 0.9],
156
- label: '',
157
- valueIndex: 0
158
- }
159
-
160
- export const DEFAULT_DATA_FORMATTER_CONTAINER: DataFormatterContainer = {
161
- columnAmount: 1,
162
- rowAmount: 1,
163
- columnGap: 'auto',
164
- rowGap: 'auto'
165
- }
166
-
167
- export const DEFAULT_DATA_FORMATTER_SERIES: DataFormatterSeries = {
168
- type: 'series',
169
- visibleFilter: (datum, context) => true,
170
- sort: null,
171
- seriesLabels: [],
172
- container: {
173
- ...DEFAULT_DATA_FORMATTER_CONTAINER
174
- },
175
- separateSeries: false,
176
- separateLabel: false,
177
- sumSeries: false
178
- // mapSeries: (datum, rowIndex, columnIndex, { data, dataFormatter }) => {
179
- // const seriesIndex = rowIndex >= dataFormatter.seriesLabels.length
180
- // ? rowIndex % dataFormatter.seriesLabels.length // 如果index大於所設定的seriesLabels的數量則從頭回來算
181
- // : rowIndex
182
- // return dataFormatter.seriesLabels[seriesIndex]
183
- // },
184
- // colorsPredicate: (datum, rowIndex, columnIndex, { chartParams }) => {
185
- // return rowIndex < chartParams.colors[chartParams.colorScheme].series.length
186
- // ? chartParams.colors[chartParams.colorScheme].series[rowIndex]
187
- // : chartParams.colors[chartParams.colorScheme].series[
188
- // rowIndex % chartParams.colors[chartParams.colorScheme].series.length
189
- // ]
190
- // },
191
- }
192
- DEFAULT_DATA_FORMATTER_SERIES.visibleFilter.toString = () => `(datum, context) => true`
193
-
194
- export const DEFAULT_DATA_FORMATTER_GRID_GRID: DataFormatterGridGrid = {
195
- seriesDirection: 'row',
196
- rowLabels: [],
197
- columnLabels: [],
198
- valueAxis: { ...DEFAULT_DATA_FORMATTER_VALUE_AXIS },
199
- groupAxis: { ...DEFAULT_DATA_FORMATTER_GROUP_AXIS, },
200
- separateSeries: false,
201
- // slotIndex: 0,
202
- // seriesSlotIndexes: null
203
- }
204
-
205
- export const DEFAULT_DATA_FORMATTER_GRID: DataFormatterGrid = {
206
- type: 'grid',
207
- visibleFilter: (datum, context) => true,
208
- // grid: {
209
- ...DEFAULT_DATA_FORMATTER_GRID_GRID,
210
- // },
211
- container: {
212
- ...DEFAULT_DATA_FORMATTER_CONTAINER
213
- }
214
- }
215
- DEFAULT_DATA_FORMATTER_GRID.visibleFilter.toString = () => `(datum, context) => true`
216
-
217
- // export const DATA_FORMATTER_MULTI_GRID_MULTI_GRID_DEFAULT: DataFormatterMultiGridMultiGrid = {
218
- // ...DEFAULT_DATA_FORMATTER_GRID,
219
- // slotIndex: 0,
220
- // seriesSlotIndexes: null
221
- // }
222
-
223
- export const DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID: DataFormatterMultiGridGrid = {
224
- ...DEFAULT_DATA_FORMATTER_GRID_GRID
225
- }
226
-
227
- export const DEFAULT_DATA_FORMATTER_MULTI_GRID: DataFormatterMultiGrid = {
228
- type: 'multiGrid',
229
- visibleFilter: (datum, context) => true,
230
- gridList: [
231
- {
232
- ...DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID
233
- },
234
- ],
235
- separateGrid: false,
236
- container: {
237
- ...DEFAULT_DATA_FORMATTER_CONTAINER
238
- }
239
- }
240
- DEFAULT_DATA_FORMATTER_MULTI_GRID.visibleFilter.toString = () => `(datum, context) => true`
241
-
242
- export const DEFAULT_DATA_FORMATTER_MULTI_VALUE: DataFormatterMultiValue = {
243
- type: 'multiValue',
244
- visibleFilter: (datum, context) => true,
245
- categoryLabels: [],
246
- valueLabels: [],
247
- xAxis: {
248
- ...DEFAULT_DATA_FORMATTER_X_Y_AXIS,
249
- valueIndex: 0
250
- },
251
- yAxis: {
252
- ...DEFAULT_DATA_FORMATTER_X_Y_AXIS,
253
- valueIndex: 1
254
- },
255
- container: {
256
- ...DEFAULT_DATA_FORMATTER_CONTAINER
257
- },
258
- separateCategory: false
259
- }
260
- DEFAULT_DATA_FORMATTER_MULTI_VALUE.visibleFilter.toString = () => `(datum, context) => true`
261
-
262
- export const DEFAULT_DATA_FORMATTER_TREE: DataFormatterTree = {
263
- type: 'tree',
264
- visibleFilter: (datum, context) => true,
265
- // labelFormat: (datum: any) => (datum && datum.label) ?? '',
266
- categoryLabels: []
267
- }
268
- DEFAULT_DATA_FORMATTER_TREE.visibleFilter.toString = () => `(datum, context) => true`
269
-
270
- export const DEFAULT_DATA_FORMATTER_RELATIONSHIP: DataFormatterRelationship = {
271
- type: 'relationship',
272
- visibleFilter: (datum, context) => true,
273
- categoryLabels: []
274
- // node: {
275
- // // labelFormat: (node: any) => (node && node.label) ?? '',
276
- // descriptionFormat: (node: any) => (node && node.label) ?? ''
277
- // },
278
- // edge: {
279
- // // labelFormat: (edge: any) => (edge && edge.label) ?? '',
280
- // descriptionFormat: (edge: any) => (edge && edge.label) ?? ''
281
- // },
282
- }
283
- DEFAULT_DATA_FORMATTER_RELATIONSHIP.visibleFilter.toString = () => `(datum, context) => true`
284
-
@@ -1,3 +0,0 @@
1
- import { createBasePlugin } from './base/createBasePlugin'
2
-
3
- export const defineGridPlugin = createBasePlugin('grid')
@@ -1,3 +0,0 @@
1
- import { createBasePlugin } from './base/createBasePlugin'
2
-
3
- export const defineMultiGridPlugin = createBasePlugin('multiGrid')
@@ -1,3 +0,0 @@
1
- import { createBasePlugin } from './base/createBasePlugin'
2
-
3
- export const defineMultiValuePlugin = createBasePlugin('multiValue')
@@ -1,4 +0,0 @@
1
- import { createBasePlugin } from './base/createBasePlugin'
2
-
3
- // chartType型別使用 'any' 是為了讓 plugin entity 能夠被加入到所有類別的 chart.plugins$ 中
4
- export const defineNoneDataPlugin = createBasePlugin<any>('noneData')
@@ -1,3 +0,0 @@
1
- import { createBasePlugin } from './base/createBasePlugin'
2
-
3
- export const defineRelationshipPlugin = createBasePlugin('relationship')
@@ -1,3 +0,0 @@
1
- import { createBasePlugin } from './base/createBasePlugin'
2
-
3
- export const defineSeriesPlugin = createBasePlugin('series')
@@ -1,3 +0,0 @@
1
- import { createBasePlugin } from './base/createBasePlugin'
2
-
3
- export const defineTreePlugin = createBasePlugin('tree')
@@ -1,129 +0,0 @@
1
- // import * as d3 from 'd3'
2
- import type { ComputedDataFn, DataGrid, DataGridDatum, DataFormatterGridGrid, ComputedDatumGrid } from '../../lib/core-types'
3
- import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, createDefaultGroupLabel } from '../utils/orbchartsUtils'
4
- import { getMinMaxValue, transposeData, createGridSeriesLabels, createGridGroupLabels, seriesColorPredicate } from '../utils/orbchartsUtils'
5
-
6
- // 統一 DataGrid 格式、並欄列資料轉置為一致方式
7
- export function createTransposedDataGrid (data: DataGrid, dataFormatterGrid: DataFormatterGridGrid): DataGridDatum[][] {
8
- // const { data = [], dataFormatter, chartParams } = context
9
- if (!data.length) {
10
- return []
11
- }
12
- try {
13
- // 最多的array length
14
- const maxArrayLength = data.reduce((prev, current) => {
15
- return current.length > prev ? current.length : prev
16
- }, 0)
17
-
18
- // 補齊短少資料
19
- const fullData = data.map((d, i) => {
20
- if (d.length === maxArrayLength) {
21
- return d
22
- }
23
- const newD = Object.assign([], d)
24
- for (let _i = newD.length; _i < maxArrayLength; _i++) {
25
- newD[_i] = null
26
- }
27
- return newD
28
- })
29
-
30
- // 完整的資料格式
31
- const dataGrid: DataGridDatum[][] = fullData.map((d, i) => {
32
- return d.map((_d, _i) => {
33
-
34
- const datum: DataGridDatum = _d == null
35
- ? {
36
- id: '',
37
- label: '',
38
- data: {},
39
- value: null,
40
- }
41
- : typeof _d === 'number'
42
- ? {
43
- id: '',
44
- label: '',
45
- data: {},
46
- value: _d,
47
- }
48
- : {
49
- id: _d.id ?? '',
50
- label: _d.label ?? '',
51
- data: _d.data ?? {},
52
- value: _d.value,
53
- }
54
-
55
- return datum
56
- })
57
- })
58
-
59
- // 依seriesDirection轉置資料矩陣
60
- const transposedDataGrid = transposeData(dataFormatterGrid.seriesDirection, dataGrid)
61
-
62
- return transposedDataGrid
63
- } catch (e) {
64
- return []
65
- }
66
- }
67
-
68
- export const computedDataFn: ComputedDataFn<'grid'> = (context) => {
69
- const { data = [], dataFormatter, chartParams } = context
70
- if (!data.length) {
71
- return []
72
- }
73
-
74
- let computedDataGrid: ComputedDatumGrid[][]
75
-
76
- try {
77
-
78
- // 依seriesDirection轉置資料矩陣
79
- const transposedDataGrid = createTransposedDataGrid(data, dataFormatter)
80
-
81
- const seriesLabels = createGridSeriesLabels({
82
- transposedDataGrid,
83
- dataFormatterGrid: dataFormatter,
84
- chartType: 'grid'
85
- })
86
- const groupLabels = createGridGroupLabels({
87
- transposedDataGrid,
88
- dataFormatterGrid: dataFormatter,
89
- chartType: 'grid'
90
- })
91
-
92
- let _index = 0
93
- computedDataGrid = transposedDataGrid.map((seriesData, seriesIndex) => {
94
- return seriesData.map((groupDatum, groupIndex) => {
95
-
96
- const defaultId = createDefaultDatumId('grid', 0, seriesIndex, groupIndex)
97
- const groupLabel = groupLabels[groupIndex]
98
-
99
- const computedDatum: ComputedDatumGrid = {
100
- id: groupDatum.id ? groupDatum.id : defaultId,
101
- index: _index,
102
- label: groupDatum.label ? groupDatum.label : defaultId,
103
- description: groupDatum.description ?? '',
104
- data: groupDatum.data,
105
- value: groupDatum.value,
106
- gridIndex: 0,
107
- seriesIndex,
108
- seriesLabel: seriesLabels[seriesIndex],
109
- groupIndex,
110
- groupLabel,
111
- color: seriesColorPredicate(seriesIndex, chartParams),
112
- visible: true // 先給一個預設值
113
- }
114
-
115
- // 先建立物件再計算visible欄位
116
- computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
117
-
118
- _index ++
119
-
120
- return computedDatum
121
- })
122
- })
123
-
124
- } catch (e) {
125
- throw Error(e)
126
- }
127
-
128
- return computedDataGrid
129
- }