SlideShare a Scribd company logo
1 of 72
Download to read offline
SVG
Scalable Vector Graphics
Codewords @redpandalabs 2016-07-29
Shweta Sadawarte
Siddhesh Nikude
@Nelkinda Software Craft Pvt Ltd
@ShwetaSadawarte @SiddheshNikude @nelkinda @redpandalabs #Codewords #SVG
Agenda
● History of SVG
● Syntax and Anatomy of SVG files
● Basic Shapes, Paths and Text
● Integrating SVG with (X)HTML5
● Styling SVG with CSS
● SVG Animation
○ Declarative with SMIL
○ Imperative with JavaScript
● Generating SVG
○ From XML with XSLT
● How SVG contributes to Reactive Design
● Comparison of SVG with (X)HTML5 Canvas
● Raster images are made up of a set grid of
dots called pixels where each pixel is
assigned a color value.
● Number of pixels is limited
● Resolution dependent.
● Raster image file types BMP, JPEG, PNG
Types of images: Raster
● In physics, vectors is a representation of
both a magnitude (or length) and a direction.
● In vector graphics, the shape is saved as
vector statements.
● Mathematical equations, rather than pixels
● Vector images file types drw, pct, svg
Types of images: Vectors
1. History of SVG
1998 Macromedia and Microsoft introduce VML
1998 Adobe and SUN submit PGML to W3C
1998 W3C creates SVG Working Group
2001 SVG 1.0 becomes W3C REC
2003 SVG 1.1 becomes W3C REC including Tiny and
Basic profiles for Mobile SVG
2008 SVG Tiny 1.2 becomes W3C REC
2011 SVG 1.1 Second Edition
History of SVG
Explaining the name: SVG
“SVG stands for Scalable Vector Graphics, an XML
grammar for styleable [and scriptable] graphics,
usable as an XML namespace.”
Explaining the name: SVG
Scalable
Change size uniformly without loss in size. Possible
because graphics are defined as numbers i.e. scaling
involves multiplying or dividing numbers defining SVG
shape
Vector Graphics
Shapes to be displayed are stored as vectors or vector
like structures (as numbers, not as pixels)
Explaining the name: SVG
XML
Parsers widely available
Namespace
Mixing SVG with other XML languages like
XHTML, SMIL and MathML
Styleable (and scriptable)
Use CSS (and JavaScript)
Why SVG?
1. Scalable
2. Fast to load/ Small in size
3. Scriptable (or Interactive)
4. Animatable
5. Searchable
6. Support on Browsers and Mobile
Where to use SVG?
1. Two dimensional graphs
2. Column charts, Pie charts
3. Scalable icons and logos
4. Architecture and design diagrams
5. Road Maps
6. Simple games
Where not to use SVG?
Not ideal for bitmap graphics like photos,
movies etc.
Related Standards
● Extensible Markup Language (XML) 1.0
● Namespaces in XML
● XML Linking Language (XLink) (incl. XML Base)
● CSS
● XSLT
● Associating Style Sheets with XML documents
● DOM (Level 1 and much of Level 2)
● Synchronized Multimedia Integration Language (SMIL) 3.0
● HTML 4, XHTML 1.0 (and (X)HTML5)
● Unicode
● Accessibility
2. Syntax of SVG
⇒ XML Syntax applies
SVG files are XML files
● Elements must be complete
(Tags must always be closed)
● Elements must be nested
(Tags must be closed in reverse order)
● Only 5 predefined entities:
& &amp; < &lt; > &gt;
' &apos; " &quot;
XML Basics for SVG
SVG Namespace and Identifiers
Namespaces:
SVG: http://www.w3.org/2000/svg
XLink: http://www.w3.org/1999/xlink
Public Identifier for SVG 1.1:
PUBLIC "-//W3C//DTD SVG 1.1//EN"
System Identifier for the SVG 1.1 Recommendation:
http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd
Example Document Type Declaration:
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
Hello, World in SVG
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
<text y="12pt">Hello, World!</text>
</svg>
Note: Document Type Declaration shown for completeness. Not needed. Not
recommended.
Structuring, Grouping and Referencing in
SVG
<g>,<use>, <defs> and <symbol> Elements
For structuring a document by using SVG elements that allow us to define,
group, and reference objects within the document. These elements make
reusing elements easy, while maintaining clean and readable code.
● The group <g> element is used for logically grouping together sets of
related graphical elements.
<g/>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="1024" height="250">
<line x1="10" y1="10" x2="85" y2="10"
style="stroke: #006600;"/>
<rect x="10" y="20" height="50" width="75"
style="stroke: #006600; fill: #006600"/>
<text x="10" y="90" style="stroke: #660000; fill: #660000">
Text to demonstrate grouping with shapes</text>
</svg>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="1024" height="250">
<g transform="rotate(45 50 50)">
<line x1="10" y1="10" x2="85" y2="10"
style="stroke: #006600;"/>
<rect x="10" y="20" height="50" width="75"
style="stroke: #006600; fill: #006600"/>
<text x="10" y="90" style="stroke: #660000; fill: #660000">
Text to demonstrate grouping with shapes</text>
</g>
</svg>
<g/>
<defs/>
● The <defs> element is like a “template” that you want to reuse later at
multiple times throughout the document.
● <defs> allows to reuse:
○ single element
○ g (group of elements)
○ symbol
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="1024" height="250">
<defs>
<linearGradient id="Gradient01">
<stop offset="20%" stop-color="#39F" />
<stop offset="90%" stop-color="#F3F" />
</linearGradient>
</defs>
<rect fill="url(#Gradient01)" x="1cm" y="2cm" width="6cm" height="1cm" />
<circle fill="url(#Gradient01)" r="20" cx="20" cy="20"/>
</svg>
<defs/> - Using pattern
● The <use> element lets you reuse existing elements, giving you a similar
functionality to the copy-paste functionality in a graphics editor.
<use/>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="1024" height="250">
<defs>
<g id="shape">
<rect x="50" y="50" width="50" height="50" />
<circle cx="50" cy="50" r="50" />
</g>
</defs>
<use xlink:href="#shape" x="50" y="50" />
<use xlink:href="#shape" x="200" y="50" />
</svg>
<defs/> - Using <g/> and <use/>
● <symbol> elements combines the benefits of both the <defs> and the <g>
elements.
● Used to define symbols such as icons, for example, that are referenced
throughout the document.
● It accepts a viewBox attribute which allows it to scale-to-fit inside any
viewport it is rendered in.
<symbol/>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="1024" height="250">
<defs>
<symbol id="symbolShape">
<circle cx="50" cy="50" r="50" />
</symbol>
</defs>
<use xlink:href="#symbolShape" x="50" y="50" />
</svg>
<defs/>-Using <symbol/> & <use/>
SVG file
<svg>
<defs>
<g id="shape-icon-1">
...
<g>
<g id="shape-icon-2">
...
<g>
</defs>
</svg>
HTML file
<svg viewBox="214.7 0 182.6
792">
<use
xlink:href="#shape-icon-1" />
</svg>
<svg viewBox="0 26 100 48">
<use
xlink:href="#shape-icon-2" />
</svg>
SVG file
<svg>
<symbol id="shape-icon-1"
viewBox="214.7 0 182.6 792">
...
</symbol>
<symbol id="shape-icon-2"
viewBox="0 26 100 48">
...
</symbol>
</svg>
HTML file
<svg>
<use
xlink:href="#shape-icon-1" />
<use
xlink:href="#shape-icon-2" />
</svg>
Viewport
<svg width="800" height="600"></svg>
ViewBox
<svg width="800" height="600" viewBox="0 0 400 300" >
preserveAspectRatio
preserveAspectRatio = <align> <meetOrSlice>
Viewport, ViewBox and
preserveAspectRatio
Unit Description
em Default font size - usually the height of a character.
ex The height of the character x
px Pixels
pt Points (1 / 72 of an inch)
pc Picas (1 / 6 of an inch)
cm Centimeters
mm Millimeters
in Inches
Coordinate System Units
3. Basic Shapes, Paths
and Texts
<line/>
<polyline/>
<polygon/>
<rect/>
<circle/>
<ellipse/>
Basic Shapes, Paths and Texts
<path/>
<text/>
4. SVG Animation
● Synchronized Multimedia Integration
Language (SMIL)
● JavaScript
● CSS
Advantage to SMIL over JS animations is that JS
animations don't work when the SVG is embedded as an
img or used as a background-image in CSS. SMIL
animations do work in both cases
SVG Animation
1. <set>
2. <animate>
3. <animateTransform>
4. <animateMotion>
SVG animation
<set>
<circle cx="30" cy="30" r="25" style="stroke: none; fill:
#0000ff;">
<set attributeName="r" attributeType="XML"
to="100"
begin="5s" />
</circle>
xlink:href
<rect id="cool_shape" …></rect>
<animate xlink:href="#cool_shape" ... />
<animate>
<circle cx="30" cy="30" r="25" style="stroke: none; fill:
#0000ff;">
<animate attributeName="cx" attributeType="XML"
from="30" to="470"
begin="0s" dur="5s"
fill="remove" repeatCount="indefinite"/>
</circle>
<animateTransform>
<rect x="20" y="20" width="100" height="40"
style="stroke: #ff00ff; fill:none;" >
<animateTransform attributeName="transform"
type="rotate"
from="0 100 100" to="360 100 100"
begin="0s" dur="10s"
repeatCount="indefinite"
/>
</rect>
<animateMotion>
<rect x="0" y="0" width="30" height="15"
style="stroke: #ff0000; fill: none;">
<animateMotion
path="M10,50 q60,50 100,0 q60,-50 100,0"
begin="0s" dur="10s" repeatCount="indefinite"
/>
</rect>
Time Units
h Hours
min Minutes
s Seconds
ms Milliseconds
hh:mm:ss
1:30:45
Coordinating Animations
<rect x="0" y="0" width="30" height="15"
style="stroke: #ff0000; fill: none;">
<animate id="one"
attributeName="x" attributeType="XML"
from="0" to="400"
begin="0s" dur="10s" fill="freeze"
/>
<animate
attributeName="y" attributeType="XML"
from="0" to="50"
begin="one.end" dur="10s" fill="freeze"
/>
</rect>
5. Integrating SVG with
HTML5
● A stand-alone SVG Web page
● Embedding by reference
(X)HTML: <img/> element
● Embedding inline (namespaces)
● External link
(X)HTML: <a/> element
● Referenced from CSS or XSL
Options for using SVG on the Web
A stand-alone SVG Web page
<svg xmlns="http://www.w3.org/2000/svg">
<text y="50pt">Hello, World!</text>
</svg>
Embedding by reference
● <img src="image.svg" />
● <iframe src="image.svg"></iframe>
Embedding inline
<!DOCTYPE html>
<html>
<head>
<title>Text</title>
</head>
<body>
<h1>Text Example</h1>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<text x="20" y="40">This is SVG text</text>
</svg>
</body>
</html>
External link using <a/>
<!DOCTYPE>
<html>
<head>
<title>Grouping g element</title>
</head>
<body>
<a href="helloWord.svg">hello</a>
</svg>
</body>
</html>
Referenced from CSS
<!DOCTYPE html>
<html>
<body>
<style type="text/css">
.logo {
background: url(helloWorld.svg);
display: block;
}
</style>
<a href="/" class="logo"></a>
</body>
</html>
6. Styling SVG with CSS
● Using presentation attribute
● Using css properties
● <style> tag inside <svg>
● Embedded stylesheet
● External Stylesheet
How SVGs can be styled in CSS
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
width="300px" height="300px" viewBox="0 0 300 300">
<polygon
fill = "#FF931E"
stroke = "#ED1C24"
stroke-width = "5"
points = "279.1,160.8 195.2,193.3 174.4,280.8 117.6,211.1
27.9,218.3 76.7,142.7 42.1,59.6 129.1,82.7 197.4,24.1 202.3,114
"/>
</svg>
Using Presentation Attribute
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
style="width: 300px; height: 300px;" viewBox="0 0 300 300">
<polygon
style = "fill: #FF931E; stroke: #ED1C24; stroke-width: 5;"
points = "279.1,160.8 195.2,193.3 174.4,280.8 117.6,211.1
27.9,218.3 76.7,142.7 42.1,59.6 129.1,82.7 197.4,24.1 202.3,114
"/>
</svg>
Using CSS Properties
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<style type="text/css">
<![CDATA[
circle {
stroke: #006600;
fill: #00cc00;
}
]]>
</style>
<circle cx="40" cy="40" r="24"/>
</svg>
SVG with <style> tag inside the SVG tag
<!DOCTYPE html><!-- HTML5 document -->
<html>
<head> … </head>
<body>
<style type="text/css">
circle {
stroke: #006600;
fill : #00cc00;
}
</style>
<!-- xmlns is optional in an HTML5 document →
<svg>
<circle cx="40" cy="40" r="24" />
</svg>
</body>
</html>
SVG with Embedded stylesheet
SVG with External Stylesheet
<?xml version="1.0" standalone="no"?>
<?xml-stylesheet type="text/css" href="style.css"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width=".."
height=".." viewBox="..">
<!-- SVG content -->
</svg>
7.1 Declarative Animation
with SMIL
Live Demo: Clock
7.2 Imperative Animation
with JavaScript
Live Demo: Clock
8. Generating SVG
8.1 Generating SVG from
XML with XSLT
9. How SVG Contributes
to Reactive Design
10. Comparison of SVG
with (X)HTML5 Canvas
SVG
● Vector based (composed of
shapes)
● Resolution independent.
● Multiple graphical elements,
which become the part of the
DOM.
● Modified through script and CSS.
● SVG is not suited for game
applications.
● Better scalability — can be
printed with high quality at any
resolution
Canvas
● Raster based (composed of
pixel)
● Resolution dependent.
● Single HTML element similar to
<img> in behavior.
● Modified through script only.
● Canvas is suited for
graphic-intensive games.
● Poor scalability — not suitable
for printing on higher resolution
● Adobe Illustrator
● Inkscape
● SVG-edit
● Boxy SVG
Editors for SVG
● Peter Collingridge’s - Online tool
● SVGO (the “O” is for “optimizer”) - Offline
tool
● SVGOMG
● Inkscape Plugin
Tools for SVG
Questions?
Thank You!
@ShwetaSadawarte @SiddheshNikude @nelkinda @redpandalabs #Codewords #SVG

More Related Content

What's hot (20)

Page layout with css
Page layout with cssPage layout with css
Page layout with css
 
Javascript
JavascriptJavascript
Javascript
 
Css position
Css positionCss position
Css position
 
Bootstrap Framework
Bootstrap Framework Bootstrap Framework
Bootstrap Framework
 
CSS
CSSCSS
CSS
 
Jquery
JqueryJquery
Jquery
 
React js
React jsReact js
React js
 
Reactjs Basics
Reactjs BasicsReactjs Basics
Reactjs Basics
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
 
HTML CSS JS in Nut shell
HTML  CSS JS in Nut shellHTML  CSS JS in Nut shell
HTML CSS JS in Nut shell
 
Bootstrap 5 whats new
Bootstrap 5   whats newBootstrap 5   whats new
Bootstrap 5 whats new
 
Presentation about html5 css3
Presentation about html5 css3Presentation about html5 css3
Presentation about html5 css3
 
Css
CssCss
Css
 
Java script
Java scriptJava script
Java script
 
CSS Dasar #3 : Penempatan CSS
CSS Dasar #3 : Penempatan CSSCSS Dasar #3 : Penempatan CSS
CSS Dasar #3 : Penempatan CSS
 
CSS Dasar #9 : Inheritance
CSS Dasar #9 : InheritanceCSS Dasar #9 : Inheritance
CSS Dasar #9 : Inheritance
 
Styled Components & React.js
Styled Components & React.jsStyled Components & React.js
Styled Components & React.js
 
Responsive web-design through bootstrap
Responsive web-design through bootstrapResponsive web-design through bootstrap
Responsive web-design through bootstrap
 
React js
React jsReact js
React js
 

Similar to SVG - Scalable Vector Graphics

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
 
HTML5 and SVG
HTML5 and SVGHTML5 and SVG
HTML5 and SVGyarcub
 
Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)Ontico
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSGil Fink
 
Visualization of Big Data in Web Apps
Visualization of Big Data in Web AppsVisualization of Big Data in Web Apps
Visualization of Big Data in Web AppsEPAM
 
CSS3 basics for beginners - Imrokraft
CSS3 basics for beginners - ImrokraftCSS3 basics for beginners - Imrokraft
CSS3 basics for beginners - Imrokraftimrokraft
 
Thats Not Flash?
Thats Not Flash?Thats Not Flash?
Thats Not Flash?Mike Wilcox
 
SVG (Devoxx 2011, 2011-NOV-14)
SVG (Devoxx 2011, 2011-NOV-14)SVG (Devoxx 2011, 2011-NOV-14)
SVG (Devoxx 2011, 2011-NOV-14)Filip Van Laenen
 
Professional reports with SVG
Professional reports with SVGProfessional reports with SVG
Professional reports with SVGSpeedPartner GmbH
 
SVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationSVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationAnthony Starks
 

Similar to SVG - Scalable Vector Graphics (20)

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...
 
D3 data visualization
D3 data visualizationD3 data visualization
D3 data visualization
 
SVG and the web
SVG and the webSVG and the web
SVG and the web
 
HTML5 and SVG
HTML5 and SVGHTML5 and SVG
HTML5 and SVG
 
SVGD3Angular2React
SVGD3Angular2ReactSVGD3Angular2React
SVGD3Angular2React
 
Learn svg
Learn svgLearn svg
Learn svg
 
Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJS
 
Css3
Css3Css3
Css3
 
Html 5 svg
Html 5 svgHtml 5 svg
Html 5 svg
 
Svcc 2013-css3-and-mobile
Svcc 2013-css3-and-mobileSvcc 2013-css3-and-mobile
Svcc 2013-css3-and-mobile
 
Visualization of Big Data in Web Apps
Visualization of Big Data in Web AppsVisualization of Big Data in Web Apps
Visualization of Big Data in Web Apps
 
Svghtml5 Meetup
Svghtml5 MeetupSvghtml5 Meetup
Svghtml5 Meetup
 
HTML5 & SVG in Cartography - Workshop
HTML5 & SVG in Cartography - WorkshopHTML5 & SVG in Cartography - Workshop
HTML5 & SVG in Cartography - Workshop
 
CSS3 basics for beginners - Imrokraft
CSS3 basics for beginners - ImrokraftCSS3 basics for beginners - Imrokraft
CSS3 basics for beginners - Imrokraft
 
Thats Not Flash?
Thats Not Flash?Thats Not Flash?
Thats Not Flash?
 
SVG (Devoxx 2011, 2011-NOV-14)
SVG (Devoxx 2011, 2011-NOV-14)SVG (Devoxx 2011, 2011-NOV-14)
SVG (Devoxx 2011, 2011-NOV-14)
 
Professional reports with SVG
Professional reports with SVGProfessional reports with SVG
Professional reports with SVG
 
SVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationSVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generation
 
SVG introduction
SVG   introductionSVG   introduction
SVG introduction
 

Recently uploaded

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 

Recently uploaded (20)

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 

SVG - Scalable Vector Graphics

  • 1. SVG Scalable Vector Graphics Codewords @redpandalabs 2016-07-29 Shweta Sadawarte Siddhesh Nikude @Nelkinda Software Craft Pvt Ltd @ShwetaSadawarte @SiddheshNikude @nelkinda @redpandalabs #Codewords #SVG
  • 2. Agenda ● History of SVG ● Syntax and Anatomy of SVG files ● Basic Shapes, Paths and Text ● Integrating SVG with (X)HTML5 ● Styling SVG with CSS ● SVG Animation ○ Declarative with SMIL ○ Imperative with JavaScript ● Generating SVG ○ From XML with XSLT ● How SVG contributes to Reactive Design ● Comparison of SVG with (X)HTML5 Canvas
  • 3. ● Raster images are made up of a set grid of dots called pixels where each pixel is assigned a color value. ● Number of pixels is limited ● Resolution dependent. ● Raster image file types BMP, JPEG, PNG Types of images: Raster
  • 4.
  • 5. ● In physics, vectors is a representation of both a magnitude (or length) and a direction. ● In vector graphics, the shape is saved as vector statements. ● Mathematical equations, rather than pixels ● Vector images file types drw, pct, svg Types of images: Vectors
  • 6.
  • 8. 1998 Macromedia and Microsoft introduce VML 1998 Adobe and SUN submit PGML to W3C 1998 W3C creates SVG Working Group 2001 SVG 1.0 becomes W3C REC 2003 SVG 1.1 becomes W3C REC including Tiny and Basic profiles for Mobile SVG 2008 SVG Tiny 1.2 becomes W3C REC 2011 SVG 1.1 Second Edition History of SVG
  • 9. Explaining the name: SVG “SVG stands for Scalable Vector Graphics, an XML grammar for styleable [and scriptable] graphics, usable as an XML namespace.”
  • 10. Explaining the name: SVG Scalable Change size uniformly without loss in size. Possible because graphics are defined as numbers i.e. scaling involves multiplying or dividing numbers defining SVG shape Vector Graphics Shapes to be displayed are stored as vectors or vector like structures (as numbers, not as pixels)
  • 11. Explaining the name: SVG XML Parsers widely available Namespace Mixing SVG with other XML languages like XHTML, SMIL and MathML Styleable (and scriptable) Use CSS (and JavaScript)
  • 12. Why SVG? 1. Scalable 2. Fast to load/ Small in size 3. Scriptable (or Interactive) 4. Animatable 5. Searchable 6. Support on Browsers and Mobile
  • 13. Where to use SVG? 1. Two dimensional graphs 2. Column charts, Pie charts 3. Scalable icons and logos 4. Architecture and design diagrams 5. Road Maps 6. Simple games
  • 14. Where not to use SVG? Not ideal for bitmap graphics like photos, movies etc.
  • 15. Related Standards ● Extensible Markup Language (XML) 1.0 ● Namespaces in XML ● XML Linking Language (XLink) (incl. XML Base) ● CSS ● XSLT ● Associating Style Sheets with XML documents ● DOM (Level 1 and much of Level 2) ● Synchronized Multimedia Integration Language (SMIL) 3.0 ● HTML 4, XHTML 1.0 (and (X)HTML5) ● Unicode ● Accessibility
  • 17. ⇒ XML Syntax applies SVG files are XML files
  • 18. ● Elements must be complete (Tags must always be closed) ● Elements must be nested (Tags must be closed in reverse order) ● Only 5 predefined entities: & &amp; < &lt; > &gt; ' &apos; " &quot; XML Basics for SVG
  • 19. SVG Namespace and Identifiers Namespaces: SVG: http://www.w3.org/2000/svg XLink: http://www.w3.org/1999/xlink Public Identifier for SVG 1.1: PUBLIC "-//W3C//DTD SVG 1.1//EN" System Identifier for the SVG 1.1 Recommendation: http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd Example Document Type Declaration: <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  • 20. Hello, World in SVG <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg"> <text y="12pt">Hello, World!</text> </svg> Note: Document Type Declaration shown for completeness. Not needed. Not recommended.
  • 21. Structuring, Grouping and Referencing in SVG <g>,<use>, <defs> and <symbol> Elements For structuring a document by using SVG elements that allow us to define, group, and reference objects within the document. These elements make reusing elements easy, while maintaining clean and readable code.
  • 22. ● The group <g> element is used for logically grouping together sets of related graphical elements. <g/>
  • 23. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1024" height="250"> <line x1="10" y1="10" x2="85" y2="10" style="stroke: #006600;"/> <rect x="10" y="20" height="50" width="75" style="stroke: #006600; fill: #006600"/> <text x="10" y="90" style="stroke: #660000; fill: #660000"> Text to demonstrate grouping with shapes</text> </svg>
  • 24. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1024" height="250"> <g transform="rotate(45 50 50)"> <line x1="10" y1="10" x2="85" y2="10" style="stroke: #006600;"/> <rect x="10" y="20" height="50" width="75" style="stroke: #006600; fill: #006600"/> <text x="10" y="90" style="stroke: #660000; fill: #660000"> Text to demonstrate grouping with shapes</text> </g> </svg> <g/>
  • 25. <defs/> ● The <defs> element is like a “template” that you want to reuse later at multiple times throughout the document. ● <defs> allows to reuse: ○ single element ○ g (group of elements) ○ symbol
  • 26. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1024" height="250"> <defs> <linearGradient id="Gradient01"> <stop offset="20%" stop-color="#39F" /> <stop offset="90%" stop-color="#F3F" /> </linearGradient> </defs> <rect fill="url(#Gradient01)" x="1cm" y="2cm" width="6cm" height="1cm" /> <circle fill="url(#Gradient01)" r="20" cx="20" cy="20"/> </svg> <defs/> - Using pattern
  • 27. ● The <use> element lets you reuse existing elements, giving you a similar functionality to the copy-paste functionality in a graphics editor. <use/>
  • 28. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1024" height="250"> <defs> <g id="shape"> <rect x="50" y="50" width="50" height="50" /> <circle cx="50" cy="50" r="50" /> </g> </defs> <use xlink:href="#shape" x="50" y="50" /> <use xlink:href="#shape" x="200" y="50" /> </svg> <defs/> - Using <g/> and <use/>
  • 29. ● <symbol> elements combines the benefits of both the <defs> and the <g> elements. ● Used to define symbols such as icons, for example, that are referenced throughout the document. ● It accepts a viewBox attribute which allows it to scale-to-fit inside any viewport it is rendered in. <symbol/>
  • 30. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1024" height="250"> <defs> <symbol id="symbolShape"> <circle cx="50" cy="50" r="50" /> </symbol> </defs> <use xlink:href="#symbolShape" x="50" y="50" /> </svg> <defs/>-Using <symbol/> & <use/>
  • 31. SVG file <svg> <defs> <g id="shape-icon-1"> ... <g> <g id="shape-icon-2"> ... <g> </defs> </svg> HTML file <svg viewBox="214.7 0 182.6 792"> <use xlink:href="#shape-icon-1" /> </svg> <svg viewBox="0 26 100 48"> <use xlink:href="#shape-icon-2" /> </svg>
  • 32. SVG file <svg> <symbol id="shape-icon-1" viewBox="214.7 0 182.6 792"> ... </symbol> <symbol id="shape-icon-2" viewBox="0 26 100 48"> ... </symbol> </svg> HTML file <svg> <use xlink:href="#shape-icon-1" /> <use xlink:href="#shape-icon-2" /> </svg>
  • 33. Viewport <svg width="800" height="600"></svg> ViewBox <svg width="800" height="600" viewBox="0 0 400 300" > preserveAspectRatio preserveAspectRatio = <align> <meetOrSlice> Viewport, ViewBox and preserveAspectRatio
  • 34. Unit Description em Default font size - usually the height of a character. ex The height of the character x px Pixels pt Points (1 / 72 of an inch) pc Picas (1 / 6 of an inch) cm Centimeters mm Millimeters in Inches Coordinate System Units
  • 35. 3. Basic Shapes, Paths and Texts
  • 38. ● Synchronized Multimedia Integration Language (SMIL) ● JavaScript ● CSS Advantage to SMIL over JS animations is that JS animations don't work when the SVG is embedded as an img or used as a background-image in CSS. SMIL animations do work in both cases SVG Animation
  • 39. 1. <set> 2. <animate> 3. <animateTransform> 4. <animateMotion> SVG animation
  • 40. <set> <circle cx="30" cy="30" r="25" style="stroke: none; fill: #0000ff;"> <set attributeName="r" attributeType="XML" to="100" begin="5s" /> </circle>
  • 41. xlink:href <rect id="cool_shape" …></rect> <animate xlink:href="#cool_shape" ... />
  • 42. <animate> <circle cx="30" cy="30" r="25" style="stroke: none; fill: #0000ff;"> <animate attributeName="cx" attributeType="XML" from="30" to="470" begin="0s" dur="5s" fill="remove" repeatCount="indefinite"/> </circle>
  • 43. <animateTransform> <rect x="20" y="20" width="100" height="40" style="stroke: #ff00ff; fill:none;" > <animateTransform attributeName="transform" type="rotate" from="0 100 100" to="360 100 100" begin="0s" dur="10s" repeatCount="indefinite" /> </rect>
  • 44. <animateMotion> <rect x="0" y="0" width="30" height="15" style="stroke: #ff0000; fill: none;"> <animateMotion path="M10,50 q60,50 100,0 q60,-50 100,0" begin="0s" dur="10s" repeatCount="indefinite" /> </rect>
  • 45. Time Units h Hours min Minutes s Seconds ms Milliseconds hh:mm:ss 1:30:45
  • 46. Coordinating Animations <rect x="0" y="0" width="30" height="15" style="stroke: #ff0000; fill: none;"> <animate id="one" attributeName="x" attributeType="XML" from="0" to="400" begin="0s" dur="10s" fill="freeze" /> <animate attributeName="y" attributeType="XML" from="0" to="50" begin="one.end" dur="10s" fill="freeze" /> </rect>
  • 47. 5. Integrating SVG with HTML5
  • 48. ● A stand-alone SVG Web page ● Embedding by reference (X)HTML: <img/> element ● Embedding inline (namespaces) ● External link (X)HTML: <a/> element ● Referenced from CSS or XSL Options for using SVG on the Web
  • 49. A stand-alone SVG Web page <svg xmlns="http://www.w3.org/2000/svg"> <text y="50pt">Hello, World!</text> </svg>
  • 50. Embedding by reference ● <img src="image.svg" /> ● <iframe src="image.svg"></iframe>
  • 51. Embedding inline <!DOCTYPE html> <html> <head> <title>Text</title> </head> <body> <h1>Text Example</h1> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <text x="20" y="40">This is SVG text</text> </svg> </body> </html>
  • 52. External link using <a/> <!DOCTYPE> <html> <head> <title>Grouping g element</title> </head> <body> <a href="helloWord.svg">hello</a> </svg> </body> </html>
  • 53. Referenced from CSS <!DOCTYPE html> <html> <body> <style type="text/css"> .logo { background: url(helloWorld.svg); display: block; } </style> <a href="/" class="logo"></a> </body> </html>
  • 54. 6. Styling SVG with CSS
  • 55. ● Using presentation attribute ● Using css properties ● <style> tag inside <svg> ● Embedded stylesheet ● External Stylesheet How SVGs can be styled in CSS
  • 56. <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="300px" height="300px" viewBox="0 0 300 300"> <polygon fill = "#FF931E" stroke = "#ED1C24" stroke-width = "5" points = "279.1,160.8 195.2,193.3 174.4,280.8 117.6,211.1 27.9,218.3 76.7,142.7 42.1,59.6 129.1,82.7 197.4,24.1 202.3,114 "/> </svg> Using Presentation Attribute
  • 57. <svg xmlns="http://www.w3.org/2000/svg" version="1.1" style="width: 300px; height: 300px;" viewBox="0 0 300 300"> <polygon style = "fill: #FF931E; stroke: #ED1C24; stroke-width: 5;" points = "279.1,160.8 195.2,193.3 174.4,280.8 117.6,211.1 27.9,218.3 76.7,142.7 42.1,59.6 129.1,82.7 197.4,24.1 202.3,114 "/> </svg> Using CSS Properties
  • 58. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <style type="text/css"> <![CDATA[ circle { stroke: #006600; fill: #00cc00; } ]]> </style> <circle cx="40" cy="40" r="24"/> </svg> SVG with <style> tag inside the SVG tag
  • 59. <!DOCTYPE html><!-- HTML5 document --> <html> <head> … </head> <body> <style type="text/css"> circle { stroke: #006600; fill : #00cc00; } </style> <!-- xmlns is optional in an HTML5 document → <svg> <circle cx="40" cy="40" r="24" /> </svg> </body> </html> SVG with Embedded stylesheet
  • 60. SVG with External Stylesheet <?xml version="1.0" standalone="no"?> <?xml-stylesheet type="text/css" href="style.css"?> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width=".." height=".." viewBox=".."> <!-- SVG content --> </svg>
  • 66. 8.1 Generating SVG from XML with XSLT
  • 67. 9. How SVG Contributes to Reactive Design
  • 68. 10. Comparison of SVG with (X)HTML5 Canvas
  • 69. SVG ● Vector based (composed of shapes) ● Resolution independent. ● Multiple graphical elements, which become the part of the DOM. ● Modified through script and CSS. ● SVG is not suited for game applications. ● Better scalability — can be printed with high quality at any resolution Canvas ● Raster based (composed of pixel) ● Resolution dependent. ● Single HTML element similar to <img> in behavior. ● Modified through script only. ● Canvas is suited for graphic-intensive games. ● Poor scalability — not suitable for printing on higher resolution
  • 70. ● Adobe Illustrator ● Inkscape ● SVG-edit ● Boxy SVG Editors for SVG
  • 71. ● Peter Collingridge’s - Online tool ● SVGO (the “O” is for “optimizer”) - Offline tool ● SVGOMG ● Inkscape Plugin Tools for SVG
  • 72. Questions? Thank You! @ShwetaSadawarte @SiddheshNikude @nelkinda @redpandalabs #Codewords #SVG