SVG Performance with Angular

893f54413c2bd9ba41d11d753aacaf2c?s=47 Yosuke Kurami
April 20, 2016
4.2k

SVG Performance with Angular

893f54413c2bd9ba41d11d753aacaf2c?s=128

Yosuke Kurami

April 20, 2016
Tweet

Transcript

  1. 2.

    About me • Yosuke KURAMI (@Quramy) • Frontend Web Developer

    at WACUL INC. • ೔ʑͷ࢓ࣄ͸AngularJS(1.x)ͰSPA։ൃ • झຯͰTypeScript༻ͷVimϓϥΪϯ։ൃͯ͠·͢ • http://vimawesome.com/plugin/tsuquyomi 

  2. 5.

    ͓୊: D3.js • Force Layout in D3.js
 (http://bl.ocks.org/mbostock/4062045) • Node,

    Linkͷؔ܎ΛݩʹॏྗܭࢉΛߦͬͯNode ͷ഑ஔΛܾఆ͢ΔΞϧΰϦζϜ • D3.layout͸୞ͷؔ਺ͳͷͰɺComponentʹbind ͢Ε͹D3.jsҎ֎ͷFrameworkʹ΋૊ΈࠐΊΔ
  3. 6.

    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();
  4. 7.

    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ϧʔϓճ͢ඞཁ͋Γ });
  5. 8.

    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͕ಈ͘ͷͰԿ΋͢Δඞཁͳ͠ });
  6. 10.

    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