aboutsummaryrefslogtreecommitdiff
path: root/src/lib.ts
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2023-01-15 22:31:04 +1100
committerTerry Truong <terry06890@gmail.com>2023-01-15 22:31:04 +1100
commitf3c97f41ee84dfdc718d1a9bc1aac24e6b6755c9 (patch)
tree7796ab0128f613c41e3ae1abf1f0545a79a1ba91 /src/lib.ts
parent019d0f0b3d9732023272fe7deb3e22ac911d76af (diff)
Avoid tick label overlap
Use rotation for horizontal timelines with long tick labels. For other labels, look for overlap, and hide problematic ones. Use darker text to indicate minor ticks instead of minor offset.
Diffstat (limited to 'src/lib.ts')
-rw-r--r--src/lib.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/lib.ts b/src/lib.ts
index 6299345..9849006 100644
--- a/src/lib.ts
+++ b/src/lib.ts
@@ -59,11 +59,20 @@ export function getNumTrailingZeros(n: number): number {
}
throw new Error('Exceeded floating point precision');
}
+// Removes a class from an element, triggers reflow, then adds the class
export function animateWithClass(el: HTMLElement, className: string){
el.classList.remove(className);
el.offsetWidth; // Triggers reflow
el.classList.add(className);
}
+// For estimating text width (via https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript)
+const _getTextWidthCanvas = document.createElement('canvas');
+export function getTextWidth(text: string, font: string): number {
+ const context = _getTextWidthCanvas.getContext('2d')!;
+ context.font = font;
+ const metrics = context.measureText(text);
+ return metrics.width;
+}
// For calendar conversion (mostly copied from backend/hist_data/cal.py)
export function gregorianToJdn(year: number, month: number, day: number): number {