@orbcharts/core 3.0.0-alpha.41 → 3.0.0-alpha.43

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +1906 -1897
  3. package/dist/orbcharts-core.umd.js +2 -2
  4. package/dist/src/defaults.d.ts +4 -3
  5. package/dist/src/grid/computeGridData.d.ts +4 -11
  6. package/dist/src/grid/gridObservables.d.ts +15 -18
  7. package/dist/src/multiGrid/multiGridObservables.d.ts +4 -11
  8. package/dist/src/series/seriesObservables.d.ts +26 -1
  9. package/dist/src/types/ComputedData.d.ts +1 -0
  10. package/dist/src/types/ComputedDataGrid.d.ts +0 -3
  11. package/dist/src/types/ComputedDataSeries.d.ts +1 -2
  12. package/dist/src/types/ContextObserverGrid.d.ts +11 -4
  13. package/dist/src/types/ContextObserverMultiGrid.d.ts +8 -3
  14. package/dist/src/types/ContextObserverSeries.d.ts +18 -0
  15. package/dist/src/types/DataFormatter.d.ts +8 -5
  16. package/dist/src/types/DataFormatterGrid.d.ts +13 -16
  17. package/dist/src/types/DataFormatterMultiGrid.d.ts +6 -3
  18. package/dist/src/types/DataFormatterMultiValue.d.ts +3 -0
  19. package/dist/src/types/DataFormatterRelationship.d.ts +3 -0
  20. package/dist/src/types/DataFormatterSeries.d.ts +10 -3
  21. package/dist/src/utils/orbchartsUtils.d.ts +14 -13
  22. package/package.json +41 -41
  23. package/src/AbstractChart.ts +48 -48
  24. package/src/GridChart.ts +20 -20
  25. package/src/MultiGridChart.ts +20 -20
  26. package/src/MultiValueChart.ts +20 -20
  27. package/src/RelationshipChart.ts +20 -20
  28. package/src/SeriesChart.ts +20 -20
  29. package/src/TreeChart.ts +20 -20
  30. package/src/base/createBaseChart.ts +367 -367
  31. package/src/base/createBasePlugin.ts +89 -89
  32. package/src/defaults.ts +220 -248
  33. package/src/defineGridPlugin.ts +3 -3
  34. package/src/defineMultiGridPlugin.ts +3 -3
  35. package/src/defineMultiValuePlugin.ts +3 -3
  36. package/src/defineNoneDataPlugin.ts +4 -4
  37. package/src/defineRelationshipPlugin.ts +3 -3
  38. package/src/defineSeriesPlugin.ts +3 -3
  39. package/src/defineTreePlugin.ts +3 -3
  40. package/src/grid/computeGridData.ts +134 -205
  41. package/src/grid/createGridContextObserver.ts +147 -130
  42. package/src/grid/gridObservables.ts +573 -486
  43. package/src/index.ts +21 -21
  44. package/src/multiGrid/computeMultiGridData.ts +130 -173
  45. package/src/multiGrid/createMultiGridContextObserver.ts +40 -40
  46. package/src/multiGrid/multiGridObservables.ts +350 -285
  47. package/src/multiValue/computeMultiValueData.ts +143 -136
  48. package/src/multiValue/createMultiValueContextObserver.ts +12 -12
  49. package/src/relationship/computeRelationshipData.ts +118 -106
  50. package/src/relationship/createRelationshipContextObserver.ts +12 -12
  51. package/src/series/computeSeriesData.ts +90 -153
  52. package/src/series/createSeriesContextObserver.ts +93 -38
  53. package/src/series/seriesObservables.ts +176 -24
  54. package/src/tree/computeTreeData.ts +131 -128
  55. package/src/tree/createTreeContextObserver.ts +61 -61
  56. package/src/tree/treeObservables.ts +94 -94
  57. package/src/types/Chart.ts +48 -48
  58. package/src/types/ChartParams.ts +51 -51
  59. package/src/types/ComputedData.ts +83 -82
  60. package/src/types/ComputedDataGrid.ts +13 -13
  61. package/src/types/ComputedDataMultiGrid.ts +2 -2
  62. package/src/types/ComputedDataMultiValue.ts +9 -9
  63. package/src/types/ComputedDataRelationship.ts +19 -19
  64. package/src/types/ComputedDataSeries.ts +8 -8
  65. package/src/types/ComputedDataTree.ts +19 -19
  66. package/src/types/ContextObserver.ts +38 -38
  67. package/src/types/ContextObserverGrid.ts +41 -33
  68. package/src/types/ContextObserverMultiGrid.ts +16 -28
  69. package/src/types/ContextObserverMultiValue.ts +4 -4
  70. package/src/types/ContextObserverRelationship.ts +4 -4
  71. package/src/types/ContextObserverSeries.ts +29 -9
  72. package/src/types/ContextObserverTree.ts +11 -11
  73. package/src/types/ContextSubject.ts +18 -18
  74. package/src/types/Data.ts +45 -45
  75. package/src/types/DataFormatter.ts +74 -95
  76. package/src/types/DataFormatterGrid.ts +67 -55
  77. package/src/types/DataFormatterMultiGrid.ts +44 -42
  78. package/src/types/DataFormatterMultiValue.ts +23 -20
  79. package/src/types/DataFormatterRelationship.ts +25 -22
  80. package/src/types/DataFormatterSeries.ts +20 -30
  81. package/src/types/DataFormatterTree.ts +12 -12
  82. package/src/types/DataGrid.ts +11 -11
  83. package/src/types/DataMultiGrid.ts +6 -6
  84. package/src/types/DataMultiValue.ts +12 -12
  85. package/src/types/DataRelationship.ts +27 -27
  86. package/src/types/DataSeries.ts +11 -11
  87. package/src/types/DataTree.ts +20 -20
  88. package/src/types/Event.ts +153 -153
  89. package/src/types/Layout.ts +11 -11
  90. package/src/types/Padding.ts +5 -5
  91. package/src/types/Plugin.ts +60 -60
  92. package/src/types/TransformData.ts +7 -7
  93. package/src/types/index.ts +37 -37
  94. package/src/utils/commonUtils.ts +50 -50
  95. package/src/utils/d3Utils.ts +89 -89
  96. package/src/utils/index.ts +4 -4
  97. package/src/utils/observables.ts +201 -201
  98. package/src/utils/orbchartsUtils.ts +349 -253
  99. package/tsconfig.json +13 -13
  100. package/vite.config.js +44 -44
package/src/index.ts CHANGED
@@ -1,21 +1,21 @@
1
-
2
- export { SeriesChart } from './SeriesChart'
3
- export { GridChart } from './GridChart'
4
- export { MultiGridChart } from './MultiGridChart'
5
- export { MultiValueChart } from './MultiValueChart'
6
- export { RelationshipChart } from './RelationshipChart'
7
- export { TreeChart } from './TreeChart'
8
-
9
- export { defineSeriesPlugin } from './defineSeriesPlugin'
10
- export { defineGridPlugin } from './defineGridPlugin'
11
- export { defineMultiGridPlugin } from './defineMultiGridPlugin'
12
- export { defineMultiValuePlugin } from './defineMultiValuePlugin'
13
- export { defineNoneDataPlugin } from './defineNoneDataPlugin'
14
- export { defineRelationshipPlugin } from './defineRelationshipPlugin'
15
- export { defineTreePlugin } from './defineTreePlugin'
16
-
17
- export * from './types'
18
- export * from './utils'
19
-
20
-
21
-
1
+
2
+ export { SeriesChart } from './SeriesChart'
3
+ export { GridChart } from './GridChart'
4
+ export { MultiGridChart } from './MultiGridChart'
5
+ export { MultiValueChart } from './MultiValueChart'
6
+ export { RelationshipChart } from './RelationshipChart'
7
+ export { TreeChart } from './TreeChart'
8
+
9
+ export { defineSeriesPlugin } from './defineSeriesPlugin'
10
+ export { defineGridPlugin } from './defineGridPlugin'
11
+ export { defineMultiGridPlugin } from './defineMultiGridPlugin'
12
+ export { defineMultiValuePlugin } from './defineMultiValuePlugin'
13
+ export { defineNoneDataPlugin } from './defineNoneDataPlugin'
14
+ export { defineRelationshipPlugin } from './defineRelationshipPlugin'
15
+ export { defineTreePlugin } from './defineTreePlugin'
16
+
17
+ export * from './types'
18
+ export * from './utils'
19
+
20
+
21
+
@@ -1,173 +1,130 @@
1
- import type { DataGrid } from '../types/DataGrid'
2
- import type { ComputedDataFn } from '../types/ComputedData'
3
- import type { ComputedDatumGrid } from '../types/ComputedDataGrid'
4
- import type { DataFormatterContext } from '../types/DataFormatter'
5
- import type { DataFormatterGrid } from '../types/DataFormatterGrid'
6
- import type { ComputedDataMultiGrid } from '../types/ComputedDataMultiGrid'
7
- // import { computeBaseGridData } from '../grid/computeGridData'
8
- import { DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT } from '../defaults'
9
- import {
10
- createDefaultDatumId,
11
- seriesColorPredicate,
12
- createGridSeriesLabels,
13
- createMultiGridSeriesLabels,
14
- createMultiGridGroupLabels
15
- } from '../utils/orbchartsUtils'
16
- import type { DataGridDatumTemp } from '../grid/computeGridData'
17
- import { createTransposedDataGrid, createGroupScale, createSeriesValueScaleArr } from '../grid/computeGridData'
18
-
19
- function createGridData ({ context, gridIndex, transposedDataGrid, gridSeriesLabels, SeriesLabelColorMap }: {
20
- context: DataFormatterContext<'grid'>
21
- gridIndex: number
22
- transposedDataGrid: DataGridDatumTemp[][]
23
- gridSeriesLabels: string[]
24
- SeriesLabelColorMap: Map<string, string>
25
- }) {
26
- const { data = [], dataFormatter, chartParams, layout } = context
27
- if (!data.length) {
28
- return []
29
- }
30
-
31
- const groupScale = createGroupScale(transposedDataGrid, dataFormatter, layout)
32
-
33
- // const seriesLabels = createGridSeriesLabels({ transposedDataGrid, dataFormatter, chartType: 'multiGrid', gridIndex })
34
-
35
- const groupLabels = createMultiGridGroupLabels({ transposedDataGrid, dataFormatter, chartType: 'multiGrid', gridIndex })
36
-
37
- // 每一個series的valueScale
38
- const seriesValueScaleArr = createSeriesValueScaleArr(transposedDataGrid, dataFormatter, layout)
39
-
40
- const zeroYArr = transposedDataGrid.map((series, seriesIndex) => {
41
- return seriesValueScaleArr[seriesIndex]!(0)
42
- })
43
-
44
- let _index = 0
45
- let computedDataGrid: ComputedDatumGrid[][] = transposedDataGrid.map((seriesData, seriesIndex) => {
46
- return seriesData.map((groupDatum, groupIndex) => {
47
-
48
- const defaultId = createDefaultDatumId('multiGrid', gridIndex, seriesIndex, groupIndex)
49
- const groupLabel = groupLabels[groupIndex]
50
- const seriesLabel = gridSeriesLabels[seriesIndex]
51
- const valueScale = seriesValueScaleArr[seriesIndex]
52
- const axisY = valueScale(groupDatum.value ?? 0)
53
- const zeroY = zeroYArr[seriesIndex]
54
-
55
- const computedDatum: ComputedDatumGrid = {
56
- id: groupDatum.id ? groupDatum.id : defaultId,
57
- index: _index,
58
- label: groupDatum.label ? groupDatum.label : defaultId,
59
- description: groupDatum.description ?? '',
60
- data: groupDatum.data,
61
- value: groupDatum.value,
62
- gridIndex,
63
- // accSeriesIndex: seriesIndex, // 預設為seriesIndex
64
- seriesIndex,
65
- seriesLabel,
66
- groupIndex,
67
- groupLabel,
68
- // color: seriesColorPredicate(seriesIndex, chartParams),
69
- color: SeriesLabelColorMap.get(seriesLabel),
70
- axisX: groupScale(groupIndex),
71
- axisY,
72
- axisYFromZero: axisY - zeroY,
73
- visible: groupDatum._visible
74
- }
75
-
76
- _index ++
77
-
78
- return computedDatum
79
- })
80
- })
81
-
82
- return computedDataGrid
83
- }
84
-
85
- export const computeMultiGridData: ComputedDataFn<'multiGrid'> = ({ data = [], dataFormatter, chartParams, layout }) => {
86
- if (!data.length) {
87
- return []
88
- }
89
-
90
- let multiGridData: ComputedDataMultiGrid = []
91
-
92
- try {
93
- const defaultGrid = dataFormatter.gridList[0] || DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT
94
-
95
- // 計算每個grid的dataFormatter
96
- const gridDataFormatterList: DataFormatterGrid[] = data.map((gridData, gridIndex) => {
97
- const currentDataFormatterGrid = dataFormatter.gridList[gridIndex] || defaultGrid
98
-
99
- return {
100
- type: 'grid',
101
- grid: {
102
- ...currentDataFormatterGrid
103
- },
104
- container: {
105
- ...dataFormatter.container
106
- }
107
- }
108
- })
109
-
110
- const gridContextList = data.map((gridData, gridIndex) => {
111
- // grid context
112
- return {
113
- data: gridData,
114
- dataFormatter: gridDataFormatterList[gridIndex],
115
- chartParams,
116
- layout
117
- }
118
- })
119
-
120
- const transposedDataGridList = data.map((gridData, gridIndex) => {
121
- // 依seriesDirection轉置資料矩陣
122
- return createTransposedDataGrid(gridContextList[gridIndex])
123
- })
124
-
125
- const createSeriesLabelsFn = (() => {
126
- const SlotIndexSet = new Set(gridDataFormatterList.map(d => d.grid.slotIndex))
127
- // 判斷是否有重疊的grid
128
- const isOverlappingMultiGrid = SlotIndexSet.size !== gridDataFormatterList.length
129
- return isOverlappingMultiGrid
130
- ? createMultiGridSeriesLabels // 有重疊的grid則使用「不同」的seriesLabels
131
- : createGridSeriesLabels // 沒有重疊的grid則使用「相同」的seriesLabels
132
- })()
133
-
134
-
135
- const multiGridSeriesLabels = transposedDataGridList
136
- .map((gridData, gridIndex) => {
137
- return createSeriesLabelsFn({
138
- transposedDataGrid: gridData,
139
- dataFormatter: gridDataFormatterList[gridIndex],
140
- chartType: 'multiGrid',
141
- gridIndex
142
- } as any)
143
- })
144
-
145
- const SeriesLabelColorMap: Map<string, string> = new Map()
146
- let accIndex = 0
147
- multiGridSeriesLabels.flat().forEach((label, i) => {
148
- if (!SeriesLabelColorMap.has(label)) {
149
- const color = seriesColorPredicate(accIndex, chartParams)
150
- SeriesLabelColorMap.set(label, color)
151
- accIndex ++
152
- }
153
- })
154
-
155
- // 計算每個grid的資料
156
- multiGridData = data.map((gridData, gridIndex) => {
157
- return createGridData({
158
- context: gridContextList[gridIndex],
159
- gridIndex,
160
- transposedDataGrid: transposedDataGridList[gridIndex],
161
- gridSeriesLabels: multiGridSeriesLabels[gridIndex],
162
- SeriesLabelColorMap
163
- })
164
- })
165
-
166
-
167
- } catch (e) {
168
- // console.error(e)
169
- throw Error(e)
170
- }
171
-
172
- return multiGridData
173
- }
1
+ import type { DataGrid, DataGridDatum } from '../types/DataGrid'
2
+ import type { ComputedDataFn } from '../types/ComputedData'
3
+ import type { ComputedDatumGrid } from '../types/ComputedDataGrid'
4
+ import type { DataFormatterContext } from '../types/DataFormatter'
5
+ import type { DataFormatterGridGrid } from '../types/DataFormatterGrid'
6
+ import type { ComputedDataMultiGrid } from '../types/ComputedDataMultiGrid'
7
+ // import { computeBaseGridData } from '../grid/computeGridData'
8
+ import { DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT } from '../defaults'
9
+ import {
10
+ createDefaultDatumId,
11
+ seriesColorPredicate,
12
+ createGridSeriesLabels,
13
+ createMultiGridSeriesLabels,
14
+ createMultiGridGroupLabels
15
+ } from '../utils/orbchartsUtils'
16
+ // import type { DataGridDatumTemp } from '../grid/computeGridData'
17
+ import { createTransposedDataGrid } from '../grid/computeGridData'
18
+
19
+ export const computeMultiGridData: ComputedDataFn<'multiGrid'> = (context) => {
20
+ const { data = [], dataFormatter, chartParams } = context
21
+ if (!data.length) {
22
+ return []
23
+ }
24
+
25
+ let multiGridData: ComputedDataMultiGrid = []
26
+
27
+ try {
28
+ const defaultGrid = dataFormatter.gridList[0] || DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT
29
+
30
+ // 計算每個grid的dataFormatter
31
+ const gridDataFormatterList: DataFormatterGridGrid[] = data.map((gridData, gridIndex) => {
32
+ return dataFormatter.gridList[gridIndex] || defaultGrid
33
+ })
34
+
35
+ const transposedDataGridList = data.map((gridData, gridIndex) => {
36
+ // 依seriesDirection轉置資料矩陣
37
+ return createTransposedDataGrid(gridData, gridDataFormatterList[gridIndex])
38
+ })
39
+
40
+ // const isOverlappingMultiGrid = (() => {
41
+ // const SlotIndexSet = new Set(gridDataFormatterList.map(d => d.slotIndex))
42
+ // // 判斷是否有重疊的grid
43
+ // return SlotIndexSet.size !== gridDataFormatterList.length
44
+ // })()
45
+
46
+ const multiGridSeriesLabels = dataFormatter.separateGrid
47
+ // grid分開的時候,預設每組的seriesLabels相同
48
+ ? transposedDataGridList
49
+ .map((gridData, gridIndex) => {
50
+ return createGridSeriesLabels({
51
+ transposedDataGrid: gridData,
52
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
53
+ chartType: 'multiGrid',
54
+ })
55
+ })
56
+ // grid不分開的時候,預設每個grid相同seriesIndex的seriesLabel相同
57
+ : transposedDataGridList
58
+ .map((gridData, gridIndex) => {
59
+ return createMultiGridSeriesLabels({
60
+ transposedDataGrid: gridData,
61
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
62
+ chartType: 'multiGrid',
63
+ gridIndex
64
+ })
65
+ })
66
+
67
+ const SeriesLabelColorMap: Map<string, string> = new Map()
68
+ let accIndex = 0
69
+ multiGridSeriesLabels.flat().forEach((label, i) => {
70
+ if (!SeriesLabelColorMap.has(label)) {
71
+ const color = seriesColorPredicate(accIndex, chartParams)
72
+ SeriesLabelColorMap.set(label, color)
73
+ accIndex ++
74
+ }
75
+ })
76
+
77
+ // 計算每個grid的資料
78
+ multiGridData = transposedDataGridList.map((gridData, gridIndex) => {
79
+ const gridSeriesLabels = multiGridSeriesLabels[gridIndex]
80
+ const groupLabels = createMultiGridGroupLabels({
81
+ transposedDataGrid: gridData,
82
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
83
+ chartType: 'multiGrid',
84
+ gridIndex
85
+ })
86
+
87
+ let _index = 0
88
+ let computedDataGrid: ComputedDatumGrid[][] = gridData.map((seriesData, seriesIndex) => {
89
+ return seriesData.map((groupDatum, groupIndex) => {
90
+
91
+ const defaultId = createDefaultDatumId('multiGrid', gridIndex, seriesIndex, groupIndex)
92
+ const groupLabel = groupLabels[groupIndex]
93
+ const seriesLabel = gridSeriesLabels[seriesIndex]
94
+
95
+ const computedDatum: ComputedDatumGrid = {
96
+ id: groupDatum.id ? groupDatum.id : defaultId,
97
+ index: _index,
98
+ label: groupDatum.label ? groupDatum.label : defaultId,
99
+ description: groupDatum.description ?? '',
100
+ data: groupDatum.data,
101
+ value: groupDatum.value,
102
+ gridIndex,
103
+ // accSeriesIndex: seriesIndex, // 預設為seriesIndex
104
+ seriesIndex,
105
+ seriesLabel,
106
+ groupIndex,
107
+ groupLabel,
108
+ color: SeriesLabelColorMap.get(seriesLabel),
109
+ visible: true // 先給一個預設值
110
+ }
111
+
112
+ computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
113
+
114
+ _index ++
115
+
116
+ return computedDatum
117
+ })
118
+ })
119
+
120
+ return computedDataGrid
121
+ })
122
+
123
+
124
+ } catch (e) {
125
+ // console.error(e)
126
+ throw Error(e)
127
+ }
128
+
129
+ return multiGridData
130
+ }
@@ -1,40 +1,40 @@
1
- import {
2
- shareReplay } from 'rxjs'
3
- import type { ContextObserverFn } from '../types'
4
- import { multiGridEachDetailObservable, multiGridContainerObservable } from './multiGridObservables'
5
- import { textSizePxObservable } from '../utils/observables'
6
-
7
- export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({ subject, observer }) => {
8
-
9
- const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
10
- shareReplay(1)
11
- )
12
-
13
- const multiGridEachDetail$ = multiGridEachDetailObservable({
14
- fullDataFormatter$: observer.fullDataFormatter$,
15
- computedData$: observer.computedData$,
16
- layout$: observer.layout$,
17
- fullChartParams$: observer.fullChartParams$,
18
- event$: subject.event$
19
- }).pipe(
20
- shareReplay(1)
21
- )
22
-
23
- const multiGridContainer$ = multiGridContainerObservable({
24
- computedData$: observer.computedData$,
25
- fullDataFormatter$: observer.fullDataFormatter$,
26
- fullChartParams$: observer.fullChartParams$,
27
- layout$: observer.layout$,
28
- })
29
-
30
- return {
31
- fullParams$: observer.fullParams$,
32
- fullChartParams$: observer.fullChartParams$,
33
- fullDataFormatter$: observer.fullDataFormatter$,
34
- computedData$: observer.computedData$,
35
- layout$: observer.layout$,
36
- textSizePx$,
37
- multiGridEachDetail$,
38
- multiGridContainer$
39
- }
40
- }
1
+ import {
2
+ shareReplay } from 'rxjs'
3
+ import type { ContextObserverFn } from '../types'
4
+ import { multiGridEachDetailObservable } from './multiGridObservables'
5
+ import { textSizePxObservable } from '../utils/observables'
6
+
7
+ export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({ subject, observer }) => {
8
+
9
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
10
+ shareReplay(1)
11
+ )
12
+
13
+ const multiGridEachDetail$ = multiGridEachDetailObservable({
14
+ fullDataFormatter$: observer.fullDataFormatter$,
15
+ computedData$: observer.computedData$,
16
+ layout$: observer.layout$,
17
+ fullChartParams$: observer.fullChartParams$,
18
+ event$: subject.event$
19
+ }).pipe(
20
+ shareReplay(1)
21
+ )
22
+
23
+ // const multiGridContainer$ = multiGridContainerObservable({
24
+ // computedData$: observer.computedData$,
25
+ // fullDataFormatter$: observer.fullDataFormatter$,
26
+ // fullChartParams$: observer.fullChartParams$,
27
+ // layout$: observer.layout$,
28
+ // })
29
+
30
+ return {
31
+ fullParams$: observer.fullParams$,
32
+ fullChartParams$: observer.fullChartParams$,
33
+ fullDataFormatter$: observer.fullDataFormatter$,
34
+ computedData$: observer.computedData$,
35
+ layout$: observer.layout$,
36
+ textSizePx$,
37
+ multiGridEachDetail$,
38
+ // multiGridContainer$
39
+ }
40
+ }