Skip to content

Commit 872bf75

Browse files
committed
Removed Error in Math function on large Arrays
1 parent 86a387e commit 872bf75

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

moongui/src/app/graph/graph-histogram/graph-histogram.component.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ export class GraphHistogramComponent implements OnChanges, AfterViewInit {
101101
type: 'histogram',
102102
autobinx: false,
103103
xbins: {
104-
start: Math.min.apply(Math, this.points[i].x),
105-
end: Math.max.apply(Math, this.points[i].x),
104+
start: this.arrayMin(this.points[i].x),
105+
end: this.arrayMax(this.points[i].x),
106106
size: this.size
107107
}
108108
});
@@ -120,8 +120,8 @@ export class GraphHistogramComponent implements OnChanges, AfterViewInit {
120120
for (let i: number = 0; i < changes.points.currentValue.length; i++) {
121121
update1.x.push(changes.points.currentValue[i].x);//Calculates the changes for each trace again
122122
update1.xbins.push({
123-
start: Math.min.apply(Math, changes.points.currentValue[i].x),
124-
end: Math.max.apply(Math, changes.points.currentValue[i].x),
123+
start: this.arrayMin(changes.points.currentValue[i].x),
124+
end: this.arrayMax(changes.points.currentValue[i].x),
125125
size: this.size
126126
});
127127
}
@@ -138,6 +138,26 @@ export class GraphHistogramComponent implements OnChanges, AfterViewInit {
138138
}
139139
}
140140

141+
/**
142+
* Maximum of given array
143+
* @param array
144+
*/
145+
private arrayMax(array) {
146+
return array.reduce(function(a, b) {
147+
return Math.max(a, b);
148+
});
149+
}
150+
151+
/**
152+
* Minimum of given array
153+
* @param array
154+
*/
155+
private arrayMin(array) {
156+
return array.reduce(function(a, b) {
157+
return Math.min(a, b);
158+
});
159+
}
160+
141161
/**
142162
* Redraw the layout after changing the YAxis title
143163
* @param $event

0 commit comments

Comments
 (0)