1212
1313import { PRIVATE_PLUGIN_SYMBOL } from "../model" ;
1414import { format_cell } from "./format_cell.js" ;
15- import { format_tree_header } from "./format_tree_header.js" ;
15+ import {
16+ format_tree_header ,
17+ format_tree_header_row_path ,
18+ } from "./format_tree_header.js" ;
1619
1720/**
1821 * Creates a new DataListener, suitable for passing to `regular-table`'s
@@ -86,15 +89,20 @@ export function createDataListener(viewer) {
8689 }
8790
8891 this . _last_window = new_window ;
89- this . _ids = columns . __ID__ ;
92+ this . _ids =
93+ columns . __ID__ ||
94+ Array ( y1 - y0 )
95+ . fill ( )
96+ . map ( ( _ , index ) => [ index + y0 ] ) ;
97+
9098 this . _reverse_columns = this . _column_paths
9199 . slice ( x0 , x1 )
92100 . reduce ( ( acc , x , i ) => {
93101 acc . set ( x , i ) ;
94102 return acc ;
95103 } , new Map ( ) ) ;
96104
97- this . _reverse_ids = this . _ids . reduce ( ( acc , x , i ) => {
105+ this . _reverse_ids = this . _ids ? .reduce ( ( acc , x , i ) => {
98106 acc . set ( x ?. join ( "|" ) , i ) ;
99107 return acc ;
100108 } , new Map ( ) ) ;
@@ -108,12 +116,6 @@ export function createDataListener(viewer) {
108116 column_paths = [ ] ;
109117
110118 const is_settings_open = viewer . hasAttribute ( "settings" ) ;
111-
112- // if (this._config.split_by?.length > 0) {
113- // this._column_paths
114- // }
115-
116- // for (const path of this._column_paths.slice(x0, x1)) {
117119 for (
118120 let ipath = x0 ;
119121 ipath < Math . min ( x1 , this . _column_paths . length ) ;
@@ -143,6 +145,7 @@ export function createDataListener(viewer) {
143145 }
144146 } )
145147 ) ;
148+
146149 metadata . push ( column ) ;
147150 if ( is_settings_open ) {
148151 path_parts . push ( "" ) ;
@@ -167,19 +170,27 @@ export function createDataListener(viewer) {
167170 last_reverse_columns = this . _reverse_columns ;
168171 }
169172
170- return {
173+ const is_row_path = columns . __ROW_PATH__ !== undefined ;
174+ const row_headers = Array . from (
175+ ( is_row_path
176+ ? format_tree_header_row_path
177+ : format_tree_header
178+ ) . call (
179+ this ,
180+ columns . __ROW_PATH__ ,
181+ this . _config . group_by ,
182+ regularTable
183+ )
184+ ) ;
185+
186+ const num_row_headers = row_headers [ 0 ] ?. length ;
187+
188+ const result = {
171189 num_column_headers : column_headers [ 0 ] ?. length || 1 ,
172- num_row_headers : this . _config . group_by . length + 1 ,
190+ num_row_headers,
173191 num_rows : this . _num_rows ,
174192 num_columns : this . _column_paths . length ,
175- row_headers : Array . from (
176- format_tree_header . call (
177- this ,
178- columns . __ROW_PATH__ ,
179- this . _config . group_by ,
180- regularTable
181- )
182- ) ,
193+ row_headers,
183194 column_headers,
184195 data,
185196 metadata,
@@ -188,5 +199,7 @@ export function createDataListener(viewer) {
188199 this . _config . split_by . length
189200 ) ,
190201 } ;
202+
203+ return result ;
191204 } ;
192205}
0 commit comments