-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/core_plugins/timelion/public/panels/timechart/tick_generator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module.exports = function generateTicksProvider() { | ||
|
||
function floorInBase(n, base) { | ||
return base * Math.floor(n / base); | ||
}; | ||
|
||
function generateTicks(axis) { | ||
const returnTicks = []; | ||
let tickSize = 2; | ||
let delta = axis.delta; | ||
let steps = 0; | ||
let tickVal; | ||
let tickCount = 0; | ||
|
||
//Count the steps | ||
while (Math.abs(delta) >= 1024) { | ||
steps++; | ||
delta /= 1024; | ||
} | ||
|
||
//Set the tick size relative to the remaining delta | ||
while (tickSize <= 1024) { | ||
if (delta <= tickSize) { | ||
break; | ||
} | ||
tickSize *= 2; | ||
} | ||
axis.tickSize = tickSize * Math.pow(1024, steps); | ||
|
||
//Calculate the new ticks | ||
const tickMin = floorInBase(axis.min, axis.tickSize); | ||
do { | ||
tickVal = tickMin + (tickCount++) * axis.tickSize; | ||
returnTicks.push(tickVal); | ||
} while (tickVal < axis.max); | ||
|
||
return returnTicks; | ||
}; | ||
|
||
return function (axis) { | ||
return generateTicks(axis); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters