Skip to content

Commit c4994ec

Browse files
committed
Added inclusion of null value consideration for all extent calculations, improved handling of edge cases when extent non existent or inverse
1 parent a197eb0 commit c4994ec

File tree

3 files changed

+93
-8
lines changed

3 files changed

+93
-8
lines changed

dist/graphly.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/FilterManager.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,29 @@ class FilterManager extends EventEmitter {
130130
this.dataSettings[d].hasOwnProperty('extent')){
131131
this.extents[d] = this.dataSettings[d].extent;
132132
}else{
133-
this.extents[d] = d3.extent(this.data[d]);
133+
let domain;
134+
if(this.dataSettings.hasOwnProperty(d) &&
135+
this.dataSettings[d].hasOwnProperty('nullValue')){
136+
let nV = this.dataSettings[d].nullValue;
137+
// If parameter has nullvalue defined ignore it
138+
// when calculating extent
139+
domain = d3.extent(
140+
this.data[d], (v)=>{
141+
if(v !== nV){
142+
return v;
143+
} else {
144+
return null;
145+
}
146+
}
147+
);
148+
} else {
149+
domain = d3.extent(this.data[d]);
150+
}
151+
if(domain[0] === domain[1]){
152+
domain[0] = domain[0]-1;
153+
domain[1] = domain[1]+1;
154+
}
155+
this.extents[d] = domain;
134156
}
135157

136158
// TODO: Possibility to use quantiles for extent if there are huge

src/graphly.js

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,23 @@ class graphly extends EventEmitter {
23142314
calculateExtent(selection) {
23152315
let currExt, resExt;
23162316
for (var i = selection.length - 1; i >= 0; i--) {
2317-
currExt = d3.extent(this.data[selection[i]]);
2317+
// Check if null value has been defined
2318+
if(this.dataSettings[selection[i]].hasOwnProperty('nullValue')){
2319+
let nV = this.dataSettings[selection[i]].nullValue;
2320+
// If parameter has nullvalue defined ignore it
2321+
// when calculating extent
2322+
currExt = d3.extent(
2323+
this.data[selection[i]], (v)=>{
2324+
if(v !== nV){
2325+
return v;
2326+
} else {
2327+
return null;
2328+
}
2329+
}
2330+
);
2331+
} else {
2332+
currExt = d3.extent(this.data[selection[i]]);
2333+
}
23182334
if(resExt){
23192335
if(currExt[0]<resExt[0]){
23202336
resExt[0] = currExt[0];
@@ -2329,10 +2345,19 @@ class graphly extends EventEmitter {
23292345
if(selection.length === 0){
23302346
return [0,1];
23312347
}
2348+
if(isNaN(resExt[0])){
2349+
resExt[0] = 0;
2350+
}
2351+
if(isNaN(resExt[1])){
2352+
resExt[1] = resExt[0]+1;
2353+
}
23322354
if(resExt[0] == resExt[1]){
23332355
resExt[0]-=1;
23342356
resExt[1]+=1;
23352357
}
2358+
if(resExt[0]>resExt[1]){
2359+
resExt = resExt.reverse();
2360+
}
23362361
return resExt;
23372362
}
23382363

@@ -2426,10 +2451,18 @@ class graphly extends EventEmitter {
24262451
} else {
24272452
domain = d3.extent(this.data[cAxis[ca]]);
24282453
}
2429-
// Check if domain start and ed is equal
2430-
if(domain[0] === domain[1]){
2454+
if(isNaN(domain[0])){
2455+
domain[0] = 0;
2456+
}
2457+
if(isNaN(domain[1])){
2458+
domain[1] = domain[0]+1;
2459+
}
2460+
if(domain[0] == domain[1]){
24312461
domain[0]-=1;
2432-
domain[0]+=1;
2462+
domain[1]+=1;
2463+
}
2464+
if(domain[0]>domain[1]){
2465+
domain = domain.reverse();
24332466
}
24342467
// Set current calculated extent to settings
24352468
this.dataSettings[cAxis[ca]].extent = domain;
@@ -5044,8 +5077,38 @@ class graphly extends EventEmitter {
50445077
if(ca !== null){
50455078
if(this.dataSettings.hasOwnProperty(ca)){
50465079
if(!this.dataSettings[ca].hasOwnProperty('extent')){
5080+
let domain;
50475081
// Set current calculated extent to settings
5048-
this.dataSettings[ca].extent = d3.extent(this.currentData[ca]);
5082+
if(this.dataSettings[ca].hasOwnProperty('nullValue')){
5083+
let nV = this.dataSettings[ca].nullValue;
5084+
// If parameter has nullvalue defined ignore it
5085+
// when calculating extent
5086+
domain = d3.extent(
5087+
this.currentData[ca], (v)=>{
5088+
if(v !== nV){
5089+
return v;
5090+
} else {
5091+
return null;
5092+
}
5093+
}
5094+
);
5095+
} else {
5096+
domain = d3.extent(this.currentData[ca]);
5097+
}
5098+
if(isNaN(domain[0])){
5099+
domain[0] = 0;
5100+
}
5101+
if(isNaN(domain[1])){
5102+
domain[1] = domain[0]+1;
5103+
}
5104+
if(domain[0] == domain[1]){
5105+
domain[0]-=1;
5106+
domain[1]+=1;
5107+
}
5108+
if(domain[0]>domain[1]){
5109+
domain = domain.reverse();
5110+
}
5111+
this.dataSettings[ca].extent = domain;
50495112
this.createColorScales();
50505113
}
50515114
}

0 commit comments

Comments
 (0)