@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
@@ -1,128 +1,131 @@
1
- import type { DataTree, DataTreeObj, DataTreeDatum } from '../types/DataTree'
2
- import type { ComputedDataFn } from '../types/ComputedData'
3
- import type { ComputedDataTree } from '../types/ComputedDataTree'
4
- import { isPlainObject } from '../utils/commonUtils'
5
- import { seriesColorPredicate } from '../utils/orbchartsUtils'
6
-
7
- export const computeTreeData: ComputedDataFn<'tree'> = (context) => {
8
- const { data = [], dataFormatter, chartParams } = context
9
-
10
- // <categoryLabel, categoryIndex>
11
- const CategoryIndexMap = new Map<string, number>(
12
- dataFormatter.categoryLabels.map((label, index) => [label, index])
13
- )
14
-
15
- let computedBranchData: ComputedDataTree = {
16
- id: '',
17
- index: 0,
18
- label: '',
19
- description: '',
20
- categoryIndex: 0,
21
- categoryLabel: '',
22
- color: '',
23
- visible: true,
24
- // tooltipContent: '',
25
- data: {},
26
- value: 0,
27
- level: 0,
28
- seq: 0,
29
- children: []
30
- }
31
-
32
- try {
33
- // 建立樹狀結構資料
34
- const dataTreeObj: DataTreeObj = (function () {
35
- if (isPlainObject(data) === true) {
36
- // 原本就是樹狀結構則直接複製
37
- return structuredClone(data) as DataTreeObj
38
- } else if (Array.isArray(data) === false) {
39
- return {
40
- id: ''
41
- }
42
- }
43
- // -- 陣列格式轉物件 --
44
- // let rootId = ''
45
- let root: DataTreeDatum | undefined = undefined
46
- // const DataMap: Map<string, DataTreeDatum> = new Map()
47
- const ChildrenMap: Map<string, DataTreeDatum[]> = new Map()
48
- ;(data as DataTreeDatum[]).forEach(d => {
49
- // DataMap.set(d.id, d)
50
-
51
- if (!d.parent) {
52
- // rootId = d.id
53
- root = d
54
- } else {
55
- const children: DataTreeDatum[] = ChildrenMap.get(d.parent) ?? []
56
- children.push(d)
57
- ChildrenMap.set(d.parent!, children)
58
- }
59
- })
60
-
61
- const createBranchData = (root: DataTreeDatum): DataTreeObj => {
62
- return {
63
- id: root.id,
64
- label: root.label,
65
- data: root.data,
66
- // tooltipContent: root.tooltipContent,
67
- value: root.value,
68
- categoryLabel: root.categoryLabel,
69
- children: (ChildrenMap.get(root.id) ?? []).map(d => {
70
- // 遞迴
71
- return createBranchData(d)
72
- })
73
- }
74
- }
75
- if (root) {
76
- return createBranchData(root)
77
- } else {
78
- return {
79
- id: ''
80
- }
81
- }
82
- })()
83
-
84
- let index = 0
85
-
86
- const formatBranchData = (branch: DataTreeObj, level: number, seq: number): ComputedDataTree => {
87
- const childLayer = level + 1
88
- const visible = dataFormatter.visibleFilter(branch, level, seq, context)
89
- const categoryLabel: string | null = branch.categoryLabel ?? null
90
- let categoryIndex = 0
91
- if (categoryLabel != null) {
92
- if (!CategoryIndexMap.has(categoryLabel)) {
93
- CategoryIndexMap.set(categoryLabel, CategoryIndexMap.size)
94
- }
95
- categoryIndex = CategoryIndexMap.get(categoryLabel) ?? 0
96
- }
97
-
98
- const currentIndex = index
99
- index++
100
- return {
101
- id: branch.id,
102
- index: currentIndex,
103
- level,
104
- seq,
105
- label: branch.label ?? '',
106
- description: branch.description ?? '',
107
- categoryIndex,
108
- categoryLabel,
109
- color: seriesColorPredicate(categoryIndex, chartParams),
110
- data: branch.data ?? {},
111
- // tooltipContent: branch.tooltipContent ? branch.tooltipContent : dataFormatter.tooltipContentFormat(branch, level, seq, context),
112
- value: branch.value,
113
- visible,
114
- children: (branch.children ?? []).map((d, i) => {
115
- // 遞迴
116
- return formatBranchData(d, childLayer, i)
117
- })
118
- }
119
- }
120
- computedBranchData = formatBranchData(dataTreeObj, 0, 0)
121
- } catch (e) {
122
- // console.error(e)
123
- throw Error(e)
124
- }
125
-
126
- return computedBranchData
127
-
128
- }
1
+ import type { DataTree, DataTreeObj, DataTreeDatum } from '../types/DataTree'
2
+ import type { ComputedDataFn } from '../types/ComputedData'
3
+ import type { ComputedDataTree } from '../types/ComputedDataTree'
4
+ import { isPlainObject } from '../utils/commonUtils'
5
+ import { seriesColorPredicate } from '../utils/orbchartsUtils'
6
+
7
+ export const computeTreeData: ComputedDataFn<'tree'> = (context) => {
8
+ const { data = [], dataFormatter, chartParams } = context
9
+
10
+ // <categoryLabel, categoryIndex>
11
+ const CategoryIndexMap = new Map<string, number>(
12
+ dataFormatter.categoryLabels.map((label, index) => [label, index])
13
+ )
14
+
15
+ let computedBranchData: ComputedDataTree = {
16
+ id: '',
17
+ index: 0,
18
+ label: '',
19
+ description: '',
20
+ categoryIndex: 0,
21
+ categoryLabel: '',
22
+ color: '',
23
+ visible: true,
24
+ // tooltipContent: '',
25
+ data: {},
26
+ value: 0,
27
+ level: 0,
28
+ seq: 0,
29
+ children: []
30
+ }
31
+
32
+ try {
33
+ // 建立樹狀結構資料
34
+ const dataTreeObj: DataTreeObj = (function () {
35
+ if (isPlainObject(data) === true) {
36
+ // 原本就是樹狀結構則直接複製
37
+ return structuredClone(data) as DataTreeObj
38
+ } else if (Array.isArray(data) === false) {
39
+ return {
40
+ id: ''
41
+ }
42
+ }
43
+ // -- 陣列格式轉物件 --
44
+ // let rootId = ''
45
+ let root: DataTreeDatum | undefined = undefined
46
+ // const DataMap: Map<string, DataTreeDatum> = new Map()
47
+ const ChildrenMap: Map<string, DataTreeDatum[]> = new Map()
48
+ ;(data as DataTreeDatum[]).forEach(d => {
49
+ // DataMap.set(d.id, d)
50
+
51
+ if (!d.parent) {
52
+ // rootId = d.id
53
+ root = d
54
+ } else {
55
+ const children: DataTreeDatum[] = ChildrenMap.get(d.parent) ?? []
56
+ children.push(d)
57
+ ChildrenMap.set(d.parent!, children)
58
+ }
59
+ })
60
+
61
+ const createBranchData = (root: DataTreeDatum): DataTreeObj => {
62
+ return {
63
+ id: root.id,
64
+ label: root.label,
65
+ data: root.data,
66
+ // tooltipContent: root.tooltipContent,
67
+ value: root.value,
68
+ categoryLabel: root.categoryLabel,
69
+ children: (ChildrenMap.get(root.id) ?? []).map(d => {
70
+ // 遞迴
71
+ return createBranchData(d)
72
+ })
73
+ }
74
+ }
75
+ if (root) {
76
+ return createBranchData(root)
77
+ } else {
78
+ return {
79
+ id: ''
80
+ }
81
+ }
82
+ })()
83
+
84
+ let index = 0
85
+
86
+ const formatBranchData = (branch: DataTreeObj, level: number, seq: number): ComputedDataTree => {
87
+ const childLayer = level + 1
88
+ const categoryLabel: string | null = branch.categoryLabel ?? null
89
+ let categoryIndex = 0
90
+ if (categoryLabel != null) {
91
+ if (!CategoryIndexMap.has(categoryLabel)) {
92
+ CategoryIndexMap.set(categoryLabel, CategoryIndexMap.size)
93
+ }
94
+ categoryIndex = CategoryIndexMap.get(categoryLabel) ?? 0
95
+ }
96
+
97
+ const currentIndex = index
98
+ index++
99
+ const formattedBranchData: ComputedDataTree = {
100
+ id: branch.id,
101
+ index: currentIndex,
102
+ level,
103
+ seq,
104
+ label: branch.label ?? '',
105
+ description: branch.description ?? '',
106
+ categoryIndex,
107
+ categoryLabel,
108
+ color: seriesColorPredicate(categoryIndex, chartParams),
109
+ data: branch.data ?? {},
110
+ // tooltipContent: branch.tooltipContent ? branch.tooltipContent : dataFormatter.tooltipContentFormat(branch, level, seq, context),
111
+ value: branch.value,
112
+ visible: true, // 先給預設值
113
+ children: (branch.children ?? []).map((d, i) => {
114
+ // 遞迴
115
+ return formatBranchData(d, childLayer, i)
116
+ })
117
+ }
118
+
119
+ formattedBranchData.visible = dataFormatter.visibleFilter(formattedBranchData, context)
120
+
121
+ return formattedBranchData
122
+ }
123
+ computedBranchData = formatBranchData(dataTreeObj, 0, 0)
124
+ } catch (e) {
125
+ // console.error(e)
126
+ throw Error(e)
127
+ }
128
+
129
+ return computedBranchData
130
+
131
+ }
@@ -1,61 +1,61 @@
1
- import { map, shareReplay } from 'rxjs'
2
- import type { ContextObserverFn } from '../types'
3
- import { highlightObservable, categoryDataMapObservable, textSizePxObservable } from '../utils/observables'
4
- import {
5
- nodeListObservable,
6
- existCategoryLabelsObservable,
7
- treeVisibleComputedDataObservable
8
- } from './treeObservables'
9
-
10
- export const createTreeContextObserver: ContextObserverFn<'tree'> = ({ subject, observer }) => {
11
-
12
- const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
- shareReplay(1)
14
- )
15
-
16
- const nodeList$ = nodeListObservable({
17
- computedData$: observer.computedData$
18
- }).pipe(
19
- shareReplay(1)
20
- )
21
-
22
- const treeHighlight$ = highlightObservable({
23
- datumList$: nodeList$,
24
- fullChartParams$: observer.fullChartParams$,
25
- event$: subject.event$
26
- }).pipe(
27
- shareReplay(1)
28
- )
29
-
30
- const existCategoryLabels$ = existCategoryLabelsObservable({
31
- nodeList$,
32
- fullDataFormatter$: observer.fullDataFormatter$
33
- }).pipe(
34
- shareReplay(1)
35
- )
36
-
37
- const CategoryDataMap$ = categoryDataMapObservable({
38
- datumList$: nodeList$
39
- }).pipe(
40
- shareReplay(1)
41
- )
42
-
43
- const visibleComputedData$ = treeVisibleComputedDataObservable({
44
- computedData$: observer.computedData$
45
- }).pipe(
46
- shareReplay(1)
47
- )
48
-
49
- return {
50
- fullParams$: observer.fullParams$,
51
- fullChartParams$: observer.fullChartParams$,
52
- fullDataFormatter$: observer.fullDataFormatter$,
53
- computedData$: observer.computedData$,
54
- layout$: observer.layout$,
55
- textSizePx$,
56
- treeHighlight$,
57
- existCategoryLabels$,
58
- CategoryDataMap$,
59
- visibleComputedData$
60
- }
61
- }
1
+ import { map, shareReplay } from 'rxjs'
2
+ import type { ContextObserverFn } from '../types'
3
+ import { highlightObservable, categoryDataMapObservable, textSizePxObservable } from '../utils/observables'
4
+ import {
5
+ nodeListObservable,
6
+ existCategoryLabelsObservable,
7
+ treeVisibleComputedDataObservable
8
+ } from './treeObservables'
9
+
10
+ export const createTreeContextObserver: ContextObserverFn<'tree'> = ({ subject, observer }) => {
11
+
12
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
+ shareReplay(1)
14
+ )
15
+
16
+ const nodeList$ = nodeListObservable({
17
+ computedData$: observer.computedData$
18
+ }).pipe(
19
+ shareReplay(1)
20
+ )
21
+
22
+ const treeHighlight$ = highlightObservable({
23
+ datumList$: nodeList$,
24
+ fullChartParams$: observer.fullChartParams$,
25
+ event$: subject.event$
26
+ }).pipe(
27
+ shareReplay(1)
28
+ )
29
+
30
+ const existCategoryLabels$ = existCategoryLabelsObservable({
31
+ nodeList$,
32
+ fullDataFormatter$: observer.fullDataFormatter$
33
+ }).pipe(
34
+ shareReplay(1)
35
+ )
36
+
37
+ const CategoryDataMap$ = categoryDataMapObservable({
38
+ datumList$: nodeList$
39
+ }).pipe(
40
+ shareReplay(1)
41
+ )
42
+
43
+ const visibleComputedData$ = treeVisibleComputedDataObservable({
44
+ computedData$: observer.computedData$
45
+ }).pipe(
46
+ shareReplay(1)
47
+ )
48
+
49
+ return {
50
+ fullParams$: observer.fullParams$,
51
+ fullChartParams$: observer.fullChartParams$,
52
+ fullDataFormatter$: observer.fullDataFormatter$,
53
+ computedData$: observer.computedData$,
54
+ layout$: observer.layout$,
55
+ textSizePx$,
56
+ treeHighlight$,
57
+ existCategoryLabels$,
58
+ CategoryDataMap$,
59
+ visibleComputedData$
60
+ }
61
+ }
@@ -1,95 +1,95 @@
1
- import {
2
- combineLatest,
3
- distinctUntilChanged,
4
- filter,
5
- map,
6
- merge,
7
- takeUntil,
8
- shareReplay,
9
- switchMap,
10
- Subject,
11
- Observable } from 'rxjs'
12
- import type {
13
- ChartParams,
14
- ComputedDataTree,
15
- ComputedDataTypeMap,
16
- DataFormatterTree } from '../types'
17
-
18
-
19
- // 所有節點list結構
20
- export const nodeListObservable = ({ computedData$ }: { computedData$: Observable<ComputedDataTree> }) => {
21
- return computedData$.pipe(
22
- map(data => {
23
- function setNodeList (accNodeList: ComputedDataTree[], branch: ComputedDataTree) {
24
- accNodeList.push(branch)
25
- if (branch.children) {
26
- branch.children.forEach(childBranch => {
27
- accNodeList = setNodeList(accNodeList, childBranch) // 遞迴子節點
28
- })
29
- }
30
- return accNodeList
31
- }
32
- return setNodeList([], data)
33
- })
34
- )
35
- }
36
-
37
- export const existCategoryLabelsObservable = ({ nodeList$, fullDataFormatter$ }: {
38
- nodeList$: Observable<ComputedDataTree[]>
39
- fullDataFormatter$: Observable<DataFormatterTree>
40
- }) => {
41
-
42
- const categoryLabels$ = fullDataFormatter$.pipe(
43
- map(d => d.categoryLabels),
44
- distinctUntilChanged((a, b) => {
45
- return JSON.stringify(a).length === JSON.stringify(b).length
46
- }),
47
- )
48
-
49
- return combineLatest({
50
- nodeList: nodeList$,
51
- categoryLabels: categoryLabels$
52
- }).pipe(
53
- switchMap(async d => d),
54
- map(data => {
55
- const CurrentLabelSet = new Set(data.categoryLabels)
56
- const ExistLabelSet = new Set(
57
- data.nodeList.filter(node => node.visible).map(node => node.categoryLabel)
58
- )
59
- // 加入已存在的label(data.nodeList有,但是dataFormatter.categoryLabels沒有)
60
- Array.from(ExistLabelSet).forEach(label => {
61
- if (!CurrentLabelSet.has(label)) {
62
- CurrentLabelSet.add(label)
63
- }
64
- })
65
- // 移除不存在的label(dataFormatter.categoryLabels有,但是data.nodeList沒有)
66
- Array.from(CurrentLabelSet).forEach(label => {
67
- if (!ExistLabelSet.has(label)) {
68
- ExistLabelSet.delete(label)
69
- }
70
- })
71
-
72
- return Array.from(CurrentLabelSet)
73
- }),
74
- distinctUntilChanged((a, b) => {
75
- return JSON.stringify(a).length === JSON.stringify(b).length
76
- }),
77
- )
78
- }
79
-
80
- // 所有可見的節點
81
- export const treeVisibleComputedDataObservable = ({ computedData$ }: { computedData$: Observable<ComputedDataTree> }) => {
82
- return computedData$.pipe(
83
- map(data => {
84
- function filterChildren (accTree: ComputedDataTree) {
85
- if (accTree.children) {
86
- accTree.children = accTree.children
87
- .filter(child => child.visible) // 篩選visible
88
- .map(child => filterChildren(child)) // 遞迴子節點
89
- }
90
- return accTree
91
- }
92
- return filterChildren(data)
93
- })
94
- )
1
+ import {
2
+ combineLatest,
3
+ distinctUntilChanged,
4
+ filter,
5
+ map,
6
+ merge,
7
+ takeUntil,
8
+ shareReplay,
9
+ switchMap,
10
+ Subject,
11
+ Observable } from 'rxjs'
12
+ import type {
13
+ ChartParams,
14
+ ComputedDataTree,
15
+ ComputedDataTypeMap,
16
+ DataFormatterTree } from '../types'
17
+
18
+
19
+ // 所有節點list結構
20
+ export const nodeListObservable = ({ computedData$ }: { computedData$: Observable<ComputedDataTree> }) => {
21
+ return computedData$.pipe(
22
+ map(data => {
23
+ function setNodeList (accNodeList: ComputedDataTree[], branch: ComputedDataTree) {
24
+ accNodeList.push(branch)
25
+ if (branch.children) {
26
+ branch.children.forEach(childBranch => {
27
+ accNodeList = setNodeList(accNodeList, childBranch) // 遞迴子節點
28
+ })
29
+ }
30
+ return accNodeList
31
+ }
32
+ return setNodeList([], data)
33
+ })
34
+ )
35
+ }
36
+
37
+ export const existCategoryLabelsObservable = ({ nodeList$, fullDataFormatter$ }: {
38
+ nodeList$: Observable<ComputedDataTree[]>
39
+ fullDataFormatter$: Observable<DataFormatterTree>
40
+ }) => {
41
+
42
+ const categoryLabels$ = fullDataFormatter$.pipe(
43
+ map(d => d.categoryLabels),
44
+ distinctUntilChanged((a, b) => {
45
+ return JSON.stringify(a).length === JSON.stringify(b).length
46
+ }),
47
+ )
48
+
49
+ return combineLatest({
50
+ nodeList: nodeList$,
51
+ categoryLabels: categoryLabels$
52
+ }).pipe(
53
+ switchMap(async d => d),
54
+ map(data => {
55
+ const CurrentLabelSet = new Set(data.categoryLabels)
56
+ const ExistLabelSet = new Set(
57
+ data.nodeList.filter(node => node.visible).map(node => node.categoryLabel)
58
+ )
59
+ // 加入已存在的label(data.nodeList有,但是dataFormatter.categoryLabels沒有)
60
+ Array.from(ExistLabelSet).forEach(label => {
61
+ if (!CurrentLabelSet.has(label)) {
62
+ CurrentLabelSet.add(label)
63
+ }
64
+ })
65
+ // 移除不存在的label(dataFormatter.categoryLabels有,但是data.nodeList沒有)
66
+ Array.from(CurrentLabelSet).forEach(label => {
67
+ if (!ExistLabelSet.has(label)) {
68
+ ExistLabelSet.delete(label)
69
+ }
70
+ })
71
+
72
+ return Array.from(CurrentLabelSet)
73
+ }),
74
+ distinctUntilChanged((a, b) => {
75
+ return JSON.stringify(a).length === JSON.stringify(b).length
76
+ }),
77
+ )
78
+ }
79
+
80
+ // 所有可見的節點
81
+ export const treeVisibleComputedDataObservable = ({ computedData$ }: { computedData$: Observable<ComputedDataTree> }) => {
82
+ return computedData$.pipe(
83
+ map(data => {
84
+ function filterChildren (accTree: ComputedDataTree) {
85
+ if (accTree.children) {
86
+ accTree.children = accTree.children
87
+ .filter(child => child.visible) // 篩選visible
88
+ .map(child => filterChildren(child)) // 遞迴子節點
89
+ }
90
+ return accTree
91
+ }
92
+ return filterChildren(data)
93
+ })
94
+ )
95
95
  }
@@ -1,48 +1,48 @@
1
- import type { ChartParams, ChartParamsPartial } from './ChartParams'
2
- import type { ContextSubject } from './ContextSubject'
3
- import type { ContextObserverFn } from './ContextObserver'
4
- import type { ComputedDataFn } from './ComputedData'
5
- import type { DataFormatterTypeMap, DataFormatterPartialTypeMap } from './DataFormatter'
6
-
7
- export type ChartType = 'series' | 'grid' | 'multiGrid' | 'multiValue' | 'tree' | 'relationship'
8
-
9
- export interface CreateBaseChart {
10
- <T extends ChartType>({ defaultDataFormatter, computedDataFn, contextObserverFn }: {
11
- defaultDataFormatter: DataFormatterTypeMap<T>
12
- computedDataFn: ComputedDataFn<T>
13
- contextObserverFn: ContextObserverFn<T>
14
- }): CreateChart<T>
15
- }
16
-
17
-
18
- export interface CreateChart<T extends ChartType> {
19
- // (element: HTMLElement | Element, pluginParams: any[], chartParams?: Partial<ChartParams>): Chart<T>
20
- (element: HTMLElement | Element, options?: ChartOptionsPartial<T>): ChartEntity<T>
21
- }
22
-
23
- export interface ChartEntity<T extends ChartType> extends ContextSubject<T> {
24
- selection: d3.Selection<SVGGElement, unknown, HTMLElement, unknown>
25
- destroy: () => void
26
- }
27
-
28
- export interface ChartOptions<T extends ChartType> {
29
- preset: Preset<T>
30
- }
31
-
32
- export interface ChartOptionsPartial<T extends ChartType> {
33
- preset?: PresetPartial<T>
34
- }
35
-
36
- export interface Preset<T extends ChartType> {
37
- chartParams: ChartParams
38
- dataFormatter: DataFormatterTypeMap<T>
39
- allPluginParams: {[key: string]: any}
40
- description: string
41
- }
42
-
43
- export interface PresetPartial<T extends ChartType> {
44
- chartParams?: ChartParamsPartial
45
- dataFormatter?: DataFormatterPartialTypeMap<T>
46
- allPluginParams?: {[key: string]: any}
47
- description?: string
48
- }
1
+ import type { ChartParams, ChartParamsPartial } from './ChartParams'
2
+ import type { ContextSubject } from './ContextSubject'
3
+ import type { ContextObserverFn } from './ContextObserver'
4
+ import type { ComputedDataFn } from './ComputedData'
5
+ import type { DataFormatterTypeMap, DataFormatterPartialTypeMap } from './DataFormatter'
6
+
7
+ export type ChartType = 'series' | 'grid' | 'multiGrid' | 'multiValue' | 'tree' | 'relationship'
8
+
9
+ export interface CreateBaseChart {
10
+ <T extends ChartType>({ defaultDataFormatter, computedDataFn, contextObserverFn }: {
11
+ defaultDataFormatter: DataFormatterTypeMap<T>
12
+ computedDataFn: ComputedDataFn<T>
13
+ contextObserverFn: ContextObserverFn<T>
14
+ }): CreateChart<T>
15
+ }
16
+
17
+
18
+ export interface CreateChart<T extends ChartType> {
19
+ // (element: HTMLElement | Element, pluginParams: any[], chartParams?: Partial<ChartParams>): Chart<T>
20
+ (element: HTMLElement | Element, options?: ChartOptionsPartial<T>): ChartEntity<T>
21
+ }
22
+
23
+ export interface ChartEntity<T extends ChartType> extends ContextSubject<T> {
24
+ selection: d3.Selection<SVGGElement, unknown, HTMLElement, unknown>
25
+ destroy: () => void
26
+ }
27
+
28
+ export interface ChartOptions<T extends ChartType> {
29
+ preset: Preset<T>
30
+ }
31
+
32
+ export interface ChartOptionsPartial<T extends ChartType> {
33
+ preset?: PresetPartial<T>
34
+ }
35
+
36
+ export interface Preset<T extends ChartType> {
37
+ chartParams: ChartParams
38
+ dataFormatter: DataFormatterTypeMap<T>
39
+ allPluginParams: {[key: string]: any}
40
+ description: string
41
+ }
42
+
43
+ export interface PresetPartial<T extends ChartType> {
44
+ chartParams?: ChartParamsPartial
45
+ dataFormatter?: DataFormatterPartialTypeMap<T>
46
+ allPluginParams?: {[key: string]: any}
47
+ description?: string
48
+ }