resizable-svg by drag and drop (in progress)
Find this at dartpad.dartlang.org/?source=83839c13-6a46-48ac-a4e9-d95cff0e6368.
Created with <3 with dartpad.dartlang.org.
resizable-svg by drag and drop (in progress)
Find this at dartpad.dartlang.org/?source=83839c13-6a46-48ac-a4e9-d95cff0e6368.
Created with <3 with dartpad.dartlang.org.
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>resizable-svg-001</title> | |
| <link rel="stylesheet" href="styles.css"> | |
| <script type="application/dart" src="main.dart"></script> | |
| </head> | |
| <body> | |
| <div id="container"> | |
| <svg id="sketch" width=100 height=100> | |
| <line x1="0" y1="0" x2="100%" y2="100%" class="gearRadial" /> | |
| <line id="handle" y1=0 y2="100%" x1="100%" x2="100%"/> | |
| </svg> | |
| </div> | |
| </body> | |
| </html> |
| import 'dart:html'; | |
| import 'dart:svg'; | |
| import 'dart:math'; | |
| int getAsPixels(String measure) { | |
| if (measure.substring(measure.length-2) == "px") { | |
| return int.parse(measure.substring(0, measure.length-2)); | |
| } else { | |
| print("Can't deal with value '${measure}'."); | |
| return 0; | |
| } | |
| } | |
| void main() { | |
| final HtmlElement container = querySelector("#container"); | |
| final SvgElement sketch = querySelector("#sketch"); | |
| final padding = getAsPixels(container.getComputedStyle().padding); | |
| final border = getAsPixels(container.getComputedStyle().borderWidth); | |
| final margin = getAsPixels(sketch.getComputedStyle().margin); | |
| final width = container.client.width - 2 * (border + padding + margin); | |
| sketch.setAttributeNS(null, "width", width.toString()); | |
| } |
| #container { | |
| border: solid 2px red | |
| } | |
| #sketch { | |
| border: dashed | |
| } | |
| .gearRadial { | |
| stroke: rgb(255,0,0); | |
| stroke-width: 2; | |
| } |