-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AG-10444 Increase axis ticks on zoom #3329
Changes from 6 commits
4bc5241
9e6f9cb
ea4ce79
a4defdd
39ddf12
f8dc4ea
293daab
80fe1a1
0e74939
34c06c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ import { AxisLabel } from './axisLabel'; | |
import { AxisLine } from './axisLine'; | ||
import { AxisTick, type TickInterval } from './axisTick'; | ||
import { AxisTitle } from './axisTitle'; | ||
import type { AxisLineDatum } from './axisUtil'; | ||
import { type AxisLineDatum, NiceMode } from './axisUtil'; | ||
|
||
export interface LabelNodeDatum { | ||
tickId: string; | ||
|
@@ -474,29 +474,47 @@ export abstract class Axis< | |
this.animatable = animatable; | ||
} | ||
|
||
_niceDomainRange: number = NaN; | ||
_scaleNiceDomainRange: number = NaN; | ||
calculateLayout(initialPrimaryTickCount?: number) { | ||
const { scale, label, visibleRange } = this; | ||
const { scale, label, visibleRange, nice } = this; | ||
|
||
const { rotation, parallelFlipRotation, regularFlipRotation } = this.calculateRotations(); | ||
const sideFlag = this.label.getSideFlag(); | ||
|
||
this.updateScale(); | ||
const { niceDomain, primaryTickCount, ticks, visibleTicks, fractionDigits, bbox } = this.calculateTickLayout( | ||
this.dataDomain.domain, | ||
visibleRange, | ||
initialPrimaryTickCount | ||
); | ||
|
||
const range = findRangeExtent(this.range); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: rename to |
||
|
||
const domain = this.dataDomain.domain; | ||
let tickLayoutDomain: D[] | undefined; | ||
if (visibleRange[0] === 0 && visibleRange[1] === 1) { | ||
this.scale.domain = niceDomain; | ||
} else if (this._niceDomainRange !== range) { | ||
this.scale.domain = this.calculateTickLayout(this.dataDomain.domain, [0, 1]).niceDomain; | ||
tickLayoutDomain = undefined; | ||
} else if (!nice) { | ||
tickLayoutDomain = domain; | ||
} else if (this._scaleNiceDomainRange === range) { | ||
tickLayoutDomain = this.scale.domain; | ||
} else { | ||
tickLayoutDomain = this.calculateTickLayout(domain, NiceMode.TickAndDomain, [0, 1]).niceDomain; | ||
} | ||
|
||
let niceMode: NiceMode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes an issue where ticks would be in the wrong place. You do want to use a nice domain, but the nice domain of the zoomed out series. This means when generating the ticks, you'll still have nice ticks, but the domain won't be adjusted |
||
if (!nice) { | ||
niceMode = NiceMode.Off; | ||
} else if (tickLayoutDomain == null) { | ||
niceMode = NiceMode.TickAndDomain; | ||
} else { | ||
niceMode = NiceMode.TicksOnly; | ||
} | ||
const { niceDomain, primaryTickCount, ticks, visibleTicks, fractionDigits, bbox } = this.calculateTickLayout( | ||
tickLayoutDomain ?? domain, | ||
niceMode, | ||
visibleRange, | ||
initialPrimaryTickCount | ||
); | ||
|
||
this.scale.domain = niceDomain; | ||
|
||
this._niceDomainRange = range; | ||
this._scaleNiceDomainRange = nice ? range : NaN; | ||
|
||
const specifier = label.format; | ||
this.labelFormatter = | ||
|
@@ -531,6 +549,7 @@ export abstract class Axis< | |
|
||
abstract calculateTickLayout( | ||
domain: D[], | ||
niceMode: NiceMode, | ||
visibleRange: [number, number], | ||
primaryTickCount?: number | ||
): { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe call it
_scaleNiceDomainRangeExtent
, not to be confused with a range, which is what we conventionally call an array of min, max?