Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
2.2k
フロントエンドテストの育て方
quramy
12
3.9k
App Router 悲喜交々
quramy
8
760
上手に付き合うコンポーネントテスト
quramy
6
2.4k
Patched fetch did not work
quramy
6
810
GraphQL あるいは React における自律的なデータ取得について
quramy
18
6k
Next.js App Router
quramy
15
4k
Fragment Composition of GraphQL
quramy
17
4.9k
reg-viz VRT tools
quramy
4
1.8k
Featured
See All Featured
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
520
Technical Leadership for Architectural Decision Making
baasie
3
560
Leo the Paperboy
mayatellez
9
2.3k
Embracing the Ebb and Flow
colly
88
5.2k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
570
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
520
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
220
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
270
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
We Have a Design System, Now What?
morganepeng
55
8.3k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
190
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/)