Package Exports
- d3plus-axis
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (d3plus-axis) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
d3plus-axis
Beautiful javascript scales and axes.
Installing
If you use NPM, npm install d3plus-axis
. Otherwise, download the latest release. The released bundle supports AMD, CommonJS, and vanilla environments. Create a custom bundle using Rollup or your preferred bundler. You can also load directly from d3plus.org:
<script src="https://d3plus.org/js/d3plus-axis.v0.3.full.min.js"></script>
Getting Started
d3plus-axis extrapolates on the ideas presented in d3-axis, most notably by adding grid lines and fitting the axis within the allotted space. To create a bottom axis in an SVG group defined like this:
<svg width=600 height=300>
<g id="my-axis"></g>
</svg>
Here is the javascript needed:
var bottom = new d3plus.AxisBottom()
.select("#my-axis")
.domain([0, 10])
.width(600)
.height(300)
.render();
The d3plus-axis module makes all four orientations available as shorthand methods for the generalized Axis class that they all extend. These axes are the brains behind d3plus-plot.
Click here to view this example live on the web.
More Examples
- Changing Axis Orientation
- Only Showing Specific Tick Labels
- Axis w/ Time Scale
- Tick Label Formatting
- Setting Custom Ticks
API Reference
Classes
- Axis ⇐
BaseClass
- AxisBottom ⇐
Axis
- AxisLeft ⇐
Axis
- AxisRight ⇐
Axis
- AxisTop ⇐
Axis
Functions
- date(*date*)
Parses numbers and strings to valid Javascript Date obejcts.
Axis ⇐ BaseClass
Kind: global class
Extends: BaseClass
- Axis ⇐
BaseClass
- new Axis()
- .render([callback]) ↩︎
- .align([value]) ↩︎
- .barConfig([value]) ↩︎
- .domain([value]) ↩︎
- .duration([value]) ↩︎
- .grid([value]) ↩︎
- .gridConfig([value]) ↩︎
- .gridSize([value]) ↩︎
- .height([value]) ↩︎
- .labels([value]) ↩︎
- .orient([orient]) ↩︎
- .outerBounds()
- .padding([value]) ↩︎
- .paddingInner([value]) ↩︎
- .paddingOuter([value]) ↩︎
- .range([value]) ↩︎
- .scale([value]) ↩︎
- .select([selector]) ↩︎
- .shape([value]) ↩︎
- .shapeConfig([value]) ↩︎
- .tickFormat([value]) ↩︎
- .ticks([value]) ↩︎
- .tickSize([value]) ↩︎
- .title([value]) ↩︎
- .titleConfig([value]) ↩︎
- .width([value]) ↩︎
new Axis()
Creates an SVG scale based on an array of data.
Axis.render([callback]) ↩︎
Renders the current Axis to the page. If a callback is specified, it will be called once the legend is done drawing.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[callback] | function |
Axis.align([value]) ↩︎
If value is specified, sets the horizontal alignment to the specified value and returns the current class instance. If value is not specified, returns the current horizontal alignment.
Kind: static method of Axis
Chainable
Param | Type | Default | Description |
---|---|---|---|
[value] | String |
"center" |
Supports "left" and "center" and "right" . |
Axis.barConfig([value]) ↩︎
If value is specified, sets the axis line style and returns the current class instance. If value is not specified, returns the current axis line style.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[value] | Object |
Axis.domain([value]) ↩︎
If value is specified, sets the scale domain of the axis and returns the current class instance. If value is not specified, returns the current scale domain.
Kind: static method of Axis
Chainable
Param | Type | Default |
---|---|---|
[value] | Array |
[0, 10] |
Axis.duration([value]) ↩︎
If value is specified, sets the transition duration of the axis and returns the current class instance. If value is not specified, returns the current duration.
Kind: static method of Axis
Chainable
Param | Type | Default |
---|---|---|
[value] | Number |
600 |
Axis.grid([value]) ↩︎
If value is specified, sets the grid values of the axis and returns the current class instance. If value is not specified, returns the current grid values, which by default are interpreted based on the domain and the available width.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[value] | Array |
Axis.gridConfig([value]) ↩︎
If value is specified, sets the grid style of the axis and returns the current class instance. If value is not specified, returns the current grid style.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[value] | Object |
Axis.gridSize([value]) ↩︎
If value is specified, sets the grid size of the axis and returns the current class instance. If value is not specified, returns the current grid size, which defaults to taking up as much space as available.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[value] | Number |
Axis.height([value]) ↩︎
If value is specified, sets the overall height of the axis and returns the current class instance. If value is not specified, returns the current height value.
Kind: static method of Axis
Chainable
Param | Type | Default |
---|---|---|
[value] | Number |
100 |
Axis.labels([value]) ↩︎
If value is specified, sets the visible tick labels of the axis and returns the current class instance. If value is not specified, returns the current visible tick labels, which defaults to showing all labels.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[value] | Array |
Axis.orient([orient]) ↩︎
If orient is specified, sets the orientation of the shape and returns the current class instance. If orient is not specified, returns the current orientation.
Kind: static method of Axis
Chainable
Param | Type | Default | Description |
---|---|---|---|
[orient] | String |
"bottom" |
Supports "top" , "right" , "bottom" , and "left" orientations. |
Axis.outerBounds()
If called after the elements have been drawn to DOM, will returns the outer bounds of the axis content.
Kind: static method of Axis
Example
{"width": 180, "height": 24, "x": 10, "y": 20}
Axis.padding([value]) ↩︎
If value is specified, sets the padding between each tick label to the specified number and returns the current class instance. If value is not specified, returns the current padding value.
Kind: static method of Axis
Chainable
Param | Type | Default |
---|---|---|
[value] | Number |
10 |
Axis.paddingInner([value]) ↩︎
If value is specified, sets the inner padding of band scale to the specified number and returns the current class instance. If value is not specified, returns the current inner padding value.
Kind: static method of Axis
Chainable
Param | Type | Default |
---|---|---|
[value] | Number |
0.1 |
Axis.paddingOuter([value]) ↩︎
If value is specified, sets the outer padding of band scales to the specified number and returns the current class instance. If value is not specified, returns the current outer padding value.
Kind: static method of Axis
Chainable
Param | Type | Default |
---|---|---|
[value] | Number |
0.1 |
Axis.range([value]) ↩︎
If value is specified, sets the scale range (in pixels) of the axis and returns the current class instance. The given array must have 2 values, but one may be undefined
to allow the default behavior for that value. If value is not specified, returns the current scale range.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[value] | Array |
Axis.scale([value]) ↩︎
If value is specified, sets the scale of the axis and returns the current class instance. If value is not specified, returns the current this._d3Scale
Kind: static method of Axis
Chainable
Param | Type | Default |
---|---|---|
[value] | String |
"linear" |
Axis.select([selector]) ↩︎
If selector is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If selector is not specified, returns the current SVG container element.
Kind: static method of Axis
Chainable
Param | Type | Default |
---|---|---|
[selector] | String | HTMLElement |
d3.select("body").append("svg") |
Axis.shape([value]) ↩︎
If value is specified, sets the tick shape constructor and returns the current class instance. If value is not specified, returns the current shape.
Kind: static method of Axis
Chainable
Param | Type | Default |
---|---|---|
[value] | String |
"Line" |
Axis.shapeConfig([value]) ↩︎
If value is specified, sets the tick style of the axis and returns the current class instance. If value is not specified, returns the current tick style.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[value] | Object |
Axis.tickFormat([value]) ↩︎
If value is specified, sets the tick formatter and returns the current class instance. If value is not specified, returns the current tick formatter, which by default is retrieved from the d3-scale.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[value] | function |
Axis.ticks([value]) ↩︎
If value is specified, sets the tick values of the axis and returns the current class instance. If value is not specified, returns the current tick values, which by default are interpreted based on the domain and the available width.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[value] | Array |
Axis.tickSize([value]) ↩︎
If value is specified, sets the tick size of the axis and returns the current class instance. If value is not specified, returns the current tick size.
Kind: static method of Axis
Chainable
Param | Type | Default |
---|---|---|
[value] | Number |
5 |
Axis.title([value]) ↩︎
If value is specified, sets the title of the axis and returns the current class instance. If value is not specified, returns the current title.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[value] | String |
Axis.titleConfig([value]) ↩︎
If value is specified, sets the title configuration of the axis and returns the current class instance. If value is not specified, returns the current title configuration.
Kind: static method of Axis
Chainable
Param | Type |
---|---|
[value] | Object |
Axis.width([value]) ↩︎
If value is specified, sets the overall width of the axis and returns the current class instance. If value is not specified, returns the current width value.
Kind: static method of Axis
Chainable
Param | Type | Default |
---|---|---|
[value] | Number |
400 |
AxisBottom ⇐ Axis
Kind: global class
Extends: Axis
new AxisBottom()
Shorthand method for creating an axis where the ticks are drawn below the horizontal domain path. Extends all functionality of the base Axis class.
AxisLeft ⇐ Axis
Kind: global class
Extends: Axis
new AxisLeft()
Shorthand method for creating an axis where the ticks are drawn to the left of the vertical domain path. Extends all functionality of the base Axis class.
AxisRight ⇐ Axis
Kind: global class
Extends: Axis
new AxisRight()
Shorthand method for creating an axis where the ticks are drawn to the right of the vertical domain path. Extends all functionality of the base Axis class.
AxisTop ⇐ Axis
Kind: global class
Extends: Axis
new AxisTop()
Shorthand method for creating an axis where the ticks are drawn above the vertical domain path. Extends all functionality of the base Axis class.
date(date)
Parses numbers and strings to valid Javascript Date obejcts.
Kind: global function
Param | Type |
---|---|
date | Date | Number | String |