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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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.1k
フロントエンドテストの育て方
quramy
12
3.8k
App Router 悲喜交々
quramy
8
740
上手に付き合うコンポーネントテスト
quramy
6
2.4k
Patched fetch did not work
quramy
6
790
GraphQL あるいは React における自律的なデータ取得について
quramy
18
5.9k
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
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Everyday Curiosity
cassininazir
0
250
The World Runs on Bad Software
bkeepers
PRO
72
12k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.1k
First, design no harm
axbom
PRO
2
1.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.4k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
870
YesSQL, Process and Tooling at Scale
rocio
174
15k
Ethics towards AI in product and experience design
skipperchong
2
330
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
Thoughts on Productivity
jonyablonski
76
5.2k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
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/)