Axis highlighting
npm install @flourish/axes-highlightsThis module lets users add highlights to flourish-chart-layout (or flourish-axes) axes.
``npm install --save @flourish/axes-highlights`
`js`
const state = {
axes_highlights: {} // Add any properties to this object to override the default settings
}
`yaml`template.yml
- property: axes_highlights
import: "@flourish/axes-highlights"
`js`
import initAxesHighlights from "@flourish/axes-highlights";
var axes_highlights = initAxesHighlights(state.axes_highlights);
In the template's update function (e.g. updateGraphic) you typically call the following methods:
`js
let container = select(...);
axes_highlights
.appendTo(container)
.chartLayout(chart_layout)
.update();
`
The minimum methods you will need to use is appendTo, chartLayout and update. See "Methods" for full configuration.
container is a D3 selection representing the element the highlights should be rendered in. You may need to import d3-transition in the module that makes the container selection, so that transitions are available. (Without this, the axis highlights might not display at all.)
This basic implementation appends the axes highlights to a container (container). If you want to append multiple axes highlights containers (for multiple facets for example) inside the same parent container, you can use the offset() method to position the axes highlights container (see example of implementation here). Axes highlights should be appended per facet, so for example in LBP and scatter it is called in the facet.js file for each facet group.
just once in the draw function, passing it a container that wraps all of the facets (such as the svg) so that the same patterns are used for all axes highlights. If it is a template that doesnt have multiple facets you dont need to call this method as the default should work fine.$3
The parent element to append it to. We tend to use the fl-data-foreground group as the parent (if it exists). e.g. `.appendTo(select(".fl-data-foreground"))`. Expects a d3 selection.$3
Specifies a chart layout (or axes) instance to attach the highlight to. Used for scales, margins, plot dimentions etc (should be one per facet).Expects it to have the following properties, typically part of the @flourish/chart-layout (or @flourish/axes) module:
`
- xDatetimeParse
- yDatetimeParse
- margins
- plot_height
- plot_width
- xData
- yData
- xScale
- yScale
`$3
Name of facet, used to know if the highlight should apply to that facet or not. Expects a string.$3
Used to parse numbers e.g. `localization.getParser()`. Used to parse numbers when one of the axes is of type number. (If the axes are of type date we use the chart layout (or axes) date parsers and strings arent parsed). Expects a function.$3
Adds offset to the axes highlights container. Expects an object containing an x and y property, eg. {x: 25, y: 10}`.