File tree 2 files changed +16
-13
lines changed
2 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -11,8 +11,10 @@ module.exports = function getLegendData(calcdata, opts) {
11
11
var lgroupi = 0 ;
12
12
var maxNameLength = 0 ;
13
13
var i , j ;
14
-
14
+ var initID = 0 ;
15
15
function addOneItem ( legendGroup , legendItem ) {
16
+ legendItem . _initID = initID ++ ;
17
+
16
18
// each '' legend group is treated as a separate group
17
19
if ( legendGroup === '' || ! helpers . isGrouped ( opts ) ) {
18
20
// TODO: check this against fullData legendgroups?
@@ -78,6 +80,7 @@ module.exports = function getLegendData(calcdata, opts) {
78
80
var B = b [ 0 ] . trace ;
79
81
var delta = A . legendrank - B . legendrank ;
80
82
if ( ! delta ) delta = A . index - B . index ;
83
+ if ( ! delta ) delta = a [ 0 ] . _initID - b [ 0 ] . _initID ;
81
84
82
85
return dir * delta ;
83
86
} ;
Original file line number Diff line number Diff line change @@ -283,22 +283,22 @@ describe('legend getLegendData', function() {
283
283
284
284
expected = [
285
285
[
286
- [ { trace : {
286
+ [ { _initID : 0 , trace : {
287
287
type : 'scatter' ,
288
288
visible : true ,
289
289
legendgroup : 'group' ,
290
290
showlegend : true
291
291
292
292
} } ] ,
293
- [ { trace : {
293
+ [ { _initID : 2 , trace : {
294
294
type : 'scatter' ,
295
295
visible : true ,
296
296
legendgroup : 'group' ,
297
297
showlegend : true
298
298
} } ]
299
299
] ,
300
300
[
301
- [ { trace : {
301
+ [ { _initID : 1 , trace : {
302
302
type : 'bar' ,
303
303
visible : 'legendonly' ,
304
304
legendgroup : '' ,
@@ -341,20 +341,20 @@ describe('legend getLegendData', function() {
341
341
342
342
expected = [
343
343
[
344
- [ { trace : {
344
+ [ { _initID : 0 , trace : {
345
345
type : 'scatter' ,
346
346
visible : true ,
347
347
legendgroup : '' ,
348
348
showlegend : true
349
349
350
350
} } ] ,
351
- [ { trace : {
351
+ [ { _initID : 1 , trace : {
352
352
type : 'bar' ,
353
353
visible : 'legendonly' ,
354
354
legendgroup : '' ,
355
355
showlegend : true
356
356
} } ] ,
357
- [ { trace : {
357
+ [ { _initID : 2 , trace : {
358
358
type : 'scatter' ,
359
359
visible : true ,
360
360
legendgroup : '' ,
@@ -427,20 +427,20 @@ describe('legend getLegendData', function() {
427
427
428
428
expected = [
429
429
[
430
- [ { trace : {
430
+ [ { _initID : 2 , trace : {
431
431
type : 'box' ,
432
432
visible : true ,
433
433
legendgroup : '' ,
434
434
showlegend : true
435
435
436
436
} } ] ,
437
- [ { trace : {
437
+ [ { _initID : 1 , trace : {
438
438
type : 'bar' ,
439
439
visible : 'legendonly' ,
440
440
legendgroup : '' ,
441
441
showlegend : true
442
442
} } ] ,
443
- [ { trace : {
443
+ [ { _initID : 0 , trace : {
444
444
type : 'scatter' ,
445
445
visible : true ,
446
446
legendgroup : '' ,
@@ -483,22 +483,22 @@ describe('legend getLegendData', function() {
483
483
484
484
expected = [
485
485
[
486
- [ { trace : {
486
+ [ { _initID : 2 , trace : {
487
487
type : 'box' ,
488
488
visible : true ,
489
489
legendgroup : 'group' ,
490
490
showlegend : true
491
491
492
492
} } ] ,
493
- [ { trace : {
493
+ [ { _initID : 0 , trace : {
494
494
type : 'scatter' ,
495
495
visible : true ,
496
496
legendgroup : 'group' ,
497
497
showlegend : true
498
498
} } ]
499
499
] ,
500
500
[
501
- [ { trace : {
501
+ [ { _initID : 1 , trace : {
502
502
type : 'bar' ,
503
503
visible : 'legendonly' ,
504
504
legendgroup : '' ,
You can’t perform that action at this time.
0 commit comments