@orbcharts/plugins-basic 3.0.0-alpha.50 → 3.0.0-alpha.51

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