@@ -89,7 +89,7 @@ export class MetricVisComponent extends Component {
8989 return fieldFormatter ( value ) ;
9090 }
9191
92- _processTableGroups ( tableGroups ) {
92+ _processTableGroups ( table ) {
9393 const config = this . props . vis . params . metric ;
9494 const isPercentageMode = config . percentageMode ;
9595 const min = config . colorsRange [ 0 ] . from ;
@@ -98,56 +98,55 @@ export class MetricVisComponent extends Component {
9898 const labels = this . _getLabels ( ) ;
9999 const metrics = [ ] ;
100100
101- tableGroups . tables . forEach ( ( table , tableIndex ) => {
102- let bucketAgg ;
103- let rowHeaderIndex ;
101+ let bucketAgg ;
102+ let bucketColumnId ;
103+ let rowHeaderIndex ;
104104
105- table . columns . forEach ( ( column , columnIndex ) => {
106- const aggConfig = column . aggConfig ;
105+ table . columns . forEach ( ( column , columnIndex ) => {
106+ const aggConfig = column . aggConfig ;
107107
108- if ( aggConfig && aggConfig . type . type === 'buckets' ) {
109- bucketAgg = aggConfig ;
110- // Store the current index, so we later know in which position in the
111- // row array, the bucket agg key will be, so we can create filters on it.
112- rowHeaderIndex = columnIndex ;
113- return ;
114- }
108+ if ( aggConfig && aggConfig . type . type === 'buckets' ) {
109+ bucketAgg = aggConfig ;
110+ // Store the current index, so we later know in which position in the
111+ // row array, the bucket agg key will be, so we can create filters on it.
112+ rowHeaderIndex = columnIndex ;
113+ bucketColumnId = column . id ;
114+ return ;
115+ }
115116
116- table . rows . forEach ( ( row , rowIndex ) => {
117+ table . rows . forEach ( ( row , rowIndex ) => {
117118
118- let title = column . title ;
119- let value = row [ columnIndex ] ;
120- const color = this . _getColor ( value , labels , colors ) ;
119+ let title = column . name ;
120+ let value = row [ column . id ] ;
121+ const color = this . _getColor ( value , labels , colors ) ;
121122
122- if ( isPercentageMode ) {
123- const percentage = Math . round ( 100 * ( value - min ) / ( max - min ) ) ;
124- value = `${ percentage } %` ;
125- }
123+ if ( isPercentageMode ) {
124+ const percentage = Math . round ( 100 * ( value - min ) / ( max - min ) ) ;
125+ value = `${ percentage } %` ;
126+ }
126127
127- if ( aggConfig ) {
128- if ( ! isPercentageMode ) value = this . _getFormattedValue ( aggConfig . fieldFormatter ( 'html' ) , value ) ;
129- if ( bucketAgg ) {
130- const bucketValue = bucketAgg . fieldFormatter ( 'text' ) ( row [ 0 ] ) ;
131- title = `${ bucketValue } - ${ aggConfig . makeLabel ( ) } ` ;
132- } else {
133- title = aggConfig . makeLabel ( ) ;
134- }
128+ if ( aggConfig ) {
129+ if ( ! isPercentageMode ) value = this . _getFormattedValue ( aggConfig . fieldFormatter ( 'html' ) , value ) ;
130+ if ( bucketAgg ) {
131+ const bucketValue = bucketAgg . fieldFormatter ( 'text' ) ( row [ bucketColumnId ] ) ;
132+ title = `${ bucketValue } - ${ aggConfig . makeLabel ( ) } ` ;
133+ } else {
134+ title = aggConfig . makeLabel ( ) ;
135135 }
136+ }
136137
137- const shouldColor = config . colorsRange . length > 1 ;
138-
139- metrics . push ( {
140- label : title ,
141- value : value ,
142- color : shouldColor && config . style . labelColor ? color : null ,
143- bgColor : shouldColor && config . style . bgColor ? color : null ,
144- lightText : shouldColor && config . style . bgColor && this . _needsLightText ( color ) ,
145- filterKey : rowHeaderIndex !== undefined ? row [ rowHeaderIndex ] : null ,
146- tableIndex : tableIndex ,
147- rowIndex : rowIndex ,
148- columnIndex : rowHeaderIndex ,
149- bucketAgg : bucketAgg ,
150- } ) ;
138+ const shouldColor = config . colorsRange . length > 1 ;
139+
140+ metrics . push ( {
141+ label : title ,
142+ value : value ,
143+ color : shouldColor && config . style . labelColor ? color : null ,
144+ bgColor : shouldColor && config . style . bgColor ? color : null ,
145+ lightText : shouldColor && config . style . bgColor && this . _needsLightText ( color ) ,
146+ filterKey : bucketColumnId !== undefined ? row [ bucketColumnId ] : null ,
147+ rowIndex : rowIndex ,
148+ columnIndex : rowHeaderIndex ,
149+ bucketAgg : bucketAgg ,
151150 } ) ;
152151 } ) ;
153152 } ) ;
@@ -159,7 +158,7 @@ export class MetricVisComponent extends Component {
159158 if ( ! metric . filterKey || ! metric . bucketAgg ) {
160159 return ;
161160 }
162- const table = this . props . visData . tables [ metric . tableIndex ] ;
161+ const table = this . props . visData ;
163162 this . props . vis . API . events . addFilter ( table , metric . columnIndex , metric . rowIndex ) ;
164163 } ;
165164
0 commit comments