Skip to content

Instantly share code, notes, and snippets.

@drewda
Created October 2, 2011 18:51
Show Gist options
  • Save drewda/1257765 to your computer and use it in GitHub Desktop.
Save drewda/1257765 to your computer and use it in GitHub Desktop.
selectively changing d3 elements when Backbone model changes
# note that this function is called whenever a GeoPoint model changes
# Backbone will pass in geo_point, which refers to the changed model
# @geo_points refers to the entire collection of GeoPoint models
# update the bound data
geo_points = @geo_points.reject (gp) => gp.get('markedForDelete')
geoPointMarkers = d3.select('#geo-point-layer').selectAll("g")
.data geo_points, (d) =>
d.cid
###
in here is the enter() code
###
# if there is a changed GeoPoint, go in and modify it
# note that cid refers to the model's local id
if geo_point
changedGeoPointMarkers = geoPointMarkers.filter (d, i) =>
d.cid == geo_point.cid
# select
changedGeoPointMarkers.selectAll('circle')
.attr "r", (d) ->
if d.get 'selected'
masterRouter.geo_point_layer.geoPointSelectedRadius
else
masterRouter.geo_point_layer.geoPointDefaultRadius
.classed "selected", (d) ->
d.get 'selected'
# move
@reapplyTransform()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment