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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. package/LICENSE +200 -200
  2. package/package.json +42 -43
  3. package/src/base/BaseBarStack.ts +778 -778
  4. package/src/base/BaseBars.ts +764 -764
  5. package/src/base/BaseBarsTriangle.ts +672 -672
  6. package/src/base/BaseDots.ts +513 -513
  7. package/src/base/BaseGroupAxis.ts +558 -558
  8. package/src/base/BaseLegend.ts +641 -641
  9. package/src/base/BaseLineAreas.ts +628 -628
  10. package/src/base/BaseLines.ts +704 -704
  11. package/src/base/BaseValueAxis.ts +478 -478
  12. package/src/base/types.ts +2 -2
  13. package/src/grid/defaults.ts +128 -128
  14. package/src/grid/gridObservables.ts +541 -541
  15. package/src/grid/index.ts +15 -15
  16. package/src/grid/plugins/BarStack.ts +43 -43
  17. package/src/grid/plugins/Bars.ts +44 -44
  18. package/src/grid/plugins/BarsPN.ts +41 -41
  19. package/src/grid/plugins/BarsTriangle.ts +42 -42
  20. package/src/grid/plugins/Dots.ts +37 -37
  21. package/src/grid/plugins/GridLegend.ts +59 -59
  22. package/src/grid/plugins/GroupAux.ts +976 -976
  23. package/src/grid/plugins/GroupAxis.ts +35 -35
  24. package/src/grid/plugins/LineAreas.ts +40 -40
  25. package/src/grid/plugins/Lines.ts +40 -40
  26. package/src/grid/plugins/ScalingArea.ts +173 -173
  27. package/src/grid/plugins/ValueAxis.ts +36 -36
  28. package/src/grid/plugins/ValueStackAxis.ts +38 -38
  29. package/src/grid/types.ts +123 -123
  30. package/src/index.ts +9 -9
  31. package/src/multiGrid/defaults.ts +158 -158
  32. package/src/multiGrid/index.ts +13 -13
  33. package/src/multiGrid/multiGridObservables.ts +49 -49
  34. package/src/multiGrid/plugins/MultiBarStack.ts +78 -78
  35. package/src/multiGrid/plugins/MultiBars.ts +77 -77
  36. package/src/multiGrid/plugins/MultiBarsTriangle.ts +77 -77
  37. package/src/multiGrid/plugins/MultiDots.ts +65 -65
  38. package/src/multiGrid/plugins/MultiGridLegend.ts +89 -89
  39. package/src/multiGrid/plugins/MultiGroupAxis.ts +69 -69
  40. package/src/multiGrid/plugins/MultiLineAreas.ts +77 -77
  41. package/src/multiGrid/plugins/MultiLines.ts +77 -77
  42. package/src/multiGrid/plugins/MultiValueAxis.ts +69 -69
  43. package/src/multiGrid/plugins/MultiValueStackAxis.ts +69 -69
  44. package/src/multiGrid/plugins/OverlappingValueAxes.ts +167 -167
  45. package/src/multiGrid/plugins/OverlappingValueStackAxes.ts +168 -168
  46. package/src/multiGrid/types.ts +72 -72
  47. package/src/noneData/defaults.ts +102 -102
  48. package/src/noneData/index.ts +3 -3
  49. package/src/noneData/plugins/Container.ts +10 -10
  50. package/src/noneData/plugins/Tooltip.ts +310 -310
  51. package/src/noneData/types.ts +26 -26
  52. package/src/series/defaults.ts +144 -144
  53. package/src/series/index.ts +9 -9
  54. package/src/series/plugins/Bubbles.ts +545 -545
  55. package/src/series/plugins/Pie.ts +576 -576
  56. package/src/series/plugins/PieEventTexts.ts +262 -262
  57. package/src/series/plugins/PieLabels.ts +304 -304
  58. package/src/series/plugins/Rose.ts +472 -472
  59. package/src/series/plugins/RoseLabels.ts +362 -362
  60. package/src/series/plugins/SeriesLegend.ts +59 -59
  61. package/src/series/seriesObservables.ts +145 -145
  62. package/src/series/seriesUtils.ts +51 -51
  63. package/src/series/types.ts +83 -83
  64. package/src/tree/defaults.ts +23 -23
  65. package/src/tree/index.ts +3 -3
  66. package/src/tree/plugins/TreeLegend.ts +59 -59
  67. package/src/tree/plugins/TreeMap.ts +305 -305
  68. package/src/tree/types.ts +23 -23
  69. package/src/utils/commonUtils.ts +21 -21
  70. package/src/utils/d3Graphics.ts +124 -124
  71. package/src/utils/d3Utils.ts +73 -73
  72. package/src/utils/observables.ts +14 -14
  73. package/src/utils/orbchartsUtils.ts +100 -100
  74. package/tsconfig.base.json +13 -13
  75. package/tsconfig.json +2 -7
  76. package/{vite.config.mjs → vite.config.js} +22 -40
  77. package/tsconfig.prod.json +0 -3
  78. /package/dist/{vite.config.d.mts → vite.config.d.ts} +0 -0
@@ -1,262 +1,262 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- switchMap,
5
- first,
6
- takeUntil,
7
- map,
8
- distinctUntilChanged,
9
- Observable,
10
- Subject } from 'rxjs'
11
- import type { Subscription } from 'rxjs'
12
- import {
13
- defineSeriesPlugin} from '@orbcharts/core'
14
- import type {
15
- ComputedDatumSeries,
16
- ChartParams,
17
- SeriesContainerPosition,
18
- EventName,
19
- EventSeries } from '@orbcharts/core'
20
- import type { PieEventTextsParams } from '../types'
21
- import { DEFAULT_PIE_EVENT_TEXTS_PARAMS } from '../defaults'
22
- import { getD3TransitionEase } from '../../utils/d3Utils'
23
- import { getClassName } from '../../utils/orbchartsUtils'
24
- import { seriesCenterSelectionObservable } from '../seriesObservables'
25
-
26
-
27
- type TextDatum = {
28
- text: string
29
- attr: { [key:string]: any }
30
- style: { [key:string]: any }
31
- }
32
-
33
- const pluginName = 'PieEventTexts'
34
- const textClassName = getClassName(pluginName, 'text')
35
-
36
- function renderText (
37
- selection: d3.Selection<SVGGElement, unknown, any, any>,
38
- data: Array<TextDatum>
39
- ): d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> {
40
- const textUpdate = selection
41
- .selectAll<SVGTextElement, TextDatum>(`text.${textClassName}`)
42
- .data(data)
43
- const textEnter = textUpdate.enter()
44
- .append('text')
45
- .classed(textClassName, true)
46
- const text = textUpdate.merge(textEnter)
47
- text
48
- .each((d, i, g) => {
49
- const t = d3.select(g[i])
50
- .text(d.text)
51
- Object.keys(d.attr)
52
- .forEach(key => {
53
- t.attr(key, d.attr[key])
54
- })
55
- Object.keys(d.style)
56
- .forEach(key => {
57
- t.style(key, d.style[key])
58
- })
59
- })
60
-
61
- textUpdate.exit().remove()
62
-
63
- return text
64
- }
65
-
66
- function makeTextData ({ eventData, eventName, t, eventFn, textAttrs, textStyles }: {
67
- eventData: EventSeries,
68
- eventName: EventName,
69
- t: number,
70
- eventFn: (d: EventSeries, eventName: EventName, t: number) => string[]
71
- textAttrs: Array<{ [key:string]: string | number }>
72
- textStyles: Array<{ [key:string]: string | number }>
73
- }): TextDatum[] {
74
- const callbackText = eventFn(eventData, eventName, t)
75
- return callbackText.map((d, i) => {
76
- return {
77
- text: d,
78
- attr: textAttrs[i],
79
- style: textStyles[i]
80
- }
81
- })
82
- }
83
-
84
- function createEachPieEventTexts (pluginName: string, context: {
85
- containerSelection: d3.Selection<SVGGElement, any, any, unknown>
86
- computedData$: Observable<ComputedDatumSeries[][]>
87
- containerComputedLayoutData$: Observable<ComputedDatumSeries[]>
88
- SeriesDataMap$: Observable<Map<string, ComputedDatumSeries[]>>
89
- fullParams$: Observable<PieEventTextsParams>
90
- fullChartParams$: Observable<ChartParams>
91
- seriesHighlight$: Observable<ComputedDatumSeries[]>
92
- seriesContainerPosition$: Observable<SeriesContainerPosition>
93
- event$: Subject<EventSeries>
94
- }) {
95
- const destroy$ = new Subject()
96
-
97
- // const graphicSelection: d3.Selection<SVGGElement, any, any, any> = selection.append('g')
98
- let centerTextSelection: d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> | undefined
99
- let storeEventSubscription: Subscription | undefined
100
-
101
- // context.layout$
102
- // .pipe(
103
- // first()
104
- // )
105
- // .subscribe(size => {
106
- // selection
107
- // .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
108
- // context.layout$
109
- // .pipe(
110
- // takeUntil(destroy$)
111
- // )
112
- // .subscribe(size => {
113
- // selection
114
- // .transition()
115
- // .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
116
- // })
117
- // })
118
-
119
- const highlightTarget$ = context.fullChartParams$.pipe(
120
- takeUntil(destroy$),
121
- map(d => d.highlightTarget),
122
- distinctUntilChanged()
123
- )
124
-
125
- combineLatest({
126
- computedData: context.computedData$,
127
- fullParams: context.fullParams$,
128
- fullChartParams: context.fullChartParams$,
129
- highlightTarget: highlightTarget$,
130
- }).pipe(
131
- takeUntil(destroy$),
132
- switchMap(async (d) => d),
133
- ).subscribe(data => {
134
-
135
- context.containerSelection
136
- .transition('move')
137
- .duration(data.fullChartParams.transitionDuration!)
138
- // .ease(getD3TransitionEase(data.fullChartParams.transitionEase!))
139
- .tween('move', (event, datum) => {
140
- return (t) => {
141
- const renderData = makeTextData({
142
- eventData: {
143
- type: 'series',
144
- pluginName,
145
- eventName: 'transitionMove',
146
- event,
147
- highlightTarget: data.highlightTarget,
148
- data: data.computedData,
149
- series: [],
150
- seriesIndex: -1,
151
- seriesLabel: '',
152
- datum: null
153
- },
154
- eventName: 'transitionMove',
155
- t,
156
- eventFn: data.fullParams.eventFn!,
157
- textAttrs: data.fullParams.textAttrs!,
158
- textStyles: data.fullParams.textStyles!
159
- })
160
- centerTextSelection = renderText(context.containerSelection, renderData)
161
- }
162
- })
163
- .on('end', (event, datum) => {
164
- const renderData = makeTextData({
165
- eventData: {
166
- type: 'series',
167
- pluginName,
168
- eventName: 'transitionEnd',
169
- event,
170
- highlightTarget: data.highlightTarget,
171
- data: data.computedData,
172
- series: [],
173
- seriesIndex: -1,
174
- seriesLabel: '',
175
- datum: null
176
- },
177
- eventName: 'transitionMove',
178
- t: 1,
179
- eventFn: data.fullParams.eventFn!,
180
- textAttrs: data.fullParams.textAttrs!,
181
- textStyles: data.fullParams.textStyles!
182
- })
183
- centerTextSelection = renderText(context.containerSelection, renderData)
184
-
185
- if (storeEventSubscription) {
186
- storeEventSubscription.unsubscribe()
187
- }
188
- storeEventSubscription = context.event$
189
- .subscribe(eventData => {
190
- const renderData = makeTextData({
191
- eventData,
192
- eventName: eventData.eventName,
193
- t: 1,
194
- eventFn: data.fullParams.eventFn!,
195
- textAttrs: data.fullParams.textAttrs!,
196
- textStyles: data.fullParams.textStyles!
197
- })
198
- centerTextSelection = renderText(context.containerSelection, renderData)
199
- })
200
- })
201
- })
202
-
203
- return () => {
204
- destroy$.next(undefined)
205
- }
206
- }
207
-
208
- export const PieEventTexts = defineSeriesPlugin(pluginName, DEFAULT_PIE_EVENT_TEXTS_PARAMS)(({ selection, name, observer, subject }) => {
209
- const destroy$ = new Subject()
210
-
211
- const { seriesCenterSelection$ } = seriesCenterSelectionObservable({
212
- selection: selection,
213
- pluginName,
214
- separateSeries$: observer.separateSeries$,
215
- seriesLabels$: observer.seriesLabels$,
216
- seriesContainerPosition$: observer.seriesContainerPosition$
217
- })
218
-
219
- const unsubscribeFnArr: (() => void)[] = []
220
-
221
- seriesCenterSelection$
222
- .pipe(
223
- takeUntil(destroy$)
224
- )
225
- .subscribe(seriesCenterSelection => {
226
- // 每次重新計算時,清除之前的訂閱
227
- unsubscribeFnArr.forEach(fn => fn())
228
-
229
- seriesCenterSelection.each((d, containerIndex, g) => {
230
-
231
- const containerSelection = d3.select(g[containerIndex])
232
-
233
- const containerComputedLayoutData$ = observer.computedLayoutData$.pipe(
234
- takeUntil(destroy$),
235
- map(data => data[containerIndex] ?? data[0])
236
- )
237
-
238
- const containerPosition$ = observer.seriesContainerPosition$.pipe(
239
- takeUntil(destroy$),
240
- map(data => data[containerIndex] ?? data[0])
241
- )
242
-
243
- unsubscribeFnArr[containerIndex] = createEachPieEventTexts(pluginName, {
244
- containerSelection: containerSelection,
245
- computedData$: observer.computedData$,
246
- containerComputedLayoutData$: containerComputedLayoutData$,
247
- SeriesDataMap$: observer.SeriesDataMap$,
248
- fullParams$: observer.fullParams$,
249
- fullChartParams$: observer.fullChartParams$,
250
- seriesHighlight$: observer.seriesHighlight$,
251
- seriesContainerPosition$: containerPosition$,
252
- event$: subject.event$,
253
- })
254
-
255
- })
256
- })
257
-
258
- return () => {
259
- destroy$.next(undefined)
260
- unsubscribeFnArr.forEach(fn => fn())
261
- }
262
- })
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ switchMap,
5
+ first,
6
+ takeUntil,
7
+ map,
8
+ distinctUntilChanged,
9
+ Observable,
10
+ Subject } from 'rxjs'
11
+ import type { Subscription } from 'rxjs'
12
+ import {
13
+ defineSeriesPlugin} from '@orbcharts/core'
14
+ import type {
15
+ ComputedDatumSeries,
16
+ ChartParams,
17
+ SeriesContainerPosition,
18
+ EventName,
19
+ EventSeries } from '@orbcharts/core'
20
+ import type { PieEventTextsParams } from '../types'
21
+ import { DEFAULT_PIE_EVENT_TEXTS_PARAMS } from '../defaults'
22
+ import { getD3TransitionEase } from '../../utils/d3Utils'
23
+ import { getClassName } from '../../utils/orbchartsUtils'
24
+ import { seriesCenterSelectionObservable } from '../seriesObservables'
25
+
26
+
27
+ type TextDatum = {
28
+ text: string
29
+ attr: { [key:string]: any }
30
+ style: { [key:string]: any }
31
+ }
32
+
33
+ const pluginName = 'PieEventTexts'
34
+ const textClassName = getClassName(pluginName, 'text')
35
+
36
+ function renderText (
37
+ selection: d3.Selection<SVGGElement, unknown, any, any>,
38
+ data: Array<TextDatum>
39
+ ): d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> {
40
+ const textUpdate = selection
41
+ .selectAll<SVGTextElement, TextDatum>(`text.${textClassName}`)
42
+ .data(data)
43
+ const textEnter = textUpdate.enter()
44
+ .append('text')
45
+ .classed(textClassName, true)
46
+ const text = textUpdate.merge(textEnter)
47
+ text
48
+ .each((d, i, g) => {
49
+ const t = d3.select(g[i])
50
+ .text(d.text)
51
+ Object.keys(d.attr)
52
+ .forEach(key => {
53
+ t.attr(key, d.attr[key])
54
+ })
55
+ Object.keys(d.style)
56
+ .forEach(key => {
57
+ t.style(key, d.style[key])
58
+ })
59
+ })
60
+
61
+ textUpdate.exit().remove()
62
+
63
+ return text
64
+ }
65
+
66
+ function makeTextData ({ eventData, eventName, t, eventFn, textAttrs, textStyles }: {
67
+ eventData: EventSeries,
68
+ eventName: EventName,
69
+ t: number,
70
+ eventFn: (d: EventSeries, eventName: EventName, t: number) => string[]
71
+ textAttrs: Array<{ [key:string]: string | number }>
72
+ textStyles: Array<{ [key:string]: string | number }>
73
+ }): TextDatum[] {
74
+ const callbackText = eventFn(eventData, eventName, t)
75
+ return callbackText.map((d, i) => {
76
+ return {
77
+ text: d,
78
+ attr: textAttrs[i],
79
+ style: textStyles[i]
80
+ }
81
+ })
82
+ }
83
+
84
+ function createEachPieEventTexts (pluginName: string, context: {
85
+ containerSelection: d3.Selection<SVGGElement, any, any, unknown>
86
+ computedData$: Observable<ComputedDatumSeries[][]>
87
+ containerComputedLayoutData$: Observable<ComputedDatumSeries[]>
88
+ SeriesDataMap$: Observable<Map<string, ComputedDatumSeries[]>>
89
+ fullParams$: Observable<PieEventTextsParams>
90
+ fullChartParams$: Observable<ChartParams>
91
+ seriesHighlight$: Observable<ComputedDatumSeries[]>
92
+ seriesContainerPosition$: Observable<SeriesContainerPosition>
93
+ event$: Subject<EventSeries>
94
+ }) {
95
+ const destroy$ = new Subject()
96
+
97
+ // const graphicSelection: d3.Selection<SVGGElement, any, any, any> = selection.append('g')
98
+ let centerTextSelection: d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> | undefined
99
+ let storeEventSubscription: Subscription | undefined
100
+
101
+ // context.layout$
102
+ // .pipe(
103
+ // first()
104
+ // )
105
+ // .subscribe(size => {
106
+ // selection
107
+ // .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
108
+ // context.layout$
109
+ // .pipe(
110
+ // takeUntil(destroy$)
111
+ // )
112
+ // .subscribe(size => {
113
+ // selection
114
+ // .transition()
115
+ // .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
116
+ // })
117
+ // })
118
+
119
+ const highlightTarget$ = context.fullChartParams$.pipe(
120
+ takeUntil(destroy$),
121
+ map(d => d.highlightTarget),
122
+ distinctUntilChanged()
123
+ )
124
+
125
+ combineLatest({
126
+ computedData: context.computedData$,
127
+ fullParams: context.fullParams$,
128
+ fullChartParams: context.fullChartParams$,
129
+ highlightTarget: highlightTarget$,
130
+ }).pipe(
131
+ takeUntil(destroy$),
132
+ switchMap(async (d) => d),
133
+ ).subscribe(data => {
134
+
135
+ context.containerSelection
136
+ .transition('move')
137
+ .duration(data.fullChartParams.transitionDuration!)
138
+ // .ease(getD3TransitionEase(data.fullChartParams.transitionEase!))
139
+ .tween('move', (event, datum) => {
140
+ return (t) => {
141
+ const renderData = makeTextData({
142
+ eventData: {
143
+ type: 'series',
144
+ pluginName,
145
+ eventName: 'transitionMove',
146
+ event,
147
+ highlightTarget: data.highlightTarget,
148
+ data: data.computedData,
149
+ series: [],
150
+ seriesIndex: -1,
151
+ seriesLabel: '',
152
+ datum: null
153
+ },
154
+ eventName: 'transitionMove',
155
+ t,
156
+ eventFn: data.fullParams.eventFn!,
157
+ textAttrs: data.fullParams.textAttrs!,
158
+ textStyles: data.fullParams.textStyles!
159
+ })
160
+ centerTextSelection = renderText(context.containerSelection, renderData)
161
+ }
162
+ })
163
+ .on('end', (event, datum) => {
164
+ const renderData = makeTextData({
165
+ eventData: {
166
+ type: 'series',
167
+ pluginName,
168
+ eventName: 'transitionEnd',
169
+ event,
170
+ highlightTarget: data.highlightTarget,
171
+ data: data.computedData,
172
+ series: [],
173
+ seriesIndex: -1,
174
+ seriesLabel: '',
175
+ datum: null
176
+ },
177
+ eventName: 'transitionMove',
178
+ t: 1,
179
+ eventFn: data.fullParams.eventFn!,
180
+ textAttrs: data.fullParams.textAttrs!,
181
+ textStyles: data.fullParams.textStyles!
182
+ })
183
+ centerTextSelection = renderText(context.containerSelection, renderData)
184
+
185
+ if (storeEventSubscription) {
186
+ storeEventSubscription.unsubscribe()
187
+ }
188
+ storeEventSubscription = context.event$
189
+ .subscribe(eventData => {
190
+ const renderData = makeTextData({
191
+ eventData,
192
+ eventName: eventData.eventName,
193
+ t: 1,
194
+ eventFn: data.fullParams.eventFn!,
195
+ textAttrs: data.fullParams.textAttrs!,
196
+ textStyles: data.fullParams.textStyles!
197
+ })
198
+ centerTextSelection = renderText(context.containerSelection, renderData)
199
+ })
200
+ })
201
+ })
202
+
203
+ return () => {
204
+ destroy$.next(undefined)
205
+ }
206
+ }
207
+
208
+ export const PieEventTexts = defineSeriesPlugin(pluginName, DEFAULT_PIE_EVENT_TEXTS_PARAMS)(({ selection, name, observer, subject }) => {
209
+ const destroy$ = new Subject()
210
+
211
+ const { seriesCenterSelection$ } = seriesCenterSelectionObservable({
212
+ selection: selection,
213
+ pluginName,
214
+ separateSeries$: observer.separateSeries$,
215
+ seriesLabels$: observer.seriesLabels$,
216
+ seriesContainerPosition$: observer.seriesContainerPosition$
217
+ })
218
+
219
+ const unsubscribeFnArr: (() => void)[] = []
220
+
221
+ seriesCenterSelection$
222
+ .pipe(
223
+ takeUntil(destroy$)
224
+ )
225
+ .subscribe(seriesCenterSelection => {
226
+ // 每次重新計算時,清除之前的訂閱
227
+ unsubscribeFnArr.forEach(fn => fn())
228
+
229
+ seriesCenterSelection.each((d, containerIndex, g) => {
230
+
231
+ const containerSelection = d3.select(g[containerIndex])
232
+
233
+ const containerComputedLayoutData$ = observer.computedLayoutData$.pipe(
234
+ takeUntil(destroy$),
235
+ map(data => data[containerIndex] ?? data[0])
236
+ )
237
+
238
+ const containerPosition$ = observer.seriesContainerPosition$.pipe(
239
+ takeUntil(destroy$),
240
+ map(data => data[containerIndex] ?? data[0])
241
+ )
242
+
243
+ unsubscribeFnArr[containerIndex] = createEachPieEventTexts(pluginName, {
244
+ containerSelection: containerSelection,
245
+ computedData$: observer.computedData$,
246
+ containerComputedLayoutData$: containerComputedLayoutData$,
247
+ SeriesDataMap$: observer.SeriesDataMap$,
248
+ fullParams$: observer.fullParams$,
249
+ fullChartParams$: observer.fullChartParams$,
250
+ seriesHighlight$: observer.seriesHighlight$,
251
+ seriesContainerPosition$: containerPosition$,
252
+ event$: subject.event$,
253
+ })
254
+
255
+ })
256
+ })
257
+
258
+ return () => {
259
+ destroy$.next(undefined)
260
+ unsubscribeFnArr.forEach(fn => fn())
261
+ }
262
+ })