-
-
Save dmundt/4690394 to your computer and use it in GitHub Desktop.
Dart: SVG Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import('dart:html'); | |
class SVGSamples { | |
void run() { | |
drawlines(); | |
} | |
void drawlines() { | |
final int maxY = 250; | |
final int maxX = 500; | |
final int step = 10; | |
var svgGroup = new SVGElement.tag("g"); | |
svgGroup.attributes["transform"] = "translate(0,$maxY) scale(1,-1)"; | |
for(int i=0; i<(maxX/step); i++) { | |
var xAxis = new SVGElement.tag("line"); | |
xAxis.attributes = { | |
"x1": i*step, | |
"y1": 0, | |
"x2": i*step, | |
"y2": (i%10 == 0 ? 16 : 8), | |
"stroke": (i%10 == 0 ? "#8cf" : "blue"), | |
"stroke-width": "1" | |
}; | |
svgGroup.nodes.add(xAxis); | |
} | |
for(int i=0; i<(maxY/step); i++) { | |
var yAxis = new SVGElement.tag("line"); | |
yAxis.attributes = { | |
"x1": 0, | |
"y1": i*step, | |
"x2": (i%10 == 0 ? 16 : 8), | |
"y2": i*step, | |
"stroke": (i%10 == 0 ? "#8cf" : "blue"), | |
"stroke-width": "1" | |
}; | |
svgGroup.nodes.add(yAxis); | |
} | |
var svg = new SVGElement.tag("svg"); | |
svg.nodes.add(svgGroup); | |
svg.attributes = { | |
"height": maxY, | |
"width": maxX, | |
"version": "1.1" | |
}; | |
document.query("#container").nodes.add(svg); | |
} | |
} | |
void main() { | |
new SVGSamples().run(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>SVGSamples</title> | |
</head> | |
<body> | |
<h1>SVGSamples</h1> | |
<div id="container"></div> | |
<script type="text/javascript" src="SVGSamples.dart.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SVG Samples