Skip to content

Latest commit

 

History

History
62 lines (43 loc) · 1.88 KB

tick-methods.md

File metadata and controls

62 lines (43 loc) · 1.88 KB

TickMethods

There are three tickMethods in @antv/scale. You can use each of them as a pure function, or you can set them to options.tickMethod for those scales which have getTicks method.

They have some differences of features.

  • d3Ticks and r-pretty guarantees that ticks generated are integers if tickCount is greater than extent of domain, while wilkinson-extended not.
  • d3Ticks guarantees the extent of ticks generated within the extent of domain, while wilkinson-extended and r-pretty not.

Usage

# d3Ticks(min: number, max: number, count: number) => number[]

D3 ticks in d3-array.

import {Linear, d3Ticks} from '@antv/scale';
import { Linear, LinearOptions, rPretty, wilkinsonExtended } from '@antv/scale';

const x = new Linear({
  domain: [2, 17],
  tickCount: 6,
  tickMethod: d3Ticks
}); 

x.getTicks(); // [2, 4, 6, 8, 10, 12, 14, 16]
d3Ticks(2, 17, 6) // 2, 4, 6, 8, 10, 12, 14, 16]

# rPretty(min: number, max: number, count: number) => number[]

An algorithm for positioning tick labels on axes in R language.

import { Linear, rPretty } from '@antv/scale';

const x = new Linear({
  domain: [2, 17],
  tickCount: 6,
  tickMethod: rPretty
}); 

x.getTicks(); // [2, 4, 6, 8, 10, 12, 14, 16, 18]
rPretty(2, 17, 6) // [2, 4, 6, 8, 10, 12, 14, 16, 18]

# wilkinsonExtended(min: number, max: number, count: number) => number[]

An extension of Wilkinson's algorithm for positioning tick labels on axes.

import { Linear, wilkinsonExtended } from '@antv/scale';

const x = new Linear({
  domain: [2, 17],
  tickCount: 6,
  tickMethod: wilkinsonExtended
}); 

x.getTicks(); // [0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5]
wilkinsonExtended(2, 17, 6) // [0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5]