File tree Expand file tree Collapse file tree 1 file changed +9
-13
lines changed Expand file tree Collapse file tree 1 file changed +9
-13
lines changed Original file line number Diff line number Diff line change 1- import { deepMix , valuesOfKey , clone } from '@antv/util' ;
1+ import { deepMix , valuesOfKey , sortBy } from '@antv/util' ;
22import { registerPlotType } from '../../base/global' ;
33import { LayerConfig } from '../../base/layer' ;
44import { ElementOption } from '../../interface/config' ;
@@ -44,19 +44,15 @@ export default class GroupedBarLayer extends BaseBarLayer<GroupedBarLayerConfig>
4444
4545 public afterRender ( ) {
4646 super . afterRender ( ) ;
47- const names = valuesOfKey ( this . options . data , this . options . groupField ) ;
47+ const names = valuesOfKey ( this . options . data , this . options . groupField ) || [ ] ;
4848 this . view . on ( 'tooltip:change' , ( e ) => {
49- const { items } = e ;
50- const origin_items = clone ( items ) ;
51- for ( let i = 0 ; i < names . length ; i ++ ) {
52- const name = names [ i ] ;
53- for ( let j = 0 ; j < origin_items . length ; j ++ ) {
54- const item = origin_items [ j ] ;
55- if ( item . name === name ) {
56- e . items [ i ] = item ;
57- }
58- }
59- }
49+ const { items = [ ] } = e ;
50+ const fixedItems = sortBy ( items . slice ( ) , ( item ) => {
51+ return names . indexOf ( item . name ) ;
52+ } ) . reverse ( ) ;
53+ fixedItems . forEach ( ( item , idx ) => {
54+ e . items [ idx ] = item ;
55+ } ) ;
6056 } ) ;
6157 }
6258
You can’t perform that action at this time.
0 commit comments