@orbcharts/core 3.0.0-alpha.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. package/.gitignore +23 -0
  2. package/LICENSE +201 -0
  3. package/dist/orbcharts-core.es.js +5096 -0
  4. package/dist/orbcharts-core.umd.js +3 -0
  5. package/dist/src/AbstractChart.d.ts +17 -0
  6. package/dist/src/GridChart.d.ts +6 -0
  7. package/dist/src/MultiGridChart.d.ts +6 -0
  8. package/dist/src/MultiValueChart.d.ts +6 -0
  9. package/dist/src/RelationshipChart.d.ts +6 -0
  10. package/dist/src/SeriesChart.d.ts +6 -0
  11. package/dist/src/TreeChart.d.ts +6 -0
  12. package/dist/src/base/createBaseChart.d.ts +3 -0
  13. package/dist/src/base/createBasePlugin.d.ts +3 -0
  14. package/dist/src/defaults.d.ts +37 -0
  15. package/dist/src/defineGridPlugin.d.ts +1 -0
  16. package/dist/src/defineMultiGridPlugin.d.ts +1 -0
  17. package/dist/src/defineMultiValuePlugin.d.ts +1 -0
  18. package/dist/src/defineNoneDataPlugin.d.ts +1 -0
  19. package/dist/src/defineRelationshipPlugin.d.ts +1 -0
  20. package/dist/src/defineSeriesPlugin.d.ts +1 -0
  21. package/dist/src/defineTreePlugin.d.ts +1 -0
  22. package/dist/src/grid/computeGridData.d.ts +3 -0
  23. package/dist/src/grid/createGridContextObserver.d.ts +3 -0
  24. package/dist/src/grid/gridObservables.d.ts +25 -0
  25. package/dist/src/index.d.ts +15 -0
  26. package/dist/src/multiGrid/computeMultiGridData.d.ts +3 -0
  27. package/dist/src/multiGrid/createMultiGridContextObserver.d.ts +3 -0
  28. package/dist/src/multiGrid/multiGridObservables.d.ts +0 -0
  29. package/dist/src/multiValue/computeMultiValueData.d.ts +3 -0
  30. package/dist/src/multiValue/createMultiValueContextObserver.d.ts +3 -0
  31. package/dist/src/multiValue/multiValueObservables.d.ts +0 -0
  32. package/dist/src/relationship/computeRelationshipData.d.ts +3 -0
  33. package/dist/src/relationship/createRelationshipContextObserver.d.ts +3 -0
  34. package/dist/src/relationship/relationshipObservables.d.ts +0 -0
  35. package/dist/src/series/computeSeriesData.d.ts +3 -0
  36. package/dist/src/series/createSeriesContextObserver.d.ts +3 -0
  37. package/dist/src/series/seriesObservables.d.ts +8 -0
  38. package/dist/src/tree/computeTreeData.d.ts +3 -0
  39. package/dist/src/tree/createTreeContextObserver.d.ts +3 -0
  40. package/dist/src/tree/treeObservables.d.ts +0 -0
  41. package/dist/src/types/Axis.d.ts +1 -0
  42. package/dist/src/types/Chart.d.ts +41 -0
  43. package/dist/src/types/ChartParams.d.ts +36 -0
  44. package/dist/src/types/ComputedData.d.ts +28 -0
  45. package/dist/src/types/ComputedDataGrid.d.ts +10 -0
  46. package/dist/src/types/ComputedDataMultiGrid.d.ts +3 -0
  47. package/dist/src/types/ComputedDataMultiValue.d.ts +6 -0
  48. package/dist/src/types/ComputedDataRelationship.d.ts +18 -0
  49. package/dist/src/types/ComputedDataSeries.d.ts +6 -0
  50. package/dist/src/types/ComputedDataTree.d.ts +7 -0
  51. package/dist/src/types/ContextObserver.d.ts +28 -0
  52. package/dist/src/types/ContextObserverGrid.d.ts +18 -0
  53. package/dist/src/types/ContextObserverMultiGrid.d.ts +4 -0
  54. package/dist/src/types/ContextObserverMultiValue.d.ts +4 -0
  55. package/dist/src/types/ContextObserverRelationship.d.ts +4 -0
  56. package/dist/src/types/ContextObserverSeries.d.ts +8 -0
  57. package/dist/src/types/ContextObserverTree.d.ts +4 -0
  58. package/dist/src/types/ContextSubject.d.ts +15 -0
  59. package/dist/src/types/Data.d.ts +19 -0
  60. package/dist/src/types/DataFormatter.d.ts +40 -0
  61. package/dist/src/types/DataFormatterGrid.d.ts +20 -0
  62. package/dist/src/types/DataFormatterMultiGrid.d.ts +16 -0
  63. package/dist/src/types/DataFormatterMultiValue.d.ts +13 -0
  64. package/dist/src/types/DataFormatterRelationship.d.ts +5 -0
  65. package/dist/src/types/DataFormatterSeries.d.ts +10 -0
  66. package/dist/src/types/DataFormatterTree.d.ts +5 -0
  67. package/dist/src/types/DataGrid.d.ts +6 -0
  68. package/dist/src/types/DataMultiGrid.d.ts +6 -0
  69. package/dist/src/types/DataMultiValue.d.ts +6 -0
  70. package/dist/src/types/DataRelationship.d.ts +20 -0
  71. package/dist/src/types/DataSeries.d.ts +6 -0
  72. package/dist/src/types/DataTree.d.ts +13 -0
  73. package/dist/src/types/Event.d.ts +64 -0
  74. package/dist/src/types/Layout.d.ts +8 -0
  75. package/dist/src/types/Padding.d.ts +6 -0
  76. package/dist/src/types/Plugin.d.ts +37 -0
  77. package/dist/src/types/TransformData.d.ts +8 -0
  78. package/dist/src/types/index.d.ts +37 -0
  79. package/dist/src/utils/commonUtils.d.ts +8 -0
  80. package/dist/src/utils/d3Utils.d.ts +25 -0
  81. package/dist/src/utils/index.d.ts +4 -0
  82. package/dist/src/utils/observables.d.ts +14 -0
  83. package/dist/src/utils/orbchartsUtils.d.ts +20 -0
  84. package/dist/vite.config.d.ts +2 -0
  85. package/package.json +40 -0
  86. package/src/AbstractChart.ts +48 -0
  87. package/src/GridChart.ts +21 -0
  88. package/src/MultiGridChart.ts +21 -0
  89. package/src/MultiValueChart.ts +21 -0
  90. package/src/RelationshipChart.ts +21 -0
  91. package/src/SeriesChart.ts +21 -0
  92. package/src/TreeChart.ts +21 -0
  93. package/src/base/createBaseChart.ts +329 -0
  94. package/src/base/createBasePlugin.ts +89 -0
  95. package/src/defaults.ts +229 -0
  96. package/src/defineGridPlugin.ts +3 -0
  97. package/src/defineMultiGridPlugin.ts +3 -0
  98. package/src/defineMultiValuePlugin.ts +3 -0
  99. package/src/defineNoneDataPlugin.ts +4 -0
  100. package/src/defineRelationshipPlugin.ts +3 -0
  101. package/src/defineSeriesPlugin.ts +3 -0
  102. package/src/defineTreePlugin.ts +3 -0
  103. package/src/grid/computeGridData.ts +192 -0
  104. package/src/grid/createGridContextObserver.ts +91 -0
  105. package/src/grid/gridObservables.ts +359 -0
  106. package/src/index.ts +21 -0
  107. package/src/multiGrid/computeMultiGridData.ts +48 -0
  108. package/src/multiGrid/createMultiGridContextObserver.ts +12 -0
  109. package/src/multiGrid/multiGridObservables.ts +0 -0
  110. package/src/multiValue/computeMultiValueData.ts +127 -0
  111. package/src/multiValue/createMultiValueContextObserver.ts +12 -0
  112. package/src/multiValue/multiValueObservables.ts +0 -0
  113. package/src/relationship/computeRelationshipData.ts +101 -0
  114. package/src/relationship/createRelationshipContextObserver.ts +12 -0
  115. package/src/relationship/relationshipObservables.ts +0 -0
  116. package/src/series/computeSeriesData.ts +154 -0
  117. package/src/series/createSeriesContextObserver.ts +33 -0
  118. package/src/series/seriesObservables.ts +23 -0
  119. package/src/tree/computeTreeData.ts +104 -0
  120. package/src/tree/createTreeContextObserver.ts +12 -0
  121. package/src/tree/treeObservables.ts +0 -0
  122. package/src/types/Axis.ts +1 -0
  123. package/src/types/Chart.ts +46 -0
  124. package/src/types/ChartParams.ts +50 -0
  125. package/src/types/ComputedData.ts +66 -0
  126. package/src/types/ComputedDataGrid.ts +12 -0
  127. package/src/types/ComputedDataMultiGrid.ts +3 -0
  128. package/src/types/ComputedDataMultiValue.ts +10 -0
  129. package/src/types/ComputedDataRelationship.ts +20 -0
  130. package/src/types/ComputedDataSeries.ts +8 -0
  131. package/src/types/ComputedDataTree.ts +20 -0
  132. package/src/types/ContextObserver.ts +38 -0
  133. package/src/types/ContextObserverGrid.ts +16 -0
  134. package/src/types/ContextObserverMultiGrid.ts +5 -0
  135. package/src/types/ContextObserverMultiValue.ts +5 -0
  136. package/src/types/ContextObserverRelationship.ts +5 -0
  137. package/src/types/ContextObserverSeries.ts +8 -0
  138. package/src/types/ContextObserverTree.ts +5 -0
  139. package/src/types/ContextSubject.ts +18 -0
  140. package/src/types/Data.ts +45 -0
  141. package/src/types/DataFormatter.ts +99 -0
  142. package/src/types/DataFormatterGrid.ts +40 -0
  143. package/src/types/DataFormatterMultiGrid.ts +23 -0
  144. package/src/types/DataFormatterMultiValue.ts +19 -0
  145. package/src/types/DataFormatterRelationship.ts +23 -0
  146. package/src/types/DataFormatterSeries.ts +26 -0
  147. package/src/types/DataFormatterTree.ts +10 -0
  148. package/src/types/DataGrid.ts +11 -0
  149. package/src/types/DataMultiGrid.ts +7 -0
  150. package/src/types/DataMultiValue.ts +11 -0
  151. package/src/types/DataRelationship.ts +27 -0
  152. package/src/types/DataSeries.ts +11 -0
  153. package/src/types/DataTree.ts +18 -0
  154. package/src/types/Event.ts +114 -0
  155. package/src/types/Layout.ts +12 -0
  156. package/src/types/Padding.ts +6 -0
  157. package/src/types/Plugin.ts +60 -0
  158. package/src/types/TransformData.ts +8 -0
  159. package/src/types/index.ts +37 -0
  160. package/src/utils/commonUtils.ts +50 -0
  161. package/src/utils/d3Utils.ts +87 -0
  162. package/src/utils/index.ts +4 -0
  163. package/src/utils/observables.ts +198 -0
  164. package/src/utils/orbchartsUtils.ts +150 -0
  165. package/tsconfig.json +14 -0
  166. package/vite.config.js +45 -0
@@ -0,0 +1,229 @@
1
+ // import type { ChartGlobalDefault } from './types/Chart'
2
+ // import { ChartRenderOptions } from './types/Chart'
3
+ import type { ChartType, ChartOptionsPartial } from './types/Chart'
4
+ import type { DataSeries } from './types/DataSeries'
5
+ import type { DataGrid } from './types/DataGrid'
6
+ import type { DataMultiGrid } from './types/DataMultiGrid'
7
+ import type { DataMultiValue } from './types/DataMultiValue'
8
+ import type { DataTree } from './types/DataTree'
9
+ import type { DataRelationship } from './types/DataRelationship'
10
+ import type { DataFormatterBase, DataFormatterValueAxis, DataFormatterGroupAxis } from './types/DataFormatter'
11
+ import type { DataFormatterSeries } from './types/DataFormatterSeries'
12
+ import type { DataFormatterGrid } from './types/DataFormatterGrid'
13
+ import type { DataFormatterMultiGrid } from './types/DataFormatterMultiGrid'
14
+ import type { DataFormatterMultiValue } from './types/DataFormatterMultiValue'
15
+ import type { DataFormatterTree } from './types/DataFormatterTree'
16
+ import type { DataFormatterRelationship } from './types/DataFormatterRelationship'
17
+ import type { ChartParams } from './types/ChartParams'
18
+ import type { Padding } from './types/Padding'
19
+
20
+ export const CHART_OPTIONS_DEFAULT: ChartOptionsPartial<any> = {
21
+ preset: {} // 預設為空
22
+ }
23
+
24
+ // export const GLOBAL_DEFAULT: ChartGlobalDefault = {
25
+ // colors: ['#67B7DC', '#6794DC', '#6771DC', '#8067DC', '#A367DC', '#C767DC', '#DC67CE', '#DC67AB', '#DC6788', '#DC6967', '#DC8C67', '#DCAF67'],
26
+ // padding: {
27
+ // top: 50,
28
+ // right: 70,
29
+ // bottom: 50,
30
+ // left: 70
31
+ // },
32
+ // // chartWidth: '100%',
33
+ // // chartHeight: 500
34
+ // }
35
+
36
+ // export const COLORS_DEFAULT = ['#67B7DC', '#6794DC', '#6771DC', '#8067DC', '#A367DC', '#C767DC', '#DC67CE', '#DC67AB', '#DC6788', '#DC6967', '#DC8C67', '#DCAF67']
37
+ // @Q@ 桃園儀表板
38
+ // ['#ff7ab9', '#66dec8', '#84c8ff', '#30ad1b', '#f8c43e', '#fa5640', '#9d79d7', '#ea4f98']
39
+
40
+ export const PADDING_DEFAULT: Padding = {
41
+ top: 60,
42
+ right: 60,
43
+ bottom: 60,
44
+ left: 60
45
+ }
46
+
47
+ // export const HIGHLIGHT_DEFAULT: HighlightDefault = {
48
+ // // trigger: 'datum',
49
+ // id: null,
50
+ // label: null
51
+ // }
52
+
53
+ export const CHART_PARAMS_DEFAULT: ChartParams = {
54
+ padding: PADDING_DEFAULT,
55
+ highlightTarget: 'datum',
56
+ // highlightDefault: HIGHLIGHT_DEFAULT,
57
+ highlightDefault: null,
58
+ colorScheme: 'light',
59
+ colors: {
60
+ light: {
61
+ series: ['#67B7DC', '#6794DC', '#6771DC', '#8067DC', '#A367DC', '#C767DC', '#DC67CE', '#DC67AB', '#DC6788', '#DC6967', '#DC8C67', '#DCAF67'],
62
+ primary: '#454545',
63
+ secondary: '#e1e1e1',
64
+ white: '#f0f0f0',
65
+ background: '#ffffff'
66
+ },
67
+ dark: {
68
+ series: ['#67B7DC', '#6794DC', '#6771DC', '#8067DC', '#A367DC', '#C767DC', '#DC67CE', '#DC67AB', '#DC6788', '#DC6967', '#DC8C67', '#DCAF67'],
69
+ primary: '#f0f0f0',
70
+ secondary: '#e1e1e1',
71
+ white: '#f0f0f0',
72
+ background: '#000000'
73
+ }
74
+ },
75
+ styles: {
76
+ textSize: 14,
77
+ unhighlightedOpacity: 0.3
78
+ },
79
+ transitionDuration: 800,
80
+ transitionEase: 'easeCubic'
81
+ }
82
+
83
+ export const CHART_WIDTH_DEFAULT = 800
84
+
85
+ export const CHART_HEIGHT_DEFAULT = 500
86
+
87
+ // -- Data --
88
+
89
+ export const DATA_SERIES_DEFAULT: DataSeries = []
90
+
91
+ export const DATA_GRID_DEFAULT: DataGrid = []
92
+
93
+ export const DATA_MULTI_GRID_DEFAULT: DataMultiGrid = []
94
+
95
+ export const DATA_MULTI_VALUE_DEFAULT: DataMultiValue = []
96
+
97
+ export const DATA_TREE_DEFAULT: DataTree = []
98
+
99
+ export const DATA_RELATIONA_DEFAULTL: DataRelationship = {
100
+ nodes: [],
101
+ edges: []
102
+ }
103
+
104
+ // -- Data Formatter --
105
+
106
+ // 基本欄位
107
+ export const DATA_FORMATTER: DataFormatterBase<ChartType> = {
108
+ // ...GLOBAL_DEFAULT,
109
+ type: ('' as any), // 後面需複蓋掉否則會有問題
110
+ visibleFilter: (datum, rowIndex, columnIndex, context) => true,
111
+ tooltipContentFormat: (datum, rowIndex, columnIndex, context) => {
112
+ if (typeof datum === 'object') {
113
+ if (datum.tooltipContent) {
114
+ return datum.tooltipContent
115
+ } else if (datum.value) {
116
+ return String(datum.value)
117
+ }
118
+ } else if (typeof datum === 'number') {
119
+ return String(datum)
120
+ } else {
121
+ return ''
122
+ }
123
+ }
124
+ }
125
+ // 有value
126
+ // export const DATA_FORMATTER_WITH_VALUE: DataFormatterValue = {
127
+ // valueFormat: ',.0f'
128
+ // }
129
+ // 有axis
130
+ // export const DATA_FORMATTER_WITH_AXIS: DataFormatterAxis = {
131
+ // // domainMinValue: 0,
132
+ // // domainMaxValue: undefined,
133
+ // // domainMinRange: undefined,
134
+ // // domainMaxRange: 0.9
135
+ // valueDomain: [0, 'auto'],
136
+ // valueRange: [0, 0.9]
137
+ // }
138
+
139
+ export const DATA_FORMATTER_VALUE_AXIS: DataFormatterValueAxis = {
140
+ position: 'left',
141
+ scaleDomain: [0, 'auto'],
142
+ scaleRange: [0, 0.9],
143
+ label: '',
144
+ }
145
+
146
+ export const DATA_FORMATTER_GROUP_AXIS: DataFormatterGroupAxis = {
147
+ position: 'bottom',
148
+ scaleDomain: [0, 'auto'],
149
+ scalePadding: 0.5,
150
+ label: ''
151
+ }
152
+
153
+ export const DATA_FORMATTER_SERIES_DEFAULT: DataFormatterSeries = {
154
+ ...DATA_FORMATTER,
155
+ // ...DATA_FORMATTER_WITH_VALUE,
156
+ type: 'series',
157
+ unitLabel: '',
158
+ seriesLabels: [],
159
+ // mapSeries: (datum, rowIndex, columnIndex, { data, dataFormatter }) => {
160
+ // const seriesIndex = rowIndex >= dataFormatter.seriesLabels.length
161
+ // ? rowIndex % dataFormatter.seriesLabels.length // 如果index大於所設定的seriesLabels的數量則從頭回來算
162
+ // : rowIndex
163
+ // return dataFormatter.seriesLabels[seriesIndex]
164
+ // },
165
+ colorsPredicate: (datum, rowIndex, columnIndex, { chartParams }) => {
166
+ return chartParams.colors[chartParams.colorScheme].series[rowIndex]
167
+ },
168
+ sort: null,
169
+ }
170
+
171
+ export const DATA_FORMATTER_GRID_DEFAULT: DataFormatterGrid = {
172
+ ...DATA_FORMATTER,
173
+ // ...DATA_FORMATTER_WITH_VALUE,
174
+ type: 'grid',
175
+ grid: {
176
+ // rowUnitLabel: '',
177
+ rowLabels: [],
178
+ // rowLabelFormat: label => label,
179
+ // columnUnitLabel: '',
180
+ columnLabels: [],
181
+ // columnLabelFormat: label => label,
182
+ seriesType: 'row'
183
+ },
184
+ valueAxis: { ...DATA_FORMATTER_VALUE_AXIS },
185
+ groupAxis: { ...DATA_FORMATTER_GROUP_AXIS, },
186
+ // visibleGroupRange: null,
187
+ colorsPredicate: (datum, rowIndex, columnIndex, { chartParams, dataFormatter }) => {
188
+ const seriesIndex = dataFormatter.grid.seriesType === 'row' ? rowIndex : columnIndex
189
+ return chartParams.colors[chartParams.colorScheme].series[seriesIndex]
190
+ },
191
+ }
192
+
193
+ export const DATA_FORMATTER_MULTI_GRID_DEFAULT: DataFormatterMultiGrid = {
194
+ ...DATA_FORMATTER,
195
+ type: 'multiGrid',
196
+ multiGrid: [], // 預設無資料,由各plugin定義預設值
197
+ // visibleGroupRange: null,
198
+ }
199
+
200
+ export const DATA_FORMATTER_MULTI_VALUE_DEFAULT: DataFormatterMultiValue = {
201
+ ...DATA_FORMATTER,
202
+ type: 'multiValue',
203
+ // labelFormat: (datum: any) => (datum && datum.label) ?? '',
204
+ multiValue: [], // 預設無資料,由各plugin定義預設值
205
+ xAxis: { ...DATA_FORMATTER_VALUE_AXIS },
206
+ yAxis: { ...DATA_FORMATTER_VALUE_AXIS },
207
+ }
208
+
209
+ export const DATA_FORMATTER_TREE_DEFAULT: DataFormatterTree = {
210
+ ...DATA_FORMATTER,
211
+ type: 'tree',
212
+ // labelFormat: (datum: any) => (datum && datum.label) ?? '',
213
+ }
214
+
215
+ export const DATA_FORMATTER_RELATIONAL_DEFAULT: DataFormatterRelationship = {
216
+ ...DATA_FORMATTER,
217
+ type: 'relationship',
218
+ // node: {
219
+ // // labelFormat: (node: any) => (node && node.label) ?? '',
220
+ // descriptionFormat: (node: any) => (node && node.label) ?? ''
221
+ // },
222
+ // edge: {
223
+ // // labelFormat: (edge: any) => (edge && edge.label) ?? '',
224
+ // descriptionFormat: (edge: any) => (edge && edge.label) ?? ''
225
+ // },
226
+ }
227
+
228
+ // -- Render Data --
229
+
@@ -0,0 +1,3 @@
1
+ import { createBasePlugin } from './base/createBasePlugin'
2
+
3
+ export const defineGridPlugin = createBasePlugin<'grid'>()
@@ -0,0 +1,3 @@
1
+ import { createBasePlugin } from './base/createBasePlugin'
2
+
3
+ export const defineMultiGridPlugin = createBasePlugin<'multiGrid'>()
@@ -0,0 +1,3 @@
1
+ import { createBasePlugin } from './base/createBasePlugin'
2
+
3
+ export const defineMultiValuePlugin = createBasePlugin<'multiValue'>()
@@ -0,0 +1,4 @@
1
+ import { createBasePlugin } from './base/createBasePlugin'
2
+ import { ChartType } from './types/Chart'
3
+
4
+ export const defineNoneDataPlugin = createBasePlugin<any>() // noneDataPlugin 可以使用在任何的 chartType
@@ -0,0 +1,3 @@
1
+ import { createBasePlugin } from './base/createBasePlugin'
2
+
3
+ export const defineRelationshipPlugin = createBasePlugin<'relationship'>()
@@ -0,0 +1,3 @@
1
+ import { createBasePlugin } from './base/createBasePlugin'
2
+
3
+ export const defineSeriesPlugin = createBasePlugin<'series'>()
@@ -0,0 +1,3 @@
1
+ import { createBasePlugin } from './base/createBasePlugin'
2
+
3
+ export const defineTreePlugin = createBasePlugin<'tree'>()
@@ -0,0 +1,192 @@
1
+ import * as d3 from 'd3'
2
+ import type { ComputedDataFn } from '../types/ComputedData'
3
+ import type { DataGrid, DataGridDatum } from '../types/DataGrid'
4
+ import type { DataFormatterContext } from '../types/DataFormatter'
5
+ import type { DataFormatterGrid } from '../types/DataFormatterGrid'
6
+ import type { ComputedDataGrid, ComputedDatumGrid } from '../types/ComputedDataGrid'
7
+ import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, createDefaultGroupLabel } from '../utils/orbchartsUtils'
8
+ import { createAxisLinearScale, createAxisPointScale } from '../utils/d3Utils'
9
+ import { getMinAndMaxValue, transposeData, createGridSeriesLabels, createGridGroupLabels } from '../utils/orbchartsUtils'
10
+
11
+ interface DataGridDatumTemp extends DataGridDatum {
12
+ _color: string // 暫放的顏色資料
13
+ _visible: boolean // 暫放的visible
14
+ }
15
+
16
+ export const computeGridData: ComputedDataFn<'grid'> = (context) => {
17
+ const { data = [], dataFormatter, chartParams, layout } = context
18
+ if (!data.length) {
19
+ return []
20
+ }
21
+
22
+ let computedDataGrid: ComputedDatumGrid[][]
23
+
24
+ try {
25
+ // 最多的array length
26
+ const maxArrayLength = data.reduce((prev, current) => {
27
+ return current.length > prev ? current.length : prev
28
+ }, 0)
29
+
30
+ // 補齊短少資料
31
+ const fullData = data.map((d, i) => {
32
+ if (d.length === maxArrayLength) {
33
+ return d
34
+ }
35
+ const newD = Object.assign([], d)
36
+ for (let _i = newD.length; _i < maxArrayLength; _i++) {
37
+ newD[_i] = null
38
+ }
39
+ return newD
40
+ })
41
+
42
+ // 完整的資料格式
43
+ const dataGrid: DataGridDatumTemp[][] = fullData.map((d, i) => {
44
+ return d.map((_d, _i) => {
45
+
46
+ const _color = dataFormatter.colorsPredicate(_d, i, _i, context)
47
+ const _visible = dataFormatter.visibleFilter(_d, i, _i, context)
48
+
49
+ const datum: DataGridDatumTemp = _d == null
50
+ ? {
51
+ id: '',
52
+ label: '',
53
+ tooltipContent: '',
54
+ data: {},
55
+ value: null,
56
+ _color,
57
+ _visible
58
+ }
59
+ : typeof _d === 'number'
60
+ ? {
61
+ id: '',
62
+ label: '',
63
+ tooltipContent: '',
64
+ data: {},
65
+ value: _d,
66
+ _color,
67
+ _visible
68
+ }
69
+ : {
70
+ id: _d.id ?? '',
71
+ label: _d.label ?? '',
72
+ tooltipContent: _d.tooltipContent ?? '',
73
+ data: _d.data ?? {},
74
+ value: _d.value,
75
+ _color,
76
+ _visible
77
+ }
78
+
79
+ return datum
80
+ })
81
+ })
82
+
83
+ // 依seriesType轉置資料矩陣
84
+ const transposedDataGrid = transposeData(dataFormatter.grid.seriesType, dataGrid)
85
+
86
+ // -- groupScale --
87
+ const groupAxisWidth = (dataFormatter.groupAxis.position === 'top' || dataFormatter.groupAxis.position === 'bottom')
88
+ ? layout.width
89
+ : layout.height
90
+ const groupEndIndex = transposedDataGrid[0] ? transposedDataGrid[0].length - 1 : 0
91
+ const groupScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
92
+ maxValue: groupEndIndex,
93
+ minValue: 0,
94
+ axisWidth: groupAxisWidth,
95
+ scaleDomain: [0, groupEndIndex], // 不使用dataFormatter設定
96
+ scaleRange: [0, 1] // 不使用dataFormatter設定
97
+ })
98
+
99
+ // const seriesColors = chartParams.colors[chartParams.colorScheme].series
100
+
101
+ const groupScaleDomain = [
102
+ dataFormatter.groupAxis.scaleDomain[0] === 'auto'
103
+ ? 0
104
+ : dataFormatter.groupAxis.scaleDomain[0],
105
+ dataFormatter.groupAxis.scaleDomain[1] === 'auto'
106
+ ? groupEndIndex
107
+ : dataFormatter.groupAxis.scaleDomain[1]
108
+ ]
109
+
110
+
111
+ // -- 依groupScale算visible --
112
+ // 篩選顯示狀態
113
+ // const scaleDomainFilter = (columnIndex: number) => {
114
+ // // 如果groupIndex不在scale的範圍內則為false,不再做visibleFilter的判斷
115
+ // if (columnIndex < groupScaleDomain[0] || columnIndex > groupScaleDomain[1]) {
116
+ // return false
117
+ // }
118
+ // return true
119
+ // }
120
+ // transposedDataGrid.forEach((seriesData, seriesIndex) => {
121
+ // seriesData.forEach((groupDatum, groupIndex) => {
122
+ // // in-place修改visible
123
+ // groupDatum._visible = groupDatum._visible == true && scaleDomainFilter(groupIndex) == true
124
+ // ? true
125
+ // : false // 兩者有一個false即為false
126
+ // })
127
+ // })
128
+
129
+ // -- valueScale --
130
+ const visibleData = transposedDataGrid.flat().filter(d => d._visible != false)
131
+ const [minValue, maxValue] = getMinAndMaxValue(visibleData)
132
+
133
+ const valueAxisWidth = (dataFormatter.valueAxis.position === 'left' || dataFormatter.valueAxis.position === 'right')
134
+ ? layout.height
135
+ : layout.width
136
+
137
+ const seriesLabels = createGridSeriesLabels(transposedDataGrid, dataFormatter)
138
+ const groupLabels = createGridGroupLabels(transposedDataGrid, dataFormatter)
139
+
140
+ const valueScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
141
+ maxValue,
142
+ minValue,
143
+ axisWidth: valueAxisWidth,
144
+ scaleDomain: [minValue, maxValue], // 不使用dataFormatter設定
145
+ scaleRange: [0, 1] // 不使用dataFormatter設定
146
+ })
147
+
148
+ const zeroY = valueScale(0)
149
+
150
+ let _index = 0
151
+ computedDataGrid = transposedDataGrid.map((seriesData, seriesIndex) => {
152
+ return seriesData.map((groupDatum, groupIndex) => {
153
+
154
+ const defaultId = createDefaultDatumId(dataFormatter.type, seriesIndex, groupIndex)
155
+ // const visible = visibleFilter(groupDatum, seriesIndex, groupIndex, context)
156
+ const groupLabel = groupLabels[groupIndex]
157
+ const axisY = valueScale(groupDatum.value ?? 0)
158
+
159
+ const computedDatum: ComputedDatumGrid = {
160
+ id: groupDatum.id ? groupDatum.id : defaultId,
161
+ index: _index,
162
+ label: groupDatum.label ? groupDatum.label : defaultId,
163
+ tooltipContent: groupDatum.tooltipContent ? groupDatum.tooltipContent : dataFormatter.tooltipContentFormat(groupDatum, seriesIndex, groupIndex, context),
164
+ data: groupDatum.data,
165
+ value: groupDatum.value,
166
+ // valueLabel: formatValueToLabel(groupDatum.value, dataFormatter.valueFormat),
167
+ seriesIndex,
168
+ seriesLabel: seriesLabels[seriesIndex],
169
+ groupIndex,
170
+ groupLabel,
171
+ // color: seriesColors[seriesIndex],
172
+ color: groupDatum._color,
173
+ axisX: groupScale(groupIndex),
174
+ axisY,
175
+ axisYFromZero: axisY - zeroY,
176
+ // visible: groupDatum._visible == true && scaleDomainFilter(groupIndex) == true ? true : false // 兩者有一個false即為false
177
+ visible: groupDatum._visible
178
+ }
179
+
180
+ _index ++
181
+
182
+ return computedDatum
183
+ })
184
+ })
185
+
186
+ } catch (e) {
187
+ // console.error(e)
188
+ throw Error(e)
189
+ }
190
+
191
+ return computedDataGrid
192
+ }
@@ -0,0 +1,91 @@
1
+ import { map, shareReplay } from 'rxjs'
2
+ import type { ContextObserverFn } from '../types'
3
+ import {
4
+ highlightObservable,
5
+ seriesDataMapObservable,
6
+ groupDataMapObservable } from '../utils/observables'
7
+ import {
8
+ gridAxesTransformObservable,
9
+ gridGraphicTransformObservable,
10
+ gridAxesOppositeTransformObservable,
11
+ gridAxesSizeObservable,
12
+ gridVisibleComputedDataObservable } from './gridObservables'
13
+
14
+ export const createGridContextObserver: ContextObserverFn<'grid'> = ({ subject, observer }) => {
15
+
16
+ const gridAxesTransform$ = gridAxesTransformObservable({
17
+ fullDataFormatter$: observer.fullDataFormatter$,
18
+ layout$: observer.layout$
19
+ }).pipe(
20
+ shareReplay(1)
21
+ )
22
+
23
+ const gridGraphicTransform$ = gridGraphicTransformObservable({
24
+ computedData$: observer.computedData$,
25
+ fullDataFormatter$: observer.fullDataFormatter$,
26
+ layout$: observer.layout$
27
+ }).pipe(
28
+ shareReplay(1)
29
+ )
30
+
31
+ const gridAxesOppositeTransform$ = gridAxesOppositeTransformObservable({
32
+ gridAxesTransform$
33
+ }).pipe(
34
+ shareReplay(1)
35
+ )
36
+
37
+ const gridAxesSize$ = gridAxesSizeObservable({
38
+ fullDataFormatter$: observer.fullDataFormatter$,
39
+ layout$: observer.layout$
40
+ }).pipe(
41
+ shareReplay(1)
42
+ )
43
+
44
+ const datumList$ = observer.computedData$.pipe(
45
+ map(d => d.flat())
46
+ ).pipe(
47
+ shareReplay(1)
48
+ )
49
+
50
+ const gridHighlight$ = highlightObservable({
51
+ datumList$,
52
+ fullChartParams$: observer.fullChartParams$,
53
+ event$: subject.event$
54
+ }).pipe(
55
+ shareReplay(1)
56
+ )
57
+
58
+ const SeriesDataMap$ = seriesDataMapObservable({
59
+ datumList$: datumList$
60
+ }).pipe(
61
+ shareReplay(1)
62
+ )
63
+
64
+ const GroupDataMap$ = groupDataMapObservable({
65
+ datumList$: datumList$
66
+ }).pipe(
67
+ shareReplay(1)
68
+ )
69
+
70
+ const visibleComputedData$ = gridVisibleComputedDataObservable({
71
+ computedData$: observer.computedData$,
72
+ }).pipe(
73
+ shareReplay(1)
74
+ )
75
+
76
+ return {
77
+ fullParams$: observer.fullParams$,
78
+ fullChartParams$: observer.fullChartParams$,
79
+ fullDataFormatter$: observer.fullDataFormatter$,
80
+ computedData$: observer.computedData$,
81
+ layout$: observer.layout$,
82
+ gridAxesTransform$,
83
+ gridGraphicTransform$,
84
+ gridAxesOppositeTransform$,
85
+ gridAxesSize$,
86
+ gridHighlight$,
87
+ SeriesDataMap$,
88
+ GroupDataMap$,
89
+ visibleComputedData$
90
+ }
91
+ }