Skip to content

API changes to Plot, Namespace Changes

Pre-release
Pre-release
Compare
Choose a tag to compare
@teamdandelion teamdandelion released this 11 Oct 00:04
· 6270 commits to master since this release

Good afternoon,

This release contains two major API changes:

  1. All Plots have been converted over to the NewStylePlot API that we unveiled in version 0.25.0 with StackedBar and ClusteredBar plots. This will significantly increase API consistency, and make it easier for us to develop new features in the future.
  2. We have removed the Plottable.Abstract module, instead moving all abstract classes to the appropriate module for their functionality. Thus, for example, Plottable.Abstract.Axis was renamed to Plottable.Axis.AbstractAxis. This will only affect Typescript consumers, who should see more sensible autocomplete information, and contributors, who will find a better-organized module system. For help upgrading, check out the Upgrade Instructions section of these release notes.

Additionally, we have altered the plottable.d.ts typing file published so as to include the_protected methods and variables as well as publicly-exposed methods. This will make it easier for Typescript developers to modify Plottable's internals and change the functionality. Be cautious when modifying or depending on _protected methods, as they are not part of the publicly supported API and their behavior may change without warning in future versions.

This release also includes a small tweak to the animation of Plot.StackedBar:

Stacked Bar Animation

All datasets in a stack now animate upward together, rather than each dataset in the stack animating in sequence.

Upgrade Instructions

The typing breaks consist solely of renames and should be very easy to resolve; see the notes below to see every individual rename. The actual API breaks will take a little more work to resolve but should still be very straightforward. Every use of a Plot.Scatter, Plot.Line, Plot.Area, Plot.Grid, Plot.HorizontalBar, or Plot.VerticalBar must be converted.

  • Their constructors have all changed; they no longer take data as the first argument. For example, the signature for Plot.Scatter has changed from Plot.Scatter(data, xScale, yScale) to Plot.Scatter(xScale, yScale).
  • The Plot.dataset method no longer exists for setting or retrieving the dataset.
  • Plot.addDataset() must be used to add data to the plot.
    Other than that, everything should be the same. If your plots do not render and you see Error: XYPlots require an xScale and a yScale printed to the console, then that means that for at least one of your plots you have forgotten to remove the first dataset argument.

API-Breaking Changes

Conversion to NewStylePlot API:

Plot.Scatter, Plot.Line, Plot.Area, Plot.Grid, Plot.HorizontalBar, and Plot.VerticalBar were all converted to the NewStylePlot API. Thus, instead of taking a dataset in the constructor, datasets may now be added via the Plot.addDataset call. Here is a re-cap for how the new, consistent Plot API works.

Adding datasets

  • Plot.addDataset(key: string, dataArray: any[]): Plot Add data to the Plot, registered with the given key. The data is automatically converted into a Plottable.Dataset.
  • Plot.addDataset(key: string, dataset: Plottable.Dataset): Plot Add a Dataset to the Plot, registered with the given key.
  • Plot.addDataset(dataArray: any[]): Plot Add data to the Plot. The data is automatically converted into a Plottable.Dataset.
  • Plot.addDataset(dataset: Plottable.Dataset): Plot. Add a Dataset to the Plot.

Removing datasets

  • Plot.removeDataset(key: string): Plot Remove a Dataset with the given key from the Plot.
  • Plot.removeDataset(dataArray: any[]): Plot Remove a Dataset from the Plot by reference equality with the underlying data.
  • Plot.removeDataset(dataset: Plottable.Dataset): Plot Remove a Dataset from the Plot by direct reference.

Retrieving datasets

  • Plot.datasets(): Plottable.Dataset[] return all Datasets bound to the Plot.

Typescript-only API Breaks

The Plottable.Abstract module was removed. Classes have been renamed as follows:

  • Plottable.Abstract.ScalePlottable.Scale.AbstractScale
  • Plottable.Abstract.QuantitativeScalePlottable.Scale.AbstractQuantitative
  • Plottable.Abstract.ComponentPlottable.Component.AbstractComponent
  • Plottable.Abstract.ComponentContainerPlottable.Component.AbstractComponentContainer
  • Plottable.Abstract.AxisPlottable.Axis.AbstractAxis
  • Plottable.Abstract.PlotPlottable.Plot.AbstractPlot
  • Plottable.Abstract.XYPlotPlottable.Plot.AbstractXYPlot
  • Plottable.Abstract.BarPlotPlottable.Plot.AbstractBarPlot
  • Plottable.Abstract.StackedPlottable.Plot.AbstractStacked
  • Plottable.Abstract.DrawerPlottable.Drawer.AbstractDrawer
  • Plottable.Abstract.DispatcherPlottable.Dispatcher.AbstractDispatcher
  • Plottable.Abstract.InteractionPlottable.Interaction.AbstractInteraction

Since all Plots are now NewStylePlots, we have removed the redundant NewStylePlot class. NewStyleBarPlot was also removed.

We stopped prefixing interfaces with the letter I. Interfaces have been renamed as follows:

  • IAppliedAccessorAppliedAccessor
  • IAttributeToProjectorAttributeToProjector
  • IBroadcasterCallbackBroadcasterCallback
  • IDataset → DatasetInterface
  • IExtentExtent
  • IKeyEventListenerCallbackKeyEventListenerCallback
  • IListenableListenable
  • IMetadataMetadata
  • IPlotAnimatorPlotAnimator
  • IPlotAnimatorMapPlotAnimatorMap
  • IRenderPolicyRenderPolicy
  • IWrappedTextWrappedText
  • _IAccessor_Accessor
  • _IProjector_Projector
  • _ISpaceRequest_SpaceRequest
  • _IPixelArea_PixelArea
  • _ITimeInterval_TimeInterval

Additionally, we fixed the typing information on some Animator return values, so that they now correctly return D3.Transition.Transition or any instead of D3.Selection. See #1104 for more details.

Upcoming API changes

Plot.Bar will replace Plot.HorizontalBar, Plot.VerticalBar, and Plot.ClusteredBar; the default behavior of Plot.Bar will be to cluster the bars. The orientation can be set in the constructor.