<script src="https://cdn.jsdelivr.net/gh/goessner/g2/dist/g2.js"></script>
+
<script src="https://cdn.jsdelivr.net/gh/goessner/g2/dist/g2.js"></script>
Tests #
Tests are found on the Github Page
diff --git a/docs/index.md b/docs/index.md
index c3a4c12..f5b1e62 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -9,7 +9,7 @@
"tags": []
---
- [![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/goessner/g2/blob/master/LICENSE)
+[![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/goessner/g2/blob/master/LICENSE)
[![npm](https://img.shields.io/npm/v/g2d.svg)](https://npmjs.com/package/g2d)
[![npm](https://img.shields.io/npm/dt/g2d.svg)](https://npmjs.com/package/g2d)
[![no dependencies](https://img.shields.io/gemnasium/mathiasbynens/he.svg)](https://github.com/goessner/g2)
@@ -26,7 +26,7 @@ So the API is minimal and easy to understand. The library is tiny, fast and rend
* Method chaining.
* Support of cartesian coordinates.
* Viewport pan and zoom transformations.
-* Low level path commands with short names adopted from SVG.
+* Low-level path commands with short names adopted from SVG.
* Higher level element commands.
* Maintaining a state stack for styling and transformations.
* Easy way to build custom symbol libraries.
@@ -45,7 +45,7 @@ So the API is minimal and easy to understand. The library is tiny, fast and rend
.exe(ctx); // draw to canvas.
```
-![first](/img/g2-first.png)
+![first](/img/g2-first.png
## API Reference
See the [API Reference for g2](api/g2.core.md) for details.
diff --git a/docs/index/index.chart.js b/docs/index/index.chart.js
index de3515a..d76271a 100644
--- a/docs/index/index.chart.js
+++ b/docs/index/index.chart.js
@@ -1,48 +1,43 @@
-new TestContainer("chart",
- tests = [
- new Test('chart',
- `g2().view({cartesian:true})
- .chart({x:40,y:40,b:190,h:90,
+tests.push(
+ new Test('chart',
+`g2().view({cartesian:true})
+ .chart({x:40,y:40,b:190,h:90,
funcs:[{data:[-2,4,2,-1,3,3,4,2],fill:true}],
title:{text:"chart"},
xaxis:{title:"x-axis",grid:true,origin:true},
yaxis:{title:"y-axis"},
})`),
- new Test('chart-2',
- `g2().view({cartesian:true})
- .chart({x:40,y:40,b:190,h:90,fs:'black',
- funcs:[
- {data:[-2,4,2,-1,3,3,4,2],style:{ls:'violet',lw:3}},
- {fn:Math.sin,dx:Math.PI/20,style:{ls:'green',lw:3}}
- ],
- title:{text:"chart"},
- xaxis:{title:"x-axis",origin:true},
- yaxis:{title:"y-axis",origin:true},
- })`),
+ new Test('chart2',
+ `g2().view({cartesian:true})
+.chart({x:40,y:40,b:190,h:90,fs:'black',
+funcs:[
+ {data:[-2,4,2,-1,3,3,4,2],style:{ls:'violet',lw:3}},
+ {fn:Math.sin,dx:Math.PI/20,style:{ls:'green',lw:3}}
+],
+title:{text:"chart"},
+xaxis:{title:"x-axis",origin:true},
+yaxis:{title:"y-axis",origin:true},
+})`),
- new Test('chart-3',
- `g2().view({cartesian:true})
- .chart({x:40,y:40,b:190,h:90,fs:'black',
- funcs:[
- {data:[-2,4,2,-1,3,3,4,2],style:{ls:'violet',
- lw:3,sh:[5,5,5,'rgba(255,0,255,0.7)']}},
- {fn:Math.sin,dx:Math.PI/20,style:{ls:'green',
- lw:3,sh:[5,5,5,'rgba(0,255,0,0.5)']}}
- ],
- title:{text:"chart"},
- xaxis:{title:"x-axis",origin:true},
- yaxis:{title:"y-axis",origin:true},
- })`),
- new Test('chart-4',
- `g2().view({cartesian:true})
- .chart({x:40,y:40,b:190,h:90,
- funcs:[{data:[-2,4,2,-1,3,3,4,2],fill:true}],
- title:{text:"chart",style:{fs:'blue'}},
- xaxis:{
- title:{text:"x-axis",style:{fs:'#0f0'}},
- grid:true,origin:true,labels:{style:{fs:'#f0f'}}
- },
- yaxis:{title:"y-axis",style:{fs:'rgb(255,0,0)'}},
- })`),
- ]
-);
+ new Test('chart3',
+ `g2().view({cartesian:true})
+.chart({x:40,y:40,b:190,h:90,fs:'black',
+ funcs:[
+ {data:[-2,4,2,-1,3,3,4,2],style:{ls:'violet',lw:3,sh:[5,5,5,'rgba(255,0,255,0.7)']}},
+ {fn:Math.sin,dx:Math.PI/20,style:{ls:'green',lw:3,sh:[5,5,5,'rgba(0,255,0,0.5)']}}
+ ],
+ title:{text:"chart"},
+ xaxis:{title:"x-axis",origin:true},
+ yaxis:{title:"y-axis",origin:true},
+})`),
+ new Test('chart4',
+ `g2().view({cartesian:true})
+.chart({x:40,y:40,b:190,h:90,
+ funcs:[{data:[-2,4,2,-1,3,3,4,2],fill:true}],
+ title:{text:"chart",style:{fs:'blue'}},
+ xaxis:{
+ title:{text:"x-axis",style:{fs:'#0f0'}},
+ grid:true,origin:true,labels:{style:{fs:'#f0f'}}
+ },
+ yaxis:{title:"y-axis",style:{fs:'rgb(255,0,0)'}},
+})`))
diff --git a/docs/index/index.core.js b/docs/index/index.core.js
deleted file mode 100644
index 703eb60..0000000
--- a/docs/index/index.core.js
+++ /dev/null
@@ -1,269 +0,0 @@
-new TestContainer(
- "core",
- tests = [
- new Test('clr',
- `g2().grid().clr()`),
-
- new Test('view',
- `g2().view({cartesian:true}).grid().origin()`),
-
- new Test('view-2',
- `g2().view({x:25,y:30}).grid().origin()`),
-
- new Test('view-3',
- `g2().view({scl:1.5,x:35,y:40}).grid().origin()`),
-
- new Test('view-4',
- `g2().view({x:35,y:35}).grid().view({scl:1.5}).origin()`),
-
- new Test('grid',
- `g2().grid()`),
-
- new Test('cir',
- `g2().cir({x:40,y:40,r:20,fs:'yellow'})
- .cir({x:120,y:60,r:40,ls:'red'})
- .cir({x:200,y:80,r:30,ld:[1,0,1]})`),
-
- new Test('cir-2',
- `g2().cir({x:40,y:40,r:20,fs:'yellow',sh:[5,5,5,'rgba(0,0,0,0.5)']})
- .cir({x:120,y:60,r:40,ls:'red',sh:[5,5,5,'rgba(0,0,0,0.7)']})
- .cir({x:200,y:80,r:30,ld:[1,0,1],sh:[5,5,5,'rgba(0,0,0,1)']})`),
-
- new Test('ell',
- `g2().ell({x:100,y:50,rx:20,ry:40,rot:2,fs:'orange'})
- .ell({x:210,y:50,rx:10,ry:30,w:1,dw:5,ls:'blue'})`),
-
- new Test('arc',
- `g2().arc({x:90,y:50,r:35,w:1/3*pi,dw:4/3*pi,
- ls:'blue',lw:5,fs:'#ddd'})
- .arc({x:120,y:50,r:35,w:1/3*pi,dw:-2/3*pi,
- ls:'blue',lw:5,fs:'#ddd'})`),
-
- new Test('arc-2',
- `g2().arc({x:90,y:50,r:35,w:1/3*pi,dw:4/3*pi,
- ls:'green',lw:5,fs:'#ddd',sh:[5,5,5,'rgba(0,0,0,0.5)']})
- .arc({x:120,y:50,r:35,w:1/3*pi,dw:-2/3*pi,
- ls:'green',lw:5,fs:'#ddd',sh:[5,5,5,'rgba(0,0,0,0.5)']})`),
-
- new Test('rec',
- `g2().rec({x:60,y:20,b:80,h:40,ls:'red',lw:3,fs:'#ddd'})
- .rec({x:120,y:70,b:80,h:40,ls:'blue',lw:3,
- fs:'#ddd',sh:[5,5,5,'rgba(0,0,0,0.5)']})`),
-
- new Test('lin',
- `g2().lin({x1:20,y1:30,x2:180,y2:80,ls:'green',lw:3})
- .lin({x1:30,y1:100,x2:200,y2:120,ls:'orange',
- lw:3,sh:[5,5,5,'rgba(0,0,0,0.5)']})`),
-
- new Test('ply',
- `g2().ply({pts:[20,10,60,80,120,30,180,90],
- ls:'red',lw:3,fs:'#ddd'})`),
-
- new Test('ply-2',
- `g2().ply({pts:[[20,10],[60,80],[120,30],[180,90]],
- ls:'red',lw:3,fs:'#ddd',w:0.3})`),
-
- new Test('ply-3',
- `g2().ply({y:30,
- pts:[{x:20,y:10},{x:60,y:80},{x:120,y:30},{x:180,y:90}],
- ls:'red',lw:3,fs:'#ddd',w:-0.3})`),
-
- new Test('ply-4',
- `g2().ply({pts:[20,10,60,80,120,30,180,90],ls:'red',lw:3})
- .ply({pts:[20,50,60,110,120,60,180,120],
- ls:'red',lw:3,sh:[5,5,5,'rgba(0,0,0,0.5)']})`),
-
- new Test('ply-5',
- `g2().ply({pts:[20,10,60,80,120,30,180,90],closed:true,
- ls:'red',lw:3,fs:'#ddd'})`),
-
- new Test('txt',
- `g2().txt({str:'Hello',x:30,y:30,w:0,
- fs:'red',font:'normal 30px serif'})
- .txt({str:'World!',x:120,y:30,w:0,fs:'blue',font:'normal 30px serif',
- sh:[5,5,5,'rgba(0,0,0,0.5)']})`),
-
- new Test('txt-2',
- `g2().txt({str:'Hello',x:100,y:50,w:0})
- .txt({str:'Hello',x:100,y:50,w:pi/2})
- .txt({str:'Hello',x:100,y:50,w:pi})
- .txt({str:'Hello',x:100,y:50,w:-pi/2})`),
-
- new Test('txt-3',
- `g2().grid({color:'#ccc',size:25})
- .txt({str:'LL',x:100,y:25,w:0,tval:'bottom'})
- .txt({str:'ML',x:100,y:50,w:0,tval:'middle'})
- .txt({str:'UL',x:100,y:75,w:0,tval:'top'})`),
-
- new Test('txt-4',
- `g2().grid({color:'#ccc',size:25})
- .beg({thal:'center'})
- .txt({str:'LL',x:100,y:25,w:0,tval:'bottom'})
- .txt({str:'ML',x:100,y:50,w:0,tval:'middle'})
- .txt({str:'UL',x:100,y:75,w:0,tval:'top'})
- .end()`),
-
- new Test('txt-5',
- `g2().grid({color:'#ccc',size:25})
- .beg({thal:'right'})
- .txt({str:'LL',x:100,y:25,w:0,tval:'bottom'})
- .txt({str:'ML',x:100,y:50,w:0,tval:'middle'})
- .txt({str:'UL',x:100,y:75,w:0,tval:'top'})
- .end()`),
-
- new Test('use',
- `g2().ins(() => { symbol = g2()
- .rec({x:-25,y:-25,b:50,h:50,ls:'gray',lw:3,fs:'@fs2'})
- .cir({x:0,y:0,r:20})
- })
- .use({grp:symbol,x:65,y:50,fs:'red',fs2:'green'})
- .use({grp:symbol,x:135,y:50,fs:'blue',fs2:'yellow'})`),
-
- new Test('use-2',
- `g2().ins(() => {smiley = g2()
- .cir({x:0,y:0,r:5})
- .arc({x:0,y:0,r:3,w:0.5,dw:2})
- .cir({x:-2,y:-1,r:1,fs:'snow'})
- .cir({x:2,y:-1,r:1,fs:'snow'})})
- .use({grp:smiley,x:50,y:50,fs:'yellow',scl:4,lw:1})
- .use({grp:smiley,x:150,y:50,fs:'orange',scl:5,lw:1});`),
-
- new Test('img',
- `g2().img({uri:'img/atom.png',b:200,h:100})`),
-
- new Test('img-2',
- `// intended 'file Not Found' error.
-g2().img({uri:'unknown.png',x:1,y:1,b:30,h:30})`),
-
- new Test('img-3',
- `g2().img({uri:'img/imageTst.png'})`),
-
- new Test('img-4',
- `g2().img({uri:'img/imageTst.png', x: 10, y: 10})`),
-
- new Test('img-5',
- `g2().img({uri:'img/imageTst.png', x: 10, y: 10, b: 100, h: 50})`),
-
- new Test('img-6',
- `g2().img({uri:'img/imageTst.png',x:10,y:10,b:100,h:50,w:0.5})
- .rec({x:10,y:10,b:100,h:50})`),
-
- new Test('img-7',
- `g2().img({uri:'img/imageTst.png',y:60,xoff:-10,yoff:-50,b:100,h:50})`),
-
- new Test('img-8',
- `g2().img({uri:'img/imageTst.png',y:60,x:10,yoff:-50,b:100,h:50,w:0.5})
- .rec({x:10,y:10,b:100,h:50})`),
-
- new Test('img-9',
- `g2().img({uri:'img/imageTst.png',y:10,x:10,scl:0.5})`),
-
- new Test('img-10',
- `g2().img({uri:'img/imageTst.png',x:10,y:10,b:200,h:100,sx:10,sy:10})
- .rec({x: 10, y: 10, b: 200, h: 100})`),
-
- new Test('img-11',
- `g2().img({uri:'img/imageTst.png',x:10,y:10,b:200,h:100,
- sx:10,sy:10,w:0.5})
- .beg({x: 10, y: 10, w: 0.5})
- .rec({b: 200, h: 100})
- .end()`),
-
- new Test('img-12',
- `g2().img({uri:'img/imageTst.png',x:50,y:50,b:140,h:65,xoff:10,yoff:10})
- .rec({x: 50, y: 50, b: 150, h: 75})`),
-
- new Test('img-13',
- `g2().img({uri:'img/imageTst.png',x:50,y:50,b:140,h:65,
- xoff:10,yoff:10,w:0.5})
- .beg({x:50, y:50, w:0.5})
- .rec({b: 150, h: 75})
- .end()`),
-
- new Test('img-14',
- `g2().img({uri:'img/imageTst.png',x:10,y:10,sb:100,sh:100,h:60})`),
-
- new Test('img-15',
- `g2().img({uri:'img/imageTst.png',x:10,y:10,sb:100,sh:100,h:60,w:0.5})`),
-
- new Test('img-16',
- `g2().view({cartesian:true})
- .img({uri:'img/imageTst.png'})`),
-
- new Test('img-17',
- `g2().view({cartesian:true})
- .img({uri:'img/imageTst.png', y: 10, x: 20, scl: 0.5, xoff:50, w:0.4}) `),
-
- new Test('img-18',
- `g2().view({cartesian:true})
- .img({uri:'img/imageTst.png',x:10,y:10,scl:.4})
- .img({uri:'img/imageTst.png',x:80,y:50,scl:.4})
- .img({uri:'img/imageTst.png',x:160,y:100,scl:.4})`),
-
- new Test('img-19',
- `g2().view({cartesian:true})
- .img({uri:'img/imageTst.png',x:10,y:10,sy:50,scl:.4})
- .cir({x:10,y:10,r:5})`),
-
- new Test('beg',
- `g2().beg({w:0.2,scl:2,ls:'#666',fs:'orange',
- lw:3,lc:'round',lj:'round'})
- .rec({x:30,y:10,b:30,h:20})
- .cir({x:130,y:20,r:20,fs:'green'})
- .end()`),
-
- new Test('end',
- `g2().beg({w:0.2,scl:2,ls:'#666',fs:'orange',
- lw:3,lc:'round',lj:'round'})
- .rec({x:30,y:10,b:30,h:20})
- .end()
- .cir({x:130,y:20,r:20,fs:'green'})`),
-
- new Test('stroke',
- `g2().p()
- .m({x:25,y:25})
- .q({x1:50,y1:0,x:75,y:25})
- .a({dw:-pi/2,x:75,y:75})
- .c({x1:50,y1:75,x2:50,y2:25,x:25,y:25})
- .z()
- .stroke({ls:'#888',lw:8,lc:'round',lj:'round'})`),
-
- new Test('fill',
- `g2().p()
- .m({x:25,y:25})
- .q({x1:50,y1:0,x:75,y:25})
- .a({dw:-pi/2,x:75,y:75})
- .c({x1:50,y1:75,x2:50,y2:25,x:25,y:25})
- .z()
- .fill({fs:'green'})`),
-
- new Test('drw',
- `g2().p()
- .m({x:25,y:25})
- .q({x1:50,y1:0,x:75,y:25})
- .a({dw:-pi/2,x:75,y:75})
- .c({x1:50,y1:75,x2:50,y2:25,x:25,y:25})
- .z()
- .drw({ls:'#888',fs:'green',lw:8,lc:'round',lj:'round'})`),
-
- new Test('drw-2',
- `g2().drw({d:'M100,10L123.5,82.4L61,37.6'+'L138,37.6L76.5,82.4Z'})`),
-
- new Test('drw-3',
- `g2().drw({lw:4,ls:'#080',fs:'#0f0',
- d:'M100,10L123.5,82.4L61,37.6'+'L138,37.6L76.5,82.4Z'})`),
-
- new Test('del',
- `g2().rec({x:60,y:30,b:80,h:40}).del().cir({x:100,y:50,r:35})`),
-
- new Test('ins',
-`const node = { fill:'lime', g2() {
- return g2().cir({x:160,y:50,r:15,fs:this.fill,lw:4,sh:[8,8,8,"gray"]})}
-};
-let color = 'red';
-g2().cir({x:40,y:50,r:15,fs:color,lw:4,sh:[8,8,8,"gray"]})
- .ins(()=>{color='green'})
- .cir({x:80,y:50,r:15,fs:color,lw:4,sh:[8,8,8,"gray"]})
- .ins((g)=>g.cir({x:120,y:50,r:15,fs:'orange',lw:4,sh:[8,8,8,"gray"]}))
- .ins(node)`)
- ]);
diff --git a/docs/index/index.ext.js b/docs/index/index.ext.js
deleted file mode 100644
index fb6896c..0000000
--- a/docs/index/index.ext.js
+++ /dev/null
@@ -1,66 +0,0 @@
-new TestContainer("ext",
- tests = [
-
- new Test('spline',
- `g2().spline({pts:[50,40,150,60,150,60],closed:false,lw:4,ls:'#080'})`),
-
- new Test('spline-2',
- `g2().spline({pts:[50,20,50,80,150,20],closed:false,lw:4,ls:'#080'})`),
-
- new Test('spline-3',
- `g2().spline({pts:[50,30,150,20,150,80,50,70],closed:true,
- lw:4,ls:'#080',fs:'orange'})`),
-
- new Test('label',
- `g2().view({cartesian:true})
- .cir({x:75,y:75,r:50,ld:[6,3]})
- .label({str:"c",loc:"c"})
- .label({str:"n",loc:"n",off:10})
- .label({str:"ne",loc:"ne",off:10})
- .label({str:"e",loc:"e",off:10})
- .label({str:"se",loc:"se",off:10})
- .label({str:"s",loc:"s",off:10})
- .label({str:"sw",loc:"sw",off:10})
- .label({str:"w",loc:"w",off:10})
- .label({str:"nw",loc:"nw",off:10})`),
-
- new Test('label-2',
- `g2().view({cartesian:true})
- .rec({x:50,y:30,b:100,h:75,ld:[6,3]})
- .label({str:"c",loc:"c",border:true})
- .label({str:"n",loc:"n",off:10,border:true})
- .label({str:"ne",loc:"ne",off:10,border:true})
- .label({str:"e",loc:"e",off:10,border:true})
- .label({str:"se",loc:"se",off:10,border:true})
- .label({str:"s",loc:"s",off:10,border:true})
- .label({str:"sw",loc:"sw",off:10,border:true})
- .label({str:"w",loc:"w",off:10,border:true})
- .label({str:"nw",loc:"nw",off:10,border:true})`),
-
- new Test('label-3',
- `g2().view({cartesian:true})
- .pol({x:20,y:75}).label({str:'pol',loc:'s',off:25})
- .gnd({x:60,y:75}).label({str:'gnd',loc:'s',off:25})
- .nod({x:100,y:75}).label({str:'nod',loc:'s',off:25})
- .dblnod({x:140,y:75}).label({str:'dblnod',loc:'s',off:25})
- .nodfix({x:180,y:75}).label({str:'nodfix',loc:'s',off:25})
- .nodflt({x:220,y:75}).label({str:'nodflt',loc:'s',off:25})
- .origin({x:260,y:75}).label({str:'origin',loc:'s',off:25})`),
-
- new Test('mark',
- `g2().view({cartesian:true})
- .cir({x:75,y:75,r:50,ld:[6,3]})
- .mark({mrk:"dot",loc:["c","n","ne","e","se","s","sw","w","nw"]})`),
-
- new Test('mark-2',
- `g2().view({cartesian:true})
- .rec({x:50,y:30,b:100,h:75,ld:[6,3]})
- .mark({mrk:"dot",loc:["c","n","ne","e","se","s","sw","w","nw"]})`),
-
- new Test('mark-3',
- `g2().view({cartesian:true})
- .ply({pts:[40,40,100,40,100,100,200,100,200,40]})
- .mark({mrk:"dot",loc:["beg",0.25,"mid",0.75,1]})
- .mark({mrk:"tick",loc:[0.1,0.3,0.5,0.7,0.9]})`),
-
- ]);
\ No newline at end of file
diff --git a/docs/index/index.js b/docs/index/index.js
new file mode 100644
index 0000000..296314a
--- /dev/null
+++ b/docs/index/index.js
@@ -0,0 +1,221 @@
+class Test {
+ constructor(name,src) {
+ this.name = name;
+ this.src = src;
+ }
+}
+const pi = Math.PI;
+const tests = [
+
+new Test('view',
+`g2().view({cartesian:true}).grid().origin()`),
+
+new Test('view2',
+`g2().view({x:25,y:30}).grid().origin()`),
+
+new Test('view3',
+`g2().view({scl:1.5,x:35,y:40}).grid().origin()`),
+
+new Test('view4',
+`g2().view({x:35,y:35}).grid().view({scl:1.5}).origin()`),
+
+new Test('del',
+`g2().rec({x:60,y:30,b:80,h:40}).del().cir({x:100,y:50,r:35})`),
+
+new Test('lin',
+`g2().lin({x1:20,y1:30,x2:180,y2:80,ls:'green',lw:3})`),
+
+new Test('rec',
+`g2().rec({x:60,y:30,b:80,h:40,ls:'red',lw:3,fs:'#ddd'})`),
+
+new Test('cir',
+`g2().cir({x:100,y:50,r:35})`),
+
+new Test('arc',
+`g2().arc({x:90,y:50,r:35,w:1/3*pi,dw:4/3*pi,ls:'blue',lw:5,fs:'#ddd'})
+.arc({x:120,y:50,r:35,w:1/3*pi,dw:-2/3*pi,ls:'blue',lw:5,fs:'#ddd'})`),
+
+new Test('ply',
+`g2().ply({pts:[20,10,60,80,120,30,180,90],ls:'red',lw:3})`),
+
+new Test('ply2',
+`g2().ply({pts:[20,10,60,80,120,30,180,90],ls:'red',lw:3,fs:'#ddd'})`),
+
+new Test('ply3',
+`g2().ply({pts:[[20,10],[60,80],[120,30],[180,90]],ls:'red',lw:3,fs:'#ddd'})`),
+
+new Test('ply4',
+`g2().ply({pts:[{x:20,y:10},{x:60,y:80},{x:120,y:30},{x:180,y:90}],ls:'red',lw:3,fs:'#ddd'})`),
+
+new Test('ply5',
+`g2().ply({pts:[20,10,60,80,120,30,180,90],closed:true,ls:'red',lw:3,fs:'#ddd'})`),
+
+new Test('path',
+`g2()
+.p()
+.m({x:25,y:25})
+.q({x1:50,y1:0,x:75,y:25})
+.a({dw:-pi/2,x:75,y:75})
+.c({x1:50,y1:75,x2:50,y2:25,x:25,y:25})
+.z()
+.stroke({ls:'#888',lw:8,lc:'round',lj:'round'})`),
+
+new Test('path2',
+`g2()
+.p()
+.m({x:25,y:25})
+.q({x1:50,y1:0,x:75,y:25})
+.a({dw:-pi/2,x:75,y:75})
+.c({x1:50,y1:75,x2:50,y2:25,x:25,y:25})
+.z()
+.fill({fs:'green'})`),
+
+new Test('path3',
+`g2()
+.p()
+.m({x:25,y:25})
+.q({x1:50,y1:0,x:75,y:25})
+.a({dw:-pi/2,x:75,y:75})
+.c({x1:50,y1:75,x2:50,y2:25,x:25,y:25})
+.z()
+.drw({ls:'#888',fs:'green',lw:8,
+lc:'round',lj:'round'})`),
+
+new Test('path4',
+`g2().drw({d:'M100,10L123.5,82.4L61,37.6'+'L138,37.6L76.5,82.4Z'})`),
+
+new Test('path5',
+`g2().drw({lw:4,ls:'#080',fs:'#0f0',d:'M100,10L123.5,82.4L61,37.6'+'L138,37.6L76.5,82.4Z'})`),
+
+new Test('spline',
+`g2().spline({pts:[50,40,150,60,150,60],closed:false,lw:4,ls:'#080'})`),
+
+new Test('spline2',
+`g2().spline({pts:[50,20,50,80,150,20],closed:false,lw:4,ls:'#080'})`),
+
+new Test('spline3',
+`g2().spline({pts:[50,30,150,20,150,80,50,70],closed:true,lw:4,ls:'#080',fs:'orange'})`),
+
+new Test('txt',
+`g2().txt({str:'Hello',x:30,y:30,w:0,fs:'red',font:'normal 30px serif'})`),
+
+new Test('txt2',
+`g2().txt({str:'Hello',x:100,y:50,w:0})
+.txt({str:'Hello',x:100,y:50,w:pi/2})
+.txt({str:'Hello',x:100,y:50,w:pi})
+.txt({str:'Hello',x:100,y:50,w:-pi/2})`),
+
+new Test('txt3',
+`g2().grid({color:'#ccc',size:25})
+.txt({str:'LL',x:100,y:25,w:0,tval:'bottom'})
+.txt({str:'ML',x:100,y:50,w:0,tval:'middle'})
+.txt({str:'UL',x:100,y:75,w:0,tval:'top'})`),
+
+new Test('txt4',
+`g2().grid({color:'#ccc',size:25})
+.beg({thal:'center'})
+.txt({str:'LL',x:100,y:25,w:0,tval:'bottom'})
+.txt({str:'ML',x:100,y:50,w:0,tval:'middle'})
+.txt({str:'UL',x:100,y:75,w:0,tval:'top'})
+.end()`),
+
+new Test('txt5',
+`g2().grid({color:'#ccc',size:25})
+.beg({thal:'right'})
+.txt({str:'LL',x:100,y:25,w:0,tval:'bottom'})
+.txt({str:'ML',x:100,y:50,w:0,tval:'middle'})
+.txt({str:'UL',x:100,y:75,w:0,tval:'top'})
+.end()`),
+
+new Test('img',
+`g2().img({uri:'../docs/img/atom.png',b:200,h:100})`),
+
+new Test('img2',
+`// intended 'file Not Found' error.
+g2().img({uri:'unknown.png',x:1,y:1,b:30,h:30})`),
+
+new Test('img3',
+`g2().img({uri:'img/imageTst.png'})`),
+
+new Test('img4',
+`g2().img({uri:'img/imageTst.png', x: 10, y: 10})`),
+
+new Test('img5',
+`g2().img({uri:'img/imageTst.png', x: 10, y: 10, b: 100, h: 50})`),
+
+new Test('img6',
+`g2().img({uri:'img/imageTst.png', x: 10, y: 10 , b: 100, h: 50, w: 0.5})
+ .rec({x: 10, y: 10, b: 100, h: 50})`),
+
+new Test('img7',
+`g2()
+ .img({uri:'img/imageTst.png', x: 10, yoff: -50, y: 60, b: 100, h: 50, w: 0.5})
+ .rec({x: 10, y: 10, b: 100, h: 50})`),
+
+new Test('img8',
+`g2().img({uri:'img/imageTst.png', y: 10, x: 10, scl: 0.5})`),
+
+new Test('img9',
+`g2().img({uri:'img/imageTst.png', x: 10, y: 10, dx: 100, dy: 100, h: 60})`),
+
+new Test('img10',
+`g2().view({cartesian:true})
+ .img({uri:'img/imageTst.png'})`),
+
+new Test('img11',
+`g2().view({cartesian:true})
+ .img({uri:'img/imageTst.png', x: 10, y: 10, scl:.4})
+ .img({uri:'img/imageTst.png', x: 80, y: 50, scl:.4})
+ .img({uri:'img/imageTst.png', x: 160, y: 100, scl:.4})`),
+
+new Test('img12',
+`g2().img({uri:'img/imageTst.png', x: 10, y: 10, b: 200, h: 100, sx: 10, sy: 10, w: 0.5})
+ .beg({x: 10, y: 10, w: 0.5})
+ .rec({b: 200, h: 100})
+ .end()`),
+
+new Test('img13',
+`g2().img({uri:'img/imageTst.png', x: 50, y: 50, b:140, h:65, xoff: 10, yoff: 10, w:0.5})
+ .beg({x:50, y:50, w:0.5})
+ .rec({b: 150, h: 75})
+ .end()`),
+
+new Test('beg-end',
+`g2().beg({x:70,y:30,w:0.2,scl:2,ls:'#666',fs:'orange',lw:3,lc:'round',lj:'round'})
+.rec({x:0,y:0,b:30,h:20}).end()`),
+
+new Test('use',
+`g2()
+.ins(() =>{ symbol = g2()
+.rec({x:-25,y:-25,b:50,h:50,ls:'gray',lw:3,fs:'@fs2'})
+.cir({x:0,y:0,r:20})})
+.use({grp:symbol,x:65,y:50,fs:'red',fs2:'green'})
+.use({grp:symbol,x:135,y:50,fs:'blue',fs2:'yellow'})`),
+
+new Test('use2',
+`g2().ins(() => {smiley = g2()
+.cir({x:0,y:0,r:5})
+.arc({x:0,y:0,r:3,w:0.5,dw:2})
+.cir({x:-2,y:-1,r:1,fs:'snow'})
+.cir({x:2,y:-1,r:1,fs:'snow'})})
+.use({grp:smiley,x:50,y:50,fs:'yellow',scl:4,lw:1})
+.use({grp:smiley,x:150,y:50,fs:'orange',scl:5,lw:1});`),
+
+new Test('shadow',
+`g2().beg({lw:3,ls:'#456',fs:'yellow',ld:[8, 4, 2, 4], sh:[5,5,5,'rgba(0,0,0,0.7)']})
+.rec({x:30,y:40,b:50,h:20})
+.cir({x:140,y:50,r:40})`),
+
+new Test('grid',
+`g2().grid()`),
+
+new Test('mark',
+`g2().view({cartesian:true})
+ .ply({y:40,pts:[40,40,100,40,100,100,200,100,200,40], mark:4})
+ .ply({y:-30,pts:[40,40,100,40,100,100,200,100,200,40], mark:4, closed:true})`),
+
+new Test('mark2',
+`g2().cir({x:50,y:50,r:25,mark:{symbol:'sqr',loc:[0,0.5,0.7]}})
+ .rec({x:150,y:30,b:40,h:60,mark:{symbol:g2.symbol.sqr,count:6}})
+ .lin({x1:50,y1:130,x2:150,y2:130,mark:8})`)
+];
\ No newline at end of file
diff --git a/docs/index/index.mec.js b/docs/index/index.mec.js
index cc70729..6bf4ef0 100644
--- a/docs/index/index.mec.js
+++ b/docs/index/index.mec.js
@@ -1,127 +1,133 @@
-new TestContainer("mec",
- tests = [
- new Test('dim',
- `g2().dim({x1:50,y1:75,x2:230,y2:75})
- .dim({x1:50,y1:125,x2:230,y2:125,inside:false})`),
-
- new Test('dim-2',
- `A = {x1: 30,y1:50,x2:200,y2:120}
-g2().lin({...A,ls:"red",lw:2})
- .dim({...A, off:-15,over:5})`),
-
- new Test('adim',
- `g2().adim({x:100,y:70,r:50,w:pi/3,dw:4*pi/3})
- .adim({x:200,y:70,r:50,w:pi/3,dw:-4*pi/3,inside:false})`),
-
- new Test('vec',
- `g2().vec({x1:50,y1:20,x2:250,y2:120})`),
+tests.push(
+new Test ('g2.mec.js',
+ `g2().txt({str:"the following tests are for g2.mec.js",x:50,y:50})`),
- new Test('avec',
- `g2().avec({x: 220, y: 50, r: 30, w: 1, dw: -Math.PI})
+new Test('symbols',
+`
+const label = (str) => ({str, loc:'s', off:15});
+g2().view({cartesian:true})
+ .pol({x:20,y:75,label:label('pol')})
+ .gnd({x:60,y:75,label:label('gnd')})
+ .nod({x:100,y:75,label:label('nod')})
+ .dblnod({x:140,y:75,label:label('dblnod')})
+ .nodfix({x:180,y:75,label:label('nodfix')})
+ .nodflt({x:220,y:75,label:label('nodflt')})
+ .origin({x:260,y:75,label:label('origin')})`),
+
+new Test('vec',
+`g2().vec({x1:50,y1:20,x2:250,y2:120})`),
+
+new Test('avec',
+`g2().avec({x: 220, y: 50, r: 30, w: 1, dw: -Math.PI})
.avec({x: 180, y: 80, w: Math.PI/2, dw: Math.PI, r: 50})
.lin({x1: 180, x2: 180, y1: 20, y2: 140})
.avec({x: 65, y: 65, r: 60, w: 1})
- .avec({x: 80, y: 50, r: 30})`),
+ .avec({x: 80, y: 50, r: 70, dw: 1, w:2})
+ .lin({x1:80,y1:50,x2:80+Math.cos(3)*75,y2:50+Math.sin(3)*75})
+ .lin({x1:80,y1:50,x2:80+Math.cos(2)*75,y2:50+Math.sin(2)*75})`),
+
+new Test('dim',
+`g2().dim({x1:20,y1:75,x2:200,y2:75})
+ .dim({x1:20,y1:125,x2:200,y2:125,inside:false})`),
+
+new Test('dim2',
+`A = {x1: 30, y1:50, x2: 200, y2: 50};
+B = {x1: 40, y1: 80, x2: 210, y2: 130};
+g2().lin({...A, ls: "red", lw: 2})
+ .dim({...A, off: 15})
+ .lin({...B, ls: "red", lw: 2})
+ .dim({...B, off: 10})`),
+
+new Test('adim',
+`g2().adim({x:100,y:70,r:50,w:pi/3,dw:4*pi/3})
+ .adim({x:200,y:70,r:50,w:pi/3,dw:-4*pi/3,inside:false})`),
- new Test('slider',
- `g2().grid().slider({x:150,y:75,w:Math.PI/4,b:64,h:32})`),
+new Test('slider',
+`g2().grid().slider({x:150,y:75,w:Math.PI/4,b:64,h:32})`),
- new Test('spring',
- `g2().spring({x1:50,y1:50,x2:200,y2:25})
+new Test('spring',
+`g2().spring({x1:50,y1:50,x2:200,y2:25})
.spring({x1:50,y1:100,x2:200,y2:125,h:32})`),
- new Test('damper',
- `g2().damper({x1:120,y1:60,x2:240,y2:70})
+new Test('damper',
+`g2().damper({x1:120,y1:60,x2:240,y2:70})
.damper({x1:50,y1:100,x2:200,y2:125,h:32})`),
- new Test('link',
- `let A = {x:50,y:25},B = {x:150,y:25},
+new Test('link',
+`let A = {x:50,y:25},B = {x:150,y:25},
C = {x:50,y:75}, D = {x:100,y:75},
E = {x:50,y:125};
g2().view({cartesian:true})
.link({pts:[A,B,E,A,D,C]})`),
- new Test('link2',
- `let A = {x:50,y:25},B = {x:150,y:25},
+new Test('link2',
+`let A = {x:50,y:25},B = {x:150,y:25},
C = {x:50,y:75}, D = {x:100,y:75},
E = {x:50,y:125};
g2().view({cartesian:true})
.link2({pts:[A,B,E,A,D,C]})
- .nodfix({...A,scl:1.5})
- .nod({...B,scl:1.5})
- .nod({...C,scl:1.5})
- .nod({...D,scl:1.5})
- .nodflt({...E,w:-Math.PI/2,scl:1.5})`),
-
- new Test('beam',
- `g2().view({cartesian:true})
+ .nodfix({...A,scl:1.2})
+ .nod({...B,scl:1.2})
+ .nod({...C,scl:1.2})
+ .nod({...D,scl:1.2})
+ .nodflt({...E,w:-Math.PI/2,scl:1.2})`),
+
+new Test('beam',
+`g2().view({cartesian:true})
.beam({pts:[[200,125],[50,125],[50,50],[200,50]]})`),
- new Test('beam2',
- `g2().view({cartesian:true})
+new Test('beam2',
+`g2().view({cartesian:true})
.beam2({pts:[[200,125],[50,125],[50,50],[200,50]]})`),
- new Test('bar',
- `g2().bar({x1:50,y1:20,x2:250,y2:120})`),
+new Test('bar',
+`g2().bar({x1:50,y1:20,x2:250,y2:120})`),
- new Test('bar2',
- `g2().bar2({x1:50,y1:120,x2:250,y2:120})`),
+new Test('bar2',
+`g2().bar2({x1:50,y1:120,x2:250,y2:120})`),
- new Test('pulley',
- `g2().view({cartesian:true})
+new Test('pulley',
+`g2().view({cartesian:true})
.pulley({x:150,y:80,r:50})`),
- new Test('pulley2',
- `g2().view({cartesian:true})
+new Test('pulley2',
+`g2().view({cartesian:true})
.pulley2({x:150,y:80,r:50})`),
- new Test('rope',
- `let A = {x:50,y:30}, B = {x:200,y:75};
+new Test('rope',
+`let A = {x:50,y:30}, B = {x:200,y:75};
g2().view({cartesian:true})
.pulley({...A,r:20}).pulley2({...B,r:40})
.rope({p1:A,r1:20,p2:B,r2:40})`),
- new Test('ground',
- `g2().ground({pts:[25,25,25,75,75,75,75,25,125,25],
- pos:'left'})`),
+new Test('ground',
+`g2().ground({pts:[25,25,25,75,75,75,75,25,125,25],pos:'left'})`),
- new Test('load',
- `g2().view({cartesian:true})
+new Test('load',
+`g2().view({cartesian:true})
.bar({x1:20,y1:50,x2:220,y2:50})
.load({pts:[20,50,30,140,250,90,220,50],
lw:1,w:-Math.PI/3,ls:"blue"})`),
- new Test('load-2',
- `g2().view({cartesian:true})
+new Test('load2',
+`g2().view({cartesian:true})
.load({pts:[10,10,100,10,100,130,200,130,200,60,10,60],spacing:10})`),
- new Test('pol',
- `g2().view({cartesian:true})
- .pol({x:20,y:75})
- .gnd({x:60,y:75})
- .nod({x:100,y:75})
- .dblnod({x:140,y:75})
- .nodfix({x:180,y:75})
- .nodflt({x:220,y:75})
- .origin({x:260,y:75})`),
-
- new Test('mec',
- `let A = {x:50,y:25},B = {x:150,y:25},
+new Test('mec',
+`let A = {x:50,y:25},B = {x:150,y:25},
C = {x:50,y:75}, D = {x:100,y:75},
E = {x:50,y:125};
g2().view({cartesian:true})
.link2({pts:[A,B,E,A,D,C]})
- .nodfix({...A,scl:1.5})
- .nod({...B,scl:1.5})
- .nod({...C,scl:1.5})
- .nod({...D,scl:1.5})
- .nodflt({...E,w:-Math.PI/2,scl:1.5})
- .ground({pts:[{x:E.x-23,y:E.y+20},
- {x:A.x-23,y:A.y-18},{x:D.x,y:A.y-18}]})
+ .nodfix({...A,scl:1.2})
+ .nod({...B,scl:1.2})
+ .nod({...C,scl:1.2})
+ .nod({...D,scl:1.2})
+ .nodflt({...E,w:-Math.PI/2,scl:1.2})
+ .ground({pts:[{x:E.x-23,y:E.y+20},{x:A.x-23,y:A.y-18},{x:D.x,y:A.y-18}]})
.vec({x1:D.x,y1:D.y,x2:D.x+50,y2:D.y,ls:'darkred',lw:2})
.vec({x1:B.x,y1:B.y,x2:B.x,y2:B.y-20,ls:'darkred',lw:0.5})
- .dim({x1:E.x,y1:E.y+15,x2:D.x,y2:E.y+15}).label({str:'b',loc:'s'})
- .dim({x1:D.x,y1:E.y+15,x2:B.x,y2:E.y+15}).label({str:'b',loc:'s'})
- .dim({x1:B.x+15,y1:E.y,x2:B.x+15,y2:D.y}).label({str:'b',loc:'w'})
- .dim({x1:B.x+15,y1:D.y,x2:B.x+15,y2:B.y}).label({str:'b',loc:'w'})`)
- ]);
+ .dim({x1:E.x,y1:E.y+15,x2:D.x,y2:E.y+15,label:'b'})
+ .dim({x1:D.x,y1:E.y+15,x2:B.x,y2:E.y+15,label:'b'})
+ .dim({x1:B.x+15,y1:E.y,x2:B.x+15,y2:D.y,label:'b'})
+ .dim({x1:B.x+15,y1:D.y,x2:B.x+15,y2:B.y,label:'b'})`));
diff --git a/docs/microjam.md/Animation.html b/docs/microjam.md/Animation.html
index 7c3a7db..9cb917b 100644
--- a/docs/microjam.md/Animation.html
+++ b/docs/microjam.md/Animation.html
@@ -33,7 +33,8 @@
Insert
Animation
Interactivity
-
Custom HTML Element
+
Custom HTML element
+
Custom chart element
@@ -87,13 +88,13 @@ Example #
g.del()
.clr()
- .ply({pts:[44,40,56,40,x0,y0],closed:true,fs:"#ddd"})
+ .ply({pts:[44,40,56,40,x0,y0],closed:true,fs:"#ddd"})
.lin({x1:x0,y1:y0,x2:x,y2:y,lw:3})
- .cir({x:x0,y:y0,r:3,fs:"#ddd"})
- .cir({x:x,y:y,r:8,fs:"#ddd"})
+ .cir({x:x0,y:y0,r:3,fs:"#ddd"})
+ .cir({x:x,y:y,r:8,fs:"#ddd"})
.exe(ctx);
phi += dphi;
- requestAnimationFrame(render);
+ requestAnimationFrame(render);
}
render();