Skip to content

Commit

Permalink
Format tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klawr committed Jun 10, 2020
1 parent d2b6b30 commit b4928b2
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 41 deletions.
6 changes: 4 additions & 2 deletions docs/index/index.chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ new TestContainer("chart",
`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)']}}
{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},
Expand Down
84 changes: 52 additions & 32 deletions docs/index/index.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,54 @@ new TestContainer(
.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'})`),
`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)']})`),
`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)']})`),
.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)']})`),
.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'})`),
`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})`),
`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})`),
`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)']})`),
.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'})`),
`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)']})`),
`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})
Expand Down Expand Up @@ -131,44 +145,46 @@ g2().img({uri:'unknown.png',x:1,y:1,b:30,h:30})`),
`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})`),
`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})`),
`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})`),
`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})`),
`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})
`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})
`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})
`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})
`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})`),
`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})`),
`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})
Expand All @@ -180,22 +196,25 @@ g2().img({uri:'unknown.png',x:1,y:1,b:30,h:30})`),

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})`),
.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})
`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'})
`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'})
`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'})`),
Expand Down Expand Up @@ -231,7 +250,8 @@ g2().img({uri:'unknown.png',x:1,y:1,b:30,h:30})`),
`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'})`),
`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})`),
Expand Down
3 changes: 2 additions & 1 deletion docs/index/index.ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ new TestContainer("ext",
`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'})`),
`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})
Expand Down
13 changes: 8 additions & 5 deletions docs/index/index.mec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,18 @@ g2().view({cartesian:true})
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})`),
.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'})`),
`g2().ground({pts:[25,25,25,75,75,75,75,25,125,25],
pos:'left'})`),

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"})`),
.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})
Expand All @@ -113,12 +116,12 @@ g2().view({cartesian:true})
.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}]})
.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'})`)

]);
2 changes: 1 addition & 1 deletion docs/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</style>
</head>
<body>
<script src="https://gitcdn.xyz/repo/goessner/g2/master/src/g2.js"></script>
<script src="https://cdn.jsdelivr.net/gh/goessner/g2@latest/src/g2.js"></script>
<div class="container-fluid" id="container">
<h1>g2 Tests</h1>
<h6>g2.js, g2.ext.js, g2.mec.js are referenced. canvas and image should look alike.</h6>
Expand Down

0 comments on commit b4928b2

Please sign in to comment.