API changes to Plot, Namespace Changes
Pre-releaseGood afternoon,
This release contains two major API changes:
- All Plots have been converted over to the
NewStylePlot
API that we unveiled in version 0.25.0 withStackedBar
andClusteredBar
plots. This will significantly increase API consistency, and make it easier for us to develop new features in the future. - 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 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.Scatter
has changed fromPlot.Scatter(data, xScale, yScale)
toPlot.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 seeError: 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 firstdataset
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 thePlot
, registered with the given key. The data is automatically converted into aPlottable.Dataset
.Plot.addDataset(key: string, dataset: Plottable.Dataset): Plot
Add aDataset
to thePlot
, registered with the given key.Plot.addDataset(dataArray: any[]): Plot
Add data to thePlot
. The data is automatically converted into aPlottable.Dataset
.Plot.addDataset(dataset: Plottable.Dataset): Plot
. Add aDataset
to thePlot
.
Removing datasets
Plot.removeDataset(key: string): Plot
Remove aDataset
with the given key from thePlot
.Plot.removeDataset(dataArray: any[]): Plot
Remove aDataset
from thePlot
by reference equality with the underlying data.Plot.removeDataset(dataset: Plottable.Dataset): Plot
Remove aDataset
from thePlot
by direct reference.
Retrieving datasets
Plot.datasets(): Plottable.Dataset[]
return allDataset
s bound to thePlot
.
Typescript-only API Breaks
The Plottable.Abstract
module was removed. Classes have been renamed as follows:
Plottable.Abstract.Scale
→Plottable.Scale.AbstractScale
Plottable.Abstract.QuantitativeScale
→Plottable.Scale.AbstractQuantitative
Plottable.Abstract.Component
→Plottable.Component.AbstractComponent
Plottable.Abstract.ComponentContainer
→Plottable.Component.AbstractComponentContainer
Plottable.Abstract.Axis
→Plottable.Axis.AbstractAxis
Plottable.Abstract.Plot
→Plottable.Plot.AbstractPlot
Plottable.Abstract.XYPlot
→Plottable.Plot.AbstractXYPlot
Plottable.Abstract.BarPlot
→Plottable.Plot.AbstractBarPlot
Plottable.Abstract.Stacked
→Plottable.Plot.AbstractStacked
Plottable.Abstract.Drawer
→Plottable.Drawer.AbstractDrawer
Plottable.Abstract.Dispatcher
→Plottable.Dispatcher.AbstractDispatcher
Plottable.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
→AppliedAccessor
IAttributeToProjector
→AttributeToProjector
IBroadcasterCallback
→BroadcasterCallback
IDataset
→ DatasetInterfaceIExtent
→Extent
IKeyEventListenerCallback
→KeyEventListenerCallback
IListenable
→Listenable
IMetadata
→Metadata
IPlotAnimator
→PlotAnimator
IPlotAnimatorMap
→PlotAnimatorMap
IRenderPolicy
→RenderPolicy
IWrappedText
→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.