Skip to content

Commit

Permalink
adds sort method
Browse files Browse the repository at this point in the history
  • Loading branch information
davelandry committed Nov 10, 2016
1 parent 75905aa commit e8652bb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ export default class Shape extends BaseClass {
if (data.key) key = data.key;
}

if (this._sort) data = data.sort((a, b) => this._sort(a.__d3plus__ ? a.data : a, b.__d3plus__ ? b.data : b));

// Makes the update state of the group selection accessible.
const update = this._select.selectAll(`.d3plus-${this._name}`).data(data, key);
update.transition(this._transition)
update.order().transition(this._transition)
.call(this._applyTransform.bind(this));
this._update = update.select(".d3plus-Shape-bg");

Expand Down Expand Up @@ -541,6 +543,17 @@ function(d, i, shape) {
: this._select;
}

/**
@memberof Shape
@desc If *value* is specified, sets the sort comparator to the specified function and returns the current class instance. If *value* is not specified, returns the current sort comparator.
@param {false|Function} [*value* = []]
*/
sort(_) {
return arguments.length
? (this._sort = _, this)
: this._sort;
}

/**
@memberof Shape
@desc If *value* is specified, sets the stroke accessor to the specified function or string and returns the current class instance. If *value* is not specified, returns the current stroke accessor.
Expand Down

0 comments on commit e8652bb

Please sign in to comment.