Skip to content

Instantly share code, notes, and snippets.

@DavidSanwald
Created September 26, 2018 12:06
Show Gist options
  • Save DavidSanwald/dcb3c1a077fd2492facbec1772a59dd6 to your computer and use it in GitHub Desktop.
Save DavidSanwald/dcb3c1a077fd2492facbec1772a59dd6 to your computer and use it in GitHub Desktop.
saving individual parts of data join
// create single idempotent container that is appended to the DOM only once
const container = selection.selectAll('.lines').data([null]).enter().append('g').attr('class', 'lines')
// bind data, create and save the update selection
let update = container.selectAll('.line')
.data(data, d => d.id)
// create and save the exit selection
let exit = update.exit()
// do something with a selection
exit
.remove()
// create and save enter selection
let enter = update
.enter()
// do something with enter selection
enter
.append('path')
.attr('class', 'line')
// create and save combined selection
let merged = update
.merge(enter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment