deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

Transitions `getColor` is terminating existing transitions.

Open locomotif opened this issue 8 years ago • 1 comments

"deck.gl": "^6.0.1" "react-map-gl": "^3.3.1" using: ScatterplotLayer

Actual Result

I am using the following accessors with the transitions prop: getRadius, getColor, and getPosition. I am experiencing expected behavior for getRadius and getPosition; however on getColor the transition on position is terminating and the circle is being rendered at its end state, and color is not animating.

Expected Result

I expect for the circle to transition to new color and for the circle to continue to interpolate when a click event changes the color state.

Reproduce Steps

Code Example

    getLayer({ data, zoom }) {
        console.log('###### start')
        const layer = this.normalizeDataLayer(data)
        this.layer = layer.entrySeq().reduce((acc, [priority, data]) => {
            // here I am attempting to ensure that the data object being passed to scatterplot is the same object as before if there are no differences - there shouldn't be because data will always equal ['a'].
            if (isEqual(data.toArray(), this.data)) {
                data = this.data
            } else {
                this.data = data.toArray()
            }
            return acc.set(priority, new ScatterplotLayer({
                id: `${this.layerId}-${priority}`,
                opacity: 1,
                pickable: this.pickable,
                fp64: true,
                data,
                dataComparator: this.areEqual,
                getColor: (id) => {
                    console.log('getPosition called')
                    return [255, ++this.counter % 255, ++this.counter % 255]
                },
                getPosition: id => {
                    console.log('getPosition called')
                    return this.position[id]
                },
                getRadius: () => this.getSize(zoom),
                updateTriggers: {
                    getRadius: [zoom],
                    getColor: [this.lastColorChange],
                    getPosition: [this.lastPositionChange]
                },
                transitions: {
                    getColor: {
                        duration: 3000,
                        easing: easeCubicInOut,
                    },
                    getRadius: {
                        duration: 100,
                        easing: easeCubicInOut,
                    },
                    getPosition: {
                        duration: 10000,
                        easing: easeLinear,
                    },
                },
            }))
        }, Map())
        return this.layer
    }

normalizeDataLayer takes an immutable map of geoJson features and extracts data into instance variables to be accessed later by the getters. For the data object returned I tried to keep it as simple as possible. In my test case, am only using one point. The data object is an immutable list when returned and only has this shape: data = ['a']

Besides using ensuring the data object is the same instance, I am also using the dataComparator. Each section that begins with ###### start, is new call to getLayer, this will happen on zoom change, click event on circle, or new position change. the areEqual lines are from the dataComparator event firing. Please note that on a click event areEqual is not called.

Below I have output from console:

###### start - Initial call to getLayer
Scatterplot.js:107 position change
Scatterplot.js:52 getPosition called (2) [-122.49904860467981, 37.78639344917349]
Scatterplot.js:52 getPosition called (2) [-122.49904860467981, 37.78639344917349]
Scatterplot.js:81 getSize called
Scatterplot.js:48 getColor called (3) [255, 255, 255]
attribute-manager.js:69 deck: Updated attributes for 1 instances in vehicle-scatterplot-0 in 7ms
Scatterplot.js:32 ###### start - position change
Scatterplot.js:107 position change
Scatterplot.js:28 areEqual false
Scatterplot.js:52 getPosition called (2) [-122.49909371223332, 37.78419051541141]
Scatterplot.js:52 getPosition called (2) [-122.49909371223332, 37.78419051541141]
Scatterplot.js:81 getSize called
Scatterplot.js:48 getColor called (3) [255, 255, 255]
attribute-manager.js:69 deck: Updated attributes for 1 instances in vehicle-scatterplot-0 in 5ms
Scatterplot.js:32 ###### start - another position change - note only getPosition is called as expected
Scatterplot.js:107 position change
Scatterplot.js:28 areEqual true
Scatterplot.js:52 getPosition called (2) [-122.49572134849166, 37.78268830596415]
Scatterplot.js:52 getPosition called (2) [-122.49572134849166, 37.78268830596415]
attribute-manager.js:69 deck: Updated attributes for 1 instances in vehicle-scatterplot-0 in 2ms
Scatterplot.js:32 ###### start - another position change
Scatterplot.js:107 position change
Scatterplot.js:28 areEqual true
Scatterplot.js:52 getPosition called (2) [-122.49442590556801, 37.780120283613485]
Scatterplot.js:52 getPosition called (2) [-122.49442590556801, 37.780120283613485]
attribute-manager.js:69 deck: Updated attributes for 1 instances in vehicle-scatterplot-0 in 2ms
Scatterplot.js:32 ###### start - zoom change - note getSize is called as expected
Scatterplot.js:28 areEqual true
Scatterplot.js:81 getSize called
attribute-manager.js:69 deck: Updated attributes for 1 instances in vehicle-scatterplot-0 in 1ms
Scatterplot.js:32 ###### start - position change
Scatterplot.js:107 position change
Scatterplot.js:28 areEqual true
Scatterplot.js:52 getPosition called (2) [-122.49425082165973, 37.777692690752886]
Scatterplot.js:52 getPosition called (2) [-122.49425082165973, 37.777692690752886]
attribute-manager.js:69 deck: Updated attributes for 1 instances in vehicle-scatterplot-0 in 2ms
Scatterplot.js:32 ###### start - click event on circle - note no `areEqual` triggered and all accessors are called.  This is not what I expected. I expected a call to areEqual and getColor.
Scatterplot.js:52 getPosition called (2) [-122.49425082165973, 37.777692690752886]
Scatterplot.js:52 getPosition called (2) [-122.49425082165973, 37.777692690752886]
Scatterplot.js:81 getSize called
Scatterplot.js:48 getColor called (3) [0, 0, 0]
attribute-manager.js:69 deck: Updated attributes for 1 instances in vehicle-scatterplot-1 in 3ms
Scatterplot.js:32 ###### start 
Scatterplot.js:107 position change
Scatterplot.js:28 areEqual true
Scatterplot.js:52 getPosition called (2) [-122.49407577971719, 37.7752650962869]
Scatterplot.js:52 getPosition called (2) [-122.49407577971719, 37.7752650962869]
attribute-manager.js:69 deck: Updated attributes for 1 instances in vehicle-scatterplot-1 in 2ms

I have tried avoiding a click event, and instead used setTimeout to change the color of the circle during the middle of position transition, and I am getting the same result.

Not sure if I have configured correctly, or I am expecting unintended behavior. Any help would be greatly appreciated. Thanks again for all the good work! Hope this makes sense.

Below is a gif of the click event.

clickevent

To Do List

  • [ ] Add label and assign to milestone
  • [ ] Coding
  • [ ] Test

locomotif avatar Jul 20 '18 22:07 locomotif

I apologize - false alarm! digging into deck.gl, I discovered what I was doing wrong.

The following was returning undefined

var oldLayer = oldLayerMap[newLayer.id];

This was because I was changing the layer.id. The reasoning behind changing layer.id was because I was prioritizing layers to be able to stack layers. This was when I was handling my own interpolation. The use case for changing id was to be able to control which images lay on top; because I was not able to prioritize assets within a same layer -- by prioritize, I mean attempting to add a sort of z-index to certain assets.

Thanks again for the great, work. I am going to close this, because its not an issue.

locomotif avatar Jul 21 '18 17:07 locomotif