Skip to content

Commit

Permalink
Add upper limit to histogram bin count (fixes #260)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Oct 28, 2024
1 parent 7dbf3f8 commit ce60d52
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/hub/controllers/StatisticsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class StatisticsController implements TabController {

private UPDATE_PERIOD_MS = 100;
private DEFAULT_DT = 0.02;
private MAX_BINS = 1000;

private TIME_RANGE: HTMLSelectElement;
private RANGE_MIN: HTMLInputElement;
Expand Down Expand Up @@ -55,7 +56,11 @@ export default class StatisticsController implements TabController {
/** Updates the step size for each histogram input. */
private updateHistogramInputs() {
if (Number(this.STEP_SIZE.value) <= 0) {
this.STEP_SIZE.value = cleanFloat(Number(this.STEP_SIZE.step) * 0.9).toString();
this.STEP_SIZE.value = cleanFloat(Number(this.STEP_SIZE.step)).toString();
}
let range = Math.abs(Number(this.RANGE_MAX.value) - Number(this.RANGE_MIN.value));
if (range / Number(this.STEP_SIZE.value) > this.MAX_BINS) {
this.STEP_SIZE.value = cleanFloat(Math.ceil(range / this.MAX_BINS)).toString();
}
let step = Math.pow(10, Math.floor(Math.log10(Number(this.STEP_SIZE.value))));
this.STEP_SIZE.step = step.toString();
Expand Down Expand Up @@ -136,12 +141,13 @@ export default class StatisticsController implements TabController {
this.lastUpdateTime = currentTime;

// Get bins
this.updateHistogramInputs;
let min = Number(this.RANGE_MIN.value);
let max = Number(this.RANGE_MAX.value);
let step = Number(this.STEP_SIZE.value);
if (step <= 0) step = 1;
let bins: number[] = [];
for (let i = min; i < max; i += step) {
for (let i = min; i < max && bins.length < this.MAX_BINS; i += step) {
bins.push(i);
}

Expand Down

0 comments on commit ce60d52

Please sign in to comment.