add maxFactor to RelativeScale to prevent large gaps
This commit is contained in:
parent
00347ed0a9
commit
2336c9f78b
@ -160,6 +160,7 @@ export class GraphDisplayManager {
|
||||
})
|
||||
|
||||
const tickCount = 10
|
||||
const maxFactor = 4
|
||||
|
||||
// eslint-disable-next-line new-cap
|
||||
this._plotInstance = new uPlot({
|
||||
@ -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
|
||||
}
|
||||
@ -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]
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
@ -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
|
||||
@ -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) {
|
||||
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user