Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/plugins/plot/tickUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TIME_UNITS_UTC = [
* Nicely formatted tick steps from d3-array.
*/
function tickStep(start, stop, count) {
const step0 = Math.abs(stop - start) / Math.max(0, count);
const step0 = Math.abs(stop - start) / Math.max(1, count);
let step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10));
const error = step0 / step1;
if (error >= e10) {
Expand All @@ -38,7 +38,7 @@ function tickStep(start, stop, count) {
* tickStep for time units - allows for snapping to 15/30 minutes and 6/12 hours, which are common intervals.
*/
function timeTickStep(start, stop, count, unitName) {
const step0 = Math.abs(stop - start) / Math.max(0, count);
const step0 = Math.abs(stop - start) / Math.max(1, count);
let step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10));
const error = step0 / step1;

Expand Down Expand Up @@ -220,7 +220,7 @@ export function getLogTicks(start, stop, mainTickCount = 8, secondaryTickCount =
const secondaryLogTicks = ticks(
tick + rangeBetweenMainTicks / (secondaryTickCount + 1),
nextTick - rangeBetweenMainTicks / (secondaryTickCount + 1),
secondaryTickCount - 2
Math.max(1, secondaryTickCount - 2)
).map((n) => symlog(n, 10));

result.push(...secondaryLogTicks);
Expand All @@ -235,6 +235,10 @@ export function getLogTicks(start, stop, mainTickCount = 8, secondaryTickCount =
* Linear tick generation from d3-array.
*/
export function ticks(start, stop, count) {
if (count < 1) {
return [];
}

const step = tickStep(start, stop, count);
const precision = getPrecision(step);

Expand Down