Skip to content

Commit

Permalink
add maxFactor to RelativeScale to prevent large gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptkeeper committed Jun 5, 2020
1 parent 00347ed commit 2336c9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions assets/js/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export class GraphDisplayManager {
})

const tickCount = 10
const maxFactor = 4

// eslint-disable-next-line new-cap
this._plotInstance = new uPlot({
Expand Down Expand Up @@ -237,7 +238,7 @@ export class GraphDisplayManager {
},
split: () => {
const visibleGraphData = this.getVisibleGraphData()
const [, max, scale] = RelativeScale.scaleMatrix(visibleGraphData, tickCount)
const [, max, scale] = RelativeScale.scaleMatrix(visibleGraphData, tickCount, maxFactor)
const ticks = RelativeScale.generateTicks(0, max, scale)
return ticks
}
Expand All @@ -248,7 +249,7 @@ export class GraphDisplayManager {
auto: false,
range: () => {
const visibleGraphData = this.getVisibleGraphData()
const [, scaledMax] = RelativeScale.scaleMatrix(visibleGraphData, tickCount)
const [, scaledMax] = RelativeScale.scaleMatrix(visibleGraphData, tickCount, maxFactor)
return [0, scaledMax]
}
}
Expand Down
8 changes: 4 additions & 4 deletions assets/js/scale.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class RelativeScale {
static scale (data, tickCount) {
static scale (data, tickCount, maxFactor) {
const [min, max] = RelativeScale.calculateBounds(data)

let factor = 1
Expand All @@ -12,7 +12,7 @@ export class RelativeScale {

const ticks = (scaledMax - scaledMin) / scale

if (ticks < tickCount + 1) {
if (ticks < tickCount + 1 || (typeof maxFactor === 'number' && factor === maxFactor)) {
return [scaledMin, scaledMax, scale]
} else {
// Too many steps between min/max, increase factor and try again
Expand All @@ -21,7 +21,7 @@ export class RelativeScale {
}
}

static scaleMatrix (data, tickCount) {
static scaleMatrix (data, tickCount, maxFactor) {
let max = Number.MIN_VALUE

for (const row of data) {
Expand All @@ -42,7 +42,7 @@ export class RelativeScale {
max = 0
}

return RelativeScale.scale([0, max], tickCount)
return RelativeScale.scale([0, max], tickCount, maxFactor)
}

static generateTicks (min, max, step) {
Expand Down

0 comments on commit 2336c9f

Please sign in to comment.