Hover Interactivity, Static Labels on Bar Plots, Tick Generators
Pre-releaseGood evening,
Tonight's release brings with it some much-requested features.
Features
Interaction.Hover
Hover interactivity has been added as Interaction.Hover
, which works with Plot.Scatter
, Plot.ClusteredBar
, Plot.VerticalBar
, and Plot.
(Vertical
/Horizontal
)Bar
. Interaction.Hover
takes two callbacks:
onHoverOver((hoverData: HoverData) => any)
: Called when the user mouses over new elements; is passed theHoverData
associated with elements the user has just hovered over.onHoverOut(callback: (hoverData: HoverData) => any)
: Called when the user mouses out of elements; is passed theHoverData
associated with elements the user is no longer hovering over.
HoverData
is an object containing the data and D3 Selection associated with items that were hovered over or out:
export interface HoverData {
data: any[];
selection: D3.Selection;
}
You can call hoverInteraction.getCurrentHoverData()
to retrieve the HoverData
associated with all elements the user is hovering over.
Static Labels on Bar Plots
Bar plots can now display static labels showing the bar values. Call BarPlot.barLabelsEnabled(true)
to enable them. Similar to Axis.Numeric
, you can supply a Formatter
to control the displayed value using barLabelFormatter(formatter: Formatter)
The label color is automatically chosen for readability against the bar's color.
Default Bar Alignment
By default, bars backed by Quantitative scales now center on top of their value.
Custom Tick Generators
You can now set custom tick generation logic on Quantitative scales using tickGenerator(generator: TickGenerator)
. A TickGenerator
is a function that produces tick values for a quantitative scale:
interface TickGenerator<D> {
(scale: Plottable.Scale.AbstractQuantitative<D>): D[]
}
The TickGenerators
module includes a function intervalTickGenerator(interval: number)
, which will return a TickGenerator
that generates tick values separated by interval.
In the event that you wish to merely filter the original set of generated ticks, you can call scale.getDefaultTicks()
.
Bugfixes
- On StackedPlots, one can expect the stacking to happen if project was called after addDataset.
- On StackedAreaPlots, the y-accessor is now not ignored when plotting.
- On StackedPlots, any string data is coerced to numbers when plotting and stacking.
- On StackedPlots, stacking a 0-length dataset no longer causes an error.
API Breaks
- We removed some unused interfaces here (#1211). In the unlikely case that you were referencing an obscure, unused interface within Plottable, this may constitute a minor API break. Just remove references to the outdated interface to fix.
Animator.ItertiveDelay
has been removed, and its functionality moved toAnimator.Base
.
Upgrade Instructions
- If you want the previous bar alignment, call
barPlot.barAlign("left")
orbarPlot.barAlign("top")
. Interaction.BarHover
has been deprecated; please useInteraction.Hover
instead. Note that the hover mode is now set by callinghoverMode(mode)
on the Bar Plot instead of theInteraction
.- Move all references to
Animator.IterativeDelay
toAnimator.Base
.
Future Changes
- We will be enabling
Interaction.Hover
onPlot.Line
andPlot.Area
soon.