Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
Toggle callback wasn’t always called
Fix wrong propagation of graph configure in slider preview
  • Loading branch information
Jérémie Foucault authored and Jérémie Foucault committed Mar 23, 2014
1 parent 1e3f51b commit ef5e02b
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 88 deletions.
78 changes: 78 additions & 0 deletions examples/scale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
var data, graph, i, max, min, point, random, scales, series, _i, _j, _k, _l, _len, _len1, _len2, _ref;

data = [[], []];

random = new Rickshaw.Fixtures.RandomData(12 * 60 * 60);

for (i = _i = 0; _i < 100; i = ++_i) {
random.addData(data);
}

window.scales = [];

_ref = data[1];
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
point = _ref[_j];
point.y *= point.y;
}

for (_k = 0, _len1 = data.length; _k < _len1; _k++) {
series = data[_k];
min = Number.MAX_VALUE;
max = Number.MIN_VALUE;
for (_l = 0, _len2 = series.length; _l < _len2; _l++) {
point = series[_l];
min = Math.min(min, point.y);
max = Math.max(max, point.y);
}
if (_k === 0) {
scales.push(d3.scale.linear().domain([min, max]).nice());
} else {
scales.push(d3.scale.pow().domain([min, max]).nice());
}
}

graph = new Rickshaw.Graph({
element: document.getElementById("chart"),
renderer: 'line',
series: [
{
color: 'steelblue',
data: data[0],
name: 'Series A',
scale: scales[0]
}, {
color: 'lightblue',
data: data[1],
name: 'Series B',
scale: scales[1]
}
]
});

new Rickshaw.Graph.Axis.Y.Scaled({
element: document.getElementById('axis0'),
graph: graph,
orientation: 'left',
scale: scales[0],
tickFormat: Rickshaw.Fixtures.Number.formatKMBT
});

new Rickshaw.Graph.Axis.Y.Scaled({
element: document.getElementById('axis1'),
graph: graph,
grid: false,
orientation: 'right',
scale: scales[1],
tickFormat: Rickshaw.Fixtures.Number.formatKMBT
});

new Rickshaw.Graph.Axis.Time({
graph: graph
});

new Rickshaw.Graph.HoverDetail({
graph: graph
});

graph.render();
81 changes: 1 addition & 80 deletions examples/scaled.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,83 +27,4 @@
<div id="chart"></div>
<div id="axis1"></div>

<script type="text/javascript">
var data, graph, i, max, min, point, random, scales, series, _i, _j, _k, _l, _len, _len1, _len2, _ref;

data = [[], []];

random = new Rickshaw.Fixtures.RandomData(12 * 60 * 60);

for (i = _i = 0; _i < 100; i = ++_i) {
random.addData(data);
}

scales = [];

_ref = data[1];
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
point = _ref[_j];
point.y *= point.y;
}

for (_k = 0, _len1 = data.length; _k < _len1; _k++) {
series = data[_k];
min = Number.MAX_VALUE;
max = Number.MIN_VALUE;
for (_l = 0, _len2 = series.length; _l < _len2; _l++) {
point = series[_l];
min = Math.min(min, point.y);
max = Math.max(max, point.y);
}
if (_k === 0) {
scales.push(d3.scale.linear().domain([min, max]).nice());
} else {
scales.push(d3.scale.pow().domain([min, max]).nice());
}
}

graph = new Rickshaw.Graph({
element: document.getElementById("chart"),
renderer: 'line',
series: [
{
color: 'steelblue',
data: data[0],
name: 'Series A',
scale: scales[0]
}, {
color: 'lightblue',
data: data[1],
name: 'Series B',
scale: scales[1]
}
]
});

new Rickshaw.Graph.Axis.Y.Scaled({
element: document.getElementById('axis0'),
graph: graph,
orientation: 'left',
scale: scales[0],
tickFormat: Rickshaw.Fixtures.Number.formatKMBT
});

new Rickshaw.Graph.Axis.Y.Scaled({
element: document.getElementById('axis1'),
graph: graph,
grid: false,
orientation: 'right',
scale: scales[1],
tickFormat: Rickshaw.Fixtures.Number.formatKMBT
});

new Rickshaw.Graph.Axis.Time({
graph: graph
});

new Rickshaw.Graph.HoverDetail({
graph: graph
});

graph.render();
</script>
<script src="scale.js"></script>
7 changes: 4 additions & 3 deletions rickshaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2144,8 +2144,8 @@ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
self.transport.dataURL = self.transport.dataURL.replace(/([0-9]+-[0-9]+)(,?[0-9]+-[0-9]+)*/g, line.series.id+"-"+line.series.data_type_id);
line.series.is_data = true;
self.transport.request();
self.callback(line.series.id+"-"+line.series.data_type_id, true);
}
self.callback(line.series.id+"-"+line.series.data_type_id, true);
line.element.classList.remove('disabled');
} else {
if (this.graph.series.filter(function(s) { return !s.disabled }).length <= 1) return;
Expand Down Expand Up @@ -2195,8 +2195,8 @@ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
self.transport.dataURL = self.transport.dataURL.replace(/([0-9]+-[0-9]+)(,?[0-9]+-[0-9]+)*/g, line.series.id+"-"+line.series.data_type_id);
line.series.is_data = true;
self.transport.request();
self.callback(line.series.id+"-"+line.series.data_type_id, true);
}
self.callback(line.series.id+"-"+line.series.data_type_id, true);
line.element.classList.remove('disabled');

self.legend.lines.forEach(function(l){
Expand Down Expand Up @@ -2972,8 +2972,9 @@ Rickshaw.Graph.RangeSlider.Preview = Rickshaw.Class.create({
parent.onUpdate(function() { graph.render(); self.render() });

parent.onConfigure(function(args) {
// don't propagate height
// don't propagate height and width
delete args.height;
delete args.width;
graph.configure(args);
graph.render();
});
Expand Down
4 changes: 2 additions & 2 deletions rickshaw.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/js/Rickshaw.Graph.Behavior.Series.Toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
self.transport.dataURL = self.transport.dataURL.replace(/([0-9]+-[0-9]+)(,?[0-9]+-[0-9]+)*/g, line.series.id+"-"+line.series.data_type_id);
line.series.is_data = true;
self.transport.request();
self.callback(line.series.id+"-"+line.series.data_type_id, true);
}
self.callback(line.series.id+"-"+line.series.data_type_id, true);
line.element.classList.remove('disabled');
} else {
if (this.graph.series.filter(function(s) { return !s.disabled }).length <= 1) return;
Expand Down Expand Up @@ -74,8 +74,8 @@ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
self.transport.dataURL = self.transport.dataURL.replace(/([0-9]+-[0-9]+)(,?[0-9]+-[0-9]+)*/g, line.series.id+"-"+line.series.data_type_id);
line.series.is_data = true;
self.transport.request();
self.callback(line.series.id+"-"+line.series.data_type_id, true);
}
self.callback(line.series.id+"-"+line.series.data_type_id, true);
line.element.classList.remove('disabled');

self.legend.lines.forEach(function(l){
Expand Down
3 changes: 2 additions & 1 deletion src/js/Rickshaw.Graph.RangeSlider.Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ Rickshaw.Graph.RangeSlider.Preview = Rickshaw.Class.create({
parent.onUpdate(function() { graph.render(); self.render() });

parent.onConfigure(function(args) {
// don't propagate height
// don't propagate height and width
delete args.height;
delete args.width;
graph.configure(args);
graph.render();
});
Expand Down

0 comments on commit ef5e02b

Please sign in to comment.