SlideShare a Scribd company logo
1 of 49
SVG, Canvas e
Animations in
Angular
Leonardo Buscemi
Agenda
Premessa
SVG CANVAS
Librerie terze parti
Confronti
Angular compila il nostro codice
Tutto quello che scriviamo nella nostra applicazione
Angular (componenti, logica e stili) viene ‘compilato’
in codice Javascript.
Elementi SVG
<rect x="120" y="0" width="100" height="100" rx="0" ry="0" />
<circle cx="50" cy="50" r="50"/>
<polygon points="20,0 80,0 100,50 0,50" />
<path d="M 10,30 A 20,20 0,0,1 50,30 A 20,20 0,0,1 90,30 Q 90,60 50,90 Q 10,60 10,30 z"/>
SVG Elements
Simple (static) Component with SVG
import { Component } from @angular/core';
@Component({
selector: 'my-component',
template: `
<svg viewBox="0 0 250 250">
<g>
<polygon class="st0" fill="#DD0031" points="125,153 … 153.4" />
<polygon class="st0" fill="#DD0031" points="108,135 … 125,94.5" />
</g>
<g class="st1">
<polygon class="st0" fill="#C3002F" points="125,153 … 3.4" />
<polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" />
</g>
</svg> `,
})
export class AppComponent {}
Angular needs to know is SVG
<svg:rect x="0" y="0" width="100" height="100"/>
“An SVG snippet template needs an svg: prefix on its root element to disambiguate the SVG
element from an HTML component.”
Fonte
Fonte
Simple (static) Component with SVG
import { Component } from @angular/core';
@Component({
selector: 'my-component',
template: `
<svg viewBox="0 0 250 250">
<g>
<polygon class="st0" fill="#DD0031" points="125,153 … 153.4" />
<polygon class="st0" fill="#DD0031" points="108,135 … 125,94.5" />
</g>
<g class="st1">
<polygon class="st0" fill="#C3002F" points="125,153 … 3.4" />
<polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" />
</g>
</svg> `,
})
export class AppComponent {}
Simple (static) Component with SVG
import { Component } from @angular/core';
@Component({
selector: 'my-component',
template: `
<svg viewBox="0 0 250 250">
<svg:g>
<svg:polygon class="st0" fill="#DD0031" points="125,153 … 153.4" />
<svg:polygon class="st0" fill="#DD0031" points="108,135 … 125,94.5" />
</svg:g>
<svg:g class="st1">
<svg:polygon class="st0" fill="#C3002F" points="125,153 … 3.4" />
<svg:polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" />
</svg:g>
</svg> `,
})
export class AppComponent {}
Esempio live
https://stackblitz.com/edit/angular-svg-static
Component with SVG
import { Component } from @angular/core';
@Component({
selector: 'my-component',
template: `
<svg viewBox="0 0 250 250">
<svg:g>
<svg:polygon class="st0" fill="#DD0031" points="125,153 … 153.4" />
<svg:polygon class="st0" fill="#DD0031" points="108,135 … 125,94.5" />
</g>
<svg:g class="st1">
<svg:polygon class="st0" fill="#C3002F" points="125,153 … 3.4" />
<svg:polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" />
</g>
</svg> `,
})
export class AppComponent {}
Component with SVG
import { Component } from @angular/core';
@Component({
selector: 'my-component',
template: `
<svg viewBox="0 0 250 250">
<svg:g>
<svg:polygon class="st0" fill="#DD0031" points="125,153 … 153.4" />
<svg:polygon class="st0" fill="#DD0031" [points]="someMagic()" />
</g>
<svg:g class="st1">
<svg:polygon class="st0" fill="#C3002F" points="125,153 … 3.4" />
<svg:polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" />
</g>
</svg> `,
})
export class AppComponent {}
Component with SVG
import { Component } from @angular/core';
@Component({
selector: 'my-component',
template: `
<svg viewBox="0 0 250 250">
<svg:g>
<svg:polygon class="st0" fill="#DD0031" points="125,153 … 153.4" />
<svg:polygon class="st0" fill="#DD0031" [points]="someMagic()" />
</g>
<svg:g class="st1">
<svg:polygon class="st0" fill="#C3002F" points="125,153 … 3.4" />
<svg:polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" />
</g>
</svg> `,
})
export class AppComponent {}
HTML attribute vs. DOM property
❖ Alcuni attributi HTML hanno un mapping 1: 1 alle proprietà
➢ Ad esempio id
❖ Alcuni attributi HTML non hanno proprietà corrispondenti
➢ Ad esempio colspan e tutti gli attributi svg
❖ Alcune proprietà DOM non hanno attributi corrispondenti
➢ Ad esempio textContent
❖ Molti attributi HTML sembrano mappare alle proprietà ... ma non nel modo in cui si potrebbe pensare!
Gli attributi inizializzano le proprietà del DOM, queste possono cambiare; i valori degli attributi no.
Fonte
Un mondo senza attributi
In Angular l'unico scopo degli attributi è quello di inizializzare lo stato degli elementi e direttive, una volta
compilati gli attributi spariscono!
Fonte
Fonte
È necessario utilizzare il binding dell'attributo quando non esiste alcuna proprietà dell'elemento da associare.
Component with SVG
import { Component } from @angular/core';
@Component({
selector: 'my-component',
template: `
<svg viewBox="0 0 250 250">
<svg:g>
<svg:polygon class="st0" fill="#DD0031" points="125,153 … 153.4" />
<svg:polygon class="st0" fill="#DD0031" [attr.points]="someMagic()" />
</g>
<svg:g class="st1">
<svg:polygon class="st0" fill="#C3002F" points="125,153 … 3.4" />
<svg:polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" />
</g>
</svg> `,
})
export class AppComponent {}
Esempio live
https://stackblitz.com/edit/angular-svg-attribute
Suddivisione in componenti
import { Component } from '@angular/core';
@Component({
selector: 'my-part-left',
template: `
<svg:g >
<svg:polygon fill="#DD0031"
points="125,153.4 … 125,94.5" />
</svg:g>`
})
export class PartLeftComponent {
}
import { Component } from '@angular/core';
@Component({
selector: 'my-part-right',
template: `
<svg:g >
<svg:polygon fill="#C3002F"
points="125,153.4 … 125,94.5" />
</svg:g>`
})
export class PartRightComponent {
}
Suddivisione in componenti
<svg viewBox="0 0 250 250">
<my-part-left></my-part-left>
<my-part-right></my-part-right>
</svg>
Non viene renderizzato!
Selettore per attributo
import { Component } from '@angular/core';
@Component({
selector: '[my-part-left]',
template: `
<svg:g >
<svg:polygon fill="#DD0031"
points="125,153.4 ... 125,94.5" />
</svg:g>`
})
export class PartLeftComponent {
}
import { Component } from '@angular/core';
@Component({
selector: '[my-part-right]',
template: `
<svg:g >
<svg:polygon fill="#C3002F"
points="125,153.4 125,94.5" />
</svg:g>`
})
export class PartRightComponent {
}
Suddivisione in componenti OK
<svg viewBox="0 0 250 250">
<svg:g my-part-left />
<svg:g my-part-right />
</svg>
Esempio live
https://stackblitz.com/edit/angular-svg-components
Animazioni su SVG
● SMIL
○ Deprecato
● CSS
● Angular Animation
● Javascript
○ Green Sock
Esempio live
Animazione di SVG in CSS
https://stackblitz.com/edit/angular-svg-components
Angular Animation
npm i @angular/animations
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
@NgModule({
imports: [ BrowserModule, BrowserAnimationsModule, FormsModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Esempio live
Animazione di SVG con
Angular Animation
https://stackblitz.com/edit/angular-svg-anim-ng
Animazione in Javascript
Vogliamo animare anche la proprietà points del nostro polygon
@ViewChild e
template reference
https://stackblitz.com/edit/viewchild-template-ref
Greensock
npm i gsap @types/greensock
import { Component, ViewChild, ElementRef } from '@angular/core';
import 'gsap';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
})
export class AppComponent {
@ViewChild('left') left: ElementRef;
@ViewChild('right') right: ElementRef;
ngOnInit() {
TweenMax.to(this.left.nativeElement, 2, {
attr: {
points: "125,153.4 … 125,195"
},
repeat: -1, yoyo: true, ease: Cubic.easeInOut
});
TweenMax.to(this.right.nativeElement, 2, {
attr: {
points: "125,153.4 … 125,153.4"
},
repeat: -1, yoyo: true, ease: Cubic.easeInOut
});
}
}
Esempio live
Animazione di SVG con GreenSock
https://stackblitz.com/edit/angular-svg-static-grensock
Canvas
SVG usa il modello “retained”
Fonte
È un modello dichiarativo. L’applicazione costruisce la scena utilizzando elementi
grafici (linee, forme) della libreria grafica che si occupa di creare il modello della scena
e inviare i comandi di disegno.
Canvas usa il modello ‘immediate’
Fonte
È un modello procedurale. L’applicazione invia direttamente i comandi di disegno e
deve tenere traccia del modello della scena
“Simple” Canvas component
import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
selector: 'my-app',
template: '<canvas #myCanvas height="200" width="200" ></canvas>'
})
export class AppComponent {
@ViewChild("myCanvas") canvasRef: ElementRef;
private ctx: CanvasRenderingContext2D;
ngOnInit() {
this.ctx = this.canvasRef.nativeElement.getContext('2d');
this.drawBorder();
this.drawPoint();
}
drawPoint() {
this.ctx.beginPath();
…
this.ctx.fill();
}
drawBorder() {
this.ctx.beginPath();
…
this.ctx.stroke();
}
}
Esempio live
Componente con canvas
https://stackblitz.com/edit/angular-canvas-simple
Esempio live
Animazione con canvas
https://stackblitz.com/edit/angular-canvas-animation
Librerie terze parti
SVG
● Raphael
● SnapSVG
● D3
CANVAS
● EaselJS
● ChartJS
● ThreeJS
Raphael
SnapSVG
D3.js
EaselJS
ChartJS
ThreeJS
Confronto SVG ⇔ Canvas
SVG CANVAS
Grafica Vettoriale Raster
Rendering Retained Immediate*
Utilizzo Markup XML Low level API
Quale scegliere ?
https://technet.microsoft.com/it-it/gg193983(v=vs.71)
Leonardo Buscemi
Software Developer presso
https://www.linkedin.com/in/leonardobuscemi/
https://www.facebook.com/leonardo.buscemi
https://twitter.com/leonardobuscemi
GRAZIE

More Related Content

What's hot

AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - ServicesNir Kaufman
 
Angular Mini-Challenges
Angular Mini-ChallengesAngular Mini-Challenges
Angular Mini-ChallengesJose Mendez
 
The battle of Protractor and Cypress - RunIT Conference 2019
The battle of Protractor and Cypress - RunIT Conference 2019The battle of Protractor and Cypress - RunIT Conference 2019
The battle of Protractor and Cypress - RunIT Conference 2019Ludmila Nesvitiy
 
How to build an AngularJS backend-ready app WITHOUT BACKEND
How to build an AngularJS backend-ready app WITHOUT BACKEND How to build an AngularJS backend-ready app WITHOUT BACKEND
How to build an AngularJS backend-ready app WITHOUT BACKEND Enrique Oriol Bermúdez
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practicesHenry Tao
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developersKai Koenig
 
Styling recipes for Angular components
Styling recipes for Angular componentsStyling recipes for Angular components
Styling recipes for Angular componentsNir Kaufman
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS BasicsRavi Mone
 
AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.Yan Yankowski
 
ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2Demey Emmanuel
 
Technozaure - Angular2
Technozaure - Angular2Technozaure - Angular2
Technozaure - Angular2Demey Emmanuel
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injectionEyal Vardi
 
Building Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularBuilding Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularIlia Idakiev
 
Beyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreBeyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreAri Lerner
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBDynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBApaichon Punopas
 
Top 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppTop 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppKaty Slemon
 

What's hot (20)

AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
Angular Mini-Challenges
Angular Mini-ChallengesAngular Mini-Challenges
Angular Mini-Challenges
 
The battle of Protractor and Cypress - RunIT Conference 2019
The battle of Protractor and Cypress - RunIT Conference 2019The battle of Protractor and Cypress - RunIT Conference 2019
The battle of Protractor and Cypress - RunIT Conference 2019
 
How to build an AngularJS backend-ready app WITHOUT BACKEND
How to build an AngularJS backend-ready app WITHOUT BACKEND How to build an AngularJS backend-ready app WITHOUT BACKEND
How to build an AngularJS backend-ready app WITHOUT BACKEND
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
 
Solid angular
Solid angularSolid angular
Solid angular
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Angularjs
AngularjsAngularjs
Angularjs
 
Styling recipes for Angular components
Styling recipes for Angular componentsStyling recipes for Angular components
Styling recipes for Angular components
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.
 
ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2
 
Technozaure - Angular2
Technozaure - Angular2Technozaure - Angular2
Technozaure - Angular2
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
 
Building Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularBuilding Reusable Custom Elements With Angular
Building Reusable Custom Elements With Angular
 
Beyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and moreBeyond AngularJS: Best practices and more
Beyond AngularJS: Best practices and more
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBDynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
 
Top 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppTop 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular App
 
Angular js-crash-course
Angular js-crash-courseAngular js-crash-course
Angular js-crash-course
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 

Similar to Svg, canvas e animations in angular (3 maggio 2019)

angular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdfangular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdfNuttavutThongjor1
 
Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...
Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...
Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...Guillaume Kossi
 
A Gentle Introduction to Angular Schematics - Angular SF 2019
A Gentle Introduction to Angular Schematics - Angular SF 2019A Gentle Introduction to Angular Schematics - Angular SF 2019
A Gentle Introduction to Angular Schematics - Angular SF 2019Matt Raible
 
Animating an svg icon
Animating an svg iconAnimating an svg icon
Animating an svg icondeepbidis
 
Use Angular Schematics to Simplify Your Life - Develop Denver 2019
Use Angular Schematics to Simplify Your Life - Develop Denver 2019Use Angular Schematics to Simplify Your Life - Develop Denver 2019
Use Angular Schematics to Simplify Your Life - Develop Denver 2019Matt Raible
 
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11Kamil Augustynowicz
 
Animating angular applications
Animating angular applicationsAnimating angular applications
Animating angular applicationsTomek Sułkowski
 
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019Matt Raible
 
はじめてのAngular2
はじめてのAngular2はじめてのAngular2
はじめてのAngular2Kenichi Kanai
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)Oswald Campesato
 
AngularJS Animations
AngularJS AnimationsAngularJS Animations
AngularJS AnimationsEyal Vardi
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java DevelopersYakov Fain
 
Building a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web ServicesBuilding a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web ServicesDavid Giard
 
PWA night vol.11 20191218
PWA night vol.11 20191218PWA night vol.11 20191218
PWA night vol.11 20191218bitpart
 

Similar to Svg, canvas e animations in angular (3 maggio 2019) (20)

angular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdfangular fundamentals.pdf angular fundamentals.pdf
angular fundamentals.pdf angular fundamentals.pdf
 
SVG introduction
SVG   introductionSVG   introduction
SVG introduction
 
Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...
Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...
Sara Soueidan: Styling and Animating Scalable Vector Graphics with CSS [CSSCo...
 
A Gentle Introduction to Angular Schematics - Angular SF 2019
A Gentle Introduction to Angular Schematics - Angular SF 2019A Gentle Introduction to Angular Schematics - Angular SF 2019
A Gentle Introduction to Angular Schematics - Angular SF 2019
 
Animating an svg icon
Animating an svg iconAnimating an svg icon
Animating an svg icon
 
Web Vector Graphics
Web Vector GraphicsWeb Vector Graphics
Web Vector Graphics
 
Use Angular Schematics to Simplify Your Life - Develop Denver 2019
Use Angular Schematics to Simplify Your Life - Develop Denver 2019Use Angular Schematics to Simplify Your Life - Develop Denver 2019
Use Angular Schematics to Simplify Your Life - Develop Denver 2019
 
Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11Angular js 2.0, ng poznań 20.11
Angular js 2.0, ng poznań 20.11
 
angular fundamentals.pdf
angular fundamentals.pdfangular fundamentals.pdf
angular fundamentals.pdf
 
Animating angular applications
Animating angular applicationsAnimating angular applications
Animating angular applications
 
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019
 
はじめてのAngular2
はじめてのAngular2はじめてのAngular2
はじめてのAngular2
 
Vue js and Dyploma
Vue js and DyplomaVue js and Dyploma
Vue js and Dyploma
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
 
AngularJS Animations
AngularJS AnimationsAngularJS Animations
AngularJS Animations
 
SVGD3Angular2React
SVGD3Angular2ReactSVGD3Angular2React
SVGD3Angular2React
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java Developers
 
Building a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web ServicesBuilding a TV show with Angular, Bootstrap, and Web Services
Building a TV show with Angular, Bootstrap, and Web Services
 
PWA night vol.11 20191218
PWA night vol.11 20191218PWA night vol.11 20191218
PWA night vol.11 20191218
 

Recently uploaded

ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 

Recently uploaded (20)

ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Svg, canvas e animations in angular (3 maggio 2019)

  • 1. SVG, Canvas e Animations in Angular Leonardo Buscemi
  • 3. Angular compila il nostro codice Tutto quello che scriviamo nella nostra applicazione Angular (componenti, logica e stili) viene ‘compilato’ in codice Javascript.
  • 4.
  • 5. Elementi SVG <rect x="120" y="0" width="100" height="100" rx="0" ry="0" /> <circle cx="50" cy="50" r="50"/> <polygon points="20,0 80,0 100,50 0,50" /> <path d="M 10,30 A 20,20 0,0,1 50,30 A 20,20 0,0,1 90,30 Q 90,60 50,90 Q 10,60 10,30 z"/> SVG Elements
  • 6. Simple (static) Component with SVG import { Component } from @angular/core'; @Component({ selector: 'my-component', template: ` <svg viewBox="0 0 250 250"> <g> <polygon class="st0" fill="#DD0031" points="125,153 … 153.4" /> <polygon class="st0" fill="#DD0031" points="108,135 … 125,94.5" /> </g> <g class="st1"> <polygon class="st0" fill="#C3002F" points="125,153 … 3.4" /> <polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" /> </g> </svg> `, }) export class AppComponent {}
  • 7. Angular needs to know is SVG <svg:rect x="0" y="0" width="100" height="100"/> “An SVG snippet template needs an svg: prefix on its root element to disambiguate the SVG element from an HTML component.” Fonte
  • 9. Simple (static) Component with SVG import { Component } from @angular/core'; @Component({ selector: 'my-component', template: ` <svg viewBox="0 0 250 250"> <g> <polygon class="st0" fill="#DD0031" points="125,153 … 153.4" /> <polygon class="st0" fill="#DD0031" points="108,135 … 125,94.5" /> </g> <g class="st1"> <polygon class="st0" fill="#C3002F" points="125,153 … 3.4" /> <polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" /> </g> </svg> `, }) export class AppComponent {}
  • 10. Simple (static) Component with SVG import { Component } from @angular/core'; @Component({ selector: 'my-component', template: ` <svg viewBox="0 0 250 250"> <svg:g> <svg:polygon class="st0" fill="#DD0031" points="125,153 … 153.4" /> <svg:polygon class="st0" fill="#DD0031" points="108,135 … 125,94.5" /> </svg:g> <svg:g class="st1"> <svg:polygon class="st0" fill="#C3002F" points="125,153 … 3.4" /> <svg:polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" /> </svg:g> </svg> `, }) export class AppComponent {}
  • 12.
  • 13. Component with SVG import { Component } from @angular/core'; @Component({ selector: 'my-component', template: ` <svg viewBox="0 0 250 250"> <svg:g> <svg:polygon class="st0" fill="#DD0031" points="125,153 … 153.4" /> <svg:polygon class="st0" fill="#DD0031" points="108,135 … 125,94.5" /> </g> <svg:g class="st1"> <svg:polygon class="st0" fill="#C3002F" points="125,153 … 3.4" /> <svg:polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" /> </g> </svg> `, }) export class AppComponent {}
  • 14. Component with SVG import { Component } from @angular/core'; @Component({ selector: 'my-component', template: ` <svg viewBox="0 0 250 250"> <svg:g> <svg:polygon class="st0" fill="#DD0031" points="125,153 … 153.4" /> <svg:polygon class="st0" fill="#DD0031" [points]="someMagic()" /> </g> <svg:g class="st1"> <svg:polygon class="st0" fill="#C3002F" points="125,153 … 3.4" /> <svg:polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" /> </g> </svg> `, }) export class AppComponent {}
  • 15. Component with SVG import { Component } from @angular/core'; @Component({ selector: 'my-component', template: ` <svg viewBox="0 0 250 250"> <svg:g> <svg:polygon class="st0" fill="#DD0031" points="125,153 … 153.4" /> <svg:polygon class="st0" fill="#DD0031" [points]="someMagic()" /> </g> <svg:g class="st1"> <svg:polygon class="st0" fill="#C3002F" points="125,153 … 3.4" /> <svg:polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" /> </g> </svg> `, }) export class AppComponent {}
  • 16. HTML attribute vs. DOM property ❖ Alcuni attributi HTML hanno un mapping 1: 1 alle proprietà ➢ Ad esempio id ❖ Alcuni attributi HTML non hanno proprietà corrispondenti ➢ Ad esempio colspan e tutti gli attributi svg ❖ Alcune proprietà DOM non hanno attributi corrispondenti ➢ Ad esempio textContent ❖ Molti attributi HTML sembrano mappare alle proprietà ... ma non nel modo in cui si potrebbe pensare! Gli attributi inizializzano le proprietà del DOM, queste possono cambiare; i valori degli attributi no. Fonte
  • 17. Un mondo senza attributi In Angular l'unico scopo degli attributi è quello di inizializzare lo stato degli elementi e direttive, una volta compilati gli attributi spariscono! Fonte Fonte È necessario utilizzare il binding dell'attributo quando non esiste alcuna proprietà dell'elemento da associare.
  • 18. Component with SVG import { Component } from @angular/core'; @Component({ selector: 'my-component', template: ` <svg viewBox="0 0 250 250"> <svg:g> <svg:polygon class="st0" fill="#DD0031" points="125,153 … 153.4" /> <svg:polygon class="st0" fill="#DD0031" [attr.points]="someMagic()" /> </g> <svg:g class="st1"> <svg:polygon class="st0" fill="#C3002F" points="125,153 … 3.4" /> <svg:polygon class="st0" fill="#C3002F" points="142,135.4 … 94.5" /> </g> </svg> `, }) export class AppComponent {}
  • 20. Suddivisione in componenti import { Component } from '@angular/core'; @Component({ selector: 'my-part-left', template: ` <svg:g > <svg:polygon fill="#DD0031" points="125,153.4 … 125,94.5" /> </svg:g>` }) export class PartLeftComponent { } import { Component } from '@angular/core'; @Component({ selector: 'my-part-right', template: ` <svg:g > <svg:polygon fill="#C3002F" points="125,153.4 … 125,94.5" /> </svg:g>` }) export class PartRightComponent { }
  • 21. Suddivisione in componenti <svg viewBox="0 0 250 250"> <my-part-left></my-part-left> <my-part-right></my-part-right> </svg> Non viene renderizzato!
  • 22. Selettore per attributo import { Component } from '@angular/core'; @Component({ selector: '[my-part-left]', template: ` <svg:g > <svg:polygon fill="#DD0031" points="125,153.4 ... 125,94.5" /> </svg:g>` }) export class PartLeftComponent { } import { Component } from '@angular/core'; @Component({ selector: '[my-part-right]', template: ` <svg:g > <svg:polygon fill="#C3002F" points="125,153.4 125,94.5" /> </svg:g>` }) export class PartRightComponent { }
  • 23. Suddivisione in componenti OK <svg viewBox="0 0 250 250"> <svg:g my-part-left /> <svg:g my-part-right /> </svg>
  • 25. Animazioni su SVG ● SMIL ○ Deprecato ● CSS ● Angular Animation ● Javascript ○ Green Sock
  • 26. Esempio live Animazione di SVG in CSS https://stackblitz.com/edit/angular-svg-components
  • 27.
  • 28. Angular Animation npm i @angular/animations app.module.ts import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { AppComponent } from './app.component'; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, FormsModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { }
  • 29. Esempio live Animazione di SVG con Angular Animation https://stackblitz.com/edit/angular-svg-anim-ng
  • 30. Animazione in Javascript Vogliamo animare anche la proprietà points del nostro polygon
  • 32. Greensock npm i gsap @types/greensock import { Component, ViewChild, ElementRef } from '@angular/core'; import 'gsap'; @Component({ selector: 'my-app', templateUrl: './app.component.html', }) export class AppComponent { @ViewChild('left') left: ElementRef; @ViewChild('right') right: ElementRef; ngOnInit() { TweenMax.to(this.left.nativeElement, 2, { attr: { points: "125,153.4 … 125,195" }, repeat: -1, yoyo: true, ease: Cubic.easeInOut }); TweenMax.to(this.right.nativeElement, 2, { attr: { points: "125,153.4 … 125,153.4" }, repeat: -1, yoyo: true, ease: Cubic.easeInOut }); } }
  • 33. Esempio live Animazione di SVG con GreenSock https://stackblitz.com/edit/angular-svg-static-grensock
  • 35. SVG usa il modello “retained” Fonte È un modello dichiarativo. L’applicazione costruisce la scena utilizzando elementi grafici (linee, forme) della libreria grafica che si occupa di creare il modello della scena e inviare i comandi di disegno.
  • 36. Canvas usa il modello ‘immediate’ Fonte È un modello procedurale. L’applicazione invia direttamente i comandi di disegno e deve tenere traccia del modello della scena
  • 37. “Simple” Canvas component import { Component, ViewChild, ElementRef } from '@angular/core'; @Component({ selector: 'my-app', template: '<canvas #myCanvas height="200" width="200" ></canvas>' }) export class AppComponent { @ViewChild("myCanvas") canvasRef: ElementRef; private ctx: CanvasRenderingContext2D; ngOnInit() { this.ctx = this.canvasRef.nativeElement.getContext('2d'); this.drawBorder(); this.drawPoint(); } drawPoint() { this.ctx.beginPath(); … this.ctx.fill(); } drawBorder() { this.ctx.beginPath(); … this.ctx.stroke(); } }
  • 38. Esempio live Componente con canvas https://stackblitz.com/edit/angular-canvas-simple
  • 39. Esempio live Animazione con canvas https://stackblitz.com/edit/angular-canvas-animation
  • 40. Librerie terze parti SVG ● Raphael ● SnapSVG ● D3 CANVAS ● EaselJS ● ChartJS ● ThreeJS
  • 43. D3.js
  • 47. Confronto SVG ⇔ Canvas SVG CANVAS Grafica Vettoriale Raster Rendering Retained Immediate* Utilizzo Markup XML Low level API
  • 49. Leonardo Buscemi Software Developer presso https://www.linkedin.com/in/leonardobuscemi/ https://www.facebook.com/leonardo.buscemi https://twitter.com/leonardobuscemi GRAZIE

Editor's Notes

  1. Spiegare icona Angular in alto
  2. Il link punta alla pagina di Mozilla
  3. Spiegare subito perchè
  4. Adesso vogliamo rendere dinamica una parte del nostro componente
  5. $0.getAttribute("value") $0.value