Skip to content

Commit cbbf36b

Browse files
committed
Merge pull requests
2 parents 11795e3 + 6d817fb commit cbbf36b

11 files changed

+154
-23
lines changed

examples/multi.html

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,27 @@
8585
});
8686

8787
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
88-
graph: graph,
89-
legend: legend,
90-
disabledColor: function() { return 'rgba(0, 0, 0, 0.2)' }
88+
graph: graph,
89+
legend: legend,
90+
disabledColor: function() { return 'rgba(0, 0, 0, 0.2)' }
9191
});
9292

9393
var highlighter = new Rickshaw.Graph.Behavior.Series.Toggle({
94-
graph: graph,
95-
legend: legend
94+
graph: graph,
95+
legend: legend,
96+
transform: function(isActive, series) {
97+
var obj = {};
98+
if (isActive) {
99+
obj.color = "rgba(255, 0, 0, 0.5)";
100+
obj.stroke = "rgba(255, 0, 0, 0.5)";
101+
} else {
102+
// lower opacity of non-highlighed data
103+
obj.stroke = "rgba(0,0,0,0.1)";
104+
obj.color = "rgba(0,0,0,0.05)";
105+
}
106+
return obj;
107+
}
96108
});
97109

98-
99-
100-
101110
</script>
102111
</body>

examples/scatterplot.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<!doctype html>
22
<link type="text/css" rel="stylesheet" href="../rickshaw.css">
3+
<style type="text/css">
4+
.rickshaw_graph .detail .item.active {
5+
white-space: pre-wrap;
6+
}
7+
</style>
38

49
<script src="../vendor/d3.v3.js"></script>
510

@@ -30,14 +35,17 @@
3035
renderer: 'scatterplot',
3136
series: [
3237
{
38+
name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
3339
color: "#ff9030",
3440
data: seriesData[0],
3541
opacity: 0.5
3642
}, {
43+
name: "Nullam in risus tellus. Donec pellentesque sit amet enim in sollicitudin.",
3744
color: "#ff4040",
3845
data: seriesData[1],
3946
opacity: 0.3
4047
}, {
48+
name: "Nunc tempus malesuada diam.",
4149
color: "#4040ff",
4250
data: seriesData[2]
4351
}

src/css/detail.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
}
1717
.rickshaw_graph .detail .item.active {
1818
opacity: 1;
19+
width: auto;
20+
height: auto;
1921
}
2022
.rickshaw_graph .detail .x_label {
2123
font-family: Arial, sans-serif;

src/js/Rickshaw.Graph.Axis.X.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Rickshaw.Graph.Axis.X = function(args) {
99

1010
this.graph = args.graph;
1111
this.orientation = args.orientation || 'top';
12+
this.color = args.color || "#000000";
1213

1314
this.pixelsPerTick = args.pixelsPerTick || 75;
1415
if (args.ticks) this.staticTicks = args.ticks;
@@ -26,6 +27,7 @@ Rickshaw.Graph.Axis.X = function(args) {
2627
.append("svg:svg")
2728
.attr('height', this.height)
2829
.attr('width', this.width)
30+
.attr('stroke', this.color)
2931
.attr('class', 'rickshaw_graph x_axis_d3');
3032

3133
this.element = this.vis[0][0];

src/js/Rickshaw.Graph.Axis.Y.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Rickshaw.Graph.Axis.Y = Rickshaw.Class.create( {
66

77
this.graph = args.graph;
88
this.orientation = args.orientation || 'right';
9+
this.color = args.color || "#000000";
910

1011
this.pixelsPerTick = args.pixelsPerTick || 75;
1112
if (args.ticks) this.staticTicks = args.ticks;
@@ -23,6 +24,7 @@ Rickshaw.Graph.Axis.Y = Rickshaw.Class.create( {
2324
this.element = args.element;
2425
this.vis = d3.select(args.element)
2526
.append("svg:svg")
27+
.attr('stroke', this.color)
2628
.attr('class', 'rickshaw_graph y_axis');
2729

2830
this.element = this.vis[0][0];

src/js/Rickshaw.Graph.Behavior.Series.Highlight.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@ Rickshaw.Graph.Behavior.Series.Highlight = function(args) {
77

88
var self = this;
99

10-
var colorSafe = {};
10+
var propertiesSafe = {};
1111
var activeLine = null;
1212

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

17+
var transformFn = args.transform || function(isActive, series) {
18+
var newProperties = {};
19+
if (!isActive) {
20+
// backwards compability
21+
newProperties.color = disabledColor(series.color);
22+
}
23+
return newProperties;
24+
};
25+
26+
1727
this.addHighlightEvents = function (l) {
1828

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

2434
self.legend.lines.forEach( function(line) {
35+
var newProperties;
36+
var isActive = false;
2537

2638
if (l === line) {
39+
isActive = true;
2740

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

40-
colorSafe[line.series.name] = colorSafe[line.series.name] || line.series.color;
41-
line.series.color = disabledColor(line.series.color);
52+
newProperties = transformFn(isActive, line.series);
53+
54+
propertiesSafe[line.series.name] = propertiesSafe[line.series.name] || {
55+
color : line.series.color,
56+
stroke : line.series.stroke
57+
};
58+
59+
if (newProperties.color) {
60+
line.series.color = newProperties.color;
61+
}
62+
if (newProperties.stroke) {
63+
line.series.stroke = newProperties.stroke;
64+
}
4265

4366
} );
4467

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

64-
if (colorSafe[line.series.name]) {
65-
line.series.color = colorSafe[line.series.name];
87+
var lineProperties = propertiesSafe[line.series.name];
88+
if (lineProperties) {
89+
line.series.color = lineProperties.color;
90+
line.series.stroke = lineProperties.stroke;
6691
}
6792
} );
6893

src/js/Rickshaw.Graph.Legend.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Rickshaw.Graph.Legend = Rickshaw.Class.create( {
88
this.element = args.element;
99
this.graph = args.graph;
1010
this.naturalOrder = args.naturalOrder;
11+
this.colorKey = args.colorKey || 'color';
1112

1213
this.element.classList.add(this.className);
1314

@@ -55,7 +56,7 @@ Rickshaw.Graph.Legend = Rickshaw.Class.create( {
5556
}
5657
var swatch = document.createElement('div');
5758
swatch.className = 'swatch';
58-
swatch.style.backgroundColor = series.color;
59+
swatch.style.backgroundColor = series[this.colorKey];
5960

6061
line.appendChild(swatch);
6162

@@ -84,4 +85,3 @@ Rickshaw.Graph.Legend = Rickshaw.Class.create( {
8485
return line;
8586
}
8687
} );
87-

src/js/Rickshaw.Graph.Renderer.ScatterPlot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Rickshaw.Graph.Renderer.ScatterPlot = Rickshaw.Class.create( Rickshaw.Graph.Rend
3535
series.forEach( function(series) {
3636

3737
if (series.disabled) return;
38-
var opacity = series.opacity ? series.opacity : 1;
38+
var opacity = series.opacity === undefined ? 1 : series.opacity;
3939

4040
var nodes = vis.selectAll("path")
4141
.data(series.stack.filter( function(d) { return d.y !== null } ))
@@ -47,7 +47,7 @@ Rickshaw.Graph.Renderer.ScatterPlot = Rickshaw.Class.create( Rickshaw.Graph.Rend
4747
if (series.className) {
4848
nodes.classed(series.className, true);
4949
}
50-
50+
5151
Array.prototype.forEach.call(nodes[0], function(n) {
5252
n.setAttribute('fill', series.color);
5353
} );

src/js/Rickshaw.Graph.Renderer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Rickshaw.Graph.Renderer = Rickshaw.Class.create( {
120120
var fill = this.fill ? series.color : 'none';
121121
var stroke = this.stroke ? series.color : 'none';
122122
var strokeWidth = series.strokeWidth ? series.strokeWidth : this.strokeWidth;
123-
var opacity = series.opacity ? series.opacity : this.opacity;
123+
var opacity = series.opacity === undefined ? this.opacity : series.opacity;
124124

125125
series.path.setAttribute('fill', fill);
126126
series.path.setAttribute('stroke', stroke);
@@ -179,4 +179,3 @@ Rickshaw.Graph.Renderer = Rickshaw.Class.create( {
179179
}
180180
}
181181
} );
182-

tests/Rickshaw.Graph.Legend.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ exports.setUp = function(callback) {
1919
series: [
2020
{
2121
name: 'foo',
22+
color: 'green',
23+
stroke: 'red',
2224
data: [
2325
{ x: 4, y: 32 }
2426
]
@@ -81,6 +83,31 @@ exports.canOverrideClassName = function(test) {
8183
test.done();
8284
};
8385

86+
exports.hasDefaultColorKey = function(test) {
87+
var legend = new Rickshaw.Graph.Legend({
88+
graph: this.graph,
89+
element: this.legendEl
90+
});
91+
92+
93+
test.equal(legend.colorKey, "color");
94+
test.equal(this.legendEl.getElementsByClassName('swatch')[1].style.backgroundColor, "green");
95+
test.done();
96+
};
97+
98+
exports.canOverrideColorKey = function(test) {
99+
var legend = new Rickshaw.Graph.Legend({
100+
graph: this.graph,
101+
element: this.legendEl,
102+
colorKey: 'stroke'
103+
});
104+
105+
106+
test.equal(legend.colorKey, "stroke");
107+
test.equal(this.legendEl.getElementsByClassName('swatch')[1].style.backgroundColor, "red");
108+
test.done();
109+
};
110+
84111
exports['should put series classes on legend elements'] = function(test) {
85112
this.graph.series[0].className = 'fnord-series-0';
86113
this.graph.series[1].className = 'fnord-series-1';

0 commit comments

Comments
 (0)