Skip to content

Instantly share code, notes, and snippets.

@jgphilpott
Last active November 17, 2022 17:40
Show Gist options
  • Save jgphilpott/cf12c05f7c30844a4d7fa70ec9a7945a to your computer and use it in GitHub Desktop.
Save jgphilpott/cf12c05f7c30844a4d7fa70ec9a7945a to your computer and use it in GitHub Desktop.
Functions for sorting SVG elements with D3.
# Requirement: https://github.com/d3/d3
# Credit: https://stackoverflow.com/a/42998001/1544937
d3.selection.prototype.setAsFrontLayer = ->
return this.each ->
this.parentNode.appendChild this
d3.selection.prototype.setAsBackLayer = ->
return this.each ->
firstChild = this.parentNode.firstChild
if firstChild
this.parentNode.insertBefore this, firstChild
// Generated by CoffeeScript 2.7.0
// Requirement: https://github.com/d3/d3
// Credit: https://stackoverflow.com/a/42998001/1544937
d3.selection.prototype.setAsFrontLayer = function() {
return this.each(function() {
return this.parentNode.appendChild(this);
});
};
d3.selection.prototype.setAsBackLayer = function() {
return this.each(function() {
var firstChild;
firstChild = this.parentNode.firstChild;
if (firstChild) {
return this.parentNode.insertBefore(this, firstChild);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment