Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make legend swatch toggle display like click for label does #484

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions rickshaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -1925,16 +1925,19 @@ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
if (line.series.disabled) {
line.series.enable();
line.element.classList.remove('disabled');
} else {
} else {
if (this.graph.series.filter(function(s) { return !s.disabled }).length <= 1) return;
line.series.disable();
line.element.classList.add('disabled');
}

self.graph.update();

}.bind(this);

var label = line.element.getElementsByTagName('span')[0];
label.onclick = function(e){
var swatch = line.element.getElementsByTagName('div')[0];
this.clickBehavior = function(e){

var disableAllOtherLines = line.series.disabled;
if ( ! disableAllOtherLines ) {
Expand Down Expand Up @@ -1976,7 +1979,13 @@ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {

}

self.graph.update();

};

// Bind the click behavior to both label and swatch elements.
label.onclick = this.clickBehavior;
swatch.onclick = this.clickBehavior;

};

Expand Down Expand Up @@ -2009,20 +2018,18 @@ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
this._addBehavior = function() {

this.graph.series.forEach( function(s) {

s.disable = function() {

if (self.graph.series.length <= 1) {
throw('only one series left');
}

s.disabled = true;
self.graph.update();
};

s.enable = function() {
s.disabled = false;
self.graph.update();
};
} );
};
Expand Down Expand Up @@ -3759,7 +3766,6 @@ Rickshaw.Graph.Smoother = Rickshaw.Class.create({
max: 100,
slide: function( event, ui ) {
self.setScale(ui.value);
self.graph.update();
}
} );
} );
Expand Down
Loading