basics reformatted

master
Matt Huntington 9 years ago
parent 8c50b6e05b
commit c9aa3f21e3

100
D3.md

@ -2,53 +2,67 @@
## Basics ## Basics
- Selection ### Selection
- `d3.select()`
- like document.querySelector() - `d3.select()`
- `d3.selectAll()` - like document.querySelector()
- like document.querySelectorAll() - `d3.selectAll()`
- can make selections from within selections - like document.querySelectorAll()
-`d3.select('main').selectAll('span');` - can make selections from within selections
- .style() -`d3.select('main').selectAll('span');`
- sets the style for an element
- `d3.select('div').style('color', 'orange');` ### .style()
- can pass an object
- `d3.select('div').style({'color': 'blue', 'font-size': '40px'});` - sets the style for an element
- `d3.select('div').style('color', 'orange');`
- can pass an object
- `d3.select('div').style({'color': 'blue', 'font-size': '40px'});`
- style will return the selection for chaining - style will return the selection for chaining
- `d3.select('div').style('color', 'orange').style({'color': 'blue', 'font-size': '40px'});` - `d3.select('div').style('color', 'orange').style({'color': 'blue', 'font-size': '40px'});`
- .attr()
- adds/changes an attribute on an selection ### .attr()
- `d3.select('div').attr('anExampleAttribute', 'someValue');`
- .classed() - adds/changes an attribute on an selection
- checks to see if all elements in selection contain the chosen class - `d3.select('div').attr('anExampleAttribute', 'someValue');`
- `d3.selectAll('.house').classed('house');`
- returns true ### .classed()
- `d3.selectAll('div').classed('house');`
- returns false if not all divs contain class `house` - checks to see if all elements in selection contain the chosen class
- chaining doesn't work since it returns true or false - `d3.selectAll('.house').classed('house');`
- can add the class using - returns true
- `d3.selectAll('div').classed('frog', true);` - `d3.selectAll('div').classed('house');`
- returns the selection, so you can chain - returns false if not all divs contain class `house`
- can remove the class using - chaining doesn't work since it returns true or false
- `d3.selectAll('div').classed('frog', false);` - can add the class using
- .append() - `d3.selectAll('div').classed('frog', true);`
- append html to a selection - returns the selection, so you can chain
- returns the appended element - can remove the class using
- `d3.selectAll('div').append('span')` - `d3.selectAll('div').classed('frog', false);`
- .html()
- change the inner html of an element ### .append()
- .text()
- set the content of the selection to the exact text (no html) - append html to a selection
- returns the appended element
- `d3.selectAll('div').append('span')`
### .html()
- change the inner html of an element
### .text()
- set the content of the selection to the exact text (no html)
## Request ## Request
- AJAX functions AJAX funcions look
- `d3.json('path', function(error, data){});`
- `d3.csv('path', function(error, data){});` - `d3.json('path', function(error, data){});`
- `d3.text('path', function(error, data){});` - `d3.csv('path', function(error, data){});`
- `d3.html('path', function(error, data){});` - `d3.text('path', function(error, data){});`
- `d3.tsv('path', function(error, data){});` - `d3.html('path', function(error, data){});`
- `d3.xml('path', function(error, data){});` - `d3.tsv('path', function(error, data){});`
- `d3.xml('path', function(error, data){});`
## Data binding ## Data binding

Loading…
Cancel
Save