@orbcharts/plugins-basic 3.0.0-alpha.75 → 3.0.0-alpha.76
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 +3461 -3468
 - package/dist/orbcharts-plugins-basic.umd.js +17 -17
 - package/lib/core-types.ts +7 -7
 - package/lib/core.ts +6 -6
 - package/package.json +43 -43
 - package/src/base/BaseBarStack.ts +779 -779
 - package/src/base/BaseBars.ts +764 -764
 - package/src/base/BaseBarsTriangle.ts +672 -672
 - package/src/base/BaseDots.ts +513 -513
 - package/src/base/BaseGroupAxis.ts +678 -678
 - package/src/base/BaseLegend.ts +642 -642
 - package/src/base/BaseLineAreas.ts +627 -627
 - package/src/base/BaseLines.ts +704 -704
 - package/src/base/BaseValueAxis.ts +578 -578
 - package/src/base/types.ts +2 -2
 - package/src/const.ts +30 -30
 - package/src/grid/defaults.ts +128 -128
 - package/src/grid/gridObservables.ts +545 -545
 - package/src/grid/index.ts +15 -15
 - package/src/grid/plugins/BarStack.ts +64 -64
 - package/src/grid/plugins/Bars.ts +69 -69
 - package/src/grid/plugins/BarsPN.ts +66 -66
 - package/src/grid/plugins/BarsTriangle.ts +73 -73
 - package/src/grid/plugins/Dots.ts +68 -68
 - package/src/grid/plugins/GridLegend.ts +96 -96
 - package/src/grid/plugins/GroupAux.ts +1098 -1098
 - package/src/grid/plugins/GroupAxis.ts +97 -97
 - package/src/grid/plugins/LineAreas.ts +65 -65
 - package/src/grid/plugins/Lines.ts +59 -59
 - package/src/grid/plugins/ScalingArea.ts +218 -218
 - package/src/grid/plugins/ValueAxis.ts +93 -93
 - package/src/grid/plugins/ValueStackAxis.ts +95 -95
 - package/src/grid/types.ts +123 -123
 - package/src/index.ts +9 -9
 - package/src/multiGrid/defaults.ts +158 -158
 - package/src/multiGrid/index.ts +13 -13
 - package/src/multiGrid/multiGridObservables.ts +49 -49
 - package/src/multiGrid/plugins/MultiBarStack.ts +106 -106
 - package/src/multiGrid/plugins/MultiBars.ts +108 -108
 - package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
 - package/src/multiGrid/plugins/MultiDots.ts +102 -102
 - package/src/multiGrid/plugins/MultiGridLegend.ts +148 -148
 - package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
 - package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
 - package/src/multiGrid/plugins/MultiLines.ts +101 -101
 - package/src/multiGrid/plugins/MultiValueAxis.ts +133 -133
 - package/src/multiGrid/plugins/MultiValueStackAxis.ts +133 -133
 - package/src/multiGrid/plugins/OverlappingValueAxes.ts +299 -299
 - package/src/multiGrid/plugins/OverlappingValueStackAxes.ts +298 -298
 - package/src/multiGrid/types.ts +72 -72
 - package/src/noneData/defaults.ts +102 -102
 - package/src/noneData/index.ts +3 -3
 - package/src/noneData/plugins/Container.ts +27 -27
 - package/src/noneData/plugins/Tooltip.ts +373 -373
 - package/src/noneData/types.ts +26 -26
 - package/src/series/defaults.ts +149 -149
 - package/src/series/index.ts +9 -9
 - package/src/series/plugins/Bubbles.ts +603 -603
 - package/src/series/plugins/Pie.ts +623 -623
 - package/src/series/plugins/PieEventTexts.ts +283 -283
 - package/src/series/plugins/PieLabels.ts +640 -640
 - package/src/series/plugins/Rose.ts +516 -516
 - package/src/series/plugins/RoseLabels.ts +600 -600
 - package/src/series/plugins/SeriesLegend.ts +96 -96
 - package/src/series/seriesObservables.ts +145 -145
 - package/src/series/seriesUtils.ts +51 -51
 - package/src/series/types.ts +87 -87
 - package/src/tree/defaults.ts +23 -23
 - package/src/tree/index.ts +3 -3
 - package/src/tree/plugins/TreeLegend.ts +96 -96
 - package/src/tree/plugins/TreeMap.ts +333 -333
 - package/src/tree/types.ts +23 -23
 - package/src/utils/commonUtils.ts +21 -21
 - package/src/utils/d3Graphics.ts +174 -174
 - package/src/utils/d3Utils.ts +73 -73
 - package/src/utils/observables.ts +14 -14
 - package/src/utils/orbchartsUtils.ts +100 -100
 - package/tsconfig.base.json +13 -13
 - package/tsconfig.json +2 -2
 - package/vite.config.js +22 -22
 
| 
         @@ -1,546 +1,546 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import * as d3 from 'd3'
         
     | 
| 
       2 
     | 
    
         
            -
            import {
         
     | 
| 
       3 
     | 
    
         
            -
              Observable,
         
     | 
| 
       4 
     | 
    
         
            -
              Subject,
         
     | 
| 
       5 
     | 
    
         
            -
              of,
         
     | 
| 
       6 
     | 
    
         
            -
              takeUntil,
         
     | 
| 
       7 
     | 
    
         
            -
              filter,
         
     | 
| 
       8 
     | 
    
         
            -
              map,
         
     | 
| 
       9 
     | 
    
         
            -
              switchMap,
         
     | 
| 
       10 
     | 
    
         
            -
              combineLatest,
         
     | 
| 
       11 
     | 
    
         
            -
              merge,
         
     | 
| 
       12 
     | 
    
         
            -
              shareReplay,
         
     | 
| 
       13 
     | 
    
         
            -
              distinctUntilChanged
         
     | 
| 
       14 
     | 
    
         
            -
            } from 'rxjs'
         
     | 
| 
       15 
     | 
    
         
            -
            import type {
         
     | 
| 
       16 
     | 
    
         
            -
              ChartParams,
         
     | 
| 
       17 
     | 
    
         
            -
              HighlightTarget,
         
     | 
| 
       18 
     | 
    
         
            -
              DataFormatterGrid,
         
     | 
| 
       19 
     | 
    
         
            -
              ComputedDataGrid,
         
     | 
| 
       20 
     | 
    
         
            -
              ComputedDatumGrid,
         
     | 
| 
       21 
     | 
    
         
            -
              TransformData,
         
     | 
| 
       22 
     | 
    
         
            -
              GridContainerPosition,
         
     | 
| 
       23 
     | 
    
         
            -
              Layout } from '../../lib/core-types'
         
     | 
| 
       24 
     | 
    
         
            -
            import { createAxisQuantizeScale } from '../../lib/core'
         
     | 
| 
       25 
     | 
    
         
            -
            import { getClassName, getUniID } from '../utils/orbchartsUtils'
         
     | 
| 
       26 
     | 
    
         
            -
            import { d3EventObservable } from '../utils/observables'
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            // grid選取器
         
     | 
| 
       29 
     | 
    
         
            -
            export const gridSelectionsObservable = ({ selection, pluginName, clipPathID, seriesLabels$, gridContainerPosition$, gridAxesTransform$, gridGraphicTransform$ }: {
         
     | 
| 
       30 
     | 
    
         
            -
              selection: d3.Selection<any, unknown, any, unknown>
         
     | 
| 
       31 
     | 
    
         
            -
              pluginName: string
         
     | 
| 
       32 
     | 
    
         
            -
              clipPathID: string
         
     | 
| 
       33 
     | 
    
         
            -
              // computedData$: Observable<ComputedDataGrid>
         
     | 
| 
       34 
     | 
    
         
            -
              seriesLabels$: Observable<string[]>
         
     | 
| 
       35 
     | 
    
         
            -
              gridContainerPosition$: Observable<GridContainerPosition[]>
         
     | 
| 
       36 
     | 
    
         
            -
              gridAxesTransform$: Observable<TransformData>
         
     | 
| 
       37 
     | 
    
         
            -
              gridGraphicTransform$: Observable<TransformData>
         
     | 
| 
       38 
     | 
    
         
            -
            }) => {
         
     | 
| 
       39 
     | 
    
         
            -
              const seriesClassName = getClassName(pluginName, 'series')
         
     | 
| 
       40 
     | 
    
         
            -
              const axesClassName = getClassName(pluginName, 'axes')
         
     | 
| 
       41 
     | 
    
         
            -
              const graphicClassName = getClassName(pluginName, 'graphic')
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
              const seriesSelection$ = seriesLabels$.pipe(
         
     | 
| 
       44 
     | 
    
         
            -
                map((existSeriesLabels, i) => {
         
     | 
| 
       45 
     | 
    
         
            -
                  return selection
         
     | 
| 
       46 
     | 
    
         
            -
                    .selectAll<SVGGElement, string>(`g.${seriesClassName}`)
         
     | 
| 
       47 
     | 
    
         
            -
                    .data(existSeriesLabels, d => d)
         
     | 
| 
       48 
     | 
    
         
            -
                    .join(
         
     | 
| 
       49 
     | 
    
         
            -
                      enter => {
         
     | 
| 
       50 
     | 
    
         
            -
                        return enter
         
     | 
| 
       51 
     | 
    
         
            -
                          .append('g')
         
     | 
| 
       52 
     | 
    
         
            -
                          .classed(seriesClassName, true)
         
     | 
| 
       53 
     | 
    
         
            -
                          .each((d, i, g) => {
         
     | 
| 
       54 
     | 
    
         
            -
                            const axesSelection = d3.select(g[i])
         
     | 
| 
       55 
     | 
    
         
            -
                              .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${axesClassName}`)
         
     | 
| 
       56 
     | 
    
         
            -
                              .data([i])
         
     | 
| 
       57 
     | 
    
         
            -
                              .join(
         
     | 
| 
       58 
     | 
    
         
            -
                                enter => {
         
     | 
| 
       59 
     | 
    
         
            -
                                  return enter
         
     | 
| 
       60 
     | 
    
         
            -
                                    .append('g')
         
     | 
| 
       61 
     | 
    
         
            -
                                    .classed(axesClassName, true)
         
     | 
| 
       62 
     | 
    
         
            -
                                    .attr('clip-path', `url(#${clipPathID})`)
         
     | 
| 
       63 
     | 
    
         
            -
                                    .each((d, i, g) => {
         
     | 
| 
       64 
     | 
    
         
            -
                                      const defsSelection = d3.select(g[i])
         
     | 
| 
       65 
     | 
    
         
            -
                                        .selectAll<SVGDefsElement, any>('defs')
         
     | 
| 
       66 
     | 
    
         
            -
                                        .data([i])
         
     | 
| 
       67 
     | 
    
         
            -
                                        .join('defs')
         
     | 
| 
       68 
     | 
    
         
            -
                        
         
     | 
| 
       69 
     | 
    
         
            -
                                      const graphicGSelection = d3.select(g[i])
         
     | 
| 
       70 
     | 
    
         
            -
                                        .selectAll<SVGGElement, any>('g')
         
     | 
| 
       71 
     | 
    
         
            -
                                        .data([i])
         
     | 
| 
       72 
     | 
    
         
            -
                                        .join('g')
         
     | 
| 
       73 
     | 
    
         
            -
                                        .classed(graphicClassName, true)
         
     | 
| 
       74 
     | 
    
         
            -
                                    })
         
     | 
| 
       75 
     | 
    
         
            -
                                },
         
     | 
| 
       76 
     | 
    
         
            -
                                update => update,
         
     | 
| 
       77 
     | 
    
         
            -
                                exit => exit.remove()
         
     | 
| 
       78 
     | 
    
         
            -
                              )
         
     | 
| 
       79 
     | 
    
         
            -
                          })
         
     | 
| 
       80 
     | 
    
         
            -
                      },
         
     | 
| 
       81 
     | 
    
         
            -
                      update => update,
         
     | 
| 
       82 
     | 
    
         
            -
                      exit => exit.remove()
         
     | 
| 
       83 
     | 
    
         
            -
                    )
         
     | 
| 
       84 
     | 
    
         
            -
                }),
         
     | 
| 
       85 
     | 
    
         
            -
                shareReplay(1)
         
     | 
| 
       86 
     | 
    
         
            -
              )
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
              combineLatest({
         
     | 
| 
       89 
     | 
    
         
            -
                seriesSelection: seriesSelection$,
         
     | 
| 
       90 
     | 
    
         
            -
                gridContainerPosition: gridContainerPosition$                                                                                                                                                                                       
         
     | 
| 
       91 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       92 
     | 
    
         
            -
                switchMap(async d => d)
         
     | 
| 
       93 
     | 
    
         
            -
              ).subscribe(data => {
         
     | 
| 
       94 
     | 
    
         
            -
                data.seriesSelection
         
     | 
| 
       95 
     | 
    
         
            -
                  .transition()
         
     | 
| 
       96 
     | 
    
         
            -
                  .attr('transform', (d, i) => {
         
     | 
| 
       97 
     | 
    
         
            -
                    const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
         
     | 
| 
       98 
     | 
    
         
            -
                    const translate = gridContainerPosition.translate
         
     | 
| 
       99 
     | 
    
         
            -
                    const scale = gridContainerPosition.scale
         
     | 
| 
       100 
     | 
    
         
            -
                    return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
         
     | 
| 
       101 
     | 
    
         
            -
                  })
         
     | 
| 
       102 
     | 
    
         
            -
              })
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
              const axesSelection$ = combineLatest({
         
     | 
| 
       105 
     | 
    
         
            -
                seriesSelection: seriesSelection$,
         
     | 
| 
       106 
     | 
    
         
            -
                gridAxesTransform: gridAxesTransform$
         
     | 
| 
       107 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       108 
     | 
    
         
            -
                switchMap(async d => d),
         
     | 
| 
       109 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       110 
     | 
    
         
            -
                  return data.seriesSelection
         
     | 
| 
       111 
     | 
    
         
            -
                    .select<SVGGElement>(`g.${axesClassName}`)
         
     | 
| 
       112 
     | 
    
         
            -
                    .style('transform', data.gridAxesTransform.value)
         
     | 
| 
       113 
     | 
    
         
            -
                }),
         
     | 
| 
       114 
     | 
    
         
            -
                shareReplay(1)
         
     | 
| 
       115 
     | 
    
         
            -
              )
         
     | 
| 
       116 
     | 
    
         
            -
              const defsSelection$ = axesSelection$.pipe(
         
     | 
| 
       117 
     | 
    
         
            -
                map(axesSelection => {
         
     | 
| 
       118 
     | 
    
         
            -
                  return axesSelection.select<SVGDefsElement>('defs')
         
     | 
| 
       119 
     | 
    
         
            -
                }),
         
     | 
| 
       120 
     | 
    
         
            -
                shareReplay(1)
         
     | 
| 
       121 
     | 
    
         
            -
              )
         
     | 
| 
       122 
     | 
    
         
            -
              const graphicGSelection$ = combineLatest({
         
     | 
| 
       123 
     | 
    
         
            -
                axesSelection: axesSelection$,
         
     | 
| 
       124 
     | 
    
         
            -
                gridGraphicTransform: gridGraphicTransform$
         
     | 
| 
       125 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       126 
     | 
    
         
            -
                switchMap(async d => d),
         
     | 
| 
       127 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       128 
     | 
    
         
            -
                  const graphicGSelection = data.axesSelection
         
     | 
| 
       129 
     | 
    
         
            -
                    .select<SVGGElement>(`g.${graphicClassName}`)
         
     | 
| 
       130 
     | 
    
         
            -
                  graphicGSelection
         
     | 
| 
       131 
     | 
    
         
            -
                    .transition()
         
     | 
| 
       132 
     | 
    
         
            -
                    .duration(50)
         
     | 
| 
       133 
     | 
    
         
            -
                    .style('transform', data.gridGraphicTransform.value)
         
     | 
| 
       134 
     | 
    
         
            -
                  return graphicGSelection
         
     | 
| 
       135 
     | 
    
         
            -
                }),
         
     | 
| 
       136 
     | 
    
         
            -
                shareReplay(1)
         
     | 
| 
       137 
     | 
    
         
            -
              )
         
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
              return {
         
     | 
| 
       140 
     | 
    
         
            -
                seriesSelection$,
         
     | 
| 
       141 
     | 
    
         
            -
                axesSelection$,
         
     | 
| 
       142 
     | 
    
         
            -
                defsSelection$,
         
     | 
| 
       143 
     | 
    
         
            -
                graphicGSelection$
         
     | 
| 
       144 
     | 
    
         
            -
              }
         
     | 
| 
       145 
     | 
    
         
            -
            }
         
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
       147 
     | 
    
         
            -
            // 由事件取得group data的function
         
     | 
| 
       148 
     | 
    
         
            -
            // @Q@ 之後重構改用 gridGroupPosition
         
     | 
| 
       149 
     | 
    
         
            -
            export const gridGroupPositionFnObservable = ({ fullDataFormatter$, gridAxesSize$, computedData$, fullChartParams$, gridContainerPosition$, layout$ }: {
         
     | 
| 
       150 
     | 
    
         
            -
              fullDataFormatter$: Observable<DataFormatterGrid>
         
     | 
| 
       151 
     | 
    
         
            -
              gridAxesSize$: Observable<{
         
     | 
| 
       152 
     | 
    
         
            -
                width: number;
         
     | 
| 
       153 
     | 
    
         
            -
                height: number;
         
     | 
| 
       154 
     | 
    
         
            -
              }>
         
     | 
| 
       155 
     | 
    
         
            -
              computedData$: Observable<ComputedDataGrid>
         
     | 
| 
       156 
     | 
    
         
            -
              // GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
         
     | 
| 
       157 
     | 
    
         
            -
              fullChartParams$: Observable<ChartParams>
         
     | 
| 
       158 
     | 
    
         
            -
              gridContainerPosition$: Observable<GridContainerPosition[]>
         
     | 
| 
       159 
     | 
    
         
            -
              layout$: Observable<Layout>
         
     | 
| 
       160 
     | 
    
         
            -
            }): Observable<(event: any) => { groupIndex: number; groupLabel: string }> => {
         
     | 
| 
       161 
     | 
    
         
            -
              const destroy$ = new Subject()
         
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
       163 
     | 
    
         
            -
              // 顯示範圍內的group labels
         
     | 
| 
       164 
     | 
    
         
            -
              // const scaleRangeGroupLabels$: Observable<string[]> = new Observable(subscriber => {
         
     | 
| 
       165 
     | 
    
         
            -
              //   combineLatest({
         
     | 
| 
       166 
     | 
    
         
            -
              //     dataFormatter: fullDataFormatter$,
         
     | 
| 
       167 
     | 
    
         
            -
              //     computedData: computedData$
         
     | 
| 
       168 
     | 
    
         
            -
              //   }).pipe(
         
     | 
| 
       169 
     | 
    
         
            -
              //     takeUntil(destroy$),
         
     | 
| 
       170 
     | 
    
         
            -
              //     switchMap(async (d) => d),
         
     | 
| 
       171 
     | 
    
         
            -
              //   ).subscribe(data => {
         
     | 
| 
       172 
     | 
    
         
            -
              //     const groupMin = 0
         
     | 
| 
       173 
     | 
    
         
            -
              //     const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
         
     | 
| 
       174 
     | 
    
         
            -
              //     const groupScaleDomainMin = data.dataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
         
     | 
| 
       175 
     | 
    
         
            -
              //       ? groupMin - data.dataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       176 
     | 
    
         
            -
              //       : data.dataFormatter.grid.groupAxis.scaleDomain[0] as number - data.dataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       177 
     | 
    
         
            -
              //     const groupScaleDomainMax = data.dataFormatter.grid.groupAxis.scaleDomain[1] === 'auto'
         
     | 
| 
       178 
     | 
    
         
            -
              //       ? groupMax + data.dataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       179 
     | 
    
         
            -
              //       : data.dataFormatter.grid.groupAxis.scaleDomain[1] as number + data.dataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       180 
     | 
    
         
            -
                  
         
     | 
| 
       181 
     | 
    
         
            -
              //     // const groupingAmount = data.computedData[0]
         
     | 
| 
       182 
     | 
    
         
            -
              //     //   ? data.computedData[0].length
         
     | 
| 
       183 
     | 
    
         
            -
              //     //   : 0
         
     | 
| 
       184 
     | 
    
         
            -
             
     | 
| 
       185 
     | 
    
         
            -
              //     let _labels = data.dataFormatter.grid.seriesDirection === 'row'
         
     | 
| 
       186 
     | 
    
         
            -
              //       ? (data.computedData[0] ?? []).map(d => d.groupLabel)
         
     | 
| 
       187 
     | 
    
         
            -
              //       : data.computedData.map(d => d[0].groupLabel)
         
     | 
| 
       188 
     | 
    
         
            -
             
     | 
| 
       189 
     | 
    
         
            -
              //     const _axisLabels = 
         
     | 
| 
       190 
     | 
    
         
            -
              //     // new Array(groupingAmount).fill(0)
         
     | 
| 
       191 
     | 
    
         
            -
              //     //   .map((d, i) => {
         
     | 
| 
       192 
     | 
    
         
            -
              //     //     return _labels[i] != null
         
     | 
| 
       193 
     | 
    
         
            -
              //     //       ? _labels[i]
         
     | 
| 
       194 
     | 
    
         
            -
              //     //       : String(i) // 沒有label則用序列號填充
         
     | 
| 
       195 
     | 
    
         
            -
              //     //   })
         
     | 
| 
       196 
     | 
    
         
            -
              //       _labels
         
     | 
| 
       197 
     | 
    
         
            -
              //       .filter((d, i) => {
         
     | 
| 
       198 
     | 
    
         
            -
              //         return i >= groupScaleDomainMin && i <= groupScaleDomainMax
         
     | 
| 
       199 
     | 
    
         
            -
              //       })
         
     | 
| 
       200 
     | 
    
         
            -
              //     subscriber.next(_axisLabels)
         
     | 
| 
       201 
     | 
    
         
            -
              //   })
         
     | 
| 
       202 
     | 
    
         
            -
              // })
         
     | 
| 
       203 
     | 
    
         
            -
              const groupScaleDomain$ = combineLatest({
         
     | 
| 
       204 
     | 
    
         
            -
                fullDataFormatter: fullDataFormatter$,
         
     | 
| 
       205 
     | 
    
         
            -
                gridAxesSize: gridAxesSize$,
         
     | 
| 
       206 
     | 
    
         
            -
                computedData: computedData$
         
     | 
| 
       207 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       208 
     | 
    
         
            -
                switchMap(async (d) => d),
         
     | 
| 
       209 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       210 
     | 
    
         
            -
                  const groupMin = 0
         
     | 
| 
       211 
     | 
    
         
            -
                  const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
         
     | 
| 
       212 
     | 
    
         
            -
                  // const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
         
     | 
| 
       213 
     | 
    
         
            -
                  //   ? groupMin - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       214 
     | 
    
         
            -
                  //   : data.fullDataFormatter.grid.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       215 
     | 
    
         
            -
                  const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       216 
     | 
    
         
            -
                  const groupScaleDomainMax = data.fullDataFormatter.grid.groupAxis.scaleDomain[1] === 'max'
         
     | 
| 
       217 
     | 
    
         
            -
                    ? groupMax + data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       218 
     | 
    
         
            -
                    : data.fullDataFormatter.grid.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       219 
     | 
    
         
            -
             
     | 
| 
       220 
     | 
    
         
            -
                  return [groupScaleDomainMin, groupScaleDomainMax]
         
     | 
| 
       221 
     | 
    
         
            -
                }),
         
     | 
| 
       222 
     | 
    
         
            -
                shareReplay(1)
         
     | 
| 
       223 
     | 
    
         
            -
              )
         
     | 
| 
       224 
     | 
    
         
            -
             
     | 
| 
       225 
     | 
    
         
            -
              const groupLabels$ = combineLatest({
         
     | 
| 
       226 
     | 
    
         
            -
                fullDataFormatter: fullDataFormatter$,
         
     | 
| 
       227 
     | 
    
         
            -
                computedData: computedData$
         
     | 
| 
       228 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       229 
     | 
    
         
            -
                switchMap(async d => d),
         
     | 
| 
       230 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       231 
     | 
    
         
            -
                  return data.fullDataFormatter.grid.seriesDirection === 'row'
         
     | 
| 
       232 
     | 
    
         
            -
                    ? (data.computedData[0] ?? []).map(d => d.groupLabel)
         
     | 
| 
       233 
     | 
    
         
            -
                    : data.computedData.map(d => d[0].groupLabel)
         
     | 
| 
       234 
     | 
    
         
            -
                })
         
     | 
| 
       235 
     | 
    
         
            -
              )
         
     | 
| 
       236 
     | 
    
         
            -
             
     | 
| 
       237 
     | 
    
         
            -
              // 顯示範圍內的group labels
         
     | 
| 
       238 
     | 
    
         
            -
              const scaleRangeGroupLabels$ = combineLatest({
         
     | 
| 
       239 
     | 
    
         
            -
                groupScaleDomain: groupScaleDomain$,
         
     | 
| 
       240 
     | 
    
         
            -
                groupLabels: groupLabels$
         
     | 
| 
       241 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       242 
     | 
    
         
            -
                switchMap(async d => d),
         
     | 
| 
       243 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       244 
     | 
    
         
            -
                  return data.groupLabels
         
     | 
| 
       245 
     | 
    
         
            -
                    .filter((d, i) => {
         
     | 
| 
       246 
     | 
    
         
            -
                      return i >= data.groupScaleDomain[0] && i <= data.groupScaleDomain[1]
         
     | 
| 
       247 
     | 
    
         
            -
                    })
         
     | 
| 
       248 
     | 
    
         
            -
                })
         
     | 
| 
       249 
     | 
    
         
            -
              )
         
     | 
| 
       250 
     | 
    
         
            -
             
     | 
| 
       251 
     | 
    
         
            -
              const columnAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
       252 
     | 
    
         
            -
                map(gridContainerPosition => {
         
     | 
| 
       253 
     | 
    
         
            -
                  const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
       254 
     | 
    
         
            -
                    return current.columnIndex > acc ? current.columnIndex : acc
         
     | 
| 
       255 
     | 
    
         
            -
                  }, 0)
         
     | 
| 
       256 
     | 
    
         
            -
                  return maxColumnIndex + 1
         
     | 
| 
       257 
     | 
    
         
            -
                }),
         
     | 
| 
       258 
     | 
    
         
            -
                distinctUntilChanged()
         
     | 
| 
       259 
     | 
    
         
            -
              )
         
     | 
| 
       260 
     | 
    
         
            -
             
     | 
| 
       261 
     | 
    
         
            -
              const rowAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
       262 
     | 
    
         
            -
                map(gridContainerPosition => {
         
     | 
| 
       263 
     | 
    
         
            -
                  const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
       264 
     | 
    
         
            -
                    return current.rowIndex > acc ? current.rowIndex : acc
         
     | 
| 
       265 
     | 
    
         
            -
                  }, 0)
         
     | 
| 
       266 
     | 
    
         
            -
                  return maxRowIndex + 1
         
     | 
| 
       267 
     | 
    
         
            -
                }),
         
     | 
| 
       268 
     | 
    
         
            -
                distinctUntilChanged()
         
     | 
| 
       269 
     | 
    
         
            -
              )
         
     | 
| 
       270 
     | 
    
         
            -
             
     | 
| 
       271 
     | 
    
         
            -
              return new Observable<(event: any) => { groupIndex: number; groupLabel: string }>(subscriber => {
         
     | 
| 
       272 
     | 
    
         
            -
                combineLatest({
         
     | 
| 
       273 
     | 
    
         
            -
                  dataFormatter: fullDataFormatter$,
         
     | 
| 
       274 
     | 
    
         
            -
                  axisSize: gridAxesSize$,
         
     | 
| 
       275 
     | 
    
         
            -
                  fullChartParams: fullChartParams$,
         
     | 
| 
       276 
     | 
    
         
            -
                  scaleRangeGroupLabels: scaleRangeGroupLabels$,
         
     | 
| 
       277 
     | 
    
         
            -
                  groupLabels: groupLabels$,
         
     | 
| 
       278 
     | 
    
         
            -
                  groupScaleDomain: groupScaleDomain$,
         
     | 
| 
       279 
     | 
    
         
            -
                  columnAmount: columnAmount$,
         
     | 
| 
       280 
     | 
    
         
            -
                  rowAmount: rowAmount$,
         
     | 
| 
       281 
     | 
    
         
            -
                  layout: layout$
         
     | 
| 
       282 
     | 
    
         
            -
                }).pipe(
         
     | 
| 
       283 
     | 
    
         
            -
                  takeUntil(destroy$),
         
     | 
| 
       284 
     | 
    
         
            -
                  switchMap(async (d) => d),
         
     | 
| 
       285 
     | 
    
         
            -
                ).subscribe(data => {
         
     | 
| 
       286 
     | 
    
         
            -
                  
         
     | 
| 
       287 
     | 
    
         
            -
                  const reverse = data.dataFormatter.grid.valueAxis.position === 'right'
         
     | 
| 
       288 
     | 
    
         
            -
                    || data.dataFormatter.grid.valueAxis.position === 'bottom'
         
     | 
| 
       289 
     | 
    
         
            -
                      ? true : false
         
     | 
| 
       290 
     | 
    
         
            -
             
     | 
| 
       291 
     | 
    
         
            -
                  // 比例尺座標對應非連續資料索引
         
     | 
| 
       292 
     | 
    
         
            -
                  const xIndexScale = createAxisQuantizeScale({
         
     | 
| 
       293 
     | 
    
         
            -
                    axisLabels: data.scaleRangeGroupLabels,
         
     | 
| 
       294 
     | 
    
         
            -
                    axisWidth: data.axisSize.width,
         
     | 
| 
       295 
     | 
    
         
            -
                    padding: data.dataFormatter.grid.groupAxis.scalePadding,
         
     | 
| 
       296 
     | 
    
         
            -
                    reverse
         
     | 
| 
       297 
     | 
    
         
            -
                  })
         
     | 
| 
       298 
     | 
    
         
            -
             
     | 
| 
       299 
     | 
    
         
            -
                  // 依比例尺位置計算座標
         
     | 
| 
       300 
     | 
    
         
            -
                  const axisValuePredicate = (event: any) => {
         
     | 
| 
       301 
     | 
    
         
            -
                    return data.dataFormatter.grid.groupAxis.position === 'bottom'
         
     | 
| 
       302 
     | 
    
         
            -
                      || data.dataFormatter.grid.groupAxis.position === 'top'
         
     | 
| 
       303 
     | 
    
         
            -
                        ? event.offsetX - data.fullChartParams.padding.left
         
     | 
| 
       304 
     | 
    
         
            -
                        : event.offsetY - data.fullChartParams.padding.top
         
     | 
| 
       305 
     | 
    
         
            -
                  }
         
     | 
| 
       306 
     | 
    
         
            -
             
     | 
| 
       307 
     | 
    
         
            -
                  // 比例尺座標取得groupData的function
         
     | 
| 
       308 
     | 
    
         
            -
                  const createEventGroupData: (event: any) => { groupIndex: number; groupLabel: string } = (event: any) => {
         
     | 
| 
       309 
     | 
    
         
            -
                    // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
         
     | 
| 
       310 
     | 
    
         
            -
                    const eventData = {
         
     | 
| 
       311 
     | 
    
         
            -
                      offsetX: event.offsetX * data.columnAmount % data.layout.rootWidth,
         
     | 
| 
       312 
     | 
    
         
            -
                      offsetY: event.offsetY * data.rowAmount % data.layout.rootHeight
         
     | 
| 
       313 
     | 
    
         
            -
                    }
         
     | 
| 
       314 
     | 
    
         
            -
                    // console.log('data.columnAmount', data.columnAmount, 'data.rowAmount', data.rowAmount, 'data.layout.rootWidth', data.layout.rootWidth, 'data.layout.rootHeight', data.layout.rootHeight)
         
     | 
| 
       315 
     | 
    
         
            -
                    const axisValue = axisValuePredicate(eventData)
         
     | 
| 
       316 
     | 
    
         
            -
                    const xIndex = xIndexScale(axisValue)
         
     | 
| 
       317 
     | 
    
         
            -
                    const currentxIndexStart = Math.ceil(data.groupScaleDomain[0]) // 因為有padding所以會有小數點,所以要無條件進位
         
     | 
| 
       318 
     | 
    
         
            -
                    const groupIndex =  xIndex + currentxIndexStart
         
     | 
| 
       319 
     | 
    
         
            -
                    
         
     | 
| 
       320 
     | 
    
         
            -
                    return {
         
     | 
| 
       321 
     | 
    
         
            -
                      groupIndex,
         
     | 
| 
       322 
     | 
    
         
            -
                      groupLabel: data.groupLabels[groupIndex] ?? ''
         
     | 
| 
       323 
     | 
    
         
            -
                    }
         
     | 
| 
       324 
     | 
    
         
            -
                  }
         
     | 
| 
       325 
     | 
    
         
            -
             
     | 
| 
       326 
     | 
    
         
            -
                  subscriber.next(createEventGroupData)
         
     | 
| 
       327 
     | 
    
         
            -
             
     | 
| 
       328 
     | 
    
         
            -
                  return function unsubscribe () {
         
     | 
| 
       329 
     | 
    
         
            -
                    destroy$.next(undefined)
         
     | 
| 
       330 
     | 
    
         
            -
                  }
         
     | 
| 
       331 
     | 
    
         
            -
                })
         
     | 
| 
       332 
     | 
    
         
            -
              })
         
     | 
| 
       333 
     | 
    
         
            -
            }
         
     | 
| 
       334 
     | 
    
         
            -
             
     | 
| 
       335 
     | 
    
         
            -
            export const gridGroupPosition = ({ rootSelection, fullDataFormatter$, gridAxesSize$, computedData$, fullChartParams$, gridContainerPosition$, layout$ }: {
         
     | 
| 
       336 
     | 
    
         
            -
              rootSelection: d3.Selection<any, unknown, any, unknown>
         
     | 
| 
       337 
     | 
    
         
            -
              fullDataFormatter$: Observable<DataFormatterGrid>
         
     | 
| 
       338 
     | 
    
         
            -
              gridAxesSize$: Observable<{
         
     | 
| 
       339 
     | 
    
         
            -
                width: number;
         
     | 
| 
       340 
     | 
    
         
            -
                height: number;
         
     | 
| 
       341 
     | 
    
         
            -
              }>
         
     | 
| 
       342 
     | 
    
         
            -
              computedData$: Observable<ComputedDataGrid>
         
     | 
| 
       343 
     | 
    
         
            -
              fullChartParams$: Observable<ChartParams>
         
     | 
| 
       344 
     | 
    
         
            -
              gridContainerPosition$: Observable<GridContainerPosition[]>
         
     | 
| 
       345 
     | 
    
         
            -
              layout$: Observable<Layout>
         
     | 
| 
       346 
     | 
    
         
            -
            }) => {
         
     | 
| 
       347 
     | 
    
         
            -
              const rootMousemove$: Observable<any> = d3EventObservable(rootSelection, 'mousemove')
         
     | 
| 
       348 
     | 
    
         
            -
             
     | 
| 
       349 
     | 
    
         
            -
              const groupScaleDomain$ = combineLatest({
         
     | 
| 
       350 
     | 
    
         
            -
                fullDataFormatter: fullDataFormatter$,
         
     | 
| 
       351 
     | 
    
         
            -
                gridAxesSize: gridAxesSize$,
         
     | 
| 
       352 
     | 
    
         
            -
                computedData: computedData$
         
     | 
| 
       353 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       354 
     | 
    
         
            -
                switchMap(async (d) => d),
         
     | 
| 
       355 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       356 
     | 
    
         
            -
                  const groupMin = 0
         
     | 
| 
       357 
     | 
    
         
            -
                  const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
         
     | 
| 
       358 
     | 
    
         
            -
                  // const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
         
     | 
| 
       359 
     | 
    
         
            -
                  //   ? groupMin - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       360 
     | 
    
         
            -
                  //   : data.fullDataFormatter.grid.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       361 
     | 
    
         
            -
                  const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       362 
     | 
    
         
            -
                  const groupScaleDomainMax = data.fullDataFormatter.grid.groupAxis.scaleDomain[1] === 'max'
         
     | 
| 
       363 
     | 
    
         
            -
                    ? groupMax + data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       364 
     | 
    
         
            -
                    : data.fullDataFormatter.grid.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
       365 
     | 
    
         
            -
             
     | 
| 
       366 
     | 
    
         
            -
                  return [groupScaleDomainMin, groupScaleDomainMax]
         
     | 
| 
       367 
     | 
    
         
            -
                }),
         
     | 
| 
       368 
     | 
    
         
            -
                shareReplay(1)
         
     | 
| 
       369 
     | 
    
         
            -
              )
         
     | 
| 
       370 
     | 
    
         
            -
             
     | 
| 
       371 
     | 
    
         
            -
              const groupLabels$ = combineLatest({
         
     | 
| 
       372 
     | 
    
         
            -
                fullDataFormatter: fullDataFormatter$,
         
     | 
| 
       373 
     | 
    
         
            -
                computedData: computedData$
         
     | 
| 
       374 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       375 
     | 
    
         
            -
                switchMap(async d => d),
         
     | 
| 
       376 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       377 
     | 
    
         
            -
                  return data.fullDataFormatter.grid.seriesDirection === 'row'
         
     | 
| 
       378 
     | 
    
         
            -
                    ? (data.computedData[0] ?? []).map(d => d.groupLabel)
         
     | 
| 
       379 
     | 
    
         
            -
                    : data.computedData.map(d => d[0].groupLabel)
         
     | 
| 
       380 
     | 
    
         
            -
                })
         
     | 
| 
       381 
     | 
    
         
            -
              )
         
     | 
| 
       382 
     | 
    
         
            -
             
     | 
| 
       383 
     | 
    
         
            -
              const scaleRangeGroupLabels$ = combineLatest({
         
     | 
| 
       384 
     | 
    
         
            -
                groupScaleDomain: groupScaleDomain$,
         
     | 
| 
       385 
     | 
    
         
            -
                groupLabels: groupLabels$
         
     | 
| 
       386 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       387 
     | 
    
         
            -
                switchMap(async d => d),
         
     | 
| 
       388 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       389 
     | 
    
         
            -
                  return data.groupLabels
         
     | 
| 
       390 
     | 
    
         
            -
                    .filter((d, i) => {
         
     | 
| 
       391 
     | 
    
         
            -
                      return i >= data.groupScaleDomain[0] && i <= data.groupScaleDomain[1]
         
     | 
| 
       392 
     | 
    
         
            -
                    })
         
     | 
| 
       393 
     | 
    
         
            -
                })
         
     | 
| 
       394 
     | 
    
         
            -
              )
         
     | 
| 
       395 
     | 
    
         
            -
             
     | 
| 
       396 
     | 
    
         
            -
              const reverse$ = fullDataFormatter$.pipe(
         
     | 
| 
       397 
     | 
    
         
            -
                map(d => {
         
     | 
| 
       398 
     | 
    
         
            -
                  return d.grid.valueAxis.position === 'right' || d.grid.valueAxis.position === 'bottom'
         
     | 
| 
       399 
     | 
    
         
            -
                      ? true
         
     | 
| 
       400 
     | 
    
         
            -
                      : false
         
     | 
| 
       401 
     | 
    
         
            -
                })
         
     | 
| 
       402 
     | 
    
         
            -
              )
         
     | 
| 
       403 
     | 
    
         
            -
             
     | 
| 
       404 
     | 
    
         
            -
              // 比例尺座標對應非連續資料索引
         
     | 
| 
       405 
     | 
    
         
            -
              const xIndexScale$ = combineLatest({
         
     | 
| 
       406 
     | 
    
         
            -
                reverse: reverse$,
         
     | 
| 
       407 
     | 
    
         
            -
                gridAxesSize: gridAxesSize$,
         
     | 
| 
       408 
     | 
    
         
            -
                scaleRangeGroupLabels: scaleRangeGroupLabels$,
         
     | 
| 
       409 
     | 
    
         
            -
                fullDataFormatter: fullDataFormatter$
         
     | 
| 
       410 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       411 
     | 
    
         
            -
                switchMap(async d => d),
         
     | 
| 
       412 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       413 
     | 
    
         
            -
                  return createAxisQuantizeScale({
         
     | 
| 
       414 
     | 
    
         
            -
                    axisLabels: data.scaleRangeGroupLabels,
         
     | 
| 
       415 
     | 
    
         
            -
                    axisWidth: data.gridAxesSize.width,
         
     | 
| 
       416 
     | 
    
         
            -
                    padding: data.fullDataFormatter.grid.groupAxis.scalePadding,
         
     | 
| 
       417 
     | 
    
         
            -
                    reverse: data.reverse
         
     | 
| 
       418 
     | 
    
         
            -
                  })
         
     | 
| 
       419 
     | 
    
         
            -
                })
         
     | 
| 
       420 
     | 
    
         
            -
              )
         
     | 
| 
       421 
     | 
    
         
            -
             
     | 
| 
       422 
     | 
    
         
            -
              const columnAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
       423 
     | 
    
         
            -
                map(gridContainerPosition => {
         
     | 
| 
       424 
     | 
    
         
            -
                  const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
       425 
     | 
    
         
            -
                    return current.columnIndex > acc ? current.columnIndex : acc
         
     | 
| 
       426 
     | 
    
         
            -
                  }, 0)
         
     | 
| 
       427 
     | 
    
         
            -
                  return maxColumnIndex + 1
         
     | 
| 
       428 
     | 
    
         
            -
                }),
         
     | 
| 
       429 
     | 
    
         
            -
                distinctUntilChanged()
         
     | 
| 
       430 
     | 
    
         
            -
              )
         
     | 
| 
       431 
     | 
    
         
            -
             
     | 
| 
       432 
     | 
    
         
            -
              const rowAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
       433 
     | 
    
         
            -
                map(gridContainerPosition => {
         
     | 
| 
       434 
     | 
    
         
            -
                  const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
       435 
     | 
    
         
            -
                    return current.rowIndex > acc ? current.rowIndex : acc
         
     | 
| 
       436 
     | 
    
         
            -
                  }, 0)
         
     | 
| 
       437 
     | 
    
         
            -
                  return maxRowIndex + 1
         
     | 
| 
       438 
     | 
    
         
            -
                }),
         
     | 
| 
       439 
     | 
    
         
            -
                distinctUntilChanged()
         
     | 
| 
       440 
     | 
    
         
            -
              )
         
     | 
| 
       441 
     | 
    
         
            -
             
     | 
| 
       442 
     | 
    
         
            -
              const axisValue$ = combineLatest({
         
     | 
| 
       443 
     | 
    
         
            -
                fullDataFormatter: fullDataFormatter$,
         
     | 
| 
       444 
     | 
    
         
            -
                fullChartParams: fullChartParams$,
         
     | 
| 
       445 
     | 
    
         
            -
                rootMousemove: rootMousemove$,
         
     | 
| 
       446 
     | 
    
         
            -
                columnAmount: columnAmount$,
         
     | 
| 
       447 
     | 
    
         
            -
                rowAmount: rowAmount$,
         
     | 
| 
       448 
     | 
    
         
            -
                layout: layout$
         
     | 
| 
       449 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       450 
     | 
    
         
            -
                switchMap(async d => d),
         
     | 
| 
       451 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       452 
     | 
    
         
            -
                  // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
         
     | 
| 
       453 
     | 
    
         
            -
                  const eventData = {
         
     | 
| 
       454 
     | 
    
         
            -
                    offsetX: data.rootMousemove.offsetX * data.columnAmount % data.layout.rootWidth,
         
     | 
| 
       455 
     | 
    
         
            -
                    offsetY: data.rootMousemove.offsetY * data.rowAmount % data.layout.rootHeight
         
     | 
| 
       456 
     | 
    
         
            -
                  }
         
     | 
| 
       457 
     | 
    
         
            -
                  return data.fullDataFormatter.grid.groupAxis.position === 'bottom'
         
     | 
| 
       458 
     | 
    
         
            -
                      || data.fullDataFormatter.grid.groupAxis.position === 'top'
         
     | 
| 
       459 
     | 
    
         
            -
                        ? eventData.offsetX - data.fullChartParams.padding.left
         
     | 
| 
       460 
     | 
    
         
            -
                        : eventData.offsetY - data.fullChartParams.padding.top
         
     | 
| 
       461 
     | 
    
         
            -
                })
         
     | 
| 
       462 
     | 
    
         
            -
              )
         
     | 
| 
       463 
     | 
    
         
            -
             
     | 
| 
       464 
     | 
    
         
            -
              const groupIndex$ = combineLatest({
         
     | 
| 
       465 
     | 
    
         
            -
                xIndexScale: xIndexScale$,
         
     | 
| 
       466 
     | 
    
         
            -
                axisValue: axisValue$,
         
     | 
| 
       467 
     | 
    
         
            -
                groupScaleDomain: groupScaleDomain$
         
     | 
| 
       468 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       469 
     | 
    
         
            -
                switchMap(async d => d),
         
     | 
| 
       470 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       471 
     | 
    
         
            -
                  const xIndex = data.xIndexScale(data.axisValue)
         
     | 
| 
       472 
     | 
    
         
            -
                  const currentxIndexStart = Math.ceil(data.groupScaleDomain[0]) // 因為有padding所以會有小數點,所以要無條件進位
         
     | 
| 
       473 
     | 
    
         
            -
                  return xIndex + currentxIndexStart
         
     | 
| 
       474 
     | 
    
         
            -
                })
         
     | 
| 
       475 
     | 
    
         
            -
              )
         
     | 
| 
       476 
     | 
    
         
            -
             
     | 
| 
       477 
     | 
    
         
            -
              const groupLabel$ = combineLatest({
         
     | 
| 
       478 
     | 
    
         
            -
                groupIndex: groupIndex$,
         
     | 
| 
       479 
     | 
    
         
            -
                groupLabels: groupLabels$
         
     | 
| 
       480 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       481 
     | 
    
         
            -
                switchMap(async d => d),
         
     | 
| 
       482 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       483 
     | 
    
         
            -
                  return data.groupLabels[data.groupIndex] ?? ''
         
     | 
| 
       484 
     | 
    
         
            -
                })
         
     | 
| 
       485 
     | 
    
         
            -
              )
         
     | 
| 
       486 
     | 
    
         
            -
             
     | 
| 
       487 
     | 
    
         
            -
              return combineLatest({
         
     | 
| 
       488 
     | 
    
         
            -
                groupIndex: groupIndex$,
         
     | 
| 
       489 
     | 
    
         
            -
                groupLabel: groupLabel$
         
     | 
| 
       490 
     | 
    
         
            -
              }).pipe(
         
     | 
| 
       491 
     | 
    
         
            -
                switchMap(async d => d),
         
     | 
| 
       492 
     | 
    
         
            -
                map(data => {
         
     | 
| 
       493 
     | 
    
         
            -
                  return {
         
     | 
| 
       494 
     | 
    
         
            -
                    groupIndex: data.groupIndex,
         
     | 
| 
       495 
     | 
    
         
            -
                    groupLabel: data.groupLabel
         
     | 
| 
       496 
     | 
    
         
            -
                  }
         
     | 
| 
       497 
     | 
    
         
            -
                })
         
     | 
| 
       498 
     | 
    
         
            -
              )
         
     | 
| 
       499 
     | 
    
         
            -
            }
         
     | 
| 
       500 
     | 
    
         
            -
             
     | 
| 
       501 
     | 
    
         
            -
            // const gridContainerEventData$ = ({ eventData$, gridContainerPosition$, layout$ }: {
         
     | 
| 
       502 
     | 
    
         
            -
            //   eventData$: Observable<any>
         
     | 
| 
       503 
     | 
    
         
            -
            //   gridContainerPosition$: Observable<GridContainerPosition[]>
         
     | 
| 
       504 
     | 
    
         
            -
            //   layout$: Observable<Layout>
         
     | 
| 
       505 
     | 
    
         
            -
            // }): Observable<{
         
     | 
| 
       506 
     | 
    
         
            -
            //   offsetX: number;
         
     | 
| 
       507 
     | 
    
         
            -
            //   offsetY: number;
         
     | 
| 
       508 
     | 
    
         
            -
            // }> => {
         
     | 
| 
       509 
     | 
    
         
            -
            //   const columnAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
       510 
     | 
    
         
            -
            //     map(gridContainerPosition => {
         
     | 
| 
       511 
     | 
    
         
            -
            //       const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
       512 
     | 
    
         
            -
            //         return current.columnIndex > acc ? current.columnIndex : acc
         
     | 
| 
       513 
     | 
    
         
            -
            //       }, 0)
         
     | 
| 
       514 
     | 
    
         
            -
            //       return maxColumnIndex + 1
         
     | 
| 
       515 
     | 
    
         
            -
            //     }),
         
     | 
| 
       516 
     | 
    
         
            -
            //     distinctUntilChanged()
         
     | 
| 
       517 
     | 
    
         
            -
            //   )
         
     | 
| 
       518 
     | 
    
         
            -
             
     | 
| 
       519 
     | 
    
         
            -
            //   const rowAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
       520 
     | 
    
         
            -
            //     map(gridContainerPosition => {
         
     | 
| 
       521 
     | 
    
         
            -
            //       const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
       522 
     | 
    
         
            -
            //         return current.rowIndex > acc ? current.rowIndex : acc
         
     | 
| 
       523 
     | 
    
         
            -
            //       }, 0)
         
     | 
| 
       524 
     | 
    
         
            -
            //       return maxRowIndex + 1
         
     | 
| 
       525 
     | 
    
         
            -
            //     }),
         
     | 
| 
       526 
     | 
    
         
            -
            //     distinctUntilChanged()
         
     | 
| 
       527 
     | 
    
         
            -
            //   )
         
     | 
| 
       528 
     | 
    
         
            -
             
     | 
| 
       529 
     | 
    
         
            -
            //   return combineLatest({
         
     | 
| 
       530 
     | 
    
         
            -
            //     eventData: eventData$,
         
     | 
| 
       531 
     | 
    
         
            -
            //     gridContainerPosition: gridContainerPosition$,
         
     | 
| 
       532 
     | 
    
         
            -
            //     layout: layout$,
         
     | 
| 
       533 
     | 
    
         
            -
            //     columnAmount: columnAmount$,
         
     | 
| 
       534 
     | 
    
         
            -
            //     rowAmount: rowAmount$
         
     | 
| 
       535 
     | 
    
         
            -
            //   }).pipe(
         
     | 
| 
       536 
     | 
    
         
            -
            //     switchMap(async d => d),
         
     | 
| 
       537 
     | 
    
         
            -
            //     map(data => {
         
     | 
| 
       538 
     | 
    
         
            -
            //       // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
         
     | 
| 
       539 
     | 
    
         
            -
            //       const eventData = {
         
     | 
| 
       540 
     | 
    
         
            -
            //         offsetX: data.eventData.offsetX * data.columnAmount % data.layout.rootWidth,
         
     | 
| 
       541 
     | 
    
         
            -
            //         offsetY: data.eventData.offsetY * data.rowAmount % data.layout.rootHeight
         
     | 
| 
       542 
     | 
    
         
            -
            //       }
         
     | 
| 
       543 
     | 
    
         
            -
            //       return eventData
         
     | 
| 
       544 
     | 
    
         
            -
            //     })
         
     | 
| 
       545 
     | 
    
         
            -
            //   )
         
     | 
| 
      
 1 
     | 
    
         
            +
            import * as d3 from 'd3'
         
     | 
| 
      
 2 
     | 
    
         
            +
            import {
         
     | 
| 
      
 3 
     | 
    
         
            +
              Observable,
         
     | 
| 
      
 4 
     | 
    
         
            +
              Subject,
         
     | 
| 
      
 5 
     | 
    
         
            +
              of,
         
     | 
| 
      
 6 
     | 
    
         
            +
              takeUntil,
         
     | 
| 
      
 7 
     | 
    
         
            +
              filter,
         
     | 
| 
      
 8 
     | 
    
         
            +
              map,
         
     | 
| 
      
 9 
     | 
    
         
            +
              switchMap,
         
     | 
| 
      
 10 
     | 
    
         
            +
              combineLatest,
         
     | 
| 
      
 11 
     | 
    
         
            +
              merge,
         
     | 
| 
      
 12 
     | 
    
         
            +
              shareReplay,
         
     | 
| 
      
 13 
     | 
    
         
            +
              distinctUntilChanged
         
     | 
| 
      
 14 
     | 
    
         
            +
            } from 'rxjs'
         
     | 
| 
      
 15 
     | 
    
         
            +
            import type {
         
     | 
| 
      
 16 
     | 
    
         
            +
              ChartParams,
         
     | 
| 
      
 17 
     | 
    
         
            +
              HighlightTarget,
         
     | 
| 
      
 18 
     | 
    
         
            +
              DataFormatterGrid,
         
     | 
| 
      
 19 
     | 
    
         
            +
              ComputedDataGrid,
         
     | 
| 
      
 20 
     | 
    
         
            +
              ComputedDatumGrid,
         
     | 
| 
      
 21 
     | 
    
         
            +
              TransformData,
         
     | 
| 
      
 22 
     | 
    
         
            +
              GridContainerPosition,
         
     | 
| 
      
 23 
     | 
    
         
            +
              Layout } from '../../lib/core-types'
         
     | 
| 
      
 24 
     | 
    
         
            +
            import { createAxisQuantizeScale } from '../../lib/core'
         
     | 
| 
      
 25 
     | 
    
         
            +
            import { getClassName, getUniID } from '../utils/orbchartsUtils'
         
     | 
| 
      
 26 
     | 
    
         
            +
            import { d3EventObservable } from '../utils/observables'
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            // grid選取器
         
     | 
| 
      
 29 
     | 
    
         
            +
            export const gridSelectionsObservable = ({ selection, pluginName, clipPathID, seriesLabels$, gridContainerPosition$, gridAxesTransform$, gridGraphicTransform$ }: {
         
     | 
| 
      
 30 
     | 
    
         
            +
              selection: d3.Selection<any, unknown, any, unknown>
         
     | 
| 
      
 31 
     | 
    
         
            +
              pluginName: string
         
     | 
| 
      
 32 
     | 
    
         
            +
              clipPathID: string
         
     | 
| 
      
 33 
     | 
    
         
            +
              // computedData$: Observable<ComputedDataGrid>
         
     | 
| 
      
 34 
     | 
    
         
            +
              seriesLabels$: Observable<string[]>
         
     | 
| 
      
 35 
     | 
    
         
            +
              gridContainerPosition$: Observable<GridContainerPosition[]>
         
     | 
| 
      
 36 
     | 
    
         
            +
              gridAxesTransform$: Observable<TransformData>
         
     | 
| 
      
 37 
     | 
    
         
            +
              gridGraphicTransform$: Observable<TransformData>
         
     | 
| 
      
 38 
     | 
    
         
            +
            }) => {
         
     | 
| 
      
 39 
     | 
    
         
            +
              const seriesClassName = getClassName(pluginName, 'series')
         
     | 
| 
      
 40 
     | 
    
         
            +
              const axesClassName = getClassName(pluginName, 'axes')
         
     | 
| 
      
 41 
     | 
    
         
            +
              const graphicClassName = getClassName(pluginName, 'graphic')
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              const seriesSelection$ = seriesLabels$.pipe(
         
     | 
| 
      
 44 
     | 
    
         
            +
                map((existSeriesLabels, i) => {
         
     | 
| 
      
 45 
     | 
    
         
            +
                  return selection
         
     | 
| 
      
 46 
     | 
    
         
            +
                    .selectAll<SVGGElement, string>(`g.${seriesClassName}`)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    .data(existSeriesLabels, d => d)
         
     | 
| 
      
 48 
     | 
    
         
            +
                    .join(
         
     | 
| 
      
 49 
     | 
    
         
            +
                      enter => {
         
     | 
| 
      
 50 
     | 
    
         
            +
                        return enter
         
     | 
| 
      
 51 
     | 
    
         
            +
                          .append('g')
         
     | 
| 
      
 52 
     | 
    
         
            +
                          .classed(seriesClassName, true)
         
     | 
| 
      
 53 
     | 
    
         
            +
                          .each((d, i, g) => {
         
     | 
| 
      
 54 
     | 
    
         
            +
                            const axesSelection = d3.select(g[i])
         
     | 
| 
      
 55 
     | 
    
         
            +
                              .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${axesClassName}`)
         
     | 
| 
      
 56 
     | 
    
         
            +
                              .data([i])
         
     | 
| 
      
 57 
     | 
    
         
            +
                              .join(
         
     | 
| 
      
 58 
     | 
    
         
            +
                                enter => {
         
     | 
| 
      
 59 
     | 
    
         
            +
                                  return enter
         
     | 
| 
      
 60 
     | 
    
         
            +
                                    .append('g')
         
     | 
| 
      
 61 
     | 
    
         
            +
                                    .classed(axesClassName, true)
         
     | 
| 
      
 62 
     | 
    
         
            +
                                    .attr('clip-path', `url(#${clipPathID})`)
         
     | 
| 
      
 63 
     | 
    
         
            +
                                    .each((d, i, g) => {
         
     | 
| 
      
 64 
     | 
    
         
            +
                                      const defsSelection = d3.select(g[i])
         
     | 
| 
      
 65 
     | 
    
         
            +
                                        .selectAll<SVGDefsElement, any>('defs')
         
     | 
| 
      
 66 
     | 
    
         
            +
                                        .data([i])
         
     | 
| 
      
 67 
     | 
    
         
            +
                                        .join('defs')
         
     | 
| 
      
 68 
     | 
    
         
            +
                        
         
     | 
| 
      
 69 
     | 
    
         
            +
                                      const graphicGSelection = d3.select(g[i])
         
     | 
| 
      
 70 
     | 
    
         
            +
                                        .selectAll<SVGGElement, any>('g')
         
     | 
| 
      
 71 
     | 
    
         
            +
                                        .data([i])
         
     | 
| 
      
 72 
     | 
    
         
            +
                                        .join('g')
         
     | 
| 
      
 73 
     | 
    
         
            +
                                        .classed(graphicClassName, true)
         
     | 
| 
      
 74 
     | 
    
         
            +
                                    })
         
     | 
| 
      
 75 
     | 
    
         
            +
                                },
         
     | 
| 
      
 76 
     | 
    
         
            +
                                update => update,
         
     | 
| 
      
 77 
     | 
    
         
            +
                                exit => exit.remove()
         
     | 
| 
      
 78 
     | 
    
         
            +
                              )
         
     | 
| 
      
 79 
     | 
    
         
            +
                          })
         
     | 
| 
      
 80 
     | 
    
         
            +
                      },
         
     | 
| 
      
 81 
     | 
    
         
            +
                      update => update,
         
     | 
| 
      
 82 
     | 
    
         
            +
                      exit => exit.remove()
         
     | 
| 
      
 83 
     | 
    
         
            +
                    )
         
     | 
| 
      
 84 
     | 
    
         
            +
                }),
         
     | 
| 
      
 85 
     | 
    
         
            +
                shareReplay(1)
         
     | 
| 
      
 86 
     | 
    
         
            +
              )
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
              combineLatest({
         
     | 
| 
      
 89 
     | 
    
         
            +
                seriesSelection: seriesSelection$,
         
     | 
| 
      
 90 
     | 
    
         
            +
                gridContainerPosition: gridContainerPosition$                                                                                                                                                                                       
         
     | 
| 
      
 91 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 92 
     | 
    
         
            +
                switchMap(async d => d)
         
     | 
| 
      
 93 
     | 
    
         
            +
              ).subscribe(data => {
         
     | 
| 
      
 94 
     | 
    
         
            +
                data.seriesSelection
         
     | 
| 
      
 95 
     | 
    
         
            +
                  .transition()
         
     | 
| 
      
 96 
     | 
    
         
            +
                  .attr('transform', (d, i) => {
         
     | 
| 
      
 97 
     | 
    
         
            +
                    const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
         
     | 
| 
      
 98 
     | 
    
         
            +
                    const translate = gridContainerPosition.translate
         
     | 
| 
      
 99 
     | 
    
         
            +
                    const scale = gridContainerPosition.scale
         
     | 
| 
      
 100 
     | 
    
         
            +
                    return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
         
     | 
| 
      
 101 
     | 
    
         
            +
                  })
         
     | 
| 
      
 102 
     | 
    
         
            +
              })
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
              const axesSelection$ = combineLatest({
         
     | 
| 
      
 105 
     | 
    
         
            +
                seriesSelection: seriesSelection$,
         
     | 
| 
      
 106 
     | 
    
         
            +
                gridAxesTransform: gridAxesTransform$
         
     | 
| 
      
 107 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 108 
     | 
    
         
            +
                switchMap(async d => d),
         
     | 
| 
      
 109 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 110 
     | 
    
         
            +
                  return data.seriesSelection
         
     | 
| 
      
 111 
     | 
    
         
            +
                    .select<SVGGElement>(`g.${axesClassName}`)
         
     | 
| 
      
 112 
     | 
    
         
            +
                    .style('transform', data.gridAxesTransform.value)
         
     | 
| 
      
 113 
     | 
    
         
            +
                }),
         
     | 
| 
      
 114 
     | 
    
         
            +
                shareReplay(1)
         
     | 
| 
      
 115 
     | 
    
         
            +
              )
         
     | 
| 
      
 116 
     | 
    
         
            +
              const defsSelection$ = axesSelection$.pipe(
         
     | 
| 
      
 117 
     | 
    
         
            +
                map(axesSelection => {
         
     | 
| 
      
 118 
     | 
    
         
            +
                  return axesSelection.select<SVGDefsElement>('defs')
         
     | 
| 
      
 119 
     | 
    
         
            +
                }),
         
     | 
| 
      
 120 
     | 
    
         
            +
                shareReplay(1)
         
     | 
| 
      
 121 
     | 
    
         
            +
              )
         
     | 
| 
      
 122 
     | 
    
         
            +
              const graphicGSelection$ = combineLatest({
         
     | 
| 
      
 123 
     | 
    
         
            +
                axesSelection: axesSelection$,
         
     | 
| 
      
 124 
     | 
    
         
            +
                gridGraphicTransform: gridGraphicTransform$
         
     | 
| 
      
 125 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 126 
     | 
    
         
            +
                switchMap(async d => d),
         
     | 
| 
      
 127 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 128 
     | 
    
         
            +
                  const graphicGSelection = data.axesSelection
         
     | 
| 
      
 129 
     | 
    
         
            +
                    .select<SVGGElement>(`g.${graphicClassName}`)
         
     | 
| 
      
 130 
     | 
    
         
            +
                  graphicGSelection
         
     | 
| 
      
 131 
     | 
    
         
            +
                    .transition()
         
     | 
| 
      
 132 
     | 
    
         
            +
                    .duration(50)
         
     | 
| 
      
 133 
     | 
    
         
            +
                    .style('transform', data.gridGraphicTransform.value)
         
     | 
| 
      
 134 
     | 
    
         
            +
                  return graphicGSelection
         
     | 
| 
      
 135 
     | 
    
         
            +
                }),
         
     | 
| 
      
 136 
     | 
    
         
            +
                shareReplay(1)
         
     | 
| 
      
 137 
     | 
    
         
            +
              )
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
              return {
         
     | 
| 
      
 140 
     | 
    
         
            +
                seriesSelection$,
         
     | 
| 
      
 141 
     | 
    
         
            +
                axesSelection$,
         
     | 
| 
      
 142 
     | 
    
         
            +
                defsSelection$,
         
     | 
| 
      
 143 
     | 
    
         
            +
                graphicGSelection$
         
     | 
| 
      
 144 
     | 
    
         
            +
              }
         
     | 
| 
      
 145 
     | 
    
         
            +
            }
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
      
 147 
     | 
    
         
            +
            // 由事件取得group data的function
         
     | 
| 
      
 148 
     | 
    
         
            +
            // @Q@ 之後重構改用 gridGroupPosition
         
     | 
| 
      
 149 
     | 
    
         
            +
            export const gridGroupPositionFnObservable = ({ fullDataFormatter$, gridAxesSize$, computedData$, fullChartParams$, gridContainerPosition$, layout$ }: {
         
     | 
| 
      
 150 
     | 
    
         
            +
              fullDataFormatter$: Observable<DataFormatterGrid>
         
     | 
| 
      
 151 
     | 
    
         
            +
              gridAxesSize$: Observable<{
         
     | 
| 
      
 152 
     | 
    
         
            +
                width: number;
         
     | 
| 
      
 153 
     | 
    
         
            +
                height: number;
         
     | 
| 
      
 154 
     | 
    
         
            +
              }>
         
     | 
| 
      
 155 
     | 
    
         
            +
              computedData$: Observable<ComputedDataGrid>
         
     | 
| 
      
 156 
     | 
    
         
            +
              // GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
         
     | 
| 
      
 157 
     | 
    
         
            +
              fullChartParams$: Observable<ChartParams>
         
     | 
| 
      
 158 
     | 
    
         
            +
              gridContainerPosition$: Observable<GridContainerPosition[]>
         
     | 
| 
      
 159 
     | 
    
         
            +
              layout$: Observable<Layout>
         
     | 
| 
      
 160 
     | 
    
         
            +
            }): Observable<(event: any) => { groupIndex: number; groupLabel: string }> => {
         
     | 
| 
      
 161 
     | 
    
         
            +
              const destroy$ = new Subject()
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
              // 顯示範圍內的group labels
         
     | 
| 
      
 164 
     | 
    
         
            +
              // const scaleRangeGroupLabels$: Observable<string[]> = new Observable(subscriber => {
         
     | 
| 
      
 165 
     | 
    
         
            +
              //   combineLatest({
         
     | 
| 
      
 166 
     | 
    
         
            +
              //     dataFormatter: fullDataFormatter$,
         
     | 
| 
      
 167 
     | 
    
         
            +
              //     computedData: computedData$
         
     | 
| 
      
 168 
     | 
    
         
            +
              //   }).pipe(
         
     | 
| 
      
 169 
     | 
    
         
            +
              //     takeUntil(destroy$),
         
     | 
| 
      
 170 
     | 
    
         
            +
              //     switchMap(async (d) => d),
         
     | 
| 
      
 171 
     | 
    
         
            +
              //   ).subscribe(data => {
         
     | 
| 
      
 172 
     | 
    
         
            +
              //     const groupMin = 0
         
     | 
| 
      
 173 
     | 
    
         
            +
              //     const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
         
     | 
| 
      
 174 
     | 
    
         
            +
              //     const groupScaleDomainMin = data.dataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
         
     | 
| 
      
 175 
     | 
    
         
            +
              //       ? groupMin - data.dataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 176 
     | 
    
         
            +
              //       : data.dataFormatter.grid.groupAxis.scaleDomain[0] as number - data.dataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 177 
     | 
    
         
            +
              //     const groupScaleDomainMax = data.dataFormatter.grid.groupAxis.scaleDomain[1] === 'auto'
         
     | 
| 
      
 178 
     | 
    
         
            +
              //       ? groupMax + data.dataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 179 
     | 
    
         
            +
              //       : data.dataFormatter.grid.groupAxis.scaleDomain[1] as number + data.dataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 180 
     | 
    
         
            +
                  
         
     | 
| 
      
 181 
     | 
    
         
            +
              //     // const groupingAmount = data.computedData[0]
         
     | 
| 
      
 182 
     | 
    
         
            +
              //     //   ? data.computedData[0].length
         
     | 
| 
      
 183 
     | 
    
         
            +
              //     //   : 0
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
      
 185 
     | 
    
         
            +
              //     let _labels = data.dataFormatter.grid.seriesDirection === 'row'
         
     | 
| 
      
 186 
     | 
    
         
            +
              //       ? (data.computedData[0] ?? []).map(d => d.groupLabel)
         
     | 
| 
      
 187 
     | 
    
         
            +
              //       : data.computedData.map(d => d[0].groupLabel)
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
      
 189 
     | 
    
         
            +
              //     const _axisLabels = 
         
     | 
| 
      
 190 
     | 
    
         
            +
              //     // new Array(groupingAmount).fill(0)
         
     | 
| 
      
 191 
     | 
    
         
            +
              //     //   .map((d, i) => {
         
     | 
| 
      
 192 
     | 
    
         
            +
              //     //     return _labels[i] != null
         
     | 
| 
      
 193 
     | 
    
         
            +
              //     //       ? _labels[i]
         
     | 
| 
      
 194 
     | 
    
         
            +
              //     //       : String(i) // 沒有label則用序列號填充
         
     | 
| 
      
 195 
     | 
    
         
            +
              //     //   })
         
     | 
| 
      
 196 
     | 
    
         
            +
              //       _labels
         
     | 
| 
      
 197 
     | 
    
         
            +
              //       .filter((d, i) => {
         
     | 
| 
      
 198 
     | 
    
         
            +
              //         return i >= groupScaleDomainMin && i <= groupScaleDomainMax
         
     | 
| 
      
 199 
     | 
    
         
            +
              //       })
         
     | 
| 
      
 200 
     | 
    
         
            +
              //     subscriber.next(_axisLabels)
         
     | 
| 
      
 201 
     | 
    
         
            +
              //   })
         
     | 
| 
      
 202 
     | 
    
         
            +
              // })
         
     | 
| 
      
 203 
     | 
    
         
            +
              const groupScaleDomain$ = combineLatest({
         
     | 
| 
      
 204 
     | 
    
         
            +
                fullDataFormatter: fullDataFormatter$,
         
     | 
| 
      
 205 
     | 
    
         
            +
                gridAxesSize: gridAxesSize$,
         
     | 
| 
      
 206 
     | 
    
         
            +
                computedData: computedData$
         
     | 
| 
      
 207 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 208 
     | 
    
         
            +
                switchMap(async (d) => d),
         
     | 
| 
      
 209 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 210 
     | 
    
         
            +
                  const groupMin = 0
         
     | 
| 
      
 211 
     | 
    
         
            +
                  const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
         
     | 
| 
      
 212 
     | 
    
         
            +
                  // const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
         
     | 
| 
      
 213 
     | 
    
         
            +
                  //   ? groupMin - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 214 
     | 
    
         
            +
                  //   : data.fullDataFormatter.grid.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 215 
     | 
    
         
            +
                  const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 216 
     | 
    
         
            +
                  const groupScaleDomainMax = data.fullDataFormatter.grid.groupAxis.scaleDomain[1] === 'max'
         
     | 
| 
      
 217 
     | 
    
         
            +
                    ? groupMax + data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 218 
     | 
    
         
            +
                    : data.fullDataFormatter.grid.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 219 
     | 
    
         
            +
             
     | 
| 
      
 220 
     | 
    
         
            +
                  return [groupScaleDomainMin, groupScaleDomainMax]
         
     | 
| 
      
 221 
     | 
    
         
            +
                }),
         
     | 
| 
      
 222 
     | 
    
         
            +
                shareReplay(1)
         
     | 
| 
      
 223 
     | 
    
         
            +
              )
         
     | 
| 
      
 224 
     | 
    
         
            +
             
     | 
| 
      
 225 
     | 
    
         
            +
              const groupLabels$ = combineLatest({
         
     | 
| 
      
 226 
     | 
    
         
            +
                fullDataFormatter: fullDataFormatter$,
         
     | 
| 
      
 227 
     | 
    
         
            +
                computedData: computedData$
         
     | 
| 
      
 228 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 229 
     | 
    
         
            +
                switchMap(async d => d),
         
     | 
| 
      
 230 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 231 
     | 
    
         
            +
                  return data.fullDataFormatter.grid.seriesDirection === 'row'
         
     | 
| 
      
 232 
     | 
    
         
            +
                    ? (data.computedData[0] ?? []).map(d => d.groupLabel)
         
     | 
| 
      
 233 
     | 
    
         
            +
                    : data.computedData.map(d => d[0].groupLabel)
         
     | 
| 
      
 234 
     | 
    
         
            +
                })
         
     | 
| 
      
 235 
     | 
    
         
            +
              )
         
     | 
| 
      
 236 
     | 
    
         
            +
             
     | 
| 
      
 237 
     | 
    
         
            +
              // 顯示範圍內的group labels
         
     | 
| 
      
 238 
     | 
    
         
            +
              const scaleRangeGroupLabels$ = combineLatest({
         
     | 
| 
      
 239 
     | 
    
         
            +
                groupScaleDomain: groupScaleDomain$,
         
     | 
| 
      
 240 
     | 
    
         
            +
                groupLabels: groupLabels$
         
     | 
| 
      
 241 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 242 
     | 
    
         
            +
                switchMap(async d => d),
         
     | 
| 
      
 243 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 244 
     | 
    
         
            +
                  return data.groupLabels
         
     | 
| 
      
 245 
     | 
    
         
            +
                    .filter((d, i) => {
         
     | 
| 
      
 246 
     | 
    
         
            +
                      return i >= data.groupScaleDomain[0] && i <= data.groupScaleDomain[1]
         
     | 
| 
      
 247 
     | 
    
         
            +
                    })
         
     | 
| 
      
 248 
     | 
    
         
            +
                })
         
     | 
| 
      
 249 
     | 
    
         
            +
              )
         
     | 
| 
      
 250 
     | 
    
         
            +
             
     | 
| 
      
 251 
     | 
    
         
            +
              const columnAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
      
 252 
     | 
    
         
            +
                map(gridContainerPosition => {
         
     | 
| 
      
 253 
     | 
    
         
            +
                  const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
      
 254 
     | 
    
         
            +
                    return current.columnIndex > acc ? current.columnIndex : acc
         
     | 
| 
      
 255 
     | 
    
         
            +
                  }, 0)
         
     | 
| 
      
 256 
     | 
    
         
            +
                  return maxColumnIndex + 1
         
     | 
| 
      
 257 
     | 
    
         
            +
                }),
         
     | 
| 
      
 258 
     | 
    
         
            +
                distinctUntilChanged()
         
     | 
| 
      
 259 
     | 
    
         
            +
              )
         
     | 
| 
      
 260 
     | 
    
         
            +
             
     | 
| 
      
 261 
     | 
    
         
            +
              const rowAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
      
 262 
     | 
    
         
            +
                map(gridContainerPosition => {
         
     | 
| 
      
 263 
     | 
    
         
            +
                  const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
      
 264 
     | 
    
         
            +
                    return current.rowIndex > acc ? current.rowIndex : acc
         
     | 
| 
      
 265 
     | 
    
         
            +
                  }, 0)
         
     | 
| 
      
 266 
     | 
    
         
            +
                  return maxRowIndex + 1
         
     | 
| 
      
 267 
     | 
    
         
            +
                }),
         
     | 
| 
      
 268 
     | 
    
         
            +
                distinctUntilChanged()
         
     | 
| 
      
 269 
     | 
    
         
            +
              )
         
     | 
| 
      
 270 
     | 
    
         
            +
             
     | 
| 
      
 271 
     | 
    
         
            +
              return new Observable<(event: any) => { groupIndex: number; groupLabel: string }>(subscriber => {
         
     | 
| 
      
 272 
     | 
    
         
            +
                combineLatest({
         
     | 
| 
      
 273 
     | 
    
         
            +
                  dataFormatter: fullDataFormatter$,
         
     | 
| 
      
 274 
     | 
    
         
            +
                  axisSize: gridAxesSize$,
         
     | 
| 
      
 275 
     | 
    
         
            +
                  fullChartParams: fullChartParams$,
         
     | 
| 
      
 276 
     | 
    
         
            +
                  scaleRangeGroupLabels: scaleRangeGroupLabels$,
         
     | 
| 
      
 277 
     | 
    
         
            +
                  groupLabels: groupLabels$,
         
     | 
| 
      
 278 
     | 
    
         
            +
                  groupScaleDomain: groupScaleDomain$,
         
     | 
| 
      
 279 
     | 
    
         
            +
                  columnAmount: columnAmount$,
         
     | 
| 
      
 280 
     | 
    
         
            +
                  rowAmount: rowAmount$,
         
     | 
| 
      
 281 
     | 
    
         
            +
                  layout: layout$
         
     | 
| 
      
 282 
     | 
    
         
            +
                }).pipe(
         
     | 
| 
      
 283 
     | 
    
         
            +
                  takeUntil(destroy$),
         
     | 
| 
      
 284 
     | 
    
         
            +
                  switchMap(async (d) => d),
         
     | 
| 
      
 285 
     | 
    
         
            +
                ).subscribe(data => {
         
     | 
| 
      
 286 
     | 
    
         
            +
                  
         
     | 
| 
      
 287 
     | 
    
         
            +
                  const reverse = data.dataFormatter.grid.valueAxis.position === 'right'
         
     | 
| 
      
 288 
     | 
    
         
            +
                    || data.dataFormatter.grid.valueAxis.position === 'bottom'
         
     | 
| 
      
 289 
     | 
    
         
            +
                      ? true : false
         
     | 
| 
      
 290 
     | 
    
         
            +
             
     | 
| 
      
 291 
     | 
    
         
            +
                  // 比例尺座標對應非連續資料索引
         
     | 
| 
      
 292 
     | 
    
         
            +
                  const xIndexScale = createAxisQuantizeScale({
         
     | 
| 
      
 293 
     | 
    
         
            +
                    axisLabels: data.scaleRangeGroupLabels,
         
     | 
| 
      
 294 
     | 
    
         
            +
                    axisWidth: data.axisSize.width,
         
     | 
| 
      
 295 
     | 
    
         
            +
                    padding: data.dataFormatter.grid.groupAxis.scalePadding,
         
     | 
| 
      
 296 
     | 
    
         
            +
                    reverse
         
     | 
| 
      
 297 
     | 
    
         
            +
                  })
         
     | 
| 
      
 298 
     | 
    
         
            +
             
     | 
| 
      
 299 
     | 
    
         
            +
                  // 依比例尺位置計算座標
         
     | 
| 
      
 300 
     | 
    
         
            +
                  const axisValuePredicate = (event: any) => {
         
     | 
| 
      
 301 
     | 
    
         
            +
                    return data.dataFormatter.grid.groupAxis.position === 'bottom'
         
     | 
| 
      
 302 
     | 
    
         
            +
                      || data.dataFormatter.grid.groupAxis.position === 'top'
         
     | 
| 
      
 303 
     | 
    
         
            +
                        ? event.offsetX - data.fullChartParams.padding.left
         
     | 
| 
      
 304 
     | 
    
         
            +
                        : event.offsetY - data.fullChartParams.padding.top
         
     | 
| 
      
 305 
     | 
    
         
            +
                  }
         
     | 
| 
      
 306 
     | 
    
         
            +
             
     | 
| 
      
 307 
     | 
    
         
            +
                  // 比例尺座標取得groupData的function
         
     | 
| 
      
 308 
     | 
    
         
            +
                  const createEventGroupData: (event: any) => { groupIndex: number; groupLabel: string } = (event: any) => {
         
     | 
| 
      
 309 
     | 
    
         
            +
                    // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
         
     | 
| 
      
 310 
     | 
    
         
            +
                    const eventData = {
         
     | 
| 
      
 311 
     | 
    
         
            +
                      offsetX: event.offsetX * data.columnAmount % data.layout.rootWidth,
         
     | 
| 
      
 312 
     | 
    
         
            +
                      offsetY: event.offsetY * data.rowAmount % data.layout.rootHeight
         
     | 
| 
      
 313 
     | 
    
         
            +
                    }
         
     | 
| 
      
 314 
     | 
    
         
            +
                    // console.log('data.columnAmount', data.columnAmount, 'data.rowAmount', data.rowAmount, 'data.layout.rootWidth', data.layout.rootWidth, 'data.layout.rootHeight', data.layout.rootHeight)
         
     | 
| 
      
 315 
     | 
    
         
            +
                    const axisValue = axisValuePredicate(eventData)
         
     | 
| 
      
 316 
     | 
    
         
            +
                    const xIndex = xIndexScale(axisValue)
         
     | 
| 
      
 317 
     | 
    
         
            +
                    const currentxIndexStart = Math.ceil(data.groupScaleDomain[0]) // 因為有padding所以會有小數點,所以要無條件進位
         
     | 
| 
      
 318 
     | 
    
         
            +
                    const groupIndex =  xIndex + currentxIndexStart
         
     | 
| 
      
 319 
     | 
    
         
            +
                    
         
     | 
| 
      
 320 
     | 
    
         
            +
                    return {
         
     | 
| 
      
 321 
     | 
    
         
            +
                      groupIndex,
         
     | 
| 
      
 322 
     | 
    
         
            +
                      groupLabel: data.groupLabels[groupIndex] ?? ''
         
     | 
| 
      
 323 
     | 
    
         
            +
                    }
         
     | 
| 
      
 324 
     | 
    
         
            +
                  }
         
     | 
| 
      
 325 
     | 
    
         
            +
             
     | 
| 
      
 326 
     | 
    
         
            +
                  subscriber.next(createEventGroupData)
         
     | 
| 
      
 327 
     | 
    
         
            +
             
     | 
| 
      
 328 
     | 
    
         
            +
                  return function unsubscribe () {
         
     | 
| 
      
 329 
     | 
    
         
            +
                    destroy$.next(undefined)
         
     | 
| 
      
 330 
     | 
    
         
            +
                  }
         
     | 
| 
      
 331 
     | 
    
         
            +
                })
         
     | 
| 
      
 332 
     | 
    
         
            +
              })
         
     | 
| 
      
 333 
     | 
    
         
            +
            }
         
     | 
| 
      
 334 
     | 
    
         
            +
             
     | 
| 
      
 335 
     | 
    
         
            +
            export const gridGroupPosition = ({ rootSelection, fullDataFormatter$, gridAxesSize$, computedData$, fullChartParams$, gridContainerPosition$, layout$ }: {
         
     | 
| 
      
 336 
     | 
    
         
            +
              rootSelection: d3.Selection<any, unknown, any, unknown>
         
     | 
| 
      
 337 
     | 
    
         
            +
              fullDataFormatter$: Observable<DataFormatterGrid>
         
     | 
| 
      
 338 
     | 
    
         
            +
              gridAxesSize$: Observable<{
         
     | 
| 
      
 339 
     | 
    
         
            +
                width: number;
         
     | 
| 
      
 340 
     | 
    
         
            +
                height: number;
         
     | 
| 
      
 341 
     | 
    
         
            +
              }>
         
     | 
| 
      
 342 
     | 
    
         
            +
              computedData$: Observable<ComputedDataGrid>
         
     | 
| 
      
 343 
     | 
    
         
            +
              fullChartParams$: Observable<ChartParams>
         
     | 
| 
      
 344 
     | 
    
         
            +
              gridContainerPosition$: Observable<GridContainerPosition[]>
         
     | 
| 
      
 345 
     | 
    
         
            +
              layout$: Observable<Layout>
         
     | 
| 
      
 346 
     | 
    
         
            +
            }) => {
         
     | 
| 
      
 347 
     | 
    
         
            +
              const rootMousemove$: Observable<any> = d3EventObservable(rootSelection, 'mousemove')
         
     | 
| 
      
 348 
     | 
    
         
            +
             
     | 
| 
      
 349 
     | 
    
         
            +
              const groupScaleDomain$ = combineLatest({
         
     | 
| 
      
 350 
     | 
    
         
            +
                fullDataFormatter: fullDataFormatter$,
         
     | 
| 
      
 351 
     | 
    
         
            +
                gridAxesSize: gridAxesSize$,
         
     | 
| 
      
 352 
     | 
    
         
            +
                computedData: computedData$
         
     | 
| 
      
 353 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 354 
     | 
    
         
            +
                switchMap(async (d) => d),
         
     | 
| 
      
 355 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 356 
     | 
    
         
            +
                  const groupMin = 0
         
     | 
| 
      
 357 
     | 
    
         
            +
                  const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
         
     | 
| 
      
 358 
     | 
    
         
            +
                  // const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
         
     | 
| 
      
 359 
     | 
    
         
            +
                  //   ? groupMin - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 360 
     | 
    
         
            +
                  //   : data.fullDataFormatter.grid.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 361 
     | 
    
         
            +
                  const groupScaleDomainMin = data.fullDataFormatter.grid.groupAxis.scaleDomain[0] - data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 362 
     | 
    
         
            +
                  const groupScaleDomainMax = data.fullDataFormatter.grid.groupAxis.scaleDomain[1] === 'max'
         
     | 
| 
      
 363 
     | 
    
         
            +
                    ? groupMax + data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 364 
     | 
    
         
            +
                    : data.fullDataFormatter.grid.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.grid.groupAxis.scalePadding
         
     | 
| 
      
 365 
     | 
    
         
            +
             
     | 
| 
      
 366 
     | 
    
         
            +
                  return [groupScaleDomainMin, groupScaleDomainMax]
         
     | 
| 
      
 367 
     | 
    
         
            +
                }),
         
     | 
| 
      
 368 
     | 
    
         
            +
                shareReplay(1)
         
     | 
| 
      
 369 
     | 
    
         
            +
              )
         
     | 
| 
      
 370 
     | 
    
         
            +
             
     | 
| 
      
 371 
     | 
    
         
            +
              const groupLabels$ = combineLatest({
         
     | 
| 
      
 372 
     | 
    
         
            +
                fullDataFormatter: fullDataFormatter$,
         
     | 
| 
      
 373 
     | 
    
         
            +
                computedData: computedData$
         
     | 
| 
      
 374 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 375 
     | 
    
         
            +
                switchMap(async d => d),
         
     | 
| 
      
 376 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 377 
     | 
    
         
            +
                  return data.fullDataFormatter.grid.seriesDirection === 'row'
         
     | 
| 
      
 378 
     | 
    
         
            +
                    ? (data.computedData[0] ?? []).map(d => d.groupLabel)
         
     | 
| 
      
 379 
     | 
    
         
            +
                    : data.computedData.map(d => d[0].groupLabel)
         
     | 
| 
      
 380 
     | 
    
         
            +
                })
         
     | 
| 
      
 381 
     | 
    
         
            +
              )
         
     | 
| 
      
 382 
     | 
    
         
            +
             
     | 
| 
      
 383 
     | 
    
         
            +
              const scaleRangeGroupLabels$ = combineLatest({
         
     | 
| 
      
 384 
     | 
    
         
            +
                groupScaleDomain: groupScaleDomain$,
         
     | 
| 
      
 385 
     | 
    
         
            +
                groupLabels: groupLabels$
         
     | 
| 
      
 386 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 387 
     | 
    
         
            +
                switchMap(async d => d),
         
     | 
| 
      
 388 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 389 
     | 
    
         
            +
                  return data.groupLabels
         
     | 
| 
      
 390 
     | 
    
         
            +
                    .filter((d, i) => {
         
     | 
| 
      
 391 
     | 
    
         
            +
                      return i >= data.groupScaleDomain[0] && i <= data.groupScaleDomain[1]
         
     | 
| 
      
 392 
     | 
    
         
            +
                    })
         
     | 
| 
      
 393 
     | 
    
         
            +
                })
         
     | 
| 
      
 394 
     | 
    
         
            +
              )
         
     | 
| 
      
 395 
     | 
    
         
            +
             
     | 
| 
      
 396 
     | 
    
         
            +
              const reverse$ = fullDataFormatter$.pipe(
         
     | 
| 
      
 397 
     | 
    
         
            +
                map(d => {
         
     | 
| 
      
 398 
     | 
    
         
            +
                  return d.grid.valueAxis.position === 'right' || d.grid.valueAxis.position === 'bottom'
         
     | 
| 
      
 399 
     | 
    
         
            +
                      ? true
         
     | 
| 
      
 400 
     | 
    
         
            +
                      : false
         
     | 
| 
      
 401 
     | 
    
         
            +
                })
         
     | 
| 
      
 402 
     | 
    
         
            +
              )
         
     | 
| 
      
 403 
     | 
    
         
            +
             
     | 
| 
      
 404 
     | 
    
         
            +
              // 比例尺座標對應非連續資料索引
         
     | 
| 
      
 405 
     | 
    
         
            +
              const xIndexScale$ = combineLatest({
         
     | 
| 
      
 406 
     | 
    
         
            +
                reverse: reverse$,
         
     | 
| 
      
 407 
     | 
    
         
            +
                gridAxesSize: gridAxesSize$,
         
     | 
| 
      
 408 
     | 
    
         
            +
                scaleRangeGroupLabels: scaleRangeGroupLabels$,
         
     | 
| 
      
 409 
     | 
    
         
            +
                fullDataFormatter: fullDataFormatter$
         
     | 
| 
      
 410 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 411 
     | 
    
         
            +
                switchMap(async d => d),
         
     | 
| 
      
 412 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 413 
     | 
    
         
            +
                  return createAxisQuantizeScale({
         
     | 
| 
      
 414 
     | 
    
         
            +
                    axisLabels: data.scaleRangeGroupLabels,
         
     | 
| 
      
 415 
     | 
    
         
            +
                    axisWidth: data.gridAxesSize.width,
         
     | 
| 
      
 416 
     | 
    
         
            +
                    padding: data.fullDataFormatter.grid.groupAxis.scalePadding,
         
     | 
| 
      
 417 
     | 
    
         
            +
                    reverse: data.reverse
         
     | 
| 
      
 418 
     | 
    
         
            +
                  })
         
     | 
| 
      
 419 
     | 
    
         
            +
                })
         
     | 
| 
      
 420 
     | 
    
         
            +
              )
         
     | 
| 
      
 421 
     | 
    
         
            +
             
     | 
| 
      
 422 
     | 
    
         
            +
              const columnAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
      
 423 
     | 
    
         
            +
                map(gridContainerPosition => {
         
     | 
| 
      
 424 
     | 
    
         
            +
                  const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
      
 425 
     | 
    
         
            +
                    return current.columnIndex > acc ? current.columnIndex : acc
         
     | 
| 
      
 426 
     | 
    
         
            +
                  }, 0)
         
     | 
| 
      
 427 
     | 
    
         
            +
                  return maxColumnIndex + 1
         
     | 
| 
      
 428 
     | 
    
         
            +
                }),
         
     | 
| 
      
 429 
     | 
    
         
            +
                distinctUntilChanged()
         
     | 
| 
      
 430 
     | 
    
         
            +
              )
         
     | 
| 
      
 431 
     | 
    
         
            +
             
     | 
| 
      
 432 
     | 
    
         
            +
              const rowAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
      
 433 
     | 
    
         
            +
                map(gridContainerPosition => {
         
     | 
| 
      
 434 
     | 
    
         
            +
                  const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
      
 435 
     | 
    
         
            +
                    return current.rowIndex > acc ? current.rowIndex : acc
         
     | 
| 
      
 436 
     | 
    
         
            +
                  }, 0)
         
     | 
| 
      
 437 
     | 
    
         
            +
                  return maxRowIndex + 1
         
     | 
| 
      
 438 
     | 
    
         
            +
                }),
         
     | 
| 
      
 439 
     | 
    
         
            +
                distinctUntilChanged()
         
     | 
| 
      
 440 
     | 
    
         
            +
              )
         
     | 
| 
      
 441 
     | 
    
         
            +
             
     | 
| 
      
 442 
     | 
    
         
            +
              const axisValue$ = combineLatest({
         
     | 
| 
      
 443 
     | 
    
         
            +
                fullDataFormatter: fullDataFormatter$,
         
     | 
| 
      
 444 
     | 
    
         
            +
                fullChartParams: fullChartParams$,
         
     | 
| 
      
 445 
     | 
    
         
            +
                rootMousemove: rootMousemove$,
         
     | 
| 
      
 446 
     | 
    
         
            +
                columnAmount: columnAmount$,
         
     | 
| 
      
 447 
     | 
    
         
            +
                rowAmount: rowAmount$,
         
     | 
| 
      
 448 
     | 
    
         
            +
                layout: layout$
         
     | 
| 
      
 449 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 450 
     | 
    
         
            +
                switchMap(async d => d),
         
     | 
| 
      
 451 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 452 
     | 
    
         
            +
                  // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
         
     | 
| 
      
 453 
     | 
    
         
            +
                  const eventData = {
         
     | 
| 
      
 454 
     | 
    
         
            +
                    offsetX: data.rootMousemove.offsetX * data.columnAmount % data.layout.rootWidth,
         
     | 
| 
      
 455 
     | 
    
         
            +
                    offsetY: data.rootMousemove.offsetY * data.rowAmount % data.layout.rootHeight
         
     | 
| 
      
 456 
     | 
    
         
            +
                  }
         
     | 
| 
      
 457 
     | 
    
         
            +
                  return data.fullDataFormatter.grid.groupAxis.position === 'bottom'
         
     | 
| 
      
 458 
     | 
    
         
            +
                      || data.fullDataFormatter.grid.groupAxis.position === 'top'
         
     | 
| 
      
 459 
     | 
    
         
            +
                        ? eventData.offsetX - data.fullChartParams.padding.left
         
     | 
| 
      
 460 
     | 
    
         
            +
                        : eventData.offsetY - data.fullChartParams.padding.top
         
     | 
| 
      
 461 
     | 
    
         
            +
                })
         
     | 
| 
      
 462 
     | 
    
         
            +
              )
         
     | 
| 
      
 463 
     | 
    
         
            +
             
     | 
| 
      
 464 
     | 
    
         
            +
              const groupIndex$ = combineLatest({
         
     | 
| 
      
 465 
     | 
    
         
            +
                xIndexScale: xIndexScale$,
         
     | 
| 
      
 466 
     | 
    
         
            +
                axisValue: axisValue$,
         
     | 
| 
      
 467 
     | 
    
         
            +
                groupScaleDomain: groupScaleDomain$
         
     | 
| 
      
 468 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 469 
     | 
    
         
            +
                switchMap(async d => d),
         
     | 
| 
      
 470 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 471 
     | 
    
         
            +
                  const xIndex = data.xIndexScale(data.axisValue)
         
     | 
| 
      
 472 
     | 
    
         
            +
                  const currentxIndexStart = Math.ceil(data.groupScaleDomain[0]) // 因為有padding所以會有小數點,所以要無條件進位
         
     | 
| 
      
 473 
     | 
    
         
            +
                  return xIndex + currentxIndexStart
         
     | 
| 
      
 474 
     | 
    
         
            +
                })
         
     | 
| 
      
 475 
     | 
    
         
            +
              )
         
     | 
| 
      
 476 
     | 
    
         
            +
             
     | 
| 
      
 477 
     | 
    
         
            +
              const groupLabel$ = combineLatest({
         
     | 
| 
      
 478 
     | 
    
         
            +
                groupIndex: groupIndex$,
         
     | 
| 
      
 479 
     | 
    
         
            +
                groupLabels: groupLabels$
         
     | 
| 
      
 480 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 481 
     | 
    
         
            +
                switchMap(async d => d),
         
     | 
| 
      
 482 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 483 
     | 
    
         
            +
                  return data.groupLabels[data.groupIndex] ?? ''
         
     | 
| 
      
 484 
     | 
    
         
            +
                })
         
     | 
| 
      
 485 
     | 
    
         
            +
              )
         
     | 
| 
      
 486 
     | 
    
         
            +
             
     | 
| 
      
 487 
     | 
    
         
            +
              return combineLatest({
         
     | 
| 
      
 488 
     | 
    
         
            +
                groupIndex: groupIndex$,
         
     | 
| 
      
 489 
     | 
    
         
            +
                groupLabel: groupLabel$
         
     | 
| 
      
 490 
     | 
    
         
            +
              }).pipe(
         
     | 
| 
      
 491 
     | 
    
         
            +
                switchMap(async d => d),
         
     | 
| 
      
 492 
     | 
    
         
            +
                map(data => {
         
     | 
| 
      
 493 
     | 
    
         
            +
                  return {
         
     | 
| 
      
 494 
     | 
    
         
            +
                    groupIndex: data.groupIndex,
         
     | 
| 
      
 495 
     | 
    
         
            +
                    groupLabel: data.groupLabel
         
     | 
| 
      
 496 
     | 
    
         
            +
                  }
         
     | 
| 
      
 497 
     | 
    
         
            +
                })
         
     | 
| 
      
 498 
     | 
    
         
            +
              )
         
     | 
| 
      
 499 
     | 
    
         
            +
            }
         
     | 
| 
      
 500 
     | 
    
         
            +
             
     | 
| 
      
 501 
     | 
    
         
            +
            // const gridContainerEventData$ = ({ eventData$, gridContainerPosition$, layout$ }: {
         
     | 
| 
      
 502 
     | 
    
         
            +
            //   eventData$: Observable<any>
         
     | 
| 
      
 503 
     | 
    
         
            +
            //   gridContainerPosition$: Observable<GridContainerPosition[]>
         
     | 
| 
      
 504 
     | 
    
         
            +
            //   layout$: Observable<Layout>
         
     | 
| 
      
 505 
     | 
    
         
            +
            // }): Observable<{
         
     | 
| 
      
 506 
     | 
    
         
            +
            //   offsetX: number;
         
     | 
| 
      
 507 
     | 
    
         
            +
            //   offsetY: number;
         
     | 
| 
      
 508 
     | 
    
         
            +
            // }> => {
         
     | 
| 
      
 509 
     | 
    
         
            +
            //   const columnAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
      
 510 
     | 
    
         
            +
            //     map(gridContainerPosition => {
         
     | 
| 
      
 511 
     | 
    
         
            +
            //       const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
      
 512 
     | 
    
         
            +
            //         return current.columnIndex > acc ? current.columnIndex : acc
         
     | 
| 
      
 513 
     | 
    
         
            +
            //       }, 0)
         
     | 
| 
      
 514 
     | 
    
         
            +
            //       return maxColumnIndex + 1
         
     | 
| 
      
 515 
     | 
    
         
            +
            //     }),
         
     | 
| 
      
 516 
     | 
    
         
            +
            //     distinctUntilChanged()
         
     | 
| 
      
 517 
     | 
    
         
            +
            //   )
         
     | 
| 
      
 518 
     | 
    
         
            +
             
     | 
| 
      
 519 
     | 
    
         
            +
            //   const rowAmount$ = gridContainerPosition$.pipe(
         
     | 
| 
      
 520 
     | 
    
         
            +
            //     map(gridContainerPosition => {
         
     | 
| 
      
 521 
     | 
    
         
            +
            //       const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
         
     | 
| 
      
 522 
     | 
    
         
            +
            //         return current.rowIndex > acc ? current.rowIndex : acc
         
     | 
| 
      
 523 
     | 
    
         
            +
            //       }, 0)
         
     | 
| 
      
 524 
     | 
    
         
            +
            //       return maxRowIndex + 1
         
     | 
| 
      
 525 
     | 
    
         
            +
            //     }),
         
     | 
| 
      
 526 
     | 
    
         
            +
            //     distinctUntilChanged()
         
     | 
| 
      
 527 
     | 
    
         
            +
            //   )
         
     | 
| 
      
 528 
     | 
    
         
            +
             
     | 
| 
      
 529 
     | 
    
         
            +
            //   return combineLatest({
         
     | 
| 
      
 530 
     | 
    
         
            +
            //     eventData: eventData$,
         
     | 
| 
      
 531 
     | 
    
         
            +
            //     gridContainerPosition: gridContainerPosition$,
         
     | 
| 
      
 532 
     | 
    
         
            +
            //     layout: layout$,
         
     | 
| 
      
 533 
     | 
    
         
            +
            //     columnAmount: columnAmount$,
         
     | 
| 
      
 534 
     | 
    
         
            +
            //     rowAmount: rowAmount$
         
     | 
| 
      
 535 
     | 
    
         
            +
            //   }).pipe(
         
     | 
| 
      
 536 
     | 
    
         
            +
            //     switchMap(async d => d),
         
     | 
| 
      
 537 
     | 
    
         
            +
            //     map(data => {
         
     | 
| 
      
 538 
     | 
    
         
            +
            //       // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
         
     | 
| 
      
 539 
     | 
    
         
            +
            //       const eventData = {
         
     | 
| 
      
 540 
     | 
    
         
            +
            //         offsetX: data.eventData.offsetX * data.columnAmount % data.layout.rootWidth,
         
     | 
| 
      
 541 
     | 
    
         
            +
            //         offsetY: data.eventData.offsetY * data.rowAmount % data.layout.rootHeight
         
     | 
| 
      
 542 
     | 
    
         
            +
            //       }
         
     | 
| 
      
 543 
     | 
    
         
            +
            //       return eventData
         
     | 
| 
      
 544 
     | 
    
         
            +
            //     })
         
     | 
| 
      
 545 
     | 
    
         
            +
            //   )
         
     | 
| 
       546 
546 
     | 
    
         
             
            // }
         
     |