Skip to content

Commit

Permalink
update README, add svgrid, svgplot definition script
Browse files Browse the repository at this point in the history
  • Loading branch information
ajstarks committed Apr 15, 2012
1 parent e4519fb commit 89b8b93
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ A video describing how to use the package can be seen on YouTube at <http://www.
* stockproduct: Visualize product and stock prices
* svgopher: SVGo Mascot
* svgplot Plot data
* svgrid Compose SVG files in a grid
* tsg: Twitter Search Grid
* vismem: Visualize data from files
* webfonts: "Hello, World" with Google Web Fonts
Expand Down
24 changes: 24 additions & 0 deletions svgplot/mksvgplotdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
rm f??*.svg
gopts="-bx=50 -by=20 -width=460 -height=130 -pw=400 -ph=90 -barsize=3 -fontsize=11"
data="test.d"
# opt
svgplot $gopts -showbg -connect=f -label=showbg $data > f00.svg
svgplot $gopts -connect -label=connect $data > f01.svg
svgplot $gopts -showbar -connect=f -label=showbar $data > f02.svg
svgplot $gopts -horizon -connect=f -label=horizon $data > f03.svg
svgplot $gopts -showdot -connect=f -label=showdot $data > f04.svg
svgplot $gopts -showx -label=showx $data > f05.svg
svgplot $gopts -showy -label=showy $data > f06.svg
svgplot $gopts -showfile -label=showfile $data > f07.svg
# attr
svgplot $gopts -bgcolor=lightsteelblue -label=bgcolor $data > f08.svg
svgplot $gopts -linecolor=red -label=linecolor $data > f09.svg
svgplot $gopts -barcolor=red -showbar -connect=f -label=barcolor $data > f10.svg
svgplot $gopts -hcolor=red -horizon -connect=f -label=hcolor $data > f11.svg
svgplot $gopts -showdot -dotcolor=red -connect=f -label=dotcolor $data > f12.svg
svgplot $gopts -label=fontsize $data > f13.svg
svgplot $gopts -font=Courier -label="font" $data > f14.svg
svgplot $gopts -label=labelcolor -labelcolor=red $data > f15.svg
svgrid -h 1200 -w 1024 -r=f -x=50 -y=50 -g 10 -c 8 f??.svg > svgplotdef.svg

51 changes: 51 additions & 0 deletions svgplot/test.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
0 493.65
1 497.57
2 506.38
3 521.03
4 532.44
5 535.36
6 546.60
7 531.99
8 527.28
9 534.01
10 538.26
11 528.94
12 597.62
13 594.94
14 602.55
15 595.35
16 606.99
17 618.23
18 618.98
19 622.52
20 607.22
21 610.94
22 603.69
23 606.77
24 592.40
25 601.17
26 577.52
27 579.04
28 546.02
29 573.41
30 549.01
31 562.13
32 563.77
33 557.23
34 539.00
35 533.15
36 504.88
37 490.92
38 498.17
39 518.82
40 523.29
41 520.04
42 526.86
43 539.08
44 540.70
45 540.96
46 532.50
47 524.84
48 522.18
49 534.03
50 534.96
90 changes: 90 additions & 0 deletions svgrid/svgrid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// svgrid -- composite SVG files in a grid
package main

import (
"encoding/xml"
"flag"
"fmt"
"io"
"os"

"github.com/ajstarks/svgo"
)

// SVG is a SVG document
type SVG struct {
Width int `xml:"width,attr"`
Height int `xml:"height,attr"`
Doc string `xml:",innerxml"`
}

var (
byrow bool
startx, starty, count, gutter, gwidth, gheight int
canvas = svg.New(os.Stdout)
)

// init sets up command line options
func init() {
flag.BoolVar(&byrow, "r", true, "order row wise")
flag.IntVar(&startx, "x", 0, "begin x")
flag.IntVar(&starty, "y", 0, "begin y")
flag.IntVar(&count, "c", 3, "columns or rows")
flag.IntVar(&gutter, "g", 100, "gutter")
flag.IntVar(&gwidth, "w", 1024, "width")
flag.IntVar(&gheight, "h", 768, "height")
flag.Parse()
}

// placepic puts a SVG file at a location
func placepic(x, y int, filename string) (int, int) {
var s SVG
f, err := os.Open(filename)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return 0, 0
}
defer f.Close()
if err := xml.NewDecoder(f).Decode(&s); err != nil {
fmt.Fprintf(os.Stderr, "Unable to parse (%v)\n", err)
return 0, 0
}
canvas.Group(`clip-path="url(#pic)"`, fmt.Sprintf(`transform="translate(%d,%d)"`, x, y))
canvas.ClipPath(`id="pic"`)
canvas.Rect(0, 0, s.Width, s.Height)
canvas.ClipEnd()
io.WriteString(canvas.Writer, s.Doc)
canvas.Gend()
return s.Width, s.Height
}

// compose places files row or column-wise
func compose(x, y, n int, rflag bool, files []string) {
px := x
py := y
var pw, ph int
for i, f := range files {
if i > 0 && i%n == 0 {
if rflag {
px = x
py += gutter + ph
} else {
px += gutter + pw
py = y
}
}
pw, ph = placepic(px, py, f)
if rflag {
px += gutter + pw
} else {
py += gutter + ph
}
}
}

// main lays out files as specified on the command line
func main() {
canvas.Start(gwidth, gheight)
compose(startx, starty, count, byrow, flag.Args())
canvas.End()
}

0 comments on commit 89b8b93

Please sign in to comment.