graphkit 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/VERSION +1 -1
- data/graphkit.gemspec +3 -3
- data/lib/graphkit/gnuplot.rb +86 -36
- data/lib/graphkit.rb +6 -64
- data/test/test_graphkit.rb +78 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30e1a05bbf7cc899ca1c2e8682de4b93dd6f3870
|
4
|
+
data.tar.gz: 9a8d784fc19bac844f949b7ff49ef1bef9994669
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 872a13313d9af37ccec3636ab625295a03c0523acc5964eacd93cd12779499b01991f5ab4c3be0ba95051d7ee493883dc2ef979b702afa454bc2fdd91e511850
|
7
|
+
data.tar.gz: a3c15244935e8dc67af1b53bd937f7ad7016e591415810a13e5f58fdc715b449ac761f5bdb9d6d8044e055b65c639c2c15cf302fd500e566ab36b690b33546c8
|
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/graphkit.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: graphkit 0.
|
5
|
+
# stub: graphkit 0.3.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "graphkit"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Edmund Highcock"]
|
14
|
-
s.date = "2014-03-
|
14
|
+
s.date = "2014-03-17"
|
15
15
|
s.description = "A GraphKit is a device independent intelligent data container that allows the easy sharing, combining and plotting of graphic data representations. Easily created from data, they can be output in a variety of formats using packages such as gnuplot. "
|
16
16
|
s.email = "edmundhighcock@sourceforge.net"
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/graphkit/gnuplot.rb
CHANGED
@@ -88,6 +88,7 @@ class GraphKit
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
class GnuplotSetOptions < KitHash
|
91
|
+
attr_accessor :multiplot_following
|
91
92
|
alias :hash_key :key
|
92
93
|
undef :key
|
93
94
|
QUOTED = [ "title", "output", "xlabel", "ylabel", "zlabel", "x2label", "y2label", "z2label" ]
|
@@ -103,7 +104,7 @@ class GnuplotSetOptions < KitHash
|
|
103
104
|
isosamples key label lmargin
|
104
105
|
loadpath locale log logscale
|
105
106
|
macros mapping margin missing
|
106
|
-
mouse
|
107
|
+
mouse mx2tics mxtics
|
107
108
|
my2tics mytics mztics object
|
108
109
|
nosurface
|
109
110
|
offsets origin output palette
|
@@ -122,7 +123,8 @@ class GnuplotSetOptions < KitHash
|
|
122
123
|
y2zeroaxis ydata ydtics ylabel
|
123
124
|
ymtics yrange ytics yzeroaxis
|
124
125
|
zdata zdtics zero zeroaxis
|
125
|
-
zlabel zmtics zrange ztics
|
126
|
+
zlabel zmtics zrange ztics
|
127
|
+
multiplot ].map{|s| s.to_sym}
|
126
128
|
# p instance_methods.sort
|
127
129
|
GNUPLOT_SETS.each do |opt|
|
128
130
|
define_method(opt + "=".to_sym) do |str|
|
@@ -141,12 +143,21 @@ class GnuplotSetOptions < KitHash
|
|
141
143
|
end
|
142
144
|
|
143
145
|
def apply(io)
|
146
|
+
io << "set term #{GNUPLOT_DEFAULT_TERM}\n" unless self[:term] or self.multiplot_following
|
144
147
|
self.each do |var,val|
|
145
148
|
next unless val
|
149
|
+
next if self.multiplot_following and ["term", "output"].include? var.to_s
|
150
|
+
next if var.to_s == "multiplot"
|
151
|
+
apply_option(io, var, val)
|
152
|
+
end
|
153
|
+
apply_option(io, :multiplot, self[:multiplot]) if self[:multiplot]
|
154
|
+
end
|
155
|
+
|
156
|
+
def apply_option(io, var, val)
|
146
157
|
if val == "unset"
|
147
158
|
#eputs "Unsetting #{var}"
|
148
159
|
io << "unset #{var}\n"
|
149
|
-
|
160
|
+
return
|
150
161
|
end
|
151
162
|
if var.to_s == 'log_axis'
|
152
163
|
var = 'log'
|
@@ -161,8 +172,6 @@ class GnuplotSetOptions < KitHash
|
|
161
172
|
else
|
162
173
|
io << "set #{var} #{val}\n"
|
163
174
|
end
|
164
|
-
end
|
165
|
-
io << "set term #{GNUPLOT_DEFAULT_TERM}\n" unless self[:term]
|
166
175
|
end
|
167
176
|
|
168
177
|
|
@@ -291,45 +300,55 @@ end
|
|
291
300
|
apply_gnuplot_options(options)
|
292
301
|
apply_graphkit_standard_options_to_gnuplot
|
293
302
|
check_integrity
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
when 3,4
|
302
|
-
io << "splot "
|
303
|
-
end
|
304
|
-
imax = data.size - 1
|
305
|
-
data.each_with_index do |dk,i|
|
306
|
-
next if i>0 and compress_datakits
|
307
|
-
dk.gnuplot_plot_options.with ||= dk.with #b.c.
|
308
|
-
dk.gnuplot_plot_options.title ||= dk.title #b.c.
|
309
|
-
dk.gnuplot_plot_options.apply(io)
|
310
|
-
#p 'imax', imax, i, i == imax
|
311
|
-
next if compress_datakits
|
312
|
-
io << ", " unless i == imax
|
313
|
-
end
|
314
|
-
io << "\n"
|
315
|
-
data.each_with_index do |dk,i|
|
316
|
-
dk.gnuplot(io)
|
317
|
-
unless compress_datakits and i<imax
|
318
|
-
io << "e\n\n"
|
319
|
-
else
|
320
|
-
io << "\n\n"
|
321
|
-
end
|
322
|
-
end
|
323
|
-
(STDIN.gets) if live
|
303
|
+
if options[:io]
|
304
|
+
send_gnuplot_commands(io)
|
305
|
+
else
|
306
|
+
Gnuplot.open(true) do |io|
|
307
|
+
send_gnuplot_commands(io)
|
308
|
+
(STDIN.gets) if live
|
309
|
+
end
|
324
310
|
end
|
325
311
|
end
|
312
|
+
|
313
|
+
def send_gnuplot_commands(io)
|
314
|
+
self.pid = io.pid
|
315
|
+
gnuplot_sets.apply(io)
|
316
|
+
gnuplot_variables.apply(io)
|
317
|
+
case naxes
|
318
|
+
when 1,2
|
319
|
+
io << "plot "
|
320
|
+
when 3,4
|
321
|
+
io << "splot "
|
322
|
+
end
|
323
|
+
imax = data.size - 1
|
324
|
+
data.each_with_index do |dk,i|
|
325
|
+
next if i>0 and compress_datakits
|
326
|
+
dk.gnuplot_plot_options.with ||= dk.with #b.c.
|
327
|
+
dk.gnuplot_plot_options.title ||= dk.title #b.c.
|
328
|
+
dk.gnuplot_plot_options.apply(io)
|
329
|
+
#p 'imax', imax, i, i == imax
|
330
|
+
next if compress_datakits
|
331
|
+
io << ", " unless i == imax
|
332
|
+
end
|
333
|
+
io << "\n"
|
334
|
+
data.each_with_index do |dk,i|
|
335
|
+
dk.gnuplot(io)
|
336
|
+
unless compress_datakits and i<imax
|
337
|
+
io << "e\n\n"
|
338
|
+
else
|
339
|
+
io << "\n\n"
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
326
343
|
|
327
344
|
def close
|
328
345
|
logf :close
|
329
346
|
begin
|
347
|
+
#require 'sys/proctable'
|
348
|
+
#p Sys::ProcTable.ps.select{ |pe| pe.ppid == pid }
|
330
349
|
Process.kill('TERM', pid) if pid
|
331
350
|
rescue => err
|
332
|
-
puts err
|
351
|
+
puts err, pid
|
333
352
|
end
|
334
353
|
self.pid = nil
|
335
354
|
end
|
@@ -459,6 +478,8 @@ end
|
|
459
478
|
|
460
479
|
def gnuplot_write(file_name, options={})
|
461
480
|
logf :gnuplot_write
|
481
|
+
old_gp_term = gp.term
|
482
|
+
old_gp_output = gp.output
|
462
483
|
if file_name
|
463
484
|
gp.output = file_name
|
464
485
|
unless gp.term or options[:terminal]
|
@@ -497,6 +518,8 @@ end
|
|
497
518
|
raise 'ps2eps failed' unless system "ps2eps #{name}.ps"
|
498
519
|
end
|
499
520
|
# ep file_name
|
521
|
+
gp.term = old_gp_term
|
522
|
+
gp.output = old_gp_output
|
500
523
|
return File.basename(file_name, File.extname(file_name))
|
501
524
|
end
|
502
525
|
|
@@ -531,6 +554,33 @@ EOF
|
|
531
554
|
|
532
555
|
|
533
556
|
|
557
|
+
class MultiWindow
|
558
|
+
|
559
|
+
def method_missing(meth, *args)
|
560
|
+
if args[-1].kind_of? Hash
|
561
|
+
options = args.pop
|
562
|
+
else
|
563
|
+
options = {}
|
564
|
+
end
|
565
|
+
raise "Nothing to plot: size = 0" if size==0
|
566
|
+
self[0].gp.multiplot = "layout #{size},1"
|
567
|
+
for i in 1...self.size
|
568
|
+
self[i].gp.multiplot_following = true
|
569
|
+
end
|
570
|
+
Gnuplot.open(true) do |io|
|
571
|
+
options[:io] = io
|
572
|
+
each do |gk|
|
573
|
+
#p gk.to_s
|
574
|
+
gk
|
575
|
+
gk.send(meth, *args, options)
|
576
|
+
end
|
577
|
+
options.delete(:io)
|
578
|
+
end
|
579
|
+
for i in 1...self.size
|
580
|
+
self[i].multiplot = false
|
581
|
+
end
|
582
|
+
end
|
583
|
+
end
|
534
584
|
|
535
585
|
|
536
586
|
end
|
data/lib/graphkit.rb
CHANGED
@@ -274,6 +274,12 @@ end
|
|
274
274
|
|
275
275
|
|
276
276
|
class GraphKit < KitHash
|
277
|
+
|
278
|
+
|
279
|
+
class MultiWindow < Array
|
280
|
+
|
281
|
+
end
|
282
|
+
|
277
283
|
|
278
284
|
|
279
285
|
include Kit
|
@@ -905,70 +911,6 @@ require 'graphkit/vtk_legacy_ruby.rb'
|
|
905
911
|
|
906
912
|
if $0 == __FILE__
|
907
913
|
|
908
|
-
a = GraphKit.autocreate({x: {data: [1,3,5,6], units: 'feet', title: 'Height'}})
|
909
|
-
a.gnuplot
|
910
|
-
gets
|
911
|
-
a.close
|
912
|
-
a = CodeRunner::GraphKit.autocreate({x: {data: [2, 5, 11, 22], units: 'years', title: 'Age'}, y: {data: [1,3,5,6], units: 'feet', title: 'Height'}})
|
913
|
-
|
914
|
-
puts a.pretty_inspect
|
915
|
-
|
916
|
-
p a.title
|
917
|
-
p a.label
|
918
|
-
p a.chox
|
919
|
-
p a.xlabel
|
920
|
-
p a.yunits
|
921
|
-
|
922
|
-
# a.gnuplot
|
923
|
-
# gets
|
924
|
-
# a.close
|
925
|
-
a.data[0].with = 'lp'
|
926
|
-
datakit = a.data[0].dup
|
927
|
-
datakit.axes[:y].data.map!{|value| value * 0.85}
|
928
|
-
datakit.title += ' of women'
|
929
|
-
a.data.push datakit
|
930
|
-
a.data[0].title += ' of men'
|
931
|
-
pp a
|
932
|
-
a.gnuplot
|
933
|
-
gets
|
934
|
-
a.close
|
935
|
-
# Gnuplot.open{a.to_gnuplot}
|
936
|
-
|
937
|
-
b = CodeRunner::GraphKit.autocreate({x: {data: [2, 5, 11, 22], units: 'years', title: 'Age'}, y: {data: [1,3,5,6], units: 'feet', title: 'Height'}, z: {data: [2,4,8,12], units: 'stone', title: 'Weight'}})
|
938
|
-
b.data[0].modify({with: 'lp'})
|
939
|
-
pp b
|
940
|
-
# d = b.data[0].f.data_for_gnuplot(2)
|
941
|
-
# p d
|
942
|
-
# p d[0,1]
|
943
|
-
# d.delete([0,0])
|
944
|
-
# p d
|
945
|
-
# p d[1,1]
|
946
|
-
# p d[1,2]
|
947
|
-
# d = SparseTensor.new(3)
|
948
|
-
# p d
|
949
|
-
# p d[0,1,4]
|
950
|
-
# p d[3, 4,6]
|
951
|
-
#
|
952
|
-
b.gnuplot
|
953
|
-
gets
|
954
|
-
b.close
|
955
|
-
b.gnuplot_write('heights.ps')
|
956
|
-
|
957
|
-
p b.data[0].plot_area_size
|
958
|
-
|
959
|
-
c = SparseTensor.new(3)
|
960
|
-
c[1,3,9]= 4
|
961
|
-
c[3,3,34] = 4.346
|
962
|
-
c[23, 234, 293] = 9.234
|
963
|
-
|
964
|
-
p c
|
965
|
-
|
966
|
-
d = SparseTensor.new(3)
|
967
|
-
d[1,3,9]= 4
|
968
|
-
d[3,3,34] = 4.346
|
969
|
-
d[23, 234, 294] = 9.234
|
970
|
-
|
971
|
-
p c + d
|
972
914
|
|
973
915
|
end
|
974
916
|
|
data/test/test_graphkit.rb
CHANGED
@@ -1,7 +1,82 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestGraphkit < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
|
5
|
+
def test_basic
|
6
|
+
a = GraphKit.autocreate({x: {data: [1,3,5,6], units: 'feet', title: 'Height'}})
|
7
|
+
#a.gnuplot
|
8
|
+
#gets
|
9
|
+
a.close
|
10
|
+
a = GraphKit.autocreate({x: {data: [2, 5, 11, 22], units: 'years', title: 'Age'}, y: {data: [1,3,5,6], units: 'feet', title: 'Height'}})
|
11
|
+
|
12
|
+
puts a.pretty_inspect
|
13
|
+
|
14
|
+
p a.title
|
15
|
+
p a.label
|
16
|
+
p a.chox
|
17
|
+
p a.xlabel
|
18
|
+
p a.yunits
|
19
|
+
|
20
|
+
# a.gnuplot
|
21
|
+
# gets
|
22
|
+
# a.close
|
23
|
+
a.data[0].with = 'lp'
|
24
|
+
datakit = a.data[0].dup
|
25
|
+
datakit.axes[:y].data.map!{|value| value * 0.85}
|
26
|
+
datakit.title += ' of women'
|
27
|
+
a.data.push datakit
|
28
|
+
a.data[0].title += ' of men'
|
29
|
+
pp a
|
30
|
+
#a.gnuplot
|
31
|
+
#gets
|
32
|
+
a.close
|
33
|
+
# Gnuplot.open{a.to_gnuplot}
|
34
|
+
|
35
|
+
b = GraphKit.autocreate({x: {data: [2, 5, 11, 22], units: 'years', title: 'Age'}, y: {data: [1,3,5,6], units: 'feet', title: 'Height'}, z: {data: [2,4,8,12], units: 'stone', title: 'Weight'}})
|
36
|
+
b.data[0].modify({with: 'lp'})
|
37
|
+
pp b
|
38
|
+
# d = b.data[0].f.data_for_gnuplot(2)
|
39
|
+
# p d
|
40
|
+
# p d[0,1]
|
41
|
+
# d.delete([0,0])
|
42
|
+
# p d
|
43
|
+
# p d[1,1]
|
44
|
+
# p d[1,2]
|
45
|
+
# d = SparseTensor.new(3)
|
46
|
+
# p d
|
47
|
+
# p d[0,1,4]
|
48
|
+
# p d[3, 4,6]
|
49
|
+
#
|
50
|
+
#b.gnuplot
|
51
|
+
#gets
|
52
|
+
b.close
|
53
|
+
b.gnuplot_write('heights.ps')
|
54
|
+
|
55
|
+
p b.data[0].plot_area_size
|
56
|
+
|
57
|
+
c = SparseTensor.new(3)
|
58
|
+
c[1,3,9]= 4
|
59
|
+
c[3,3,34] = 4.346
|
60
|
+
c[23, 234, 293] = 9.234
|
61
|
+
|
62
|
+
p c
|
63
|
+
|
64
|
+
d = SparseTensor.new(3)
|
65
|
+
d[1,3,9]= 4
|
66
|
+
d[3,3,34] = 4.346
|
67
|
+
d[23, 234, 294] = 9.234
|
68
|
+
|
69
|
+
p c + d
|
70
|
+
|
71
|
+
multiplot = GraphKit::MultiWindow.new
|
72
|
+
multiplot.push a
|
73
|
+
multiplot.push b
|
74
|
+
|
75
|
+
|
76
|
+
pp multiplot
|
77
|
+
|
78
|
+
#multiplot.gnuplot
|
79
|
+
multiplot.gnuplot_write('multiplot.ps')
|
80
|
+
end
|
81
|
+
|
7
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edmund Highcock
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyhacks
|