Skip to content

Hover Interactivity, Static Labels on Bar Plots, Tick Generators

Pre-release
Pre-release
Compare
Choose a tag to compare
@jtlan jtlan released this 25 Oct 01:20
· 6052 commits to master since this release

Good 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 the HoverData associated with elements the user has just hovered over.
  • onHoverOut(callback: (hoverData: HoverData) => any): Called when the user mouses out of elements; is passed the HoverData 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

screen shot 2014-10-24 at 6 14 29 pm
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

screen shot 2014-10-24 at 6 16 43 pm
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 to Animator.Base.

Upgrade Instructions

  • If you want the previous bar alignment, call barPlot.barAlign("left") or barPlot.barAlign("top").
  • Interaction.BarHover has been deprecated; please use Interaction.Hover instead. Note that the hover mode is now set by calling hoverMode(mode) on the Bar Plot instead of the Interaction.
  • Move all references to Animator.IterativeDelay to Animator.Base.

Future Changes

  • We will be enabling Interaction.Hover on Plot.Line and Plot.Area soon.