@@ -100,24 +100,6 @@ class StackedBar {
100
100
. domain ( [ 0 , Math . max ( ...allCols ) ] )
101
101
. range ( [ this . height , 0 ] ) ;
102
102
103
- // Merge all the lists into a single list, and store the
104
- // offests in a corresponding list. Use dataLength to
105
- // track how many total columns there should be.
106
- const mergedData = this . data . datasets
107
- . reduce ( ( pre , cur ) => pre . concat ( cur . data ) , [ ] ) ;
108
-
109
- const dataLength = this . data . datasets [ 0 ] . data . length ;
110
-
111
- const offsets = this . data . datasets
112
- . reduce ( ( r , x , i ) => {
113
- if ( i > 0 ) {
114
- r . push ( x . data . map ( ( y , j ) => this . data . datasets [ i - 1 ] . data [ j ] + r [ i - 1 ] [ j ] ) ) ;
115
- } else {
116
- r . push ( new Array ( x . data . length ) . fill ( 0 ) ) ;
117
- }
118
- return r ;
119
- } , [ ] ) . flat ( ) ;
120
-
121
103
const graphPart = this . chart . append ( 'g' ) ;
122
104
123
105
// axis
@@ -137,6 +119,24 @@ class StackedBar {
137
119
stroke : this . options . strokeColor ,
138
120
} ) ;
139
121
122
+ // Merge all the lists into a single list, and store the
123
+ // offests in a corresponding list. Use dataLength to
124
+ // track how many total columns there should be.
125
+ const mergedData = this . data . datasets
126
+ . reduce ( ( pre , cur ) => pre . concat ( cur . data ) , [ ] ) ;
127
+
128
+ const dataLength = this . data . datasets [ 0 ] . data . length ;
129
+
130
+ const offsets = this . data . datasets
131
+ . reduce ( ( r , x , i ) => {
132
+ if ( i > 0 ) {
133
+ r . push ( x . data . map ( ( y , j ) => this . data . datasets [ i - 1 ] . data [ j ] + r [ i - 1 ] [ j ] ) ) ;
134
+ } else {
135
+ r . push ( new Array ( x . data . length ) . fill ( 0 ) ) ;
136
+ }
137
+ return r ;
138
+ } , [ ] ) . flat ( ) ;
139
+
140
140
// Bars
141
141
graphPart . selectAll ( '.xkcd-chart-stacked-bar' )
142
142
. data ( mergedData )
@@ -161,7 +161,7 @@ class StackedBar {
161
161
162
162
const tooltipItems = this . data . datasets . map ( ( dataset , j ) => ( {
163
163
color : this . options . dataColors [ j ] ,
164
- text : `${ this . data . datasets [ j ] . label || '' } : ${ this . data . datasets [ j ] . data [ i ] } ` ,
164
+ text : `${ this . data . datasets [ j ] . label || '' } : ${ this . data . datasets [ j ] . data [ i % dataLength ] } ` ,
165
165
} ) ) . reverse ( ) ;
166
166
167
167
let tooltipPositionType = config . positionType . downRight ;
@@ -172,6 +172,7 @@ class StackedBar {
172
172
} else if ( tipX < this . width / 2 && tipY > this . height / 2 ) {
173
173
tooltipPositionType = config . positionType . upRight ;
174
174
}
175
+
175
176
tooltip . update ( {
176
177
title : this . data . labels [ i ] ,
177
178
items : tooltipItems ,
0 commit comments