A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/palantir/plottable/wiki/Upgrading-to-1.0.0 below:

Upgrading to 1.0.0 · palantir/plottable Wiki · GitHub

This Guide consists of a few sections to help you get started

  1. Upgrade steps - step by step walk through of the changes you need to make
  2. Detailed information on the changes - explanations and motivations for changes, as well as any additional details about usage or best practices

The following modules have been renamed:

2. Rename All Abstract Classes

Abstract classes have been renamed as follows:

3. Convert project() --> attr()

The way display properties are set on Plots has changed: see "Removal of project()" for a more detailed explanation as to why. Rename all invocations of project() to attr(). With a global find-replace:

4. Unpack all key-strings into Accessors.

Previously, a string passed in as the second argument to project() would be used as a key into the data (unless it began with "#"), so project("fill", "color") was the same as project("fill", function(d) { return d.color; }). This functionality has been removed.

With a global find-replace (with regular expressions):

5. Convert XYPlot project() calls to property-setter calls

project() calls that did not directly set DOM attributes have been spun off into their own methods:

With a global find-replace (with regular expressions):

6. Convert Plots.Pie project() calls to property-setter calls

With a global find-replace (with regular expressions):

Methods that previously returned PlotData now use the PlotEntity type:

```Typescript
interface PlotEntity extends Entity<Plot> {
  dataset: Dataset;
  index: number;
  component: Plot;
}
```

Unlike PlotData, an PlotEntity corresponds to exactly one datum and its visual representation on the screen.

8. Remove Scales from Plot constructors.

Since the Scales are supplied through the property setters for a Plot, specifying them in the constructor is redundant. With global find-replace (with regular expressions):

9. Rename Methods (by class)

See "Interaction changes" for details.

Has been renamed to Drawers.Rectangle. The label-drawing functionality has been moved to Plots.Bar. Consequently:

Datasets are now manipulated by direct references rather than string keys. See "Working With Datasets" for details.

The methods automaticallyAdjustXScaleOverVisiblePoints() and automaticallyAdjustYScaleOverVisiblePoints() have been combined into a single method, autorangeMode(). The autorange functionality is now set as follows:

xyPlot.autorangeMode("x"); // to adjust the x scale based on the y domain
xyPlot.autorangeMode("y"); // to adjust the y scale based on the x domain
xyPlot.autorangeMode("none"); // to disable autorange functionality.

StackedPlot was transformed into a set of static utilities called Plottable.Utils.Stacking.

and

```Typescript
public entitiesIn(bounds: Bounds): Entity[];
public entitiesIn(xRange: Range, yRange: Range): Entity[];
```
Plots.Grid --> Plots.Rectangle

Domainers have been removed, and their functionality moved to QuantitativeScale. See "Replacing Domainers" for details.

Scales now work with IncludedValuesProviders. An IncludedValuesProvider is a function that returns an array of domain values:

interface IncludedValuesProvider<D> {
  (scale: Scale<D, any>): D[];
}

The returned values will be included in the domain of the Scale when it autoDomain()s. IncludedValuesProviders are added and removed from a Scale with the following methods on Scale:

addIncludedValuesProvider(provider: Scales.IncludedValuesProvider<D>): Scale<D, R>;
removeIncludedValuesProvider(provider: Scales.IncludedValuesProvider<D>): Scale<D, R>;

If any of the above methods are important to your use-case, please contact us or file an issue and we'll help you out.

A PaddingExceptionsProvider is a function that returns an array of domain values. If any of those values are either end of the domain computed when autoDomain()-ing, that end of the domain will not be padded. PaddingExceptionsProvider can be added and removed from the QuantitativeScale with the following methods:

```Typescript
addPaddingExceptionsProvider(provider: Scales.PaddingExceptionsProvider<D>): QuantitativeScale<D>;
removePaddingExceptionsProvider(provider: Scales.PaddingExceptionsProvider<D>): QuantitativeScale<D>;
```

Scales.Log has been deprecated for a while, and has now been removed. ModifiedLog is recommended as a replacement due to its better behavior when autoDomain()ing, as well as its better support for negative numbers.

To set the color range, call range() after construction.

Animators.Base --> Animators.Easing

A number of renames for clarity:

Animators.Rect / Animators.MovingRect

Plottable.Utils.Methods has been split into multiple modules. As a result, the module hierarchy (and sometimes the name of the method itself) have been changed changed:

Utils.Methods.inRange()           -> Utils.Math.inRange();
Utils.Methods.clamp()             -> Utils.Math.clamp();
Utils.Methods.max()               -> Utils.Math.max();
Utils.Methods.min()               -> Utils.Math.min();
Utils.Methods.isNaN()             -> Utils.Math.isNaN();
Utils.Methods.isValidNumber()     -> Utils.Math.isValidNumber();
Utils.Methods.range()             -> Utils.Math.range();
Utils.Methods.distanceSquared()   -> Utils.Math.distanceSquared();

Utils.Methods.addArrays()         -> Utils.Array.add();
Utils.Methods.uniq()              -> Utils.Array.uniq();
Utils.Methods.createFilledArray() -> Utils.Array.createFilledArray();
Utils.Methods.flatten()           -> Utils.Array.flatten();
Utils.Methods.arrayEq()           -> DELETED

Utils.Methods.copyMap()           -> DELETED
Utils.Methods.populateMap()       -> DELETED

Utils.Methods.warn()              -> Utils.Window.warn();
Utils.Methods.setTimeout()        -> Utils.Window.setTimeout();
Utils.Methods.objEq()             -> DELETED
Utils.Methods.isIE()              -> DELETED
Utils.Methods.parseRange()        -> DELETED

Utils.Methods.colorTest()         -> Utils.Color.colorTest();
Utils.Methods.lightenColor()      -> Utils.Color.lightenColor();

Utils.Methods.intersectsBBox()    -> Utils.DOM.intersectsBBox();
10. Rename Component-adding methods on Group and Table

The semantics of adding Components to Groups and Tables has been improved. To add a Component to a Group:

// previously: group.addComponent(component);
group.append(component);

To add a Component to a Table:

// previously: table.addComponent(rowIndex, columnIndex, component);
table.add(component, rowIndex, columnIndex);

To convert to the new API:

11. Remove uses of above() and below()

above() and below() had some odd behavior -- combining two non-Group Components would create a Group out of nowhere, but if the caller or target was a Group the non-Group Component would be added to the existing Group. If both caller and target were Groups one would be appended to the other, but it wasn't clear which way that would be. Consequently, we have removed these API points. A Group must be explicitly created to group multiple Components:

// previously: component1.above(component2);
var group = new Plottable.Components.Group([component2, component1]); 
// previously: component1.below(component2);
var group = new Plottable.Components.Group([component1, component2]); 
// previously: group.below(component);
group.append(component);
12. No automagic Groups in Tables.

Continuing with the theme of not creating Groups automatically, adding a Component to an occupied cell in a Table will now throw an error. To put multiple Components in the same cell of a Table, add the Components to a Group, then place the Group in that cell.

13. Remove callbacks using direct reference

Previously, a callback was removed like this:

clickInteraction.onClick(null);

Now, to remove a callback:

clickInteraction.offClick(callback); // === operator is used to decide which callback to remove

where callback is the callback that was originally passed in to the registration call (onClick() in this case).

project() previously performed a lot of magic in the background. For example, calling .project("fill", () => "red"), would set the "fill" attribute in the DOM to "red", but calling .project("x", ...) set a variety of DOM attributes depending on what kind of Plot was used. Furthermore, if the second argument to project() was a string, it would automatically be used as a key into the data (unless the string began with "#"...), meaning that .project("fill", "red") didn't do what might be expected.

We have decided to remedy this by splitting the functionality of project() into attr() and "property setters".

attr() previously existed as an alias for project(). Now, it directly sets DOM attributes to the results of an Accessor and a Scale:

attr(attr: string, attrValue: number | string | Accessor<number> | Accessor<string>): Plot;
attr<A>(attr: string, attrValue: A | Accessor<A>, scale: Scale<A, number | string>): Plot;

Example invocations:

The Scale must be passed as the third argument for it to autoDomain() over the data passing through it.

attr() can also be invoked at as a getter that returns the AccessorScaleBinding for a particular attribute:

interface AccessorScaleBinding {
  accessor: Accessor;
  scale?: Scale;
}

Property setters are methods for setting Plot properties that are not actual DOM attributes. These have a similar signature to attr(), taking in an Accessor and a Scale. For example:

x(x: number | Accessor<number>): XYPlot<X, Y>;
x(x: X | Accessor<X>, xScale: Scale<X, number>): XYPlot<X, Y>;

x() is used to set the "x" property on an XYPlot: the previous invocation would have been something like project("x", function(d) { return d.x; }, xScale). Now, instead:

plot.x(function(d) { return d.x; }, xScale);

Invoking a property setter with no arguments will return an AccessorScaleBinding for that property.

Here is the list of property setters:

Since keys are no longer used to register Datasets, operations involving Datasets are now done by using the Datasets directly. For example, to loop over all Datasets in a Plot:

var datasets = plot.datasets(); // Dataset[]
datasets.forEach((dataset) => {
  ...
});

Reversing the order of Datasets in a Plot:

plot.datasets(plot.datasets().reverse());

Methods that previously accepted keys associated with Datasets now take an array of Datasets. For example, to get the Selections associated with a particular Dataset:

var selectionsOfInterest = plot.getAllSelections([datasetOfInterest]);

Previously generateProjectors() was used to get the projectors (scaled Accessors) associated with particular Dataset keys. Since the property-setting methods and attr() now function as getters, they can be used to retrieve the AccessorScaleBinding instead:

var yBinding = plot.y();
var yAccessor = yBinding.accessor;
var yScale = yBinding.scale;
plot.datasets().forEach((dataset) => {
  var yValues = dataset.data().map((datum, index) => yAccessor(datum, index, dataset));
  var scaledYValues = yValues.map((value) => yScale.scale(value));
  // do something with the y-values
  ...
});

If a Scale was not originally set with attr() or the property setter, no Scale will be present in the AccessorScaleBinding:

plot.attr("fill", (datum) => datum.color);
...
...
var fillBinding = plot.attr("fill");
var fillAccessor = fillBinding.accessor;
var fillScale = fillBinding.scale; // will be undefined

Previously, Components used a transparent hitbox to detect events; Interactions would attach event listeners to the hitbox. However, this mechanism created a problem because the hitboxes of Components higher up in a Group would block the hitboxes of Components below them.

All of Plottable's Interactions have been changed to use a different event-detecting mechanism that does not require a hitbox, so the hitbox and its associated retrieval call hitBox() have been removed.

The semantics for attaching Interactions has been changed to make it clearer that an Interaction can only be attached to one Component at a time:

// previously: component.registerInteraction(interaction);
interaction.attachTo(component);

Interactions can now also be detached from Components:

interaction.detachFrom(component);

Domainers were previously used when autoDomain()-ing a QuantitativeScale. However, this functionality more properly belongs on the QuantitativeScale itself, so it has been moved there:

padProportion(): number;
padProportion(padProportion: number): QuantitativeScale<D>;
addPaddingExceptionsProvider(provider: Scales.PaddingExceptionsProvider<D>): QuantitativeScale<D>;
removePaddingExceptionsProvider(provider: Scales.PaddingExceptionsProvider<D>): QuantitativeScale<D>;
addIncludedValuesProvider(provider: Scales.IncludedValuesProvider<D>): Scale<D, R>;
removeIncludedValuesProvider(provider: Scales.IncludedValuesProvider<D>): Scale<D, R>;

See here and here for details on how to use those methods.

domainMin() and domainMax()

If you were previously extending Domainer to control the min and max values on the QuantitativeScale's domain, we have added two methods for setting only one end of the domain on QuantitativeScale:

If only one is set, the other end of the scale will behave as though it was autoDomain()-ed.

Calling both domainMin(min) and domainMax(max) is equivalent to calling domain([min, max]). Setting both can reverse the domain on QuantitativeScale`s that support reversal.

Calling autoDomain() will clear both set values, the same way calling autoDomain() overrides domain().

Example fiddle: http://jsfiddle.net/fv2a2jej/

If you were previously using a Scales.Color inside an Accessor:

plot.project("fill", function(d) { return colorScale.scale(d.type); });

The Scale's domain would have expanded to cover all the data, which was an error. Scales must be passed as the third argument to attr() (or the second argument to the property setters) for the Scale to autoDomain() over all the data. Instead, do this:

plot.attr("fill", function(d) { return d.type; }, colorScale);

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4