Mercurial > hg > digilib-old
diff client/src/main/webapp/jquery/svg/svgBasics.html @ 892:ba1eb2d821a2 mvnify
rearrange sources to maven directory standard
author | robcast |
---|---|
date | Tue, 19 Apr 2011 18:44:25 +0200 |
parents | client/digitallibrary/jquery/svg/svgBasics.html@65cdf970934d |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/src/main/webapp/jquery/svg/svgBasics.html Tue Apr 19 18:44:25 2011 +0200 @@ -0,0 +1,153 @@ + +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" + "http://www.w3.org/TR/html4/strict.dtd"> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> + <title>jQuery SVG Basics</title> + +<style type="text/css"> + +@import "jquery.svg.css"; + +#svgbasics { position: absolute; border: 1px solid blue; } + +#img img {width: 400px; } + +</style> + +<script type="text/javascript" src="../dlGeometry.js"></script> +<script type="text/javascript" src="../jquery-1.4.4.js"></script> +<script type="text/javascript" src="jquery.svg.js"></script> +<script type="text/javascript"> + +var $resDiv; + +$(function() { + var geom = dlGeometry(); + var svg = $('#svgbasics'); + var $div = $('#img img'); + var divrect = geom.rectangle($div); + divrect.addPosition({x: -1, y: -1}).adjustDiv(svg); + svg.svg({onLoad: drawInitial}); + $('button').click(drawShape); + $resDiv = $('div#res'); + console.log($resDiv); +}); + +function drawInitial(svg) { + // svg.configure({viewBox: '0 0 400 300' }, true); + svg.configure({transform: 'scale(0.5)' }, true); + svg.circle(75, 75, 50, {fill: 'none', stroke: 'red', 'stroke-width': 3}); + var g = svg.group({stroke: 'black', 'stroke-width': 2}); + svg.line(g, 15, 75, 135, 75); + svg.line(g, 75, 15, 75, 135); + var g = svg.group({stroke: 'yellow', 'stroke-width': 4}); + svg.line(g, 0, 0, 400, 0); + svg.line(g, 0, 0, 0, 300); + svg.line(g, 400, 0, 400, 300); + svg.line(g, 400, 300, 0, 300); + // svg.configure({viewPort: '0 0 100 100', overflow: 'visible' }, false); + +} + +var colours = ['purple', 'red', 'orange', 'yellow', 'lime', 'green', 'blue', 'navy', 'black']; + +var x=0,y=0,w=400,h=300; + +function setViewBox(svg) { + var s = [x,y,w,h].join(' '); + svg.configure({viewBox: s }, true); + $resDiv.text(s); +} + + +function drawShape() { + var shape = this.id; + var svg = $('#svgbasics').svg('get'); + if (shape == 'rect') { + svg.rect(random(300), random(200), random(100) + 100, random(100) + 100, + {fill: colours[random(9)], stroke: colours[random(9)], + 'stroke-width': random(5) + 1}); + } + else if (shape == 'line') { + svg.line(random(400), random(300), random(400), random(300), + {stroke: colours[random(9)], 'stroke-width': random(5) + 1}); + } + else if (shape == 'circle') { + svg.circle(random(300) + 50, random(200) + 50, random(80) + 20, + {fill: colours[random(9)], stroke: colours[random(9)], + 'stroke-width': random(5) + 1}); + } + else if (shape == 'ellipse') { + svg.ellipse(random(300) + 50, random(200) + 50, random(80) + 20, random(80) + 20, + {fill: colours[random(9)], stroke: colours[random(9)], + 'stroke-width': random(5) + 1}); + } + else if (shape == 'clear') { + svg.clear(); + } + else if (shape == 'x+') { + x+=10; + setViewBox(svg); + } + else if (shape == 'x-') { + x-=10; + setViewBox(svg); + } + else if (shape == 'y+') { + y+=10; + setViewBox(svg); + } + else if (shape == 'y-') { + y-=10; + setViewBox(svg); + } + else if (shape == 'w+') { + w+=10; + setViewBox(svg); + } + else if (shape == 'w-') { + w-=10; + setViewBox(svg); + } + else if (shape == 'h+') { + h+=10; + setViewBox(svg); + } + else if (shape == 'h-') { + h-=10; + setViewBox(svg); + } + +} + +function random(range) { + return Math.floor(Math.random() * range); +} +</script> + </head> + <body> + <h1>jQuery SVG</h1> + <div id="img"> + <img src="peterskuppel.jpg" /> + </div> + <div id="svgbasics"></div> + <p> + <button id="rect">Add rectangle</button> + <button id="line">Add line</button> + <button id="circle">Add circle</button> + <button id="ellipse">Add ellipse</button> + <button id="x+">x+</button> + <button id="x-">x-</button> + <button id="y+">y+</button> + <button id="y-">y-</button> + <button id="w+">w+</button> + <button id="w-">w-</button> + <button id="h+">h+</button> + <button id="h-">h-</button> + <button id="clear">Clear</button> + </p> + <div id="res"/> + </body> +</html>