D3 JS
Java scirpt is an awesome language for Internface Design.
All Obejcts in JavaScirpt could be used as an argument to pass around.

Important Objects:
d3
var width = 500;
var height = 500;

svg obeject:
var canvas = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);

array:
var dataArray = [20, 40, 50, 60]
...
var bars = canvas.selectAll("rect")
.data(dataArray) //traverse over the array
.enter()
.append("rect")
.attr("width", function(d) {return d}) //note the annoymos function
.attr("height", 50)
.attr("y", function(d, i) {return i * 100});

scale:
var widthScale = d3.scale.linear()
.domain([0, 60])
.range([0, width]);

var color = d3.scale.linear()
.domain([0, 60])
.range(["read", "blue"])

var bars = canvas.selectAll("rect")
.data(dataArray) //traverse over the array
.enter()
.append("rect")
.attr("width", function(d) {return widthScale(d)}) //note the annoymos function
.attr("height", 50)
.attr("y", function(d, i) {return i * 100});

group: (group some svg objects together, and mainpulat on all elements of the group)

var canvas = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
.append("g")
.attr("transform", "translate(20, 0)")

The three important states when binding data elements with DOM elements
DOM elements(rect, circle)
Data elements(xArray = [1, 2, 3, 5, 7])
The beautiful: mainpulate the DOM elements through the data elements

Three states:(when binding) for each DOM element and data element
1. DOM elements :< data elements (enter) : for the data element that do not bond to a DOM element
2. DOM elements :> data elements (exit) : for the DOM element that do not bond to a data element
3. DOM elements := data elements (update) : the element justly bond to a DOM element

Example:
var data = [10, 20];
var canvas = d3.select("body")
.append("svg")
.attr("width", 500)
.attr("height", 500)

update state and enter state:
var circle1 = canvas.append("circle")
.attr("cx", 50)
.attr("cy", 100)
.attr("r", 25)

var circles = canvas.selectAll("circle") //select all circles
.data(data)
.attr("fill", "red") // for data element "10" and circle1
.enter() // for data element "20"
.append("circle")
.attr("cx", 50)
.attr("cy", 50)
.attr("fill", "green")
.attr("r", 25);

Update state and exit state:
var data = [10];
var canvas = d3.select("body")
.append("svg")
.attr("width", 500)
.attr("height", 500)

var circle1 = canvas.append("circle")
.attr("cx", 50)
.attr("cy", 100)
.attr("r", 25)

var circle2 = canvas.append("circle")
.attr("cx", 50)
.attr("cy", 200)
.attr("r", 25)

var circles = canvas.selectAll("circle") //select all circles
.data(data)
.attr("fill", "red") // for data element "10" and circle1
.exit() // for circle2
.attr("fill", "blue")

Animation effects: Using transition

var canvas = d3.select("body")
.append("svg")
.attr("width", 500)
.attr("height", 500)

var circle = cavas.append("circle")
.attr("cx", 50)
.attr("cy", 50)
.attr("r", 25)

circle.transition()
.duration(1500)
.attr("cx", 150)
.transition()
.attr("cy", 200)
.transition()
.attr("cx", 50)

Add event listener for animation:

circle.transition()
.duration(1500)
.attr("cx", 150)
.each("end", function() {d3.select(this).attr("fill", "red")})
//when the transition is over, change color

Loading External data (use properly with call back mechanism)

//when the load process finished, the "data" would be passed into the function
d3.json("mydata.json", function (data)) {
//the critical part is to understand how arguments were passed around
var canvas = d3.select("body").append("svg")
.attr("width", 500)
.attr("height", 500)

canvas.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("width", function(d) { return d.age * 10; })
.attr("height", 50)
.attr("y", function(d, i) { return i * 50;})
.attr("fill", "blue")

canvas.selectAll("text")
.data(data)
.enter()
.append("text")
.attr("fill", "white")
.attr("y", function (d, i) { return i * 50; })
.text(function (d) {return d.name; })
}}

The powerfull "Path" Componet in D3.JS

var canvas = d3.select("body").append("svg")
.attr("width", 500)
.attr("height", 500)

var data = [
{x: 10, y: 20},
{x: 40, y: 60},
{x: 50, y: 70}
];

var group = canvas.append("g") //create a group over the canvas
.attr("transform", "translate(100, 100)");

var line = d3.svg.line()
.x(function (d) { return d.x; })
.y(function (d) { return d.y; })

group.selectAll("path")
.data([data]) //pass in as only one array
.enter()
.append("path")
.attr("d", line) //directly pass the data array to constract line.
.attr("fill", "none")
.attr("stroke", "#000")
.attr("stroke-width", 10);

The powerful "Arc" Componet in D3.JS

var canvas = d3.select("body").append("svg")
.attr("width", 500)
.attr("height", 500)

var group = canvas.append("g")
.attr("transform", "translate(100, 100)");

var r = 100;
var p = Math.PI * 2;

var arc = d3.svg.arc()
.innerRadius(r - 20)
.outerRadius(r)
.startAngle(0)
.endAngle(p);

group.append("path")
.attr("d", arc)

Layout: D3JS has provieded convenient libraires for converting a number/array into a layout object(array).
Combine group, component and layout to create an awesome work.
***How to refer a group is very very important!
1. create container(document componet with proper group)
2. prepare data by using proper layout function
3. bind the data with container

var data = [10, 50, 80];
var r = 300;

var color = d3.scale.ordinal()
.range(["red", "blue", "orange"]);

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

var group = canvas.append("g") //create the canvas group
.attr("transform", "translate(300, 300)");

var arc = d3.svg.arc()
.innerRadius(200)
.outerRadius(r);

//convert the passed in array into into the objects for creating arc
var pie = d3.layout.pie()
.value(function (d) { return d; });

var arcs = group.selectAll(".arc")
.data(pie(data))
.enter()
.append("g") //each arc is a group in the arcs group
.attr("class", "arc");

//note here, we use arcs to refer all arc contains in the arcs
//the same execution would be performed over all arcs
arcs.append("path")
.attr("d", arc) //we use arc as passed in object to constract the path
.attr("full", function (d) { return color(d.data);});

arcs.append("text")
.attr("transform", function(d) {return "translate(" + arc.centroid(d) +")"})
.attr("text-anchor", "middle")
.attr("front-size", "1.5em")
.text(function (d) {return d.data;});

The Tree Layout:
//Path could be used to create any sharp

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

var diagonal = d3.svg.diagonal()
.source({x: 10, y: 10})
.target({x: 300, y: 300});

canvas.append("path")
.attr("fill", "none")
.attr("stroke", "black")
.attr("d", digonal) //all use pass as container, but depict based on passed in object

The fundamental knowledge of Node JS.的更多相关文章

  1. [转]Getting Start With Node.JS Tools For Visual Studio

    本文转自:http://www.c-sharpcorner.com/UploadFile/g_arora/getting-started-with-node-js-tools-for-visual-s ...

  2. A chatroom for all! Part 1 - Introduction to Node.js(转发)

    项目组用到了 Node.js,发现下面这篇文章不错.转发一下.原文地址:<原文>. ------------------------------------------- A chatro ...

  3. (翻译)《Hands-on Node.js》—— Introduction

    今天开始会和大熊君{{bb}}一起着手翻译node的系列外文书籍,大熊负责翻译<Node.js IN ACTION>一书,而我暂时负责翻译这本<Hands-on Node.js> ...

  4. Base64 Encoding / Decoding in Node.js

    Posted on April 20th, 2012 under Node.js Tags: ASCII, Buffer, Encoding, node.js, UTF So how do you e ...

  5. [转]Building a REST-Backend for Angular with Node.js & Express

    本文转自:https://malcoded.com/posts/angular-backend-express Angular is a single page application framewo ...

  6. Node.js v7.4.0 Documentation Addons

    https://nodejs.org/docs/latest/api/addons.html Node.js Addons are dynamically-linked shared objects, ...

  7. Node.js NPM Tutorial

    Node.js NPM Tutorial – How to Get Started with NPM? NPM is the core of any application that is devel ...

  8. node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理

    一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...

  9. 利用Node.js的Net模块实现一个命令行多人聊天室

    1.net模块基本API 要使用Node.js的net模块实现一个命令行聊天室,就必须先了解NET模块的API使用.NET模块API分为两大类:Server和Socket类.工厂方法. Server类 ...

随机推荐

  1. 熟练掌握HDFS的Java API接口访问

    HDFS设计的主要目的是对海量数据进行存储,也就是说在其上能够存储很大量文件(可以存储TB级的文件).HDFS将这些文件分割之后,存储在不同的DataNode上, HDFS 提供了两种访问接口:She ...

  2. Android推送技术研究

    前言 最近研究Android推送的实现, 研究了两天一夜, 有了一点收获, 写下来既为了分享, 也为了吐槽. 需要说明的是有些东西偏底层硬件和通信行业, 我对这些一窍不通, 只能说说自己的理解. 为什 ...

  3. 如何自定义echarts主题

    上一篇,选择echarts原有的主题样式,那么如何自定义自己的主题 与选择原有主题类似 1.echarts官网地址http://echarts.baidu.com/echarts2/doc  在工具中 ...

  4. ASP.NET图片验证码

    1. 新建一个Validate.aspx,然后在Validate.aspx.cs编写代码: using System; using System.Collections; using System.C ...

  5. mysql workbench 建表时 PK,NN,UQ,BIN,UN,ZF,AI解释

    mysql workbench 建表时 - PK: primary key (column is part of a pk) 主键 - NN: not null (column is nullable ...

  6. 对 Xcode 菜单选项的详细探索(转)

    转自 http://www.cnblogs.com/dsxniubility/p/4983614.html 本文调研Xcode的版本是 7.1,基本是探索了菜单的每一个按钮.虽然从xcode4一直用到 ...

  7. 重要性!important

    我们在做网页代码的时,有些特殊的情况需要为某些样式设置具有最高权值,怎么办?这时候我们可以使用!important来解决. 如下代码: p{color:red!important;} p{color: ...

  8. javascript基础学习(四)

    javascript之流程控制语句 学习要点: 表达式语句含义 选择语句:if.if...else.switch 循环语句:while.do...while.for.for...in 跳转语句:bre ...

  9. 总结Widows 7 Start->Run 命令

    Widows + R基本上成为很常用的方式,那么通过Windows + R我们可以在运行中做什么手脚呢. 下面从最基本的系统命令说起 notepad--------打开记事本    services. ...

  10. 浅说prop与attr的区别

    jquery中attr和prop的区别   在高版本的jquery引入prop方法后,什么时候该用prop?什么时候用attr?它们两个之间有什么区别?这些问题就出现了. 关于它们两个的区别,网上的答 ...