@orbcharts/core 3.0.0-alpha.61 → 3.0.0-alpha.63

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. package/LICENSE +200 -200
  2. package/dist/lib/core-types.d.ts +1 -0
  3. package/dist/orbcharts-core.es.js +3418 -2726
  4. package/dist/orbcharts-core.umd.js +6 -2
  5. package/dist/src/AbstractChart.d.ts +5 -3
  6. package/dist/src/GridChart.d.ts +1 -1
  7. package/dist/src/MultiGridChart.d.ts +1 -1
  8. package/dist/src/MultiValueChart.d.ts +1 -1
  9. package/dist/src/RelationshipChart.d.ts +1 -1
  10. package/dist/src/SeriesChart.d.ts +1 -1
  11. package/dist/src/TreeChart.d.ts +1 -1
  12. package/dist/src/base/createBaseChart.d.ts +1 -1
  13. package/dist/src/base/createBasePlugin.d.ts +1 -1
  14. package/dist/src/base/validators/chartOptionsValidator.d.ts +3 -0
  15. package/dist/src/base/validators/chartParamsValidator.d.ts +3 -0
  16. package/dist/src/base/validators/elementValidator.d.ts +3 -0
  17. package/dist/src/base/validators/pluginsValidator.d.ts +3 -0
  18. package/dist/src/defaults.d.ts +1 -16
  19. package/dist/src/defineGridPlugin.d.ts +1 -1
  20. package/dist/src/defineMultiGridPlugin.d.ts +1 -1
  21. package/dist/src/defineMultiValuePlugin.d.ts +1 -1
  22. package/dist/src/defineNoneDataPlugin.d.ts +1 -1
  23. package/dist/src/defineRelationshipPlugin.d.ts +1 -1
  24. package/dist/src/defineSeriesPlugin.d.ts +1 -1
  25. package/dist/src/defineTreePlugin.d.ts +1 -1
  26. package/dist/src/grid/computedDataFn.d.ts +4 -0
  27. package/dist/src/grid/contextObserverCallback.d.ts +3 -0
  28. package/dist/src/grid/dataFormatterValidator.d.ts +3 -0
  29. package/dist/src/grid/dataValidator.d.ts +3 -0
  30. package/dist/src/index.d.ts +1 -1
  31. package/dist/src/multiGrid/computedDataFn.d.ts +3 -0
  32. package/dist/src/multiGrid/contextObserverCallback.d.ts +3 -0
  33. package/dist/src/multiGrid/dataFormatterValidator.d.ts +3 -0
  34. package/dist/src/multiGrid/dataValidator.d.ts +3 -0
  35. package/dist/src/multiValue/computedDataFn.d.ts +3 -0
  36. package/dist/src/multiValue/contextObserverCallback.d.ts +3 -0
  37. package/dist/src/multiValue/dataFormatterValidator.d.ts +3 -0
  38. package/dist/src/multiValue/dataValidator.d.ts +3 -0
  39. package/dist/src/relationship/computedDataFn.d.ts +3 -0
  40. package/dist/src/relationship/contextObserverCallback.d.ts +3 -0
  41. package/dist/src/relationship/dataFormatterValidator.d.ts +3 -0
  42. package/dist/src/relationship/dataValidator.d.ts +3 -0
  43. package/dist/src/series/computedDataFn.d.ts +3 -0
  44. package/dist/src/series/contextObserverCallback.d.ts +3 -0
  45. package/dist/src/series/dataFormatterValidator.d.ts +3 -0
  46. package/dist/src/series/dataValidator.d.ts +3 -0
  47. package/dist/src/tree/computedDataFn.d.ts +3 -0
  48. package/dist/src/tree/contextObserverCallback.d.ts +3 -0
  49. package/dist/src/tree/dataFormatterValidator.d.ts +3 -0
  50. package/dist/src/tree/dataValidator.d.ts +3 -0
  51. package/dist/src/utils/commonUtils.d.ts +1 -0
  52. package/dist/src/utils/errorMessage.d.ts +14 -0
  53. package/dist/src/{grid → utils}/gridObservables.d.ts +2 -2
  54. package/dist/src/utils/index.d.ts +7 -3
  55. package/dist/src/{multiGrid → utils}/multiGridObservables.d.ts +1 -1
  56. package/dist/src/utils/observables.d.ts +2 -1
  57. package/dist/src/utils/orbchartsUtils.d.ts +1 -12
  58. package/dist/src/{series → utils}/seriesObservables.d.ts +3 -3
  59. package/dist/src/{tree → utils}/treeObservables.d.ts +1 -1
  60. package/dist/src/utils/validator.d.ts +3 -0
  61. package/lib/core-types.ts +7 -0
  62. package/package.json +42 -41
  63. package/src/AbstractChart.ts +57 -48
  64. package/src/GridChart.ts +24 -20
  65. package/src/MultiGridChart.ts +24 -20
  66. package/src/MultiValueChart.ts +24 -20
  67. package/src/RelationshipChart.ts +24 -20
  68. package/src/SeriesChart.ts +24 -20
  69. package/src/TreeChart.ts +24 -20
  70. package/src/base/createBaseChart.ts +500 -388
  71. package/src/base/createBasePlugin.ts +152 -95
  72. package/src/base/validators/chartOptionsValidator.ts +24 -0
  73. package/src/base/validators/chartParamsValidator.ts +134 -0
  74. package/src/base/validators/elementValidator.ts +14 -0
  75. package/src/base/validators/pluginsValidator.ts +15 -0
  76. package/src/defaults.ts +232 -228
  77. package/src/defineGridPlugin.ts +3 -3
  78. package/src/defineMultiGridPlugin.ts +3 -3
  79. package/src/defineMultiValuePlugin.ts +3 -3
  80. package/src/defineNoneDataPlugin.ts +4 -4
  81. package/src/defineRelationshipPlugin.ts +3 -3
  82. package/src/defineSeriesPlugin.ts +3 -3
  83. package/src/defineTreePlugin.ts +3 -3
  84. package/src/grid/{computeGridData.ts → computedDataFn.ts} +129 -134
  85. package/src/grid/{createGridContextObserver.ts → contextObserverCallback.ts} +155 -155
  86. package/src/grid/dataFormatterValidator.ts +102 -0
  87. package/src/grid/dataValidator.ts +13 -0
  88. package/src/index.ts +20 -21
  89. package/src/multiGrid/{computeMultiGridData.ts → computedDataFn.ts} +123 -130
  90. package/src/multiGrid/{createMultiGridContextObserver.ts → contextObserverCallback.ts} +41 -41
  91. package/src/multiGrid/dataFormatterValidator.ts +116 -0
  92. package/src/multiGrid/dataValidator.ts +13 -0
  93. package/src/multiValue/{computeMultiValueData.ts → computedDataFn.ts} +176 -179
  94. package/src/multiValue/{createMultiValueContextObserver.ts → contextObserverCallback.ts} +12 -12
  95. package/src/multiValue/dataFormatterValidator.ts +10 -0
  96. package/src/multiValue/dataValidator.ts +10 -0
  97. package/src/relationship/{computeRelationshipData.ts → computedDataFn.ts} +125 -118
  98. package/src/relationship/{createRelationshipContextObserver.ts → contextObserverCallback.ts} +12 -12
  99. package/src/relationship/dataFormatterValidator.ts +10 -0
  100. package/src/relationship/dataValidator.ts +10 -0
  101. package/src/series/{computeSeriesData.ts → computedDataFn.ts} +88 -90
  102. package/src/series/{createSeriesContextObserver.ts → contextObserverCallback.ts} +100 -93
  103. package/src/series/dataFormatterValidator.ts +42 -0
  104. package/src/series/dataValidator.ts +13 -0
  105. package/src/tree/{computeTreeData.ts → computedDataFn.ts} +130 -132
  106. package/src/tree/{createTreeContextObserver.ts → contextObserverCallback.ts} +61 -61
  107. package/src/tree/dataFormatterValidator.ts +14 -0
  108. package/src/tree/dataValidator.ts +14 -0
  109. package/src/utils/commonUtils.ts +54 -50
  110. package/src/utils/d3Utils.ts +108 -108
  111. package/src/utils/errorMessage.ts +43 -0
  112. package/src/{grid → utils}/gridObservables.ts +611 -614
  113. package/src/utils/index.ts +10 -4
  114. package/src/{multiGrid → utils}/multiGridObservables.ts +366 -365
  115. package/src/utils/observables.ts +219 -202
  116. package/src/utils/orbchartsUtils.ts +352 -349
  117. package/src/{series → utils}/seriesObservables.ts +175 -175
  118. package/src/{tree → utils}/treeObservables.ts +94 -94
  119. package/src/utils/validator.ts +126 -0
  120. package/tsconfig.base.json +13 -13
  121. package/tsconfig.json +2 -2
  122. package/vite-env.d.ts +7 -0
  123. package/vite.config.js +22 -22
  124. package/dist/src/grid/computeGridData.d.ts +0 -6
  125. package/dist/src/grid/createGridContextObserver.d.ts +0 -3
  126. package/dist/src/multiGrid/computeMultiGridData.d.ts +0 -3
  127. package/dist/src/multiGrid/createMultiGridContextObserver.d.ts +0 -3
  128. package/dist/src/multiValue/computeMultiValueData.d.ts +0 -3
  129. package/dist/src/multiValue/createMultiValueContextObserver.d.ts +0 -3
  130. package/dist/src/relationship/computeRelationshipData.d.ts +0 -3
  131. package/dist/src/relationship/createRelationshipContextObserver.d.ts +0 -3
  132. package/dist/src/series/computeSeriesData.d.ts +0 -3
  133. package/dist/src/series/createSeriesContextObserver.d.ts +0 -3
  134. package/dist/src/tree/computeTreeData.d.ts +0 -3
  135. package/dist/src/tree/createTreeContextObserver.d.ts +0 -3
  136. package/dist/src/types/Axis.d.ts +0 -1
  137. package/dist/src/types/Chart.d.ts +0 -45
  138. package/dist/src/types/ChartParams.d.ts +0 -36
  139. package/dist/src/types/ComputedData.d.ts +0 -42
  140. package/dist/src/types/ComputedDataGrid.d.ts +0 -5
  141. package/dist/src/types/ComputedDataMultiGrid.d.ts +0 -3
  142. package/dist/src/types/ComputedDataMultiValue.d.ts +0 -6
  143. package/dist/src/types/ComputedDataRelationship.d.ts +0 -18
  144. package/dist/src/types/ComputedDataSeries.d.ts +0 -5
  145. package/dist/src/types/ComputedDataTree.d.ts +0 -7
  146. package/dist/src/types/ContextObserver.d.ts +0 -28
  147. package/dist/src/types/ContextObserverGrid.d.ts +0 -41
  148. package/dist/src/types/ContextObserverMultiGrid.d.ts +0 -15
  149. package/dist/src/types/ContextObserverMultiValue.d.ts +0 -4
  150. package/dist/src/types/ContextObserverRelationship.d.ts +0 -4
  151. package/dist/src/types/ContextObserverSeries.d.ts +0 -27
  152. package/dist/src/types/ContextObserverTree.d.ts +0 -11
  153. package/dist/src/types/ContextSubject.d.ts +0 -15
  154. package/dist/src/types/Data.d.ts +0 -19
  155. package/dist/src/types/DataFormatter.d.ts +0 -41
  156. package/dist/src/types/DataFormatterGrid.d.ts +0 -34
  157. package/dist/src/types/DataFormatterMultiGrid.d.ts +0 -20
  158. package/dist/src/types/DataFormatterMultiValue.d.ts +0 -18
  159. package/dist/src/types/DataFormatterRelationship.d.ts +0 -10
  160. package/dist/src/types/DataFormatterSeries.d.ts +0 -19
  161. package/dist/src/types/DataFormatterTree.d.ts +0 -7
  162. package/dist/src/types/DataGrid.d.ts +0 -6
  163. package/dist/src/types/DataMultiGrid.d.ts +0 -6
  164. package/dist/src/types/DataMultiValue.d.ts +0 -7
  165. package/dist/src/types/DataRelationship.d.ts +0 -21
  166. package/dist/src/types/DataSeries.d.ts +0 -6
  167. package/dist/src/types/DataTree.d.ts +0 -15
  168. package/dist/src/types/Event.d.ts +0 -56
  169. package/dist/src/types/Layout.d.ts +0 -8
  170. package/dist/src/types/Padding.d.ts +0 -6
  171. package/dist/src/types/Plugin.d.ts +0 -37
  172. package/dist/src/types/TransformData.d.ts +0 -8
  173. package/dist/src/types/index.d.ts +0 -37
  174. package/src/types/Axis.ts +0 -1
  175. package/src/types/Chart.ts +0 -54
  176. package/src/types/ChartParams.ts +0 -51
  177. package/src/types/ComputedData.ts +0 -84
  178. package/src/types/ComputedDataGrid.ts +0 -14
  179. package/src/types/ComputedDataMultiGrid.ts +0 -3
  180. package/src/types/ComputedDataMultiValue.ts +0 -9
  181. package/src/types/ComputedDataRelationship.ts +0 -20
  182. package/src/types/ComputedDataSeries.ts +0 -8
  183. package/src/types/ComputedDataTree.ts +0 -20
  184. package/src/types/ContextObserver.ts +0 -38
  185. package/src/types/ContextObserverGrid.ts +0 -43
  186. package/src/types/ContextObserverMultiGrid.ts +0 -17
  187. package/src/types/ContextObserverMultiValue.ts +0 -5
  188. package/src/types/ContextObserverRelationship.ts +0 -5
  189. package/src/types/ContextObserverSeries.ts +0 -29
  190. package/src/types/ContextObserverTree.ts +0 -11
  191. package/src/types/ContextSubject.ts +0 -18
  192. package/src/types/Data.ts +0 -45
  193. package/src/types/DataFormatter.ts +0 -74
  194. package/src/types/DataFormatterGrid.ts +0 -68
  195. package/src/types/DataFormatterMultiGrid.ts +0 -45
  196. package/src/types/DataFormatterMultiValue.ts +0 -24
  197. package/src/types/DataFormatterRelationship.ts +0 -26
  198. package/src/types/DataFormatterSeries.ts +0 -20
  199. package/src/types/DataFormatterTree.ts +0 -12
  200. package/src/types/DataGrid.ts +0 -11
  201. package/src/types/DataMultiGrid.ts +0 -7
  202. package/src/types/DataMultiValue.ts +0 -12
  203. package/src/types/DataRelationship.ts +0 -28
  204. package/src/types/DataSeries.ts +0 -11
  205. package/src/types/DataTree.ts +0 -20
  206. package/src/types/Event.ts +0 -153
  207. package/src/types/Layout.ts +0 -12
  208. package/src/types/Padding.ts +0 -6
  209. package/src/types/Plugin.ts +0 -60
  210. package/src/types/TransformData.ts +0 -8
  211. package/src/types/index.ts +0 -37
  212. /package/dist/src/{multiValue → utils}/multiValueObservables.d.ts +0 -0
  213. /package/dist/src/{relationship → utils}/relationshipObservables.d.ts +0 -0
  214. /package/src/{multiValue → utils}/multiValueObservables.ts +0 -0
  215. /package/src/{relationship → utils}/relationshipObservables.ts +0 -0
@@ -1,118 +1,125 @@
1
- import type { DataRelationship, DataRelationshipObj, DataRelationshipList, Node, Edge } from '../types/DataRelationship'
2
- import type { ComputedDataFn } from '../types/ComputedData'
3
- import type { ComputedDataRelationship, ComputedNode, ComputedEdge } from '../types/ComputedDataRelationship'
4
-
5
- export const computeRelationshipData: ComputedDataFn<'relationship'> = (context) => {
6
- const { data, dataFormatter, chartParams } = context
7
-
8
- let computedNodes: ComputedNode[] = []
9
- let computedEdges: ComputedEdge[] = []
10
-
11
- try {
12
- // -- 取得nodes和edges資料 --
13
- let nodes: Node[] = []
14
- let edges: Edge[] = []
15
- if ((data as DataRelationshipObj).nodes) {
16
- nodes = (data as DataRelationshipObj).nodes
17
- edges = (data as DataRelationshipObj).edges
18
- } else if ((data as DataRelationshipList)[0]) {
19
- nodes = (data as DataRelationshipList)[0]
20
- edges = (data as DataRelationshipList)[1]
21
- } else {
22
- // 無值直接回傳
23
- return {
24
- nodes: [],
25
- edges: []
26
- } as ComputedDataRelationship
27
- }
28
-
29
- // -- nodes --
30
- computedNodes = nodes.map((node, i) => {
31
- const computedNode: ComputedNode = {
32
- id: node.id,
33
- index: i,
34
- label: node.label ?? '',
35
- description: node.description ?? '',
36
- // tooltipContent: node.tooltipContent ? node.tooltipContent : dataFormatter.tooltipContentFormat(node, 0, i, context), // 0代表node
37
- data: node.data ?? {},
38
- value: node.value ?? 0,
39
- categoryIndex: 0, // @Q@ 未完成
40
- categoryLabel: '', // @Q@ 未完成
41
- color: '', // @Q@ 未完成
42
- startNodes: [], // 後面再取得資料
43
- startNodeIds: [], // 後面再取得資料
44
- endNodes: [], // 後面再取得資料
45
- endNodeIds: [], // 後面再取得資料
46
- visible: true // 後面再取得資料
47
- }
48
- return computedNode
49
- })
50
-
51
- const NodesMap: Map<string, ComputedNode> = new Map(computedNodes.map(d => [d.id, d]))
52
-
53
- // -- edges --
54
- computedEdges = edges.map((edge, i) => {
55
- const computedEdge: ComputedEdge = {
56
- id: edge.id,
57
- index: i,
58
- label: edge.label ?? '',
59
- description: edge.description ?? '',
60
- // tooltipContent: edge.tooltipContent ? edge.tooltipContent : dataFormatter.tooltipContentFormat(edge, 1, i, context), // 1代表edge
61
- data: edge.data ?? {},
62
- value: edge.value ?? 0,
63
- startNode: NodesMap.get(edge.start),
64
- startNodeId: edge.start,
65
- endNode: NodesMap.get(edge.end),
66
- endNodeId: edge.end,
67
- visible: true // 先給預設值
68
- }
69
-
70
- return computedEdge
71
- })
72
-
73
- const StartNodesMap: Map<string, ComputedNode[]> = (function () {
74
- const _StartNodesMap = new Map()
75
- computedEdges.forEach(edge => {
76
- const startNodes: ComputedNode[] = _StartNodesMap.get(edge.endNodeId) ?? []
77
- startNodes.push(edge.startNode)
78
- _StartNodesMap.set(edge.endNodeId, startNodes)
79
- })
80
- return _StartNodesMap
81
- })()
82
-
83
- const EndNodesMap: Map<string, ComputedNode[]> = (function () {
84
- const _EndNodesMap = new Map()
85
- computedEdges.forEach(edge => {
86
- const endNodes: ComputedNode[] = _EndNodesMap.get(edge.startNodeId) ?? []
87
- endNodes.push(edge.endNode)
88
- _EndNodesMap.set(edge.startNodeId, endNodes)
89
- })
90
- return _EndNodesMap
91
- })()
92
-
93
- // -- 補齊nodes資料 --
94
- Array.from(NodesMap).forEach(([nodeId, node]) => {
95
- node.startNodes = StartNodesMap.get(nodeId)
96
- node.startNodeIds = node.startNodes.map(d => d.id)
97
- node.endNodes = EndNodesMap.get(nodeId)
98
- node.endNodeIds = node.endNodes.map(d => d.id)
99
- node.visible = dataFormatter.visibleFilter(node, context)
100
- })
101
-
102
- // -- 補齊edges資料 --
103
- computedEdges = computedEdges.map(edge => {
104
- edge.visible = edge.startNode.visible && edge.endNode.visible
105
- ? true
106
- : false
107
- return edge
108
- })
109
- } catch (e) {
110
- // console.error(e)
111
- throw Error(e)
112
- }
113
-
114
- return {
115
- nodes: computedNodes,
116
- edges: computedEdges
117
- }
118
- }
1
+ import type {
2
+ DataRelationshipObj,
3
+ DataRelationshipList,
4
+ Node,
5
+ Edge,
6
+ ComputedDataFn,
7
+ ComputedDataRelationship,
8
+ ComputedNode,
9
+ ComputedEdge
10
+ } from '../../lib/core-types'
11
+
12
+ export const computedDataFn: ComputedDataFn<'relationship'> = (context) => {
13
+ const { data, dataFormatter, chartParams } = context
14
+
15
+ let computedNodes: ComputedNode[] = []
16
+ let computedEdges: ComputedEdge[] = []
17
+
18
+ try {
19
+ // -- 取得nodes和edges資料 --
20
+ let nodes: Node[] = []
21
+ let edges: Edge[] = []
22
+ if ((data as DataRelationshipObj).nodes) {
23
+ nodes = (data as DataRelationshipObj).nodes
24
+ edges = (data as DataRelationshipObj).edges
25
+ } else if ((data as DataRelationshipList)[0]) {
26
+ nodes = (data as DataRelationshipList)[0]
27
+ edges = (data as DataRelationshipList)[1]
28
+ } else {
29
+ // 無值直接回傳
30
+ return {
31
+ nodes: [],
32
+ edges: []
33
+ } as ComputedDataRelationship
34
+ }
35
+
36
+ // -- nodes --
37
+ computedNodes = nodes.map((node, i) => {
38
+ const computedNode: ComputedNode = {
39
+ id: node.id,
40
+ index: i,
41
+ label: node.label ?? '',
42
+ description: node.description ?? '',
43
+ // tooltipContent: node.tooltipContent ? node.tooltipContent : dataFormatter.tooltipContentFormat(node, 0, i, context), // 0代表node
44
+ data: node.data ?? {},
45
+ value: node.value ?? 0,
46
+ categoryIndex: 0, // @Q@ 未完成
47
+ categoryLabel: '', // @Q@ 未完成
48
+ color: '', // @Q@ 未完成
49
+ startNodes: [], // 後面再取得資料
50
+ startNodeIds: [], // 後面再取得資料
51
+ endNodes: [], // 後面再取得資料
52
+ endNodeIds: [], // 後面再取得資料
53
+ visible: true // 後面再取得資料
54
+ }
55
+ return computedNode
56
+ })
57
+
58
+ const NodesMap: Map<string, ComputedNode> = new Map(computedNodes.map(d => [d.id, d]))
59
+
60
+ // -- edges --
61
+ computedEdges = edges.map((edge, i) => {
62
+ const computedEdge: ComputedEdge = {
63
+ id: edge.id,
64
+ index: i,
65
+ label: edge.label ?? '',
66
+ description: edge.description ?? '',
67
+ // tooltipContent: edge.tooltipContent ? edge.tooltipContent : dataFormatter.tooltipContentFormat(edge, 1, i, context), // 1代表edge
68
+ data: edge.data ?? {},
69
+ value: edge.value ?? 0,
70
+ startNode: NodesMap.get(edge.start),
71
+ startNodeId: edge.start,
72
+ endNode: NodesMap.get(edge.end),
73
+ endNodeId: edge.end,
74
+ visible: true // 先給預設值
75
+ }
76
+
77
+ return computedEdge
78
+ })
79
+
80
+ const StartNodesMap: Map<string, ComputedNode[]> = (function () {
81
+ const _StartNodesMap = new Map()
82
+ computedEdges.forEach(edge => {
83
+ const startNodes: ComputedNode[] = _StartNodesMap.get(edge.endNodeId) ?? []
84
+ startNodes.push(edge.startNode)
85
+ _StartNodesMap.set(edge.endNodeId, startNodes)
86
+ })
87
+ return _StartNodesMap
88
+ })()
89
+
90
+ const EndNodesMap: Map<string, ComputedNode[]> = (function () {
91
+ const _EndNodesMap = new Map()
92
+ computedEdges.forEach(edge => {
93
+ const endNodes: ComputedNode[] = _EndNodesMap.get(edge.startNodeId) ?? []
94
+ endNodes.push(edge.endNode)
95
+ _EndNodesMap.set(edge.startNodeId, endNodes)
96
+ })
97
+ return _EndNodesMap
98
+ })()
99
+
100
+ // -- 補齊nodes資料 --
101
+ Array.from(NodesMap).forEach(([nodeId, node]) => {
102
+ node.startNodes = StartNodesMap.get(nodeId)
103
+ node.startNodeIds = node.startNodes.map(d => d.id)
104
+ node.endNodes = EndNodesMap.get(nodeId)
105
+ node.endNodeIds = node.endNodes.map(d => d.id)
106
+ node.visible = dataFormatter.visibleFilter(node, context)
107
+ })
108
+
109
+ // -- 補齊edges資料 --
110
+ computedEdges = computedEdges.map(edge => {
111
+ edge.visible = edge.startNode.visible && edge.endNode.visible
112
+ ? true
113
+ : false
114
+ return edge
115
+ })
116
+ } catch (e) {
117
+ // console.error(e)
118
+ throw Error(e)
119
+ }
120
+
121
+ return {
122
+ nodes: computedNodes,
123
+ edges: computedEdges
124
+ }
125
+ }
@@ -1,12 +1,12 @@
1
- import type { ContextObserverFn } from '../types'
2
-
3
- export const createRelationshipContextObserver: ContextObserverFn<'relationship'> = ({ subject, observer }) => {
4
-
5
- return {
6
- fullParams$: observer.fullParams$,
7
- fullChartParams$: observer.fullChartParams$,
8
- fullDataFormatter$: observer.fullDataFormatter$,
9
- computedData$: observer.computedData$,
10
- layout$: observer.layout$,
11
- }
12
- }
1
+ import type { ContextObserverCallback } from '../../lib/core-types'
2
+
3
+ export const contextObserverCallback: ContextObserverCallback<'relationship'> = ({ subject, observer }) => {
4
+
5
+ return {
6
+ fullParams$: observer.fullParams$,
7
+ fullChartParams$: observer.fullChartParams$,
8
+ fullDataFormatter$: observer.fullDataFormatter$,
9
+ computedData$: observer.computedData$,
10
+ layout$: observer.layout$,
11
+ }
12
+ }
@@ -0,0 +1,10 @@
1
+ import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
+
3
+ export const dataFormatterValidator: DataFormatterValidator<'relationship'> = (dataFormatter: DataFormatterTypeMap<'relationship'>) => {
4
+
5
+ return {
6
+ status: 'success',
7
+ columnName: '',
8
+ expectToBe: ''
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
+
3
+ export const dataValidator: DataValidator<'relationship'> = (data: DataTypeMap<'relationship'>) => {
4
+
5
+ return {
6
+ status: 'success',
7
+ columnName: '',
8
+ expectToBe: ''
9
+ }
10
+ }
@@ -1,90 +1,88 @@
1
- import type { DataSeries, DataSeriesDatum } from '../types/DataSeries'
2
- import type { ComputedDataFn } from '../types/ComputedData'
3
- import type { ComputedDatumSeries } from '../types/ComputedDataSeries'
4
- import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
5
-
6
- export const computeSeriesData: ComputedDataFn<'series'> = (context) => {
7
- const { data = [], dataFormatter, chartParams } = context
8
- if (!data.length) {
9
- return []
10
- }
11
-
12
- let computedDataSeries: ComputedDatumSeries[][] = []
13
-
14
- try {
15
-
16
- const createComputedDatumSeries = (seriesData: number | DataSeriesDatum, seriesIndex: number, itemIndex: number, currentIndex: number): ComputedDatumSeries => {
17
- const defaultId = createDefaultDatumId(dataFormatter.type, seriesIndex, itemIndex)
18
- const seriesLabel = dataFormatter.seriesLabels[seriesIndex] || createDefaultSeriesLabel('series', seriesIndex)
19
- const color = seriesColorPredicate(seriesIndex, chartParams)
20
- if (typeof seriesData === 'number') {
21
- return {
22
- id: defaultId,
23
- index: currentIndex,
24
- seq: 0, // 先給預設值
25
- label: defaultId,
26
- description: '',
27
- data: {},
28
- value: seriesData,
29
- seriesIndex: seriesIndex,
30
- seriesLabel,
31
- color,
32
- visible: true // 先給預設值
33
- }
34
- } else {
35
- return {
36
- id: seriesData.id ? seriesData.id : defaultId,
37
- index: currentIndex,
38
- seq: 0, // 先給預設值
39
- label: seriesData.label ? seriesData.label : defaultId,
40
- description: seriesData.description,
41
- data: seriesData.data ?? {},
42
- value: seriesData.value,
43
- seriesIndex: seriesIndex,
44
- seriesLabel,
45
- color,
46
- visible: true // 先給預設值
47
- }
48
- }
49
- }
50
-
51
- computedDataSeries = data
52
- .map((seriesData, seriesIndex) => {
53
- if (Array.isArray(seriesData)) {
54
- return seriesData.map((item, itemIndex) =>
55
- createComputedDatumSeries(item, seriesIndex, itemIndex, computedDataSeries.length + itemIndex)
56
- )
57
- } else {
58
- return createComputedDatumSeries(seriesData, seriesIndex, 0, computedDataSeries.length)
59
- }
60
- })
61
- // 攤為一維陣列
62
- .flat()
63
- // 排序後給 seq
64
- .sort(dataFormatter.sort ?? undefined)
65
- .map((datum, index) => {
66
- datum.seq = index
67
- return datum
68
- })
69
- .map(datum => {
70
- datum.visible = dataFormatter.visibleFilter(datum, context)
71
- return datum
72
- })
73
- // 恢復原排序
74
- .sort((a, b) => a.index - b.index)
75
- // seriesIndex分組(二維陣列)
76
- .reduce((acc, datum) => {
77
- if (!acc[datum.seriesIndex]) {
78
- acc[datum.seriesIndex] = []
79
- }
80
- acc[datum.seriesIndex].push(datum)
81
- return acc
82
- }, [])
83
-
84
- } catch (e) {
85
- // console.error(e)
86
- throw Error(e)
87
- }
88
-
89
- return computedDataSeries
90
- }
1
+ import type { DataSeries, DataSeriesDatum, ComputedDataFn, ComputedDatumSeries } from '../../lib/core-types'
2
+ import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
3
+
4
+ export const computedDataFn: ComputedDataFn<'series'> = (context) => {
5
+ const { data = [], dataFormatter, chartParams } = context
6
+ if (!data.length) {
7
+ return []
8
+ }
9
+
10
+ let computedDataSeries: ComputedDatumSeries[][] = []
11
+
12
+ try {
13
+
14
+ const createComputedDatumSeries = (seriesData: number | DataSeriesDatum, seriesIndex: number, itemIndex: number, currentIndex: number): ComputedDatumSeries => {
15
+ const defaultId = createDefaultDatumId(dataFormatter.type, seriesIndex, itemIndex)
16
+ const seriesLabel = dataFormatter.seriesLabels[seriesIndex] || createDefaultSeriesLabel('series', seriesIndex)
17
+ const color = seriesColorPredicate(seriesIndex, chartParams)
18
+ if (typeof seriesData === 'number') {
19
+ return {
20
+ id: defaultId,
21
+ index: currentIndex,
22
+ seq: 0, // 先給預設值
23
+ label: defaultId,
24
+ description: '',
25
+ data: {},
26
+ value: seriesData,
27
+ seriesIndex: seriesIndex,
28
+ seriesLabel,
29
+ color,
30
+ visible: true // 先給預設值
31
+ }
32
+ } else {
33
+ return {
34
+ id: seriesData.id ? seriesData.id : defaultId,
35
+ index: currentIndex,
36
+ seq: 0, // 先給預設值
37
+ label: seriesData.label ? seriesData.label : defaultId,
38
+ description: seriesData.description,
39
+ data: seriesData.data ?? {},
40
+ value: seriesData.value,
41
+ seriesIndex: seriesIndex,
42
+ seriesLabel,
43
+ color,
44
+ visible: true // 先給預設值
45
+ }
46
+ }
47
+ }
48
+
49
+ computedDataSeries = data
50
+ .map((seriesData, seriesIndex) => {
51
+ if (Array.isArray(seriesData)) {
52
+ return seriesData.map((item, itemIndex) =>
53
+ createComputedDatumSeries(item, seriesIndex, itemIndex, computedDataSeries.length + itemIndex)
54
+ )
55
+ } else {
56
+ return createComputedDatumSeries(seriesData, seriesIndex, 0, computedDataSeries.length)
57
+ }
58
+ })
59
+ // 攤為一維陣列
60
+ .flat()
61
+ // 排序後給 seq
62
+ .sort(dataFormatter.sort ?? undefined)
63
+ .map((datum, index) => {
64
+ datum.seq = index
65
+ return datum
66
+ })
67
+ .map(datum => {
68
+ datum.visible = dataFormatter.visibleFilter(datum, context)
69
+ return datum
70
+ })
71
+ // 恢復原排序
72
+ .sort((a, b) => a.index - b.index)
73
+ // 依seriesIndex分組(二維陣列)
74
+ .reduce((acc, datum) => {
75
+ if (!acc[datum.seriesIndex]) {
76
+ acc[datum.seriesIndex] = []
77
+ }
78
+ acc[datum.seriesIndex].push(datum)
79
+ return acc
80
+ }, [])
81
+
82
+ } catch (e) {
83
+ // console.error(e)
84
+ throw Error(e)
85
+ }
86
+
87
+ return computedDataSeries
88
+ }