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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +1152 -1124
  3. package/dist/orbcharts-core.umd.js +2 -2
  4. package/dist/src/types/ChartParams.d.ts +1 -1
  5. package/dist/src/types/ContextObserverGrid.d.ts +1 -0
  6. package/dist/src/types/ContextObserverMultiGrid.d.ts +1 -0
  7. package/dist/src/types/ContextObserverSeries.d.ts +1 -0
  8. package/dist/src/types/ContextObserverTree.d.ts +1 -0
  9. package/dist/src/utils/observables.d.ts +1 -0
  10. package/package.json +41 -41
  11. package/src/AbstractChart.ts +48 -48
  12. package/src/GridChart.ts +20 -20
  13. package/src/MultiGridChart.ts +20 -20
  14. package/src/MultiValueChart.ts +20 -20
  15. package/src/RelationshipChart.ts +20 -20
  16. package/src/SeriesChart.ts +20 -20
  17. package/src/TreeChart.ts +20 -20
  18. package/src/base/createBaseChart.ts +367 -367
  19. package/src/base/createBasePlugin.ts +89 -89
  20. package/src/defaults.ts +248 -247
  21. package/src/defineGridPlugin.ts +3 -3
  22. package/src/defineMultiGridPlugin.ts +3 -3
  23. package/src/defineMultiValuePlugin.ts +3 -3
  24. package/src/defineNoneDataPlugin.ts +4 -4
  25. package/src/defineRelationshipPlugin.ts +3 -3
  26. package/src/defineSeriesPlugin.ts +3 -3
  27. package/src/defineTreePlugin.ts +3 -3
  28. package/src/grid/computeGridData.ts +205 -205
  29. package/src/grid/createGridContextObserver.ts +130 -124
  30. package/src/grid/gridObservables.ts +486 -486
  31. package/src/index.ts +21 -21
  32. package/src/multiGrid/computeMultiGridData.ts +173 -173
  33. package/src/multiGrid/createMultiGridContextObserver.ts +40 -34
  34. package/src/multiGrid/multiGridObservables.ts +285 -285
  35. package/src/multiValue/computeMultiValueData.ts +136 -136
  36. package/src/multiValue/createMultiValueContextObserver.ts +12 -12
  37. package/src/relationship/computeRelationshipData.ts +106 -106
  38. package/src/relationship/createRelationshipContextObserver.ts +12 -12
  39. package/src/series/computeSeriesData.ts +153 -153
  40. package/src/series/createSeriesContextObserver.ts +38 -33
  41. package/src/series/seriesObservables.ts +23 -23
  42. package/src/tree/computeTreeData.ts +128 -128
  43. package/src/tree/createTreeContextObserver.ts +61 -56
  44. package/src/tree/treeObservables.ts +94 -94
  45. package/src/types/Chart.ts +48 -48
  46. package/src/types/ChartParams.ts +51 -51
  47. package/src/types/ComputedData.ts +82 -82
  48. package/src/types/ComputedDataGrid.ts +13 -13
  49. package/src/types/ComputedDataMultiGrid.ts +2 -2
  50. package/src/types/ComputedDataMultiValue.ts +9 -9
  51. package/src/types/ComputedDataRelationship.ts +19 -19
  52. package/src/types/ComputedDataSeries.ts +7 -7
  53. package/src/types/ComputedDataTree.ts +19 -19
  54. package/src/types/ContextObserver.ts +38 -38
  55. package/src/types/ContextObserverGrid.ts +33 -33
  56. package/src/types/ContextObserverMultiGrid.ts +28 -27
  57. package/src/types/ContextObserverMultiValue.ts +4 -4
  58. package/src/types/ContextObserverRelationship.ts +4 -4
  59. package/src/types/ContextObserverSeries.ts +8 -7
  60. package/src/types/ContextObserverTree.ts +11 -10
  61. package/src/types/ContextSubject.ts +18 -18
  62. package/src/types/Data.ts +45 -45
  63. package/src/types/DataFormatter.ts +95 -95
  64. package/src/types/DataFormatterGrid.ts +55 -55
  65. package/src/types/DataFormatterMultiGrid.ts +42 -42
  66. package/src/types/DataFormatterMultiValue.ts +20 -20
  67. package/src/types/DataFormatterRelationship.ts +22 -22
  68. package/src/types/DataFormatterSeries.ts +29 -29
  69. package/src/types/DataFormatterTree.ts +12 -12
  70. package/src/types/DataGrid.ts +11 -11
  71. package/src/types/DataMultiGrid.ts +6 -6
  72. package/src/types/DataMultiValue.ts +12 -12
  73. package/src/types/DataRelationship.ts +27 -27
  74. package/src/types/DataSeries.ts +11 -11
  75. package/src/types/DataTree.ts +20 -20
  76. package/src/types/Event.ts +153 -153
  77. package/src/types/Layout.ts +11 -11
  78. package/src/types/Padding.ts +5 -5
  79. package/src/types/Plugin.ts +60 -60
  80. package/src/types/TransformData.ts +7 -7
  81. package/src/types/index.ts +37 -37
  82. package/src/utils/commonUtils.ts +50 -50
  83. package/src/utils/d3Utils.ts +89 -89
  84. package/src/utils/index.ts +4 -4
  85. package/src/utils/observables.ts +202 -181
  86. package/src/utils/orbchartsUtils.ts +253 -253
  87. package/tsconfig.json +13 -13
  88. package/vite.config.js +44 -44
@@ -1,128 +1,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 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 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,56 +1,61 @@
1
- import { map, shareReplay } from 'rxjs'
2
- import type { ContextObserverFn } from '../types'
3
- import { highlightObservable, categoryDataMapObservable } 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 nodeList$ = nodeListObservable({
13
- computedData$: observer.computedData$
14
- }).pipe(
15
- shareReplay(1)
16
- )
17
-
18
- const treeHighlight$ = highlightObservable({
19
- datumList$: nodeList$,
20
- fullChartParams$: observer.fullChartParams$,
21
- event$: subject.event$
22
- }).pipe(
23
- shareReplay(1)
24
- )
25
-
26
- const existCategoryLabels$ = existCategoryLabelsObservable({
27
- nodeList$,
28
- fullDataFormatter$: observer.fullDataFormatter$
29
- }).pipe(
30
- shareReplay(1)
31
- )
32
-
33
- const CategoryDataMap$ = categoryDataMapObservable({
34
- datumList$: nodeList$
35
- }).pipe(
36
- shareReplay(1)
37
- )
38
-
39
- const visibleComputedData$ = treeVisibleComputedDataObservable({
40
- computedData$: observer.computedData$
41
- }).pipe(
42
- shareReplay(1)
43
- )
44
-
45
- return {
46
- fullParams$: observer.fullParams$,
47
- fullChartParams$: observer.fullChartParams$,
48
- fullDataFormatter$: observer.fullDataFormatter$,
49
- computedData$: observer.computedData$,
50
- layout$: observer.layout$,
51
- treeHighlight$,
52
- existCategoryLabels$,
53
- CategoryDataMap$,
54
- visibleComputedData$
55
- }
56
- }
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
+ }