@orbcharts/plugins-basic 3.0.0-alpha.49 → 3.0.0-alpha.51
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.
- package/LICENSE +200 -200
- package/dist/orbcharts-plugins-basic.es.js +6325 -6272
- package/dist/orbcharts-plugins-basic.umd.js +8 -8
- package/dist/src/base/BaseGroupAxis.d.ts +1 -0
- package/dist/src/grid/index.d.ts +1 -1
- package/dist/src/grid/plugins/BarsPN.d.ts +1 -0
- package/dist/src/grid/types.d.ts +3 -2
- package/dist/src/multiGrid/defaults.d.ts +2 -1
- package/dist/src/multiGrid/index.d.ts +2 -0
- package/dist/src/multiGrid/multiGridObservables.d.ts +1 -1
- package/dist/src/multiGrid/plugins/MultiValueStackAxis.d.ts +1 -0
- package/dist/src/multiGrid/plugins/OverlappingValueStackAxes.d.ts +1 -0
- package/dist/src/multiGrid/types.d.ts +3 -0
- package/dist/src/series/types.d.ts +2 -3
- package/package.json +42 -42
- package/src/base/BaseBarStack.ts +778 -778
- package/src/base/BaseBars.ts +764 -764
- package/src/base/BaseBarsTriangle.ts +672 -672
- package/src/base/BaseDots.ts +513 -502
- package/src/base/BaseGroupAxis.ts +562 -496
- package/src/base/BaseLegend.ts +641 -641
- package/src/base/BaseLineAreas.ts +625 -625
- package/src/base/BaseLines.ts +699 -699
- package/src/base/BaseValueAxis.ts +478 -478
- package/src/base/types.ts +2 -2
- package/src/grid/defaults.ts +125 -121
- package/src/grid/gridObservables.ts +248 -247
- package/src/grid/index.ts +15 -15
- package/src/grid/plugins/BarStack.ts +43 -50
- package/src/grid/plugins/Bars.ts +44 -51
- package/src/grid/plugins/{BarsDiverging.ts → BarsPN.ts} +41 -41
- package/src/grid/plugins/BarsTriangle.ts +42 -50
- package/src/grid/plugins/Dots.ts +37 -37
- package/src/grid/plugins/GridLegend.ts +59 -59
- package/src/grid/plugins/GroupAux.ts +645 -645
- package/src/grid/plugins/GroupAxis.ts +35 -42
- package/src/grid/plugins/LineAreas.ts +39 -39
- package/src/grid/plugins/Lines.ts +38 -38
- package/src/grid/plugins/ScalingArea.ts +173 -173
- package/src/grid/plugins/ValueAxis.ts +36 -43
- package/src/grid/plugins/ValueStackAxis.ts +38 -79
- package/src/grid/types.ts +122 -120
- package/src/index.ts +9 -9
- package/src/multiGrid/defaults.ts +152 -147
- package/src/multiGrid/index.ts +14 -12
- package/src/multiGrid/multiGridObservables.ts +44 -43
- package/src/multiGrid/plugins/MultiBarStack.ts +78 -78
- package/src/multiGrid/plugins/MultiBars.ts +77 -77
- package/src/multiGrid/plugins/MultiBarsTriangle.ts +77 -77
- package/src/multiGrid/plugins/MultiDots.ts +65 -65
- package/src/multiGrid/plugins/MultiGridLegend.ts +89 -89
- package/src/multiGrid/plugins/MultiGroupAxis.ts +69 -69
- package/src/multiGrid/plugins/MultiLineAreas.ts +67 -67
- package/src/multiGrid/plugins/MultiLines.ts +66 -66
- package/src/multiGrid/plugins/MultiValueAxis.ts +69 -69
- package/src/multiGrid/plugins/MultiValueStackAxis.ts +69 -0
- package/src/multiGrid/plugins/OverlappingValueAxes.ts +166 -173
- package/src/multiGrid/plugins/OverlappingValueStackAxes.ts +167 -0
- package/src/multiGrid/types.ts +71 -67
- package/src/noneData/defaults.ts +64 -64
- package/src/noneData/index.ts +3 -3
- package/src/noneData/plugins/Container.ts +10 -10
- package/src/noneData/plugins/Tooltip.ts +310 -310
- package/src/noneData/types.ts +26 -26
- package/src/series/defaults.ts +126 -126
- package/src/series/index.ts +9 -9
- package/src/series/plugins/Bubbles.ts +545 -602
- package/src/series/plugins/Pie.ts +576 -576
- package/src/series/plugins/PieEventTexts.ts +262 -262
- package/src/series/plugins/PieLabels.ts +304 -304
- package/src/series/plugins/Rose.ts +472 -472
- package/src/series/plugins/RoseLabels.ts +362 -362
- package/src/series/plugins/SeriesLegend.ts +59 -59
- package/src/series/seriesObservables.ts +145 -145
- package/src/series/seriesUtils.ts +51 -51
- package/src/series/types.ts +83 -83
- package/src/tree/defaults.ts +22 -22
- package/src/tree/index.ts +3 -3
- package/src/tree/plugins/TreeLegend.ts +59 -59
- package/src/tree/plugins/TreeMap.ts +305 -305
- package/src/tree/types.ts +23 -23
- package/src/utils/commonUtils.ts +21 -21
- package/src/utils/d3Graphics.ts +124 -124
- package/src/utils/d3Utils.ts +73 -73
- package/src/utils/observables.ts +14 -14
- package/src/utils/orbchartsUtils.ts +100 -100
- package/tsconfig.dev.json +16 -16
- package/tsconfig.json +13 -13
- package/tsconfig.prod.json +13 -13
- package/vite.config.js +49 -49
- package/dist/src/grid/plugins/BarsDiverging.d.ts +0 -1
| @@ -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 | 
            +
            })
         |