score:2
In this example there is no update to the data that would require a re-bind. In fact, there is only one single datum which gets modified during the drag gesture. When the drag actually starts, the subject as specified by
.subject(function() { var p = [d3.event.x, d3.event.y]; return [p, p]; })
is captured and stored in variable d
:
var d = d3.event.subject,
As can be seen from the above two lines, this will start off as an array containing two coordinate pairs defining the start and end points of the path, which are initially identical.
The next line binds this single datum/subject to the newly created path for this drag gesture:
active = svg.append("path").datum(d),
It is important to keep in mind, that the variable d
contains a reference to the actual data bound to the path. When modifying d
you are in fact modifying the datum which was bound beforehand. This happens because you are dealing with a reference.
That said, the next steps are pretty straightforward as during the gesture, the array of coordinates is kept up to date by adjusting coodinate values or pushing new values to the array. Again, this is actually modifying the datum bound to the path.
When finally setting the line generator line
on the path's d
attribute
active.attr("d", line);
the generator will be called implicitly passing in the new value of the datum bound and, thus, generate the path following the pointer's movement during the gesture.
Source: stackoverflow.com
Related Query
- D3: Using a closure to update a selection without re-binding data
- How do I create a tree layout using JSON data in d3.v4 - without stratify()
- How to update elements of an HTML that the elements are created using data from a CSV file?
- d3.js: Nested Selection with update using `join`
- Binding data to each element using HTML textarea
- d3 data binding not creating child elements using join
- Data binding in D3 fails when using "cloned" data
- how to update data form file json using d3.js (zoomable circle pack)
- Create axes using data binding in d3
- Binding configuration to a function using a closure
- D3 How to update the chart after selection from drop down menu with new data
- Using Javascript D3 library, how replace data in selection of rects?
- Filtering in stacked bar chart using d3 v3.js by changing data on input selection
- Update display of hierarchical data using D3
- D3: update data in group selection with additional ('g')
- How to update all data representing an SVG line using d3?
- First data is ignored without using selectAll in d3.js
- D3: data update "enter" selection is empty
- d3 chart update automatically when data change by using vue
- add a sub element in d3js using data binding
- d3.js Update data binding
- How to update a single data point in d3 without touching other elements?
- How can I group data to be filtered without losing crossfilter functionality using dc.js?
- Propagating datum to children on selection data update
- How do I update this data without redrawing datapoints that are already there?
- How to update a d3 grouped barchart with new data by using join in v6
- Update a d3.js (v5) selection bound with double nested data
- Infinite scrolling bar chart without re-rendering of data using d3.js
- How to update data using on.click events in D3
- d3.js can not update the chart - using json data
More Query from same tag
- Multidonut chart d3 legendds not working
- Apply multiple styles with .style() method in D3.js
- D3: How to assign style css to a specified id
- failed to use d3 to update legend data, entering is empty for changed data
- d3.js 4.0 — Gridlines for linechart with centered axis
- Select content of text element with tspan specifier in SVG with D3js
- D3 with AngularJs, Multiple charts on same page with different data based on common key
- Reduce number of plots in D3 Scatterplot Matrix
- Client side topojson rendering seemingly incorrect paths
- Getting d3.js data from html
- Using d3 drag, why doesn't dragstart have d3.event.x set?
- Why do the y axis values shift up from real point in line chart?
- Labeling and adding an icon to D3 SVG nodes
- Link to Rails partial in D3.js circles?
- How to move labels to outside pie chart in D3
- How to subset a column from loaded in CSV in D3 javascript from
- Updating D3 bubble radius with collide simulation
- d3 exit selection comes up empty even with unique id value
- D3.js transition bug in Firefox?
- TypeError: d3.layout.cloud is not a function
- How to show tooltip by data index on d3js charts? (with no mouseover event)
- D3.js multiple force layout graphs from json file
- Use legend in stacked bar Graph along with tooltip d3 js
- Troubles viewing Git Gist on bl.ocks.org
- D3 - Center the globe to the clicked country
- How to select certain time period in d3 js?
- How to rescale x axis using the crossfilter?
- what's the difference between selection.style and selection.attr in D3.js?
- How can I make an arc thiker than the other in D3.js
- What is the default width and height of a group element in html (if it has any)?