UNPKG

749 BJavaScriptView Raw
1import {Transform, stableCompare} from 'vega-dataflow';
2import {inherits} from 'vega-util';
3
4/**
5 * Sorts scenegraph items in the pulse source array.
6 * @constructor
7 * @param {object} params - The parameters for this operator.
8 * @param {function(*,*): number} [params.sort] - A comparator
9 * function for sorting tuples.
10 */
11export default function SortItems(params) {
12 Transform.call(this, null, params);
13}
14
15var prototype = inherits(SortItems, Transform);
16
17prototype.transform = function(_, pulse) {
18 var mod = _.modified('sort')
19 || pulse.changed(pulse.ADD)
20 || pulse.modified(_.sort.fields)
21 || pulse.modified('datum');
22
23 if (mod) pulse.source.sort(stableCompare(_.sort));
24
25 this.modified(mod);
26 return pulse;
27};