Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d52b51

Browse files
committed
Remove updatevalue and updateevent
1 parent 2cfa81b commit 1d52b51

File tree

4 files changed

+0
-176
lines changed

4 files changed

+0
-176
lines changed

src/components/sliders/attributes.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -78,39 +78,6 @@ module.exports = {
7878

7979
steps: stepsAttrs,
8080

81-
updateevent: {
82-
valType: 'string',
83-
arrayOk: true,
84-
role: 'info',
85-
description: [
86-
'The name of the event to which this component subscribes',
87-
'in order to trigger updates. When the event is received',
88-
'the component will attempt to update the slider position',
89-
'to reflect the value passed as the data property of the',
90-
'event. The corresponding step\'s API method is assumed to',
91-
'have been triggered externally and so is not triggered again',
92-
'when the event is received. If an array is provided, multiple',
93-
'events will be subscribed to for updates.'
94-
].join(' ')
95-
},
96-
97-
updatevalue: {
98-
valType: 'string',
99-
arrayOk: true,
100-
role: 'info',
101-
description: [
102-
'The property of the event data that is matched to a slider',
103-
'value when an event of type `updateevent` is received. If',
104-
'undefined, the data argument itself is used. If a string,',
105-
'that property is used, and if a string with dots, e.g.',
106-
'`item.0.label`, then `data[0].label` is used. If an array,',
107-
'it is matched to the respective updateevent item or if there',
108-
'is no corresponding updatevalue for a particular updateevent,',
109-
'it is interpreted as `undefined` and defaults to the data',
110-
'property itself.'
111-
].join(' ')
112-
},
113-
11481
lenmode: {
11582
valType: 'enumerated',
11683
values: ['fraction', 'pixels'],

src/components/sliders/defaults.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,9 @@ function sliderDefaults(sliderIn, sliderOut, layoutOut) {
7070
coerce('currentvalue.prefix');
7171
coerce('currentvalue.offset');
7272

73-
coerce('updateevent');
74-
coerce('updatevalue');
75-
7673
coerce('transition.duration');
7774
coerce('transition.easing');
7875

79-
if(sliderOut.updateevent) {
80-
if(!Array.isArray(sliderOut.updateevent)) {
81-
sliderOut.updateevent = [sliderOut.updateevent];
82-
}
83-
} else {
84-
sliderOut.updateevent = [];
85-
}
86-
87-
if(sliderOut.updatevalue) {
88-
if(!Array.isArray(sliderOut.updatevalue)) {
89-
sliderOut.updatevalue = [sliderOut.updatevalue];
90-
}
91-
} else {
92-
sliderOut.updatevalue = [];
93-
}
94-
9576
Lib.coerceFont(coerce, 'font', layoutOut.font);
9677
Lib.coerceFont(coerce, 'currentvalue.font', layoutOut.font);
9778

src/components/sliders/draw.js

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,6 @@ function drawSlider(gd, sliderGroup, sliderOpts) {
227227
// Position the rectangle:
228228
Lib.setTranslate(sliderGroup, sliderOpts.lx + sliderOpts.pad.l, sliderOpts.ly + sliderOpts.pad.t);
229229

230-
// Every time the slider is draw from scratch, just detach and reattach the event listeners.
231-
// This could perhaps be avoided.
232-
removeListeners(gd, sliderGroup, sliderOpts);
233-
attachListeners(gd, sliderGroup, sliderOpts);
234-
235230
setActive(gd, sliderGroup, sliderOpts, sliderOpts.active, false, false);
236231
}
237232

@@ -282,52 +277,6 @@ function drawCurrentValue(sliderGroup, sliderOpts, valueOverride) {
282277
return text;
283278
}
284279

285-
function removeListeners(gd, sliderGroup, sliderOpts) {
286-
var listeners = sliderOpts._input.listeners;
287-
var eventNames = sliderOpts._input.eventNames;
288-
if(!Array.isArray(listeners) || !Array.isArray(eventNames)) return;
289-
while(listeners.length) {
290-
gd._removeInternalListener(eventNames.pop(), listeners.pop());
291-
}
292-
}
293-
294-
function attachListeners(gd, sliderGroup, sliderOpts) {
295-
if(!sliderOpts.updateevent || !sliderOpts.updateevent.length) {
296-
return;
297-
}
298-
299-
var listeners = sliderOpts._input.listeners = [];
300-
var eventNames = sliderOpts._input.eventNames = [];
301-
302-
function makeListener(eventname, updatevalue) {
303-
return function(data) {
304-
var value = data;
305-
if(updatevalue) {
306-
value = Lib.nestedProperty(data, updatevalue).get();
307-
}
308-
309-
// If it's *currently* invoking a command an event is received,
310-
// then we'll ignore the event in order to avoid complicated
311-
// infinite loops.
312-
if(sliderOpts._invokingCommand) return;
313-
314-
setActiveByLabel(gd, sliderGroup, sliderOpts, value, false, true);
315-
};
316-
}
317-
318-
for(var i = 0; i < sliderOpts.updateevent.length; i++) {
319-
var updateEventName = sliderOpts.updateevent[i];
320-
var updatevalue = (sliderOpts.updatevalue || [])[i];
321-
322-
var updatelistener = makeListener(updateEventName, updatevalue);
323-
324-
gd._internalEv.on(updateEventName, updatelistener);
325-
326-
eventNames.push(updateEventName);
327-
listeners.push(updatelistener);
328-
}
329-
}
330-
331280
function drawGrip(sliderGroup, gd, sliderOpts) {
332281
var grip = sliderGroup.selectAll('rect.' + constants.gripRectClass)
333282
.data([0]);

test/jasmine/tests/sliders_test.js

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -253,76 +253,3 @@ describe('update sliders interactions', function() {
253253
expect(d3.selectAll(query).size()).toEqual(cnt);
254254
}
255255
});
256-
257-
describe('updateevent and updatevalue', function() {
258-
'use strict';
259-
260-
var mock = require('@mocks/sliders.json');
261-
262-
var gd;
263-
264-
beforeEach(function(done) {
265-
gd = createGraphDiv();
266-
267-
var mockCopy = Lib.extendDeep({}, mock);
268-
269-
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done);
270-
});
271-
272-
afterEach(function() {
273-
Plotly.purge(gd);
274-
destroyGraphDiv();
275-
});
276-
277-
it('updates a slider when an event is triggered', function(done) {
278-
Plotly.relayout(gd, {
279-
'sliders[0].updateevent': 'plotly_someevent',
280-
'sliders[0].updatevalue': 'value'
281-
}).then(function() {
282-
expect(gd._fullLayout.sliders[0].active).toEqual(2);
283-
gd.emit('plotly_someevent', {value: 'green'});
284-
}).then(function() {
285-
expect(gd._fullLayout.sliders[0].active).toEqual(3);
286-
}).catch(fail).then(done);
287-
});
288-
289-
it('updates a slider when updatevalue unspecified', function(done) {
290-
Plotly.relayout(gd, {
291-
'sliders[0].updateevent': 'plotly_someevent'
292-
}).then(function() {
293-
expect(gd._fullLayout.sliders[0].active).toEqual(2);
294-
gd.emit('plotly_someevent', 'green');
295-
}).then(function() {
296-
expect(gd._fullLayout.sliders[0].active).toEqual(3);
297-
}).catch(fail).then(done);
298-
});
299-
300-
it('updates a slider when any of multiple updateevents occurs', function(done) {
301-
Plotly.relayout(gd, {
302-
'sliders[0].updateevent': ['plotly_someevent', 'plotly_anotherevent']
303-
}).then(function() {
304-
expect(gd._fullLayout.sliders[0].active).toEqual(2);
305-
gd.emit('plotly_someevent', 'green');
306-
}).then(function() {
307-
expect(gd._fullLayout.sliders[0].active).toEqual(3);
308-
gd.emit('plotly_anotherevent', 'yellow');
309-
}).then(function() {
310-
expect(gd._fullLayout.sliders[0].active).toEqual(2);
311-
}).catch(fail).then(done);
312-
});
313-
314-
it('matches update events with update values', function(done) {
315-
Plotly.relayout(gd, {
316-
'sliders[0].updateevent': ['plotly_someevent', 'plotly_anotherevent'],
317-
'sliders[0].updatevalue': ['foo', 'bar']
318-
}).then(function() {
319-
expect(gd._fullLayout.sliders[0].active).toEqual(2);
320-
gd.emit('plotly_someevent', {foo: 'green'});
321-
}).then(function() {
322-
expect(gd._fullLayout.sliders[0].active).toEqual(3);
323-
gd.emit('plotly_anotherevent', {bar: 'yellow'});
324-
}).then(function() {
325-
expect(gd._fullLayout.sliders[0].active).toEqual(2);
326-
}).catch(fail).then(done);
327-
});
328-
});

0 commit comments

Comments
 (0)