Skip to content

Commit e48fda3

Browse files
committed
Added example of using pplot.
1 parent 6df803e commit e48fda3

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ demos/getparam
1515
demos/alarm
1616
demos/dlgs
1717
demos/webbrowser
18+
demos/pplot

demos/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ ALL = \
3232
getparam$(EXE) \
3333
alarm$(EXE) \
3434
dlgs$(EXE) \
35-
webbrowser$(EXE)
35+
webbrowser$(EXE) \
36+
pplot$(EXE)
3637

3738
INC_DIRS=-I../iup/_obj
3839
LIB_DIRS=-L../iup/_obj

demos/pplot.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright (C) 2011 by Jeremy Cowgar <[email protected]>
3+
4+
This file is part of go-iup.
5+
6+
go-iup is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Lesser General Public License as
8+
published by the Free Software Foundation, either version 3 of
9+
the License, or (at your option) any later version.
10+
11+
go-iup is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with go-iup. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
package main
21+
22+
import (
23+
"github.com/jcowgar/go-iup"
24+
)
25+
26+
func main() {
27+
iup.Open()
28+
defer iup.Close()
29+
30+
pplot := iup.PPlot("EXPAND=YES")
31+
pplot.StoreAttribute("TITLE", "Bar Mode")
32+
pplot.StoreAttribute("TITLEFONTSIZE", "16")
33+
pplot.StoreAttribute("MARGINTOP", "40")
34+
pplot.StoreAttribute("MARGINLEFT", "30")
35+
pplot.StoreAttribute("MARGINBOTTOM","65")
36+
37+
labels := []string{
38+
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
39+
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
40+
values := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
41+
42+
pplot.PlotBegin(1)
43+
for i := 0; i < len(labels); i++ {
44+
pplot.PlotAddStr(labels[i], values[i])
45+
}
46+
pplot.PlotEnd()
47+
pplot.StoreAttribute("DS_MODE", "BAR")
48+
pplot.StoreAttribute("DS_COLOR", "100 100 200")
49+
50+
dlg := iup.Dialog(pplot, "SIZE=200x200,TITLE=\"PPlot Example\"")
51+
dlg.Show()
52+
53+
pplot.StoreAttribute("REDRAW", "")
54+
55+
iup.MainLoop()
56+
}

iup/pplot.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ package iup
2828
import "C"
2929
import "unsafe"
3030

31+
var pplotLibOpened = false
32+
3133
func PPlot(opts ...interface{}) *Ihandle {
3234
ensureControlLibOpened()
35+
36+
if pplotLibOpened == false {
37+
C.IupPPlotOpen()
38+
pplotLibOpened = true
39+
}
3340

3441
ih := &Ihandle{h: C.IupPPlot()}
3542

@@ -96,7 +103,7 @@ func (ih *Ihandle) PlotInsertStrPoints(index, sample_index int, x []string, y []
96103
}
97104

98105
// Differs from IupPlotInsertPoints as `count' is determined automatically in this case
99-
func (ih *Ihandle) IupPlotAddPoints(index int, x, y []float64) {
106+
func (ih *Ihandle) PlotAddPoints(index int, x, y []float64) {
100107
count := len(x)
101108
cX := float64ArrayToC(x)
102109
cY := float64ArrayToC(y)
@@ -105,7 +112,7 @@ func (ih *Ihandle) IupPlotAddPoints(index int, x, y []float64) {
105112
}
106113

107114
// Differs from IupPlotInsertPoints as `count' is determined automatically in this case
108-
func (ih *Ihandle) IupPlotAddStrPoints(index int, x []string, y []float64) {
115+
func (ih *Ihandle) PlotAddStrPoints(index int, x []string, y []float64) {
109116
count := len(x)
110117

111118
cX := stringArrayToC(x)

0 commit comments

Comments
 (0)