API changes to Plot, Namespace Changes
Pre-releaseGood afternoon,
This release contains two major API changes:
- All Plots have been converted over to the
NewStylePlotAPI that we unveiled in version 0.25.0 withStackedBarandClusteredBarplots. This will significantly increase API consistency, and make it easier for us to develop new features in the future. - We have removed the
Plottable.Abstractmodule, instead moving all abstract classes to the appropriate module for their functionality. Thus, for example,Plottable.Abstract.Axiswas renamed toPlottable.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.Scatterhas changed fromPlot.Scatter(data, xScale, yScale)toPlot.Scatter(xScale, yScale). - The
Plot.datasetmethod 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 seeError: XYPlots require an xScale and a yScaleprinted to the console, then that means that for at least one of your plots you have forgotten to remove the firstdatasetargument.
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[]): PlotAdd data to thePlot, registered with the given key. The data is automatically converted into aPlottable.Dataset.Plot.addDataset(key: string, dataset: Plottable.Dataset): PlotAdd aDatasetto thePlot, registered with the given key.Plot.addDataset(dataArray: any[]): PlotAdd data to thePlot. The data is automatically converted into aPlottable.Dataset.Plot.addDataset(dataset: Plottable.Dataset): Plot. Add aDatasetto thePlot.
Removing datasets
Plot.removeDataset(key: string): PlotRemove aDatasetwith the given key from thePlot.Plot.removeDataset(dataArray: any[]): PlotRemove aDatasetfrom thePlotby reference equality with the underlying data.Plot.removeDataset(dataset: Plottable.Dataset): PlotRemove aDatasetfrom thePlotby direct reference.
Retrieving datasets
Plot.datasets(): Plottable.Dataset[]return allDatasets bound to thePlot.
Typescript-only API Breaks
The Plottable.Abstract module was removed. Classes have been renamed as follows:
Plottable.Abstract.Scale→Plottable.Scale.AbstractScalePlottable.Abstract.QuantitativeScale→Plottable.Scale.AbstractQuantitativePlottable.Abstract.Component→Plottable.Component.AbstractComponentPlottable.Abstract.ComponentContainer→Plottable.Component.AbstractComponentContainerPlottable.Abstract.Axis→Plottable.Axis.AbstractAxisPlottable.Abstract.Plot→Plottable.Plot.AbstractPlotPlottable.Abstract.XYPlot→Plottable.Plot.AbstractXYPlotPlottable.Abstract.BarPlot→Plottable.Plot.AbstractBarPlotPlottable.Abstract.Stacked→Plottable.Plot.AbstractStackedPlottable.Abstract.Drawer→Plottable.Drawer.AbstractDrawerPlottable.Abstract.Dispatcher→Plottable.Dispatcher.AbstractDispatcherPlottable.Abstract.Interaction→Plottable.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:
IAppliedAccessor→AppliedAccessorIAttributeToProjector→AttributeToProjectorIBroadcasterCallback→BroadcasterCallbackIDataset→ DatasetInterfaceIExtent→ExtentIKeyEventListenerCallback→KeyEventListenerCallbackIListenable→ListenableIMetadata→MetadataIPlotAnimator→PlotAnimatorIPlotAnimatorMap→PlotAnimatorMapIRenderPolicy→RenderPolicyIWrappedText→WrappedText_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.