Axis - nteract/semiotic GitHub Wiki

<Axis> provides convenient axes elements, such as tick values and tick lines, and also labels and interactivity, roughly following the API of d3-axis (though under the hood d3-axis isn't used). Most of the time axes are created from objects that are sent to the axes attribute of the XYFrame or the axis attribute of the ORFrame, in which case the object follows the structure of the component but doesn't have a reference to scale or size because that is passed from the frame and may have its orient overwritten if it's invalid (for ORFrames).

import { Axis } from 'semiotic'

<Axis
   size={[ 20,200 ]}
   scale={scaleLinear().domain([ 10, 1000 ]).range([ 20, 200 ])}
   orient={'right'}
   label={'A label for this axis'}
/>

<API Reference>

size: {[width, height]}

If size is specified, sets the width and height of the axis from the array of values. The array must contain two numbers which represents the width and height, respectively.

<Axis size={[500,500]} ... />

orient: { string }

One of: left, right, top, bottom. Determines the position of the axis.

<Axis orient="left" ... />

label: { string | object }

A string label that is presented along the axis or an object with name equivalent to the string label and optional settings to adjust its placement: { location, anchor, locationDistance }. Only locationDistance is honored in ORFrame radial axes (which are not generated by this component).

<!-- String Example -->
<Axis label="Units Sold" ... />
<!-- Object Example -->
<Axis label={{ name: "Units Sold", location: "inside", anchor: "start", locationDistance: -20 }} ... />

tickValues: { array }

An explicit array of values where you want the ticks to display. This must be in a format that can be processed by the assigned scale.

<Axis tickValues={[1,2,3,4,5]} ... />

ticks: { number }

A suggested number of ticks to display.

<Axis ticks={4} ... />

tickFormat: { function }

A function that takes a tick value and returns the formatted tick value (string or component). Overrides format if both are set.

<Axis tickFormat={d => `${d} bunnies` } ... />
<Axis tickFormat={d => <text className="axis-label">{`${d} bunnies`}</text> } ... />

tickLineGenerator: { function }

A function that takes axis properties (eg. xy = {x1,y1, x2,y2, tx, ty, value}) and returns a JSX object, such as a svg path, representing a single tick mark at the tick location.

<Axis 
tickLineGenerator={({ xy }) => (
          <path
            style={{ fill: "lightgrey", stroke: "grey" }}
            d={`M${xy.x1},${xy.y1 - 5}L${xy.x2},${xy.y1 - 5}L${xy.x2},${xy.y1 + 5}L${xy.x1},${xy.y1 + 5}Z`}
          />
        )}
...
/>

rotate: { number }

The rotation of the tick values (the text representing the value of the tick line).

<Axis rotate={45} ... />

padding: { number }

The space in pixels between the start of the tick line and the tick value.

<Axis padding={10} ... />

scale: { d3-scale }

The scale from which to generate the axis. The scale has to be a d3-scale like object.

<Axis scale={scaleLinear().domain([0,1]).range([0,500])} ... />

annotationFunction: { function }

If annotationFunction is assigned a function, it activates a hoverable region above the axis which places a line corresponding to the position of the cursor, and fires the function when you click with the value hovered over. This is useful for setting threshold annotations or measuring the data before or past a certain value.

<Axis annotationFunction={e => {this.setState({ clickedThreshold: e})} ... />

className: { string }

Appended to the class of the element.

<Axis className="special" ... />

margin: { object }

An object of { left, right, top, bottom } that is used to determine the hoverable region when annotationFunction is set as well as the initial and end positions of tick lines and the position of tick values.

<Axis margin={{ top: 0, left: 50, bottom: 50, right: 0 }} ... />

name: { string }

Used under the hood. Probably not something you'd find useful.

<Axis name="then-why-are-you-exposing-this?" ... />
⚠️ **GitHub.com Fallback** ⚠️