@orbcharts/plugins-basic 3.0.0-alpha.61 → 3.0.0-alpha.62

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 (78) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic.es.js +1 -1
  3. package/dist/orbcharts-plugins-basic.umd.js +1 -1
  4. package/package.json +42 -42
  5. package/src/base/BaseBarStack.ts +778 -778
  6. package/src/base/BaseBars.ts +764 -764
  7. package/src/base/BaseBarsTriangle.ts +672 -672
  8. package/src/base/BaseDots.ts +513 -513
  9. package/src/base/BaseGroupAxis.ts +558 -558
  10. package/src/base/BaseLegend.ts +641 -641
  11. package/src/base/BaseLineAreas.ts +628 -628
  12. package/src/base/BaseLines.ts +704 -704
  13. package/src/base/BaseValueAxis.ts +480 -478
  14. package/src/base/types.ts +2 -2
  15. package/src/grid/defaults.ts +128 -128
  16. package/src/grid/gridObservables.ts +541 -541
  17. package/src/grid/index.ts +15 -15
  18. package/src/grid/plugins/BarStack.ts +43 -43
  19. package/src/grid/plugins/Bars.ts +44 -44
  20. package/src/grid/plugins/BarsPN.ts +41 -41
  21. package/src/grid/plugins/BarsTriangle.ts +42 -42
  22. package/src/grid/plugins/Dots.ts +37 -37
  23. package/src/grid/plugins/GridLegend.ts +59 -59
  24. package/src/grid/plugins/GroupAux.ts +976 -976
  25. package/src/grid/plugins/GroupAxis.ts +35 -35
  26. package/src/grid/plugins/LineAreas.ts +40 -40
  27. package/src/grid/plugins/Lines.ts +40 -40
  28. package/src/grid/plugins/ScalingArea.ts +173 -173
  29. package/src/grid/plugins/ValueAxis.ts +36 -36
  30. package/src/grid/plugins/ValueStackAxis.ts +38 -38
  31. package/src/grid/types.ts +123 -123
  32. package/src/index.ts +9 -9
  33. package/src/multiGrid/defaults.ts +158 -158
  34. package/src/multiGrid/index.ts +13 -13
  35. package/src/multiGrid/multiGridObservables.ts +49 -49
  36. package/src/multiGrid/plugins/MultiBarStack.ts +78 -78
  37. package/src/multiGrid/plugins/MultiBars.ts +77 -77
  38. package/src/multiGrid/plugins/MultiBarsTriangle.ts +77 -77
  39. package/src/multiGrid/plugins/MultiDots.ts +65 -65
  40. package/src/multiGrid/plugins/MultiGridLegend.ts +89 -89
  41. package/src/multiGrid/plugins/MultiGroupAxis.ts +69 -69
  42. package/src/multiGrid/plugins/MultiLineAreas.ts +77 -77
  43. package/src/multiGrid/plugins/MultiLines.ts +77 -77
  44. package/src/multiGrid/plugins/MultiValueAxis.ts +69 -69
  45. package/src/multiGrid/plugins/MultiValueStackAxis.ts +69 -69
  46. package/src/multiGrid/plugins/OverlappingValueAxes.ts +167 -167
  47. package/src/multiGrid/plugins/OverlappingValueStackAxes.ts +168 -168
  48. package/src/multiGrid/types.ts +72 -72
  49. package/src/noneData/defaults.ts +102 -102
  50. package/src/noneData/index.ts +3 -3
  51. package/src/noneData/plugins/Container.ts +10 -10
  52. package/src/noneData/plugins/Tooltip.ts +310 -310
  53. package/src/noneData/types.ts +26 -26
  54. package/src/series/defaults.ts +144 -144
  55. package/src/series/index.ts +9 -9
  56. package/src/series/plugins/Bubbles.ts +545 -545
  57. package/src/series/plugins/Pie.ts +576 -576
  58. package/src/series/plugins/PieEventTexts.ts +262 -262
  59. package/src/series/plugins/PieLabels.ts +304 -304
  60. package/src/series/plugins/Rose.ts +472 -472
  61. package/src/series/plugins/RoseLabels.ts +362 -362
  62. package/src/series/plugins/SeriesLegend.ts +59 -59
  63. package/src/series/seriesObservables.ts +145 -145
  64. package/src/series/seriesUtils.ts +51 -51
  65. package/src/series/types.ts +83 -83
  66. package/src/tree/defaults.ts +23 -23
  67. package/src/tree/index.ts +3 -3
  68. package/src/tree/plugins/TreeLegend.ts +59 -59
  69. package/src/tree/plugins/TreeMap.ts +305 -305
  70. package/src/tree/types.ts +23 -23
  71. package/src/utils/commonUtils.ts +21 -21
  72. package/src/utils/d3Graphics.ts +124 -124
  73. package/src/utils/d3Utils.ts +73 -73
  74. package/src/utils/observables.ts +14 -14
  75. package/src/utils/orbchartsUtils.ts +100 -100
  76. package/tsconfig.base.json +13 -13
  77. package/tsconfig.json +2 -2
  78. package/vite.config.js +22 -22
@@ -1,167 +1,167 @@
1
- import * as d3 from 'd3'
2
- import {
3
- of,
4
- map,
5
- switchMap,
6
- combineLatest,
7
- takeUntil,
8
- distinctUntilChanged,
9
- shareReplay,
10
- iif,
11
- Observable,
12
- Subject } from 'rxjs'
13
- import type { ContextObserverMultiGrid, DataFormatterGrid, DataFormatterTypeMap, Layout } from '@orbcharts/core'
14
- import {
15
- defineMultiGridPlugin } from '@orbcharts/core'
16
- import { DEFAULT_OVERLAPPING_VALUE_AXES_PARAMS } from '../defaults'
17
- import { createBaseValueAxis } from '../../base/BaseValueAxis'
18
- import { multiGridPluginDetailObservables } from '../multiGridObservables'
19
- import { getClassName, getUniID } from '../../utils/orbchartsUtils'
20
- import { gridAxesTransformObservable, gridAxesReverseTransformObservable, gridContainerPositionObservable } from '@orbcharts/core/src/grid/gridObservables'
21
-
22
- const pluginName = 'OverlappingValueAxes'
23
-
24
- const gridClassName = getClassName(pluginName, 'grid')
25
-
26
- export const OverlappingValueAxes = defineMultiGridPlugin(pluginName, DEFAULT_OVERLAPPING_VALUE_AXES_PARAMS)(({ selection, name, subject, observer }) => {
27
- const destroy$ = new Subject()
28
-
29
- const unsubscribeFnArr: (() => void)[] = []
30
-
31
- const firstGridIndex$ = observer.fullParams$.pipe(
32
- takeUntil(destroy$),
33
- map(fullParams => fullParams.gridIndexes[0])
34
- )
35
-
36
- const secondGridIndex$ = observer.fullParams$.pipe(
37
- takeUntil(destroy$),
38
- map(fullParams => fullParams.gridIndexes[1])
39
- )
40
-
41
- // 為了要反轉第二個valueAxis的位置所以要重新計算
42
- const secondGridDataFormatter$: Observable<DataFormatterGrid> = combineLatest({
43
- firstGridIndex: firstGridIndex$,
44
- secondGridIndex: secondGridIndex$,
45
- fullDataFormatter: observer.fullDataFormatter$,
46
- }).pipe(
47
- takeUntil(destroy$),
48
- switchMap(async (d) => d),
49
- map(data => {
50
- if (!data.fullDataFormatter.gridList[data.secondGridIndex]) {
51
- data.fullDataFormatter.gridList[data.secondGridIndex] = Object.assign({}, data.fullDataFormatter.gridList[data.firstGridIndex])
52
- }
53
- const position = data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position
54
- // 反轉第二個valueAxis的位置
55
- let reversePosition = position
56
- if (position === 'left') {
57
- reversePosition = 'right'
58
- } else if (position === 'bottom') {
59
- reversePosition = 'top'
60
- } else if (position === 'top') {
61
- reversePosition = 'bottom'
62
- } else if (position === 'right') {
63
- reversePosition = 'left'
64
- }
65
- return <DataFormatterGrid>{
66
- type: 'grid',
67
- visibleFilter: data.fullDataFormatter.visibleFilter as any,
68
- grid: {
69
- ...data.fullDataFormatter.gridList[data.secondGridIndex],
70
- valueAxis: {
71
- ...data.fullDataFormatter.gridList[data.secondGridIndex].valueAxis,
72
- position: reversePosition
73
- }
74
- },
75
- container: {
76
- ...data.fullDataFormatter.container
77
- }
78
- }
79
- })
80
- )
81
-
82
- const multiGridPluginDetail$ = of(observer).pipe(
83
- takeUntil(destroy$),
84
- map(observer => {
85
- // 將observer的gridIndexes限制在2個
86
- return {
87
- ...observer,
88
- fullParams$: observer.fullParams$.pipe(
89
- map(fullParams => {
90
- if (fullParams.gridIndexes.length > 2) {
91
- fullParams.gridIndexes.length = 2
92
- }
93
- return fullParams
94
- })
95
- )
96
- }
97
- }),
98
- switchMap(observer => multiGridPluginDetailObservables(observer)),
99
- map(data => {
100
- return data.map((observables, index) => {
101
- if (index === 0) {
102
- return observables
103
- }
104
- // index === 1,將跟第二個valueAxis有關的observables全部重新計算
105
- const gridAxesTransform$ = gridAxesTransformObservable({
106
- fullDataFormatter$: secondGridDataFormatter$,
107
- layout$: observer.layout$
108
- })
109
- const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
110
- gridAxesTransform$
111
- })
112
- const gridContainerPosition$ = gridContainerPositionObservable({
113
- computedData$: observables.computedData$,
114
- fullDataFormatter$: secondGridDataFormatter$,
115
- layout$: observer.layout$
116
- })
117
- return {
118
- ...observables,
119
- gridAxesTransform$,
120
- gridAxesReverseTransform$,
121
- gridContainerPosition$,
122
- }
123
- })
124
- })
125
- )
126
-
127
- multiGridPluginDetail$
128
- .pipe(
129
- takeUntil(destroy$)
130
- )
131
- .subscribe(data => {
132
- // 每次重新計算時,清除之前的訂閱
133
- unsubscribeFnArr.forEach(fn => fn())
134
-
135
- selection.selectAll(`g.${gridClassName}`)
136
- .data(data)
137
- .join('g')
138
- .attr('class', gridClassName)
139
- .each((d, i, g) => {
140
- if (i > 1) {
141
- return
142
- }
143
-
144
- const gridSelection = d3.select(g[i])
145
-
146
- unsubscribeFnArr[i] = createBaseValueAxis(pluginName, {
147
- selection: gridSelection,
148
- computedData$: d.computedData$,
149
- fullParams$: observer.fullParams$.pipe(
150
- map(fullParams => i === 0 ? fullParams.firstAxis : fullParams.secondAxis)
151
- ),
152
- fullDataFormatter$: d.dataFormatter$,
153
- fullChartParams$: observer.fullChartParams$,
154
- gridAxesTransform$: d.gridAxesTransform$,
155
- gridAxesReverseTransform$: d.gridAxesReverseTransform$,
156
- gridAxesSize$: d.gridAxesSize$,
157
- gridContainerPosition$: d.gridContainerPosition$,
158
- isSeriesSeprate$: d.isSeriesSeprate$,
159
- })
160
- })
161
- })
162
-
163
- return () => {
164
- destroy$.next(undefined)
165
- unsubscribeFnArr.forEach(fn => fn())
166
- }
167
- })
1
+ import * as d3 from 'd3'
2
+ import {
3
+ of,
4
+ map,
5
+ switchMap,
6
+ combineLatest,
7
+ takeUntil,
8
+ distinctUntilChanged,
9
+ shareReplay,
10
+ iif,
11
+ Observable,
12
+ Subject } from 'rxjs'
13
+ import type { ContextObserverMultiGrid, DataFormatterGrid, DataFormatterTypeMap, Layout } from '@orbcharts/core'
14
+ import {
15
+ defineMultiGridPlugin } from '@orbcharts/core'
16
+ import { DEFAULT_OVERLAPPING_VALUE_AXES_PARAMS } from '../defaults'
17
+ import { createBaseValueAxis } from '../../base/BaseValueAxis'
18
+ import { multiGridPluginDetailObservables } from '../multiGridObservables'
19
+ import { getClassName, getUniID } from '../../utils/orbchartsUtils'
20
+ import { gridAxesTransformObservable, gridAxesReverseTransformObservable, gridContainerPositionObservable } from '@orbcharts/core/src/grid/gridObservables'
21
+
22
+ const pluginName = 'OverlappingValueAxes'
23
+
24
+ const gridClassName = getClassName(pluginName, 'grid')
25
+
26
+ export const OverlappingValueAxes = defineMultiGridPlugin(pluginName, DEFAULT_OVERLAPPING_VALUE_AXES_PARAMS)(({ selection, name, subject, observer }) => {
27
+ const destroy$ = new Subject()
28
+
29
+ const unsubscribeFnArr: (() => void)[] = []
30
+
31
+ const firstGridIndex$ = observer.fullParams$.pipe(
32
+ takeUntil(destroy$),
33
+ map(fullParams => fullParams.gridIndexes[0])
34
+ )
35
+
36
+ const secondGridIndex$ = observer.fullParams$.pipe(
37
+ takeUntil(destroy$),
38
+ map(fullParams => fullParams.gridIndexes[1])
39
+ )
40
+
41
+ // 為了要反轉第二個valueAxis的位置所以要重新計算
42
+ const secondGridDataFormatter$: Observable<DataFormatterGrid> = combineLatest({
43
+ firstGridIndex: firstGridIndex$,
44
+ secondGridIndex: secondGridIndex$,
45
+ fullDataFormatter: observer.fullDataFormatter$,
46
+ }).pipe(
47
+ takeUntil(destroy$),
48
+ switchMap(async (d) => d),
49
+ map(data => {
50
+ if (!data.fullDataFormatter.gridList[data.secondGridIndex]) {
51
+ data.fullDataFormatter.gridList[data.secondGridIndex] = Object.assign({}, data.fullDataFormatter.gridList[data.firstGridIndex])
52
+ }
53
+ const position = data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position
54
+ // 反轉第二個valueAxis的位置
55
+ let reversePosition = position
56
+ if (position === 'left') {
57
+ reversePosition = 'right'
58
+ } else if (position === 'bottom') {
59
+ reversePosition = 'top'
60
+ } else if (position === 'top') {
61
+ reversePosition = 'bottom'
62
+ } else if (position === 'right') {
63
+ reversePosition = 'left'
64
+ }
65
+ return <DataFormatterGrid>{
66
+ type: 'grid',
67
+ visibleFilter: data.fullDataFormatter.visibleFilter as any,
68
+ grid: {
69
+ ...data.fullDataFormatter.gridList[data.secondGridIndex],
70
+ valueAxis: {
71
+ ...data.fullDataFormatter.gridList[data.secondGridIndex].valueAxis,
72
+ position: reversePosition
73
+ }
74
+ },
75
+ container: {
76
+ ...data.fullDataFormatter.container
77
+ }
78
+ }
79
+ })
80
+ )
81
+
82
+ const multiGridPluginDetail$ = of(observer).pipe(
83
+ takeUntil(destroy$),
84
+ map(observer => {
85
+ // 將observer的gridIndexes限制在2個
86
+ return {
87
+ ...observer,
88
+ fullParams$: observer.fullParams$.pipe(
89
+ map(fullParams => {
90
+ if (fullParams.gridIndexes.length > 2) {
91
+ fullParams.gridIndexes.length = 2
92
+ }
93
+ return fullParams
94
+ })
95
+ )
96
+ }
97
+ }),
98
+ switchMap(observer => multiGridPluginDetailObservables(observer)),
99
+ map(data => {
100
+ return data.map((observables, index) => {
101
+ if (index === 0) {
102
+ return observables
103
+ }
104
+ // index === 1,將跟第二個valueAxis有關的observables全部重新計算
105
+ const gridAxesTransform$ = gridAxesTransformObservable({
106
+ fullDataFormatter$: secondGridDataFormatter$,
107
+ layout$: observer.layout$
108
+ })
109
+ const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
110
+ gridAxesTransform$
111
+ })
112
+ const gridContainerPosition$ = gridContainerPositionObservable({
113
+ computedData$: observables.computedData$,
114
+ fullDataFormatter$: secondGridDataFormatter$,
115
+ layout$: observer.layout$
116
+ })
117
+ return {
118
+ ...observables,
119
+ gridAxesTransform$,
120
+ gridAxesReverseTransform$,
121
+ gridContainerPosition$,
122
+ }
123
+ })
124
+ })
125
+ )
126
+
127
+ multiGridPluginDetail$
128
+ .pipe(
129
+ takeUntil(destroy$)
130
+ )
131
+ .subscribe(data => {
132
+ // 每次重新計算時,清除之前的訂閱
133
+ unsubscribeFnArr.forEach(fn => fn())
134
+
135
+ selection.selectAll(`g.${gridClassName}`)
136
+ .data(data)
137
+ .join('g')
138
+ .attr('class', gridClassName)
139
+ .each((d, i, g) => {
140
+ if (i > 1) {
141
+ return
142
+ }
143
+
144
+ const gridSelection = d3.select(g[i])
145
+
146
+ unsubscribeFnArr[i] = createBaseValueAxis(pluginName, {
147
+ selection: gridSelection,
148
+ computedData$: d.computedData$,
149
+ fullParams$: observer.fullParams$.pipe(
150
+ map(fullParams => i === 0 ? fullParams.firstAxis : fullParams.secondAxis)
151
+ ),
152
+ fullDataFormatter$: d.dataFormatter$,
153
+ fullChartParams$: observer.fullChartParams$,
154
+ gridAxesTransform$: d.gridAxesTransform$,
155
+ gridAxesReverseTransform$: d.gridAxesReverseTransform$,
156
+ gridAxesSize$: d.gridAxesSize$,
157
+ gridContainerPosition$: d.gridContainerPosition$,
158
+ isSeriesSeprate$: d.isSeriesSeprate$,
159
+ })
160
+ })
161
+ })
162
+
163
+ return () => {
164
+ destroy$.next(undefined)
165
+ unsubscribeFnArr.forEach(fn => fn())
166
+ }
167
+ })
@@ -1,168 +1,168 @@
1
- import * as d3 from 'd3'
2
- import {
3
- of,
4
- map,
5
- switchMap,
6
- combineLatest,
7
- takeUntil,
8
- distinctUntilChanged,
9
- shareReplay,
10
- iif,
11
- Observable,
12
- Subject } from 'rxjs'
13
- import type { ContextObserverMultiGrid, DataFormatterGrid, DataFormatterTypeMap, Layout } from '@orbcharts/core'
14
- import {
15
- defineMultiGridPlugin } from '@orbcharts/core'
16
- import { DEFAULT_OVERLAPPING_VALUE_STACK_AXES_PARAMS } from '../defaults'
17
- import { createBaseValueAxis } from '../../base/BaseValueAxis'
18
- import { multiGridPluginDetailObservables } from '../multiGridObservables'
19
- import { getClassName, getUniID } from '../../utils/orbchartsUtils'
20
- import { gridAxesTransformObservable, gridAxesReverseTransformObservable, gridContainerPositionObservable } from '@orbcharts/core/src/grid/gridObservables'
21
-
22
- const pluginName = 'OverlappingValueStackAxes'
23
-
24
- const gridClassName = getClassName(pluginName, 'grid')
25
-
26
- // 第一個圖軸使用堆疊的資料,第二個圖軸使用原始資料
27
- export const OverlappingValueStackAxes = defineMultiGridPlugin(pluginName, DEFAULT_OVERLAPPING_VALUE_STACK_AXES_PARAMS)(({ selection, name, subject, observer }) => {
28
- const destroy$ = new Subject()
29
-
30
- const unsubscribeFnArr: (() => void)[] = []
31
-
32
- const firstGridIndex$ = observer.fullParams$.pipe(
33
- takeUntil(destroy$),
34
- map(fullParams => fullParams.gridIndexes[0])
35
- )
36
-
37
- const secondGridIndex$ = observer.fullParams$.pipe(
38
- takeUntil(destroy$),
39
- map(fullParams => fullParams.gridIndexes[1])
40
- )
41
-
42
- // 為了要反轉第二個valueAxis的位置所以要重新計算
43
- const secondGridDataFormatter$: Observable<DataFormatterGrid> = combineLatest({
44
- firstGridIndex: firstGridIndex$,
45
- secondGridIndex: secondGridIndex$,
46
- fullDataFormatter: observer.fullDataFormatter$,
47
- }).pipe(
48
- takeUntil(destroy$),
49
- switchMap(async (d) => d),
50
- map(data => {
51
- if (!data.fullDataFormatter.gridList[data.secondGridIndex]) {
52
- data.fullDataFormatter.gridList[data.secondGridIndex] = Object.assign({}, data.fullDataFormatter.gridList[data.firstGridIndex])
53
- }
54
- const position = data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position
55
- // 反轉第二個valueAxis的位置
56
- let reversePosition = position
57
- if (position === 'left') {
58
- reversePosition = 'right'
59
- } else if (position === 'bottom') {
60
- reversePosition = 'top'
61
- } else if (position === 'top') {
62
- reversePosition = 'bottom'
63
- } else if (position === 'right') {
64
- reversePosition = 'left'
65
- }
66
- return <DataFormatterGrid>{
67
- type: 'grid',
68
- visibleFilter: data.fullDataFormatter.visibleFilter as any,
69
- grid: {
70
- ...data.fullDataFormatter.gridList[data.secondGridIndex],
71
- valueAxis: {
72
- ...data.fullDataFormatter.gridList[data.secondGridIndex].valueAxis,
73
- position: reversePosition
74
- }
75
- },
76
- container: {
77
- ...data.fullDataFormatter.container
78
- }
79
- }
80
- })
81
- )
82
-
83
- const multiGridPluginDetail$ = of(observer).pipe(
84
- takeUntil(destroy$),
85
- map(observer => {
86
- // 將observer的gridIndexes限制在2個
87
- return {
88
- ...observer,
89
- fullParams$: observer.fullParams$.pipe(
90
- map(fullParams => {
91
- if (fullParams.gridIndexes.length > 2) {
92
- fullParams.gridIndexes.length = 2
93
- }
94
- return fullParams
95
- })
96
- )
97
- }
98
- }),
99
- switchMap(observer => multiGridPluginDetailObservables(observer)),
100
- map(data => {
101
- return data.map((observables, index) => {
102
- if (index === 0) {
103
- return observables
104
- }
105
- // index === 1,將跟第二個valueAxis有關的observables全部重新計算
106
- const gridAxesTransform$ = gridAxesTransformObservable({
107
- fullDataFormatter$: secondGridDataFormatter$,
108
- layout$: observer.layout$
109
- })
110
- const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
111
- gridAxesTransform$
112
- })
113
- const gridContainerPosition$ = gridContainerPositionObservable({
114
- computedData$: observables.computedData$,
115
- fullDataFormatter$: secondGridDataFormatter$,
116
- layout$: observer.layout$
117
- })
118
- return {
119
- ...observables,
120
- gridAxesTransform$,
121
- gridAxesReverseTransform$,
122
- gridContainerPosition$,
123
- }
124
- })
125
- })
126
- )
127
-
128
- multiGridPluginDetail$
129
- .pipe(
130
- takeUntil(destroy$)
131
- )
132
- .subscribe(data => {
133
- // 每次重新計算時,清除之前的訂閱
134
- unsubscribeFnArr.forEach(fn => fn())
135
-
136
- selection.selectAll(`g.${gridClassName}`)
137
- .data(data)
138
- .join('g')
139
- .attr('class', gridClassName)
140
- .each((d, i, g) => {
141
- if (i > 1) {
142
- return
143
- }
144
-
145
- const gridSelection = d3.select(g[i])
146
-
147
- unsubscribeFnArr[i] = createBaseValueAxis(pluginName, {
148
- selection: gridSelection,
149
- computedData$: i === 0 ? d.computedStackedData$ : d.computedData$, // 第一個圖軸計算疊加value的資料
150
- fullParams$: observer.fullParams$.pipe(
151
- map(fullParams => i === 0 ? fullParams.firstAxis : fullParams.secondAxis)
152
- ),
153
- fullDataFormatter$: d.dataFormatter$,
154
- fullChartParams$: observer.fullChartParams$,
155
- gridAxesTransform$: d.gridAxesTransform$,
156
- gridAxesReverseTransform$: d.gridAxesReverseTransform$,
157
- gridAxesSize$: d.gridAxesSize$,
158
- gridContainerPosition$: d.gridContainerPosition$,
159
- isSeriesSeprate$: d.isSeriesSeprate$,
160
- })
161
- })
162
- })
163
-
164
- return () => {
165
- destroy$.next(undefined)
166
- unsubscribeFnArr.forEach(fn => fn())
167
- }
168
- })
1
+ import * as d3 from 'd3'
2
+ import {
3
+ of,
4
+ map,
5
+ switchMap,
6
+ combineLatest,
7
+ takeUntil,
8
+ distinctUntilChanged,
9
+ shareReplay,
10
+ iif,
11
+ Observable,
12
+ Subject } from 'rxjs'
13
+ import type { ContextObserverMultiGrid, DataFormatterGrid, DataFormatterTypeMap, Layout } from '@orbcharts/core'
14
+ import {
15
+ defineMultiGridPlugin } from '@orbcharts/core'
16
+ import { DEFAULT_OVERLAPPING_VALUE_STACK_AXES_PARAMS } from '../defaults'
17
+ import { createBaseValueAxis } from '../../base/BaseValueAxis'
18
+ import { multiGridPluginDetailObservables } from '../multiGridObservables'
19
+ import { getClassName, getUniID } from '../../utils/orbchartsUtils'
20
+ import { gridAxesTransformObservable, gridAxesReverseTransformObservable, gridContainerPositionObservable } from '@orbcharts/core/src/grid/gridObservables'
21
+
22
+ const pluginName = 'OverlappingValueStackAxes'
23
+
24
+ const gridClassName = getClassName(pluginName, 'grid')
25
+
26
+ // 第一個圖軸使用堆疊的資料,第二個圖軸使用原始資料
27
+ export const OverlappingValueStackAxes = defineMultiGridPlugin(pluginName, DEFAULT_OVERLAPPING_VALUE_STACK_AXES_PARAMS)(({ selection, name, subject, observer }) => {
28
+ const destroy$ = new Subject()
29
+
30
+ const unsubscribeFnArr: (() => void)[] = []
31
+
32
+ const firstGridIndex$ = observer.fullParams$.pipe(
33
+ takeUntil(destroy$),
34
+ map(fullParams => fullParams.gridIndexes[0])
35
+ )
36
+
37
+ const secondGridIndex$ = observer.fullParams$.pipe(
38
+ takeUntil(destroy$),
39
+ map(fullParams => fullParams.gridIndexes[1])
40
+ )
41
+
42
+ // 為了要反轉第二個valueAxis的位置所以要重新計算
43
+ const secondGridDataFormatter$: Observable<DataFormatterGrid> = combineLatest({
44
+ firstGridIndex: firstGridIndex$,
45
+ secondGridIndex: secondGridIndex$,
46
+ fullDataFormatter: observer.fullDataFormatter$,
47
+ }).pipe(
48
+ takeUntil(destroy$),
49
+ switchMap(async (d) => d),
50
+ map(data => {
51
+ if (!data.fullDataFormatter.gridList[data.secondGridIndex]) {
52
+ data.fullDataFormatter.gridList[data.secondGridIndex] = Object.assign({}, data.fullDataFormatter.gridList[data.firstGridIndex])
53
+ }
54
+ const position = data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position
55
+ // 反轉第二個valueAxis的位置
56
+ let reversePosition = position
57
+ if (position === 'left') {
58
+ reversePosition = 'right'
59
+ } else if (position === 'bottom') {
60
+ reversePosition = 'top'
61
+ } else if (position === 'top') {
62
+ reversePosition = 'bottom'
63
+ } else if (position === 'right') {
64
+ reversePosition = 'left'
65
+ }
66
+ return <DataFormatterGrid>{
67
+ type: 'grid',
68
+ visibleFilter: data.fullDataFormatter.visibleFilter as any,
69
+ grid: {
70
+ ...data.fullDataFormatter.gridList[data.secondGridIndex],
71
+ valueAxis: {
72
+ ...data.fullDataFormatter.gridList[data.secondGridIndex].valueAxis,
73
+ position: reversePosition
74
+ }
75
+ },
76
+ container: {
77
+ ...data.fullDataFormatter.container
78
+ }
79
+ }
80
+ })
81
+ )
82
+
83
+ const multiGridPluginDetail$ = of(observer).pipe(
84
+ takeUntil(destroy$),
85
+ map(observer => {
86
+ // 將observer的gridIndexes限制在2個
87
+ return {
88
+ ...observer,
89
+ fullParams$: observer.fullParams$.pipe(
90
+ map(fullParams => {
91
+ if (fullParams.gridIndexes.length > 2) {
92
+ fullParams.gridIndexes.length = 2
93
+ }
94
+ return fullParams
95
+ })
96
+ )
97
+ }
98
+ }),
99
+ switchMap(observer => multiGridPluginDetailObservables(observer)),
100
+ map(data => {
101
+ return data.map((observables, index) => {
102
+ if (index === 0) {
103
+ return observables
104
+ }
105
+ // index === 1,將跟第二個valueAxis有關的observables全部重新計算
106
+ const gridAxesTransform$ = gridAxesTransformObservable({
107
+ fullDataFormatter$: secondGridDataFormatter$,
108
+ layout$: observer.layout$
109
+ })
110
+ const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
111
+ gridAxesTransform$
112
+ })
113
+ const gridContainerPosition$ = gridContainerPositionObservable({
114
+ computedData$: observables.computedData$,
115
+ fullDataFormatter$: secondGridDataFormatter$,
116
+ layout$: observer.layout$
117
+ })
118
+ return {
119
+ ...observables,
120
+ gridAxesTransform$,
121
+ gridAxesReverseTransform$,
122
+ gridContainerPosition$,
123
+ }
124
+ })
125
+ })
126
+ )
127
+
128
+ multiGridPluginDetail$
129
+ .pipe(
130
+ takeUntil(destroy$)
131
+ )
132
+ .subscribe(data => {
133
+ // 每次重新計算時,清除之前的訂閱
134
+ unsubscribeFnArr.forEach(fn => fn())
135
+
136
+ selection.selectAll(`g.${gridClassName}`)
137
+ .data(data)
138
+ .join('g')
139
+ .attr('class', gridClassName)
140
+ .each((d, i, g) => {
141
+ if (i > 1) {
142
+ return
143
+ }
144
+
145
+ const gridSelection = d3.select(g[i])
146
+
147
+ unsubscribeFnArr[i] = createBaseValueAxis(pluginName, {
148
+ selection: gridSelection,
149
+ computedData$: i === 0 ? d.computedStackedData$ : d.computedData$, // 第一個圖軸計算疊加value的資料
150
+ fullParams$: observer.fullParams$.pipe(
151
+ map(fullParams => i === 0 ? fullParams.firstAxis : fullParams.secondAxis)
152
+ ),
153
+ fullDataFormatter$: d.dataFormatter$,
154
+ fullChartParams$: observer.fullChartParams$,
155
+ gridAxesTransform$: d.gridAxesTransform$,
156
+ gridAxesReverseTransform$: d.gridAxesReverseTransform$,
157
+ gridAxesSize$: d.gridAxesSize$,
158
+ gridContainerPosition$: d.gridContainerPosition$,
159
+ isSeriesSeprate$: d.isSeriesSeprate$,
160
+ })
161
+ })
162
+ })
163
+
164
+ return () => {
165
+ destroy$.next(undefined)
166
+ unsubscribeFnArr.forEach(fn => fn())
167
+ }
168
+ })