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

Fix Graph.dataDomain where series have empty data array #475

Open
wants to merge 3 commits 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
19 changes: 16 additions & 3 deletions src/js/Rickshaw.Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,23 @@ Rickshaw.Graph = function(args) {

this.dataDomain = function() {

var data = this.series.map( function(s) { return s.data } );
var data = this.series.active().map( function(s) { return s.data } );

var min = d3.min( data.map( function(d) { return d[0].x } ) );
var max = d3.max( data.map( function(d) { return d[d.length - 1].x } ) );
var min = d3.min( data.map( function(d) {
if (d.length === 0) {
return Infinity;
} else {
return d[0].x;
}
} ) );

var max = d3.max( data.map( function(d) {
if (d.length === 0) {
return -Infinity;
} else {
return d[d.length - 1].x;
}
} ) );

return [min, max];
};
Expand Down
36 changes: 35 additions & 1 deletion tests/Rickshaw.Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ exports.inconsistent = function(test) {
});

}, "we don't throw for inconsistent length series for lines" );

test.throws( function() {

var graph = new Rickshaw.Graph({
Expand All @@ -231,6 +231,40 @@ exports.inconsistent = function(test) {

}, null, "throw an error for undefined element reference" );

// Test that dataDomain only considers active series
series[1].data.push({x: 100, y: 22});
series[1].disabled = true;

var graph = new Rickshaw.Graph({
element: el,
width: 960,
height: 500,
renderer: 'line',
series: series
});

test.deepEqual(graph.dataDomain(), [0, 3]);

series.push(
{
color: "red",
data: []
}
);

test.doesNotThrow( function() {

var graph = new Rickshaw.Graph({
element: el,
width: 960,
height: 500,
renderer: 'line',
series: series
});

test.deepEqual(graph.dataDomain(), [0, 3]);
}, "We don't throw on dataDomain if a series has no data" );

test.done();
};

Expand Down