Skip to content

Commit

Permalink
Improve behavior of histogram step input
Browse files Browse the repository at this point in the history
Handle step down between orders of magnitude and properly enforce max bin count
  • Loading branch information
jwbonner committed Dec 27, 2024
1 parent 55c691e commit a65443a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/hub/controllers/StatisticsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export default class StatisticsController implements TabController {
[this.TIME_RANGE, this.RANGE_MIN, this.RANGE_MAX, this.STEP_SIZE].forEach((input) =>
input.addEventListener("change", () => (this.shouldUpdate = true))
);
this.STEP_SIZE.addEventListener("change", () => {
this.updateHistogramInputs();
});
[this.RANGE_MIN, this.RANGE_MAX, this.STEP_SIZE].forEach((input) =>
input.addEventListener("change", () => this.updateHistogramInputs())
);

// Set initial values for histogram inputs
this.RANGE_MIN.value = "0";
Expand All @@ -56,11 +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)).toString();
this.STEP_SIZE.value = cleanFloat(Number(this.STEP_SIZE.step) * 0.9).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();
this.STEP_SIZE.value = cleanFloat(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

0 comments on commit a65443a

Please sign in to comment.