Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SVG + D3.JS Course Slide
Search
tkirby
May 28, 2015
Education
0
180
SVG + D3.JS Course Slide
tkirby
May 28, 2015
Tweet
Share
More Decks by tkirby
See All by tkirby
前端網頁資料視覺化設計
tkirby
1
380
Theory of Graphical Perception
tkirby
0
370
Open Refine Course
tkirby
0
170
Language Reference
tkirby
0
85
新聞記者的程式設計第一課
tkirby
0
440
Visualization over Web
tkirby
0
94
迎戰壞資料 @ dbootcamp Taipei
tkirby
0
680
Rasterize D3.js
tkirby
7
1.5k
資料新聞學手冊導讀
tkirby
0
200
Other Decks in Education
See All in Education
Поступление в ТОГУ 2024
pnuslide
0
34k
財務分析 - 入門編
lsuzuki
0
360
自由の森学園学校紹介資料
jiyunomori
0
1.4k
保育とふりかえりをコネクト! / connect childcare and retrospectives!
psj59129
1
140
【滋賀大学データサイエンス学部】PropTech(不動産テック)における AI・データサイエンス活用
takehikohashimoto
0
4.1k
2024年度春学期 統計学 講義の進め方と成績評価について (2024. 4. 11)
akiraasano
PRO
0
100
5 занятие. Разбор метода "8 кубиков"бизнес-модели #ideaNN 16.02.2024.
karlov
0
180
「小・中・高等学校における情報教育の体系的な学習を目指したカリキュラムモデル基本方針」
codeforeveryone
0
1.3k
Switches
irocho
0
180
AWS試験全冠したら新しい道が開けた話
nagisa53
3
1.1k
経験に複利を効かせろ!ふりかえり研修2024
pokotyamu
19
7.3k
Railsチュートリアルの歩き方 (第7版)
yasslab
PRO
1
1M
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
258
12k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
186
16k
Typedesign – Prime Four
hannesfritz
36
2.1k
Atom: Resistance is Futile
akmur
258
25k
Fantastic passwords and where to find them - at NoRuKo
philnash
36
2.5k
Building Adaptive Systems
keathley
30
1.8k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
356
22k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
5
1.5k
StorybookのUI Testing Handbookを読んだ
zakiyama
11
4.6k
Large-scale JavaScript Application Architecture
addyosmani
503
110k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
658
120k
Raft: Consensus for Rubyists
vanstee
132
6.2k
Transcript
Visualization over Web
HTML <a href=“link”>content</a> <img src=“blah.png”> <br> <a href=“link”> this link
</a> links to a page <br> <p><a href=“link”> this link </a> links to a page </p>
block / inline-block table / list / flex … static
/ relative absolute / fixed … Display Mode Position Method
None
Scalable Vector Graphics SVG
<p> <svg> … </svg> </p>
<svg> <rect x=“10” y=“10” width=“20” height=“20”> </svg>
<circle> <ellipse> <line> <path> <text> hello world!
<circle cx=“10” cy=“10” r=“10” >
<ellipse cx=“10” cy=“10” rx=“20” ry=“10” >
<line x1=“10” y1=“10” x2=“20” y2=“20” >
<circle cx=“10” cy=“10” r=“10” stroke=“color” fill=“color” stroke-width=“size” >
None
#abcdef RG B 0 ~ 255 = 0 ~ ff
#adf = #aaddff
#abcdef RG B rgb(255,128,64) rgba(255,128,64,0.8)
<circle cx=“10” cy=“10” r=“10” stroke=“black” fill=“#8fc” stroke-width=“5” >
Exercise 1
?
None
None
<path d=“....”> M (x,y)+ - Move to (+ lineto) Z
- Close Path L (x,y)+ - Line to C (x1,y1,x2,y2,x,y)- Curve to ctrl1 ctrl2 M1,1 L2,1 L 2,2 L1,2Z
<path d=“....”> M1,1 L2,1 L 2,2 L1,2Z (1,1) (2,1) (2,2)
(1,2) M L L L Z
<path d=“....”> M (x,y)+ - Move to (+ lineto) C
(x1,y1,x2,y2,x,y)- Curve to ctrl1 ctrl2
None
<path d=“....”> Q (x1,y1,x,y)+ - Quadratic Bezier T (x,y)+ -
Quadratic Bezier
<path d=“....”> A (rx,ry,a,b,c,x,y)+ - Quadratic Bezier
<path d=“....”> m (x,y)+ - Move to (+ lineto) z
- Close Path l (x,y)+ - Line to c (x1,y1,x2,y2,x,y)+ - Curve to ctrl1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0.8-1.6l5.2,0.5c0.7-2,1.3-4, 1.6-6.2l-4.8-2.1C74.9,51.7,75,51.1,75,50.5zM50,65c-8.3,0-15-6.7-1 5-15c0-8.3,6.7-15,15-15s15,6.7,15,15 C65,58.3,58.3,65,50,65z d=“ ”
http://goo.gl/fPUFgv SVG Editor
Exercise 2
<path d=“……” fill=“…” stroke=“…” stroke-width=“size” stroke-dasharray=“…” stroke-dashoffset=“…” transform=“ translate(x y)
rotate(r x y) scale(x y) ” >
None
transform=“ translate(x,y) “
transform=“ rotate(r,x,y) “
transform=“ scale(x,y) “
<text x=“0” dx=“0” y=“0” dy=“0” text-anchor=“middle" dominant-baseline="central" textLength=“100" rotate=“ 30
60 90 120 150 180 210 240 270 300 330 360”> helloworld! </text>
Hello World! Hello World! Hello World! start middle end Hello
World! dominant-baseline text-anchor central
rotate=“ 30 60 90 120 150 180 210 240 270
300 330 360”
SMIL <path d=“……”> <animate/> <animateTransform/> <animateMotion/> Animation in SVG (IE
not support)
<animate/> 屬性變化 <animateTransform/> 線性轉換變化 <animateMotion/> 路徑
<animate attributeName=“r” dur=“1s” repeatCount=“indefinite” from=“…” to=“…” begin=“…” end=“…” values=“…” keyTimes=“…”
keySplines=“…” calcMode=“…”/> discrete,paced,linear,spline
<animateTransform attributeName=“transform” type=“…”/> <animateMotion> <mpath xlink:href=“…”/> </animateMotion>
<ellipse rx=“1” ry=“8”> <animate attributeName=“rx” from=“1” to=“10” dur=“1s” repeatCount=“indefinite”/>
<animateTransform attributeName=“transform” type=“rotate” from=“0” to=“180” dur=“0.5s” repeatCount=“indefinite”/> </ellipse>
Coordinate <svg width=“200px” height=“200px” viewBox=“0 0 100 100” preserveAspectRatio=“…”> ……
</svg> preserveAspectRatio=“None” or x{Min,Mid,Max}Y{Min,Mid,Max}
width height (x1,y1) (x2,y2) <svg width=“w” height=“h” viewBox=“x1 y1 x2
y1”>
None
preserveAspectRatio xMin xMid xMax yMin yMid yMax
D3JS js library for manipulating documents based on data <script
type=“text/javascript” src=“d3.min.js”></script> <script type=“text/javascript”> d3.json(“data.json”, function(data) { min = d3.min(data); }); </script>
Data Driven Document Model Powerful Visualizing Lib d3js d3js d3js
d3js d3js d3js d3js d3js d3js d3js
data data data data data selection enter exit selection
data data data data selection enter exit selection d3.selectAll(“div”) .data(data)
.enter().append(“div”) .exit().remove() d3.selectAll(“div”)
new data data new data.onChange enter exit selection
Topic 1 - Selections
d3.select(“body”) .attr(“class”, “root”) d3.select(“body”) .style({ background: “#999”, color: “#009” })
d3.select(“body”) .text(“123”); d3.select(“body”) .html(“123”);
d3.select(“body”).selectAll(“div”) .style({ background: “#999”, color: “#009” }) d3.select(“body”).selectAll(“div”) .style({ background:
function() { return “#f00” }, color: “#009” })
d3.select(“body”).selectAll(“div”) .style({ background: function(d,i) { return "rgba("+(i*85)+",128,192,1)"; }, color: “#009”
})
d3.select(“body”).selectAll(“div”) .data([“#f00”,”#f90”,”#ff0”]) .style({ background: function(d,i){ return d; }, color: “#009”
})
v = d3.select(“body”).selectAll(“div”) .data([“#f00”,”#f90”,”#ff0”]) v.exit().remove(); v.enter().append(“div”); d3.select(“body”).selectAll(“div”) .style({ background: function(d,i){
return d; }, color: “#009” }) .text(function(d) { return d; });
Topic 2 - Utilities
Utility functions d3.json(path, callback) d3.csv(path, accessor, callback) d3.html(path, callback) d3.text(path,
type, callback) d3.xhr() …
Utility functions d3.min(array) d3.max(array) d3.sum(array) d3.mean(array) d3.median(array) d3.random.normal d3.set set.has
set.forEach d3.map map.has map.forEach d3.transition d3.svg
Scale functions d3.scale.linear().domain(array).range(array) radius = d3.scale.linear() .domain([d3.min(data), d3.max(data)]) .range([“#f00”,”#00f”]) ticks
= radius.ticks(20); d3.scale.pow().exponent(3).domain(array).range(array) d3.scale.log().domain(array).range(array)
Scale functions d3.scale.linear() .domain([0,100]) .range([“#000”,”#f00”]) d3.scale.category10() d3.scale.category20() d3.scale.category20b() d3.scale.category20c()
Topic 3 - Layout
Pack Layout
Pack Layout nodes = d3.layout.pack().size([w,h]) .nodes(data) structure of data: {
value: ?, children: [ ] } { value: ?, children: [ ], parent, depth, x, y, r }
{ parent: null, children: [ {value: 3}, {value: 1}, {value:
4}, {value: 1}, {value: 5}, ………… ] } c = data.map( function(d) { return {value: d}; } ); root = { children: c }
{ parent: null, children: [ {value: 3}, {value: 1}, {value:
4}, {value: 1}, {value: 5}, ………… ] } [ {value:0,depth: 0, x:…, y:…, r:…}, {value:3,depth: 1, x:…, y:…, r:…}, {value:1,depth: 1, x:…, y:…, r:…}, {value:4,depth: 1, x:…, y:…, r:…}, …… ]
Pack Layout d3.layout.pack() .sort(function(a,b) {…}) .padding(5) .size([w,h]) .nodes(data) d3.layout.pack().links(nodes) {
source: <node>, target: <node> }
Partition Layout d3.layout.partition() .sort(function(a,b) {…}) .size([w,h]) .nodes(data) d3.layout.partition().links(data) { value:
?, children: [], parent, depth, x, y, r, dx, dy }
arc = d3.svg.arc() .startAngle(function(d) { return d.x; }).endAngle(function(d) { return
d.x + d.dx; }).innerRadius(function(d) { return Math.sqrt(d.y); }).outerRadius(function(d) { return Math.sqrt(d.y + d.dy); }); Use d3.svg.arc * also check the pie layout
Force Layout d3.layout.force() .size() .gravity() .charge() .friction() .nodes() .start() d3.on(“tick”,
callback) [{…},{…},…] [ {…, x:…, y:…}, {…, x:…, y:…}, {…, x:…, y:…}, … ]
data = [1,2,3,4].map(function(d) { return {v:d}; }); force = d3.layout.force().nodes(data);
force.on(“tick”, function() { d3.selectAll(“…”).attr({ x: function(d) { return d.x; }, y: function(d) { return d.y; }, … }); force.start();
Cluster Layout d3.layout.cluster() .sort(function(a,b) {…}) .size([w,h]) .nodes(data) d3.layout.cluster().links(data) { value:
?, children: [], parent, depth, x, y }