@orbcharts/core 3.0.3 → 3.0.5

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 (70) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +1896 -1847
  3. package/dist/orbcharts-core.umd.js +5 -5
  4. package/dist/src/series/seriesObservables.d.ts +18 -7
  5. package/dist/src/utils/errorMessage.d.ts +1 -4
  6. package/lib/core-types.ts +7 -7
  7. package/package.json +46 -46
  8. package/src/AbstractChart.ts +57 -57
  9. package/src/GridChart.ts +24 -24
  10. package/src/MultiGridChart.ts +24 -24
  11. package/src/MultiValueChart.ts +24 -24
  12. package/src/RelationshipChart.ts +24 -24
  13. package/src/SeriesChart.ts +24 -24
  14. package/src/TreeChart.ts +24 -24
  15. package/src/base/createBaseChart.ts +524 -526
  16. package/src/base/createBasePlugin.ts +154 -154
  17. package/src/base/validators/chartOptionsValidator.ts +23 -23
  18. package/src/base/validators/chartParamsValidator.ts +133 -133
  19. package/src/base/validators/elementValidator.ts +13 -13
  20. package/src/base/validators/pluginsValidator.ts +14 -14
  21. package/src/defaults.ts +284 -283
  22. package/src/defineGridPlugin.ts +3 -3
  23. package/src/defineMultiGridPlugin.ts +3 -3
  24. package/src/defineMultiValuePlugin.ts +3 -3
  25. package/src/defineNoneDataPlugin.ts +4 -4
  26. package/src/defineRelationshipPlugin.ts +3 -3
  27. package/src/defineSeriesPlugin.ts +3 -3
  28. package/src/defineTreePlugin.ts +3 -3
  29. package/src/grid/computedDataFn.ts +129 -129
  30. package/src/grid/contextObserverCallback.ts +201 -201
  31. package/src/grid/dataFormatterValidator.ts +125 -125
  32. package/src/grid/dataValidator.ts +12 -12
  33. package/src/grid/gridObservables.ts +694 -718
  34. package/src/index.ts +20 -20
  35. package/src/multiGrid/computedDataFn.ts +123 -123
  36. package/src/multiGrid/contextObserverCallback.ts +75 -75
  37. package/src/multiGrid/dataFormatterValidator.ts +120 -120
  38. package/src/multiGrid/dataValidator.ts +12 -12
  39. package/src/multiGrid/multiGridObservables.ts +357 -401
  40. package/src/multiValue/computedDataFn.ts +113 -113
  41. package/src/multiValue/contextObserverCallback.ts +328 -328
  42. package/src/multiValue/dataFormatterValidator.ts +94 -94
  43. package/src/multiValue/dataValidator.ts +12 -12
  44. package/src/multiValue/multiValueObservables.ts +865 -1219
  45. package/src/relationship/computedDataFn.ts +159 -159
  46. package/src/relationship/contextObserverCallback.ts +80 -80
  47. package/src/relationship/dataFormatterValidator.ts +13 -13
  48. package/src/relationship/dataValidator.ts +13 -13
  49. package/src/relationship/relationshipObservables.ts +84 -84
  50. package/src/series/computedDataFn.ts +88 -88
  51. package/src/series/contextObserverCallback.ts +132 -107
  52. package/src/series/dataFormatterValidator.ts +46 -46
  53. package/src/series/dataValidator.ts +12 -12
  54. package/src/series/seriesObservables.ts +209 -175
  55. package/src/tree/computedDataFn.ts +129 -129
  56. package/src/tree/contextObserverCallback.ts +58 -58
  57. package/src/tree/dataFormatterValidator.ts +13 -13
  58. package/src/tree/dataValidator.ts +13 -13
  59. package/src/tree/treeObservables.ts +105 -105
  60. package/src/utils/commonUtils.ts +55 -55
  61. package/src/utils/d3Scale.ts +198 -198
  62. package/src/utils/errorMessage.ts +40 -43
  63. package/src/utils/index.ts +3 -3
  64. package/src/utils/observables.ts +308 -293
  65. package/src/utils/orbchartsUtils.ts +396 -396
  66. package/src/utils/validator.ts +126 -126
  67. package/tsconfig.base.json +13 -13
  68. package/tsconfig.json +2 -2
  69. package/vite-env.d.ts +6 -6
  70. package/vite.config.js +22 -22
package/src/index.ts CHANGED
@@ -1,20 +1,20 @@
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 './utils'
18
- export * from './defaults'
19
-
20
-
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 './utils'
18
+ export * from './defaults'
19
+
20
+
@@ -1,123 +1,123 @@
1
- import type { ComputedDataFn, ComputedDatumGrid, DataFormatterGridGrid, ComputedDataMultiGrid } from '../../lib/core-types'
2
- import { DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID } from '../defaults'
3
- import {
4
- createDefaultDatumId,
5
- seriesColorPredicate,
6
- createGridSeriesLabels,
7
- createMultiGridSeriesLabels,
8
- createMultiGridGroupLabels
9
- } from '../utils/orbchartsUtils'
10
- import { createTransposedDataGrid } from '../grid/computedDataFn'
11
-
12
- export const computedDataFn: ComputedDataFn<'multiGrid'> = (context) => {
13
- const { data = [], dataFormatter, chartParams } = context
14
- if (!data.length) {
15
- return []
16
- }
17
-
18
- let multiGridData: ComputedDataMultiGrid = []
19
-
20
- try {
21
- const defaultGrid = dataFormatter.gridList[0] || DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID
22
-
23
- // 計算每個grid的dataFormatter
24
- const gridDataFormatterList: DataFormatterGridGrid[] = data.map((gridData, gridIndex) => {
25
- return dataFormatter.gridList[gridIndex] || defaultGrid
26
- })
27
-
28
- const transposedDataGridList = data.map((gridData, gridIndex) => {
29
- // 依seriesDirection轉置資料矩陣
30
- return createTransposedDataGrid(gridData, gridDataFormatterList[gridIndex])
31
- })
32
-
33
- // const isOverlappingMultiGrid = (() => {
34
- // const SlotIndexSet = new Set(gridDataFormatterList.map(d => d.slotIndex))
35
- // // 判斷是否有重疊的grid
36
- // return SlotIndexSet.size !== gridDataFormatterList.length
37
- // })()
38
-
39
- const multiGridSeriesLabels = dataFormatter.separateGrid
40
- // grid分開的時候,預設每組的seriesLabels相同
41
- ? transposedDataGridList
42
- .map((gridData, gridIndex) => {
43
- return createGridSeriesLabels({
44
- transposedDataGrid: gridData,
45
- dataFormatterGrid: gridDataFormatterList[gridIndex],
46
- chartType: 'multiGrid',
47
- })
48
- })
49
- // grid不分開的時候,預設每個grid相同seriesIndex的seriesLabel相同
50
- : transposedDataGridList
51
- .map((gridData, gridIndex) => {
52
- return createMultiGridSeriesLabels({
53
- transposedDataGrid: gridData,
54
- dataFormatterGrid: gridDataFormatterList[gridIndex],
55
- chartType: 'multiGrid',
56
- gridIndex
57
- })
58
- })
59
-
60
- const SeriesLabelColorMap: Map<string, string> = new Map()
61
- let accIndex = 0
62
- multiGridSeriesLabels.flat().forEach((label, i) => {
63
- if (!SeriesLabelColorMap.has(label)) {
64
- const color = seriesColorPredicate(accIndex, chartParams)
65
- SeriesLabelColorMap.set(label, color)
66
- accIndex ++
67
- }
68
- })
69
-
70
- // 計算每個grid的資料
71
- multiGridData = transposedDataGridList.map((gridData, gridIndex) => {
72
- const gridSeriesLabels = multiGridSeriesLabels[gridIndex]
73
- const groupLabels = createMultiGridGroupLabels({
74
- transposedDataGrid: gridData,
75
- dataFormatterGrid: gridDataFormatterList[gridIndex],
76
- chartType: 'multiGrid',
77
- gridIndex
78
- })
79
-
80
- let _index = 0
81
- let computedDataGrid: ComputedDatumGrid[][] = gridData.map((seriesData, seriesIndex) => {
82
- return seriesData.map((groupDatum, groupIndex) => {
83
-
84
- const defaultId = createDefaultDatumId('multiGrid', gridIndex, seriesIndex, groupIndex)
85
- const groupLabel = groupLabels[groupIndex]
86
- const seriesLabel = gridSeriesLabels[seriesIndex]
87
-
88
- const computedDatum: ComputedDatumGrid = {
89
- id: groupDatum.id ? groupDatum.id : defaultId,
90
- index: _index,
91
- label: groupDatum.label ? groupDatum.label : defaultId,
92
- description: groupDatum.description ?? '',
93
- data: groupDatum.data,
94
- value: groupDatum.value,
95
- gridIndex,
96
- // accSeriesIndex: seriesIndex, // 預設為seriesIndex
97
- seriesIndex,
98
- seriesLabel,
99
- groupIndex,
100
- groupLabel,
101
- color: SeriesLabelColorMap.get(seriesLabel),
102
- visible: true // 先給一個預設值
103
- }
104
-
105
- computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
106
-
107
- _index ++
108
-
109
- return computedDatum
110
- })
111
- })
112
-
113
- return computedDataGrid
114
- })
115
-
116
-
117
- } catch (e) {
118
- // console.error(e)
119
- throw Error(e)
120
- }
121
-
122
- return multiGridData
123
- }
1
+ import type { ComputedDataFn, ComputedDatumGrid, DataFormatterGridGrid, ComputedDataMultiGrid } from '../../lib/core-types'
2
+ import { DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID } from '../defaults'
3
+ import {
4
+ createDefaultDatumId,
5
+ seriesColorPredicate,
6
+ createGridSeriesLabels,
7
+ createMultiGridSeriesLabels,
8
+ createMultiGridGroupLabels
9
+ } from '../utils/orbchartsUtils'
10
+ import { createTransposedDataGrid } from '../grid/computedDataFn'
11
+
12
+ export const computedDataFn: ComputedDataFn<'multiGrid'> = (context) => {
13
+ const { data = [], dataFormatter, chartParams } = context
14
+ if (!data.length) {
15
+ return []
16
+ }
17
+
18
+ let multiGridData: ComputedDataMultiGrid = []
19
+
20
+ try {
21
+ const defaultGrid = dataFormatter.gridList[0] || DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID
22
+
23
+ // 計算每個grid的dataFormatter
24
+ const gridDataFormatterList: DataFormatterGridGrid[] = data.map((gridData, gridIndex) => {
25
+ return dataFormatter.gridList[gridIndex] || defaultGrid
26
+ })
27
+
28
+ const transposedDataGridList = data.map((gridData, gridIndex) => {
29
+ // 依seriesDirection轉置資料矩陣
30
+ return createTransposedDataGrid(gridData, gridDataFormatterList[gridIndex])
31
+ })
32
+
33
+ // const isOverlappingMultiGrid = (() => {
34
+ // const SlotIndexSet = new Set(gridDataFormatterList.map(d => d.slotIndex))
35
+ // // 判斷是否有重疊的grid
36
+ // return SlotIndexSet.size !== gridDataFormatterList.length
37
+ // })()
38
+
39
+ const multiGridSeriesLabels = dataFormatter.separateGrid
40
+ // grid分開的時候,預設每組的seriesLabels相同
41
+ ? transposedDataGridList
42
+ .map((gridData, gridIndex) => {
43
+ return createGridSeriesLabels({
44
+ transposedDataGrid: gridData,
45
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
46
+ chartType: 'multiGrid',
47
+ })
48
+ })
49
+ // grid不分開的時候,預設每個grid相同seriesIndex的seriesLabel相同
50
+ : transposedDataGridList
51
+ .map((gridData, gridIndex) => {
52
+ return createMultiGridSeriesLabels({
53
+ transposedDataGrid: gridData,
54
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
55
+ chartType: 'multiGrid',
56
+ gridIndex
57
+ })
58
+ })
59
+
60
+ const SeriesLabelColorMap: Map<string, string> = new Map()
61
+ let accIndex = 0
62
+ multiGridSeriesLabels.flat().forEach((label, i) => {
63
+ if (!SeriesLabelColorMap.has(label)) {
64
+ const color = seriesColorPredicate(accIndex, chartParams)
65
+ SeriesLabelColorMap.set(label, color)
66
+ accIndex ++
67
+ }
68
+ })
69
+
70
+ // 計算每個grid的資料
71
+ multiGridData = transposedDataGridList.map((gridData, gridIndex) => {
72
+ const gridSeriesLabels = multiGridSeriesLabels[gridIndex]
73
+ const groupLabels = createMultiGridGroupLabels({
74
+ transposedDataGrid: gridData,
75
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
76
+ chartType: 'multiGrid',
77
+ gridIndex
78
+ })
79
+
80
+ let _index = 0
81
+ let computedDataGrid: ComputedDatumGrid[][] = gridData.map((seriesData, seriesIndex) => {
82
+ return seriesData.map((groupDatum, groupIndex) => {
83
+
84
+ const defaultId = createDefaultDatumId('multiGrid', gridIndex, seriesIndex, groupIndex)
85
+ const groupLabel = groupLabels[groupIndex]
86
+ const seriesLabel = gridSeriesLabels[seriesIndex]
87
+
88
+ const computedDatum: ComputedDatumGrid = {
89
+ id: groupDatum.id ? groupDatum.id : defaultId,
90
+ index: _index,
91
+ label: groupDatum.label ? groupDatum.label : defaultId,
92
+ description: groupDatum.description ?? '',
93
+ data: groupDatum.data,
94
+ value: groupDatum.value,
95
+ gridIndex,
96
+ // accSeriesIndex: seriesIndex, // 預設為seriesIndex
97
+ seriesIndex,
98
+ seriesLabel,
99
+ groupIndex,
100
+ groupLabel,
101
+ color: SeriesLabelColorMap.get(seriesLabel),
102
+ visible: true // 先給一個預設值
103
+ }
104
+
105
+ computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
106
+
107
+ _index ++
108
+
109
+ return computedDatum
110
+ })
111
+ })
112
+
113
+ return computedDataGrid
114
+ })
115
+
116
+
117
+ } catch (e) {
118
+ // console.error(e)
119
+ throw Error(e)
120
+ }
121
+
122
+ return multiGridData
123
+ }
@@ -1,75 +1,75 @@
1
- import {
2
- map,
3
- shareReplay } from 'rxjs'
4
- import type { ContextObserverCallback, DataGridDatum } from '../../lib/core-types'
5
- import { multiGridEachDetailObservable, multiGridContainerObservable } from './multiGridObservables'
6
- import { textSizePxObservable, containerSizeObservable, highlightObservable } from '../utils/observables'
7
- // import { createMultiGridSeriesLabels } from '../utils/orbchartsUtils'
8
- import { combineLatest } from 'rxjs/internal/observable/combineLatest'
9
-
10
- export const contextObserverCallback: ContextObserverCallback<'multiGrid'> = ({ subject, observer }) => {
11
-
12
- const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
- shareReplay(1)
14
- )
15
-
16
- const multiGridContainerPosition$ = multiGridContainerObservable({
17
- computedData$: observer.computedData$,
18
- fullDataFormatter$: observer.fullDataFormatter$,
19
- layout$: observer.layout$,
20
- }).pipe(
21
- shareReplay(1)
22
- )
23
-
24
- const containerSize$ = containerSizeObservable({
25
- layout$: observer.layout$,
26
- containerPosition$: multiGridContainerPosition$.pipe(
27
- map(d => d.flat())
28
- ),
29
- container$: observer.fullDataFormatter$.pipe(
30
- map(d => d.container)
31
- )
32
- }).pipe(
33
- shareReplay(1)
34
- )
35
-
36
- // highlight全部grid
37
- const multiGridHighlight$ = highlightObservable({
38
- datumList$: observer.computedData$.pipe(
39
- map(d => d.flat().flat()),
40
- shareReplay(1)
41
- ),
42
- fullChartParams$: observer.fullChartParams$,
43
- event$: subject.event$
44
- }).pipe(
45
- shareReplay(1)
46
- )
47
-
48
- const multiGridEachDetail$ = multiGridEachDetailObservable({
49
- fullDataFormatter$: observer.fullDataFormatter$,
50
- computedData$: observer.computedData$,
51
- layout$: observer.layout$,
52
- fullChartParams$: observer.fullChartParams$,
53
- event$: subject.event$,
54
- containerSize$
55
- }).pipe(
56
- shareReplay(1)
57
- )
58
- // multiGridContainerPosition$.subscribe(d => {
59
- // console.log('multiGridContainerPosition$', d)
60
- // })
61
-
62
- return {
63
- fullParams$: observer.fullParams$,
64
- fullChartParams$: observer.fullChartParams$,
65
- fullDataFormatter$: observer.fullDataFormatter$,
66
- computedData$: observer.computedData$,
67
- layout$: observer.layout$,
68
- textSizePx$,
69
- containerSize$,
70
- multiGridHighlight$,
71
- multiGridContainerPosition$,
72
- multiGridEachDetail$,
73
- // multiGridContainer$
74
- }
75
- }
1
+ import {
2
+ map,
3
+ shareReplay } from 'rxjs'
4
+ import type { ContextObserverCallback, DataGridDatum } from '../../lib/core-types'
5
+ import { multiGridEachDetailObservable, multiGridContainerObservable } from './multiGridObservables'
6
+ import { textSizePxObservable, containerSizeObservable, highlightObservable } from '../utils/observables'
7
+ // import { createMultiGridSeriesLabels } from '../utils/orbchartsUtils'
8
+ import { combineLatest } from 'rxjs/internal/observable/combineLatest'
9
+
10
+ export const contextObserverCallback: ContextObserverCallback<'multiGrid'> = ({ subject, observer }) => {
11
+
12
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
+ shareReplay(1)
14
+ )
15
+
16
+ const multiGridContainerPosition$ = multiGridContainerObservable({
17
+ computedData$: observer.computedData$,
18
+ fullDataFormatter$: observer.fullDataFormatter$,
19
+ layout$: observer.layout$,
20
+ }).pipe(
21
+ shareReplay(1)
22
+ )
23
+
24
+ const containerSize$ = containerSizeObservable({
25
+ layout$: observer.layout$,
26
+ containerPosition$: multiGridContainerPosition$.pipe(
27
+ map(d => d.flat())
28
+ ),
29
+ container$: observer.fullDataFormatter$.pipe(
30
+ map(d => d.container)
31
+ )
32
+ }).pipe(
33
+ shareReplay(1)
34
+ )
35
+
36
+ // highlight全部grid
37
+ const multiGridHighlight$ = highlightObservable({
38
+ datumList$: observer.computedData$.pipe(
39
+ map(d => d.flat().flat()),
40
+ shareReplay(1)
41
+ ),
42
+ fullChartParams$: observer.fullChartParams$,
43
+ event$: subject.event$
44
+ }).pipe(
45
+ shareReplay(1)
46
+ )
47
+
48
+ const multiGridEachDetail$ = multiGridEachDetailObservable({
49
+ fullDataFormatter$: observer.fullDataFormatter$,
50
+ computedData$: observer.computedData$,
51
+ layout$: observer.layout$,
52
+ fullChartParams$: observer.fullChartParams$,
53
+ event$: subject.event$,
54
+ containerSize$
55
+ }).pipe(
56
+ shareReplay(1)
57
+ )
58
+ // multiGridContainerPosition$.subscribe(d => {
59
+ // console.log('multiGridContainerPosition$', d)
60
+ // })
61
+
62
+ return {
63
+ fullParams$: observer.fullParams$,
64
+ fullChartParams$: observer.fullChartParams$,
65
+ fullDataFormatter$: observer.fullDataFormatter$,
66
+ computedData$: observer.computedData$,
67
+ layout$: observer.layout$,
68
+ textSizePx$,
69
+ containerSize$,
70
+ multiGridHighlight$,
71
+ multiGridContainerPosition$,
72
+ multiGridEachDetail$,
73
+ // multiGridContainer$
74
+ }
75
+ }