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 Performance with Angular
Search
Yosuke Kurami
April 20, 2016
4.5k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SVG Performance with Angular
Yosuke Kurami
April 20, 2016
More Decks by Yosuke Kurami
See All by Yosuke Kurami
TypeScript LSP の今までとこれから
quramy
1
2k
フロントエンドテストの育て方
quramy
12
3.8k
App Router 悲喜交々
quramy
8
730
上手に付き合うコンポーネントテスト
quramy
6
2.3k
Patched fetch did not work
quramy
6
780
GraphQL あるいは React における自律的なデータ取得について
quramy
18
5.8k
Next.js App Router
quramy
15
3.9k
Fragment Composition of GraphQL
quramy
17
4.8k
reg-viz VRT tools
quramy
4
1.7k
Featured
See All Featured
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
610
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
830
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
360
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
140
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Practical Orchestrator
shlominoach
191
11k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
190
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
530
Become a Pro
speakerdeck
PRO
31
6k
Transcript
SVG Performance with Angular @Quramy 2016.04.20 #ng_sake
About me • Yosuke KURAMI (@Quramy) • Frontend Web Developer
at WACUL INC. • ʑͷࣄAngularJS(1.x)ͰSPA։ൃ • झຯͰTypeScript༻ͷVimϓϥΪϯ։ൃͯ͠·͢ • http://vimawesome.com/plugin/tsuquyomi
Angular2ຊʹ͍ͷ͔ʁ
ࢼͯ͠Έͨ
͓: D3.js • Force Layout in D3.js (http://bl.ocks.org/mbostock/4062045) • Node,
LinkͷؔΛݩʹॏྗܭࢉΛߦͬͯNode ͷஔΛܾఆ͢ΔΞϧΰϦζϜ • D3.layoutͷؔͳͷͰɺComponentʹbind ͢ΕD3.jsҎ֎ͷFrameworkʹΈࠐΊΔ
Force Layout const size = 600; const force = d3.layout.force()
.nodes(this.UserLink.nodes()) .links(this.UserLink.links()) .size([size, size]) .gravity(1.1) .friction(0.98) .charge(-30) .linkDistance(size / 18.0) .alpha(.9) ; const nodes = <UserNode[]>force.nodes(); // nodeͷ࠲ඪใͷऔಘ const links = <Link[]>force.links(); // linkͷ࠲ඪใͷऔಘ force.on('tick', () => { // ߋ৽ຖͷϋϯυϥΛ͜͜ʹॻ͘ }); force.start();
With AngularJS 1.5 <svg> <g ng-if="ctrl.nodes.length && ctrl.links.length"> <line ng-repeat="link
in ctrl.links" ng-attr-x1="{{link.source.x}}" ng-attr-y1="{{link.source.y}}" ng-attr-x2="{{link.target.x}}" ng-attr-y2="{{link.target.y}}" ></line> <circle ng-repeat="node in ctrl.nodes" r="5" title="node.id" ng-attr-cx="{{node.x}}" ng-attr-cy="{{node.y}}" ng-attr-fill="{{ctrl.hsl(node)}}" ng-click="ctrl.onClick(node)" ng-class="{selected: node.id===ctrl.selectedNode.id}" ></circle> </g> </svg> force.on('tick', () => { this.$scope.$digest(); // ࣗͰDigestϧʔϓճ͢ඞཁ͋Γ });
With Angular 2 <svg> <g *ngIf="nodes?.length && links?.length"> <line *ngFor="#link
of links" [attr.x1]="link.source.x" [attr.y1]="link.source.y" [attr.x2]="link.target.x" [attr.y2]="link.target.y" ></line> <circle *ngFor="#node of nodes" r="5" [attr.title]="node?.id" [attr.cx]="node.x" [attr.cy]="node.y" [attr.fill]="hsl(node)" (click)="onClick(node)" [class.selected]="node?.id===selectedNode?.id" ></circle> </g> </svg> force.on('tick', () => { // উखʹzone.js͕ಈ͘ͷͰԿ͢Δඞཁͳ͠ });
Demonstration http://quramy.github.io/ng-svg-perf/ng1/ http://quramy.github.io/ng-svg-perf/ng2/
Results 7PMVNF$POEJUJPO "OHVMBS+4 "OHVMBS CFUB d/PEFT d-JOLT '14 '14 d/PEFT
d-JOLT '14 '14 d/PEFT d -JOLT '14 '14 d /PEFT d -JOLT '14 '14
Angular2ຊʹ͔ͬͨ(͜ͳΈ)
ࢀߟ • Angular2ͰͱΓ͋͑ͣSVGΛඳ͍ͯΈΔ (http://qiita.com/_likr/items/b2cbaa0e5e3e21a92e57) • D3.js on AngularJSͷ࣮ύλʔϯൺֱ (http://qiita.com/Quramy/items/4ed72ae91899b47fb167) •
Replacing (most of) d3.js with pure SVG + AngularJS (http://alexandros.resin.io/angular-d3-svg/)