Skip to content

Commit

Permalink
Merge remote-tracking branch 'KATT/feature/highlight-transform'
Browse files Browse the repository at this point in the history
  • Loading branch information
cesine committed Mar 29, 2020
2 parents 254a83f + 048efd8 commit 9dbab1c
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/js/Rickshaw.Graph.Behavior.Series.Highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ Rickshaw.Graph.Behavior.Series.Highlight = function(args) {

var self = this;

var colorSafe = {};
var propertiesSafe = {};
var activeLine = null;

var disabledColor = args.disabledColor || function(seriesColor) {
return d3.interpolateRgb(seriesColor, d3.rgb('#d8d8d8'))(0.8).toString();
};

var transformFn = args.transform || function(isActive, series) {
var newProperties = {};
if (!isActive) {
// backwards compability
newProperties.color = disabledColor(series.color);
}
return newProperties;
};


this.addHighlightEvents = function (l) {

l.element.addEventListener( 'mouseover', function(e) {
Expand All @@ -22,8 +32,11 @@ Rickshaw.Graph.Behavior.Series.Highlight = function(args) {
else activeLine = l;

self.legend.lines.forEach( function(line) {
var newProperties = {};
var isActive = false;

if (l === line) {
isActive = true;

// if we're not in a stacked renderer bring active line to the top
if (self.graph.renderer.unstack && (line.series.renderer ? line.series.renderer.unstack : true)) {
Expand All @@ -34,11 +47,21 @@ Rickshaw.Graph.Behavior.Series.Highlight = function(args) {
var series = self.graph.series.splice(seriesIndex, 1)[0];
self.graph.series.push(series);
}
return;
}

colorSafe[line.series.name] = colorSafe[line.series.name] || line.series.color;
line.series.color = disabledColor(line.series.color);
var newProperties = transformFn(isActive, line.series);

propertiesSafe[line.series.name] = propertiesSafe[line.series.name] || {
color : line.series.color,
stroke : line.series.stroke
};

if (newProperties.color) {
line.series.color = newProperties.color;
}
if (newProperties.stroke) {
line.series.stroke = newProperties.stroke;
}

} );

Expand All @@ -61,8 +84,10 @@ Rickshaw.Graph.Behavior.Series.Highlight = function(args) {
delete line.originalIndex;
}

if (colorSafe[line.series.name]) {
line.series.color = colorSafe[line.series.name];
var lineProperties = propertiesSafe[line.series.name];
if (lineProperties) {
line.series.color = lineProperties.color;
line.series.stroke = lineProperties.stroke;
}
} );

Expand Down

0 comments on commit 9dbab1c

Please sign in to comment.