From 4e6c350794edcd8d2bff308ca9117136f2aa6982 Mon Sep 17 00:00:00 2001 From: Ricky Reusser Date: Tue, 15 Nov 2016 09:36:37 -0500 Subject: [PATCH] Animate scatter trace opacity --- src/traces/scatter/plot.js | 2 ++ test/jasmine/tests/animate_test.js | 32 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/traces/scatter/plot.js b/src/traces/scatter/plot.js index 45a3b180b4e..3cd4663ea40 100644 --- a/src/traces/scatter/plot.js +++ b/src/traces/scatter/plot.js @@ -169,6 +169,8 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition if(trace.visible !== true) return; + transition(tr).style('opacity', trace.opacity); + // BUILD LINES AND FILLS var ownFillEl3, tonext; var ownFillDir = trace.fill.charAt(trace.fill.length - 1); diff --git a/test/jasmine/tests/animate_test.js b/test/jasmine/tests/animate_test.js index 98b5e5f2227..570a9e741f9 100644 --- a/test/jasmine/tests/animate_test.js +++ b/test/jasmine/tests/animate_test.js @@ -737,3 +737,35 @@ describe('non-animatable fallback', function() { }); }); + +describe('animating scatter traces', function() { + 'use strict'; + var gd; + + beforeEach(function() { + gd = createGraphDiv(); + }); + + afterEach(function() { + Plotly.purge(gd); + destroyGraphDiv(); + }); + + it('animates trace opacity', function(done) { + var trace; + Plotly.plot(gd, [{ + x: [1, 2, 3], + y: [4, 5, 6], + opacity: 1 + }]).then(function() { + trace = Plotly.d3.selectAll('g.scatter.trace'); + expect(trace.style('opacity')).toEqual('1'); + + return Plotly.animate(gd, [{ + data: [{opacity: 0.1}] + }], {transition: {duration: 0}, frame: {duration: 0, redraw: false}}); + }).then(function() { + expect(trace.style('opacity')).toEqual('0.1'); + }).catch(fail).then(done); + }); +});