/d3-notes

Notatki do prezentacji D3 Workshop

Primary LanguageJavaScript

Notatki do slajdów z „D3 Workshop”

Będę korzystał z serwera serve (NodeJS, NPM):

npm install -g serve
cd d3-notes
serve .

Użyteczne:

Resources

Użyteczne:

SVG

D3

Blog:

Talks:

Misc

Uwagi

Zaczynamy od utworzenia elementu svg i dodania go do strony:

var svg = d3.select("body")
  .append("svg")
    .attr("width", 600)
    .attr("height", 400);

Jeśli będziemy potrzebować jakiś danych to definiujemy je teraz:

var data = [ {"x": 0, "y": 0} ];  // zawsze tablica

Po tych przygotowaniach zaczynamy dodawać różne elementy do strony:

svg.selectAll("circle")
    .data(data)
  .enter().append("circle")
    .attr("cx", data.x)
    .attr("cy", data.y)
    .attr("r", 100);

Data is Messy

This doesn’t scratch the surface of the data cleaning problem. For that, see projects such as Google Refine and Stanford’s Data Wrangler:

  • DataWrangler– an interactive tool for data cleaning and transformation
  • Google Refine – tool for working with messy data, cleaning it up, transforming it from one format into another, extending it with web services, and linking it to databases like Freebase

An example

Converting from decimal to binary + left padding with zeroes:

y = (new Array(6 - Number(5).toString(2).length)).join('0') + Number(5).toString(2)

var fillZeroes = "000000"
input = Number(5).toString(2)
fillZeroes.slice(0, input.length) + input

TL;TR