1
- nv . models . multiChart = function ( ) {
1
+ nv . models . multiChart = function ( ) {
2
2
"use strict" ;
3
3
4
4
//============================================================
@@ -38,8 +38,10 @@ nv.models.multiChart = function() {
38
38
scatters1 = nv . models . scatter ( ) . yScale ( yScale1 ) . duration ( duration ) ,
39
39
scatters2 = nv . models . scatter ( ) . yScale ( yScale2 ) . duration ( duration ) ,
40
40
41
- bars1 = nv . models . multiBar ( ) . stacked ( false ) . yScale ( yScale1 ) . duration ( duration ) ,
42
- bars2 = nv . models . multiBar ( ) . stacked ( false ) . yScale ( yScale2 ) . duration ( duration ) ,
41
+ barsModel ,
42
+
43
+ bars1 = getBarModel ( yScale1 ) ,
44
+ bars2 = getBarModel ( yScale2 ) ,
43
45
44
46
stack1 = nv . models . stackedArea ( ) . yScale ( yScale1 ) . duration ( duration ) ,
45
47
stack2 = nv . models . stackedArea ( ) . yScale ( yScale2 ) . duration ( duration ) ,
@@ -54,6 +56,18 @@ nv.models.multiChart = function() {
54
56
55
57
var charts = [ lines1 , lines2 , scatters1 , scatters2 , bars1 , bars2 , stack1 , stack2 ] ;
56
58
59
+ function getBarModel ( yScale ) {
60
+ var model ;
61
+
62
+ if ( typeof barsModel === 'function' ) {
63
+ model = barsModel ( ) ;
64
+ } else {
65
+ model = nv . models . multiBar ( ) . stacked ( false ) . duration ( duration ) ;
66
+ }
67
+
68
+ return model . yScale ( yScale ) ;
69
+ }
70
+
57
71
function chart ( selection ) {
58
72
selection . each ( function ( data ) {
59
73
var container = d3 . select ( this ) ,
@@ -66,6 +80,11 @@ nv.models.multiChart = function() {
66
80
var availableWidth = nv . utils . availableWidth ( width , container , margin ) ,
67
81
availableHeight = nv . utils . availableHeight ( height , container , margin ) ;
68
82
83
+ charts . forEach ( function ( chart ) {
84
+ chart . x ( getX ) ;
85
+ chart . y ( getY ) ;
86
+ } ) ;
87
+
69
88
var dataLines1 = data . filter ( function ( d ) { return d . type == 'line' && d . yAxis == 1 } ) ;
70
89
var dataLines2 = data . filter ( function ( d ) { return d . type == 'line' && d . yAxis == 2 } ) ;
71
90
var dataScatters1 = data . filter ( function ( d ) { return d . type == 'scatter' && d . yAxis == 1 } ) ;
@@ -75,6 +94,15 @@ nv.models.multiChart = function() {
75
94
var dataStack1 = data . filter ( function ( d ) { return d . type == 'area' && d . yAxis == 1 } ) ;
76
95
var dataStack2 = data . filter ( function ( d ) { return d . type == 'area' && d . yAxis == 2 } ) ;
77
96
97
+ // fixes tooltips for bar models other than multibar
98
+ data . forEach ( function ( series , i ) {
99
+ series . values . forEach ( function ( point ) {
100
+ point . series = i ;
101
+ point . key = series . key ;
102
+ } ) ;
103
+ } ) ;
104
+
105
+ // TODO: duplicate in linePlusBarChart.js#
78
106
// Display noData message if there's nothing to show.
79
107
if ( ! data || ! data . length || ! data . filter ( function ( d ) { return d . values . length } ) . length ) {
80
108
nv . utils . noData ( chart , container ) ;
@@ -516,6 +544,16 @@ nv.models.multiChart = function() {
516
544
517
545
chart . _options = Object . create ( { } , {
518
546
// simple options, just get/set the necessary values
547
+ barsModel : { get : function ( ) { return barsModel } , set : function ( _ ) {
548
+ var bars1Idx = charts . indexOf ( bars1 ) ,
549
+ bars2Idx = charts . indexOf ( bars2 ) ;
550
+
551
+ barsModel = _ ;
552
+ bars1 = getBarModel ( yScale1 ) ;
553
+ bars2 = getBarModel ( yScale2 ) ;
554
+ charts . splice ( bars1Idx , bars1Idx + 1 , bars1 ) ;
555
+ charts . splice ( bars2Idx , bars2Idx + 1 , bars2 ) ;
556
+ } } ,
519
557
width : { get : function ( ) { return width ; } , set : function ( _ ) { width = _ ; } } ,
520
558
height : { get : function ( ) { return height ; } , set : function ( _ ) { height = _ ; } } ,
521
559
showLegend : { get : function ( ) { return showLegend ; } , set : function ( _ ) { showLegend = _ ; } } ,
@@ -541,25 +579,9 @@ nv.models.multiChart = function() {
541
579
} } ,
542
580
x : { get : function ( ) { return getX ; } , set : function ( _ ) {
543
581
getX = _ ;
544
- lines1 . x ( _ ) ;
545
- lines2 . x ( _ ) ;
546
- scatters1 . x ( _ ) ;
547
- scatters2 . x ( _ ) ;
548
- bars1 . x ( _ ) ;
549
- bars2 . x ( _ ) ;
550
- stack1 . x ( _ ) ;
551
- stack2 . x ( _ ) ;
552
582
} } ,
553
583
y : { get : function ( ) { return getY ; } , set : function ( _ ) {
554
584
getY = _ ;
555
- lines1 . y ( _ ) ;
556
- lines2 . y ( _ ) ;
557
- scatters1 . y ( _ ) ;
558
- scatters2 . y ( _ ) ;
559
- stack1 . y ( _ ) ;
560
- stack2 . y ( _ ) ;
561
- bars1 . y ( _ ) ;
562
- bars2 . y ( _ ) ;
563
585
} } ,
564
586
useVoronoi : { get : function ( ) { return useVoronoi ; } , set : function ( _ ) {
565
587
useVoronoi = _ ;
0 commit comments