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
12 changes: 10 additions & 2 deletions src/plugins/plot/tickUtils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prettier/prettier */
import { antisymlog, symlog } from './mathUtils.js';

const e10 = Math.sqrt(50);
Expand All @@ -8,6 +9,10 @@ const e2 = Math.sqrt(2);
* Nicely formatted tick steps from d3-array.
*/
function tickStep(start, stop, count) {
// fix-1
if (count <= 0 || !Number.isFinite(count)) {
throw new Error('Count must be a positive finite number');
}
const step0 = Math.abs(stop - start) / Math.max(0, count);
let step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10));
const error = step0 / step1;
Expand Down Expand Up @@ -63,10 +68,12 @@ export function getLogTicks(start, stop, mainTickCount = 8, secondaryTickCount =
const nextTick = mainTicks[i + 1];
const rangeBetweenMainTicks = nextTick - tick;

// fix-2
const adjustedTickCount = Math.max(1, secondaryTickCount - 2);
const secondaryLogTicks = ticks(
tick + rangeBetweenMainTicks / (secondaryTickCount + 1),
nextTick - rangeBetweenMainTicks / (secondaryTickCount + 1),
secondaryTickCount - 2
adjustedTickCount
).map((n) => symlog(n, 10));

result.push(...secondaryLogTicks);
Expand All @@ -76,7 +83,7 @@ export function getLogTicks(start, stop, mainTickCount = 8, secondaryTickCount =

return result;
}

// getLogTicks(0, 100, 4, 2);
/**
* Linear tick generation from d3-array.
*/
Expand Down Expand Up @@ -154,3 +161,4 @@ export function getFormattedTicks(newTicks, format) {

return newTicks;
}