@orbcharts/plugins-basic 3.0.0-alpha.68 → 3.0.0-alpha.69

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