Top Level Namespace
- Includes:
- Cosmos::Script, Math
Defined Under Namespace
Modules: Cosmos, CosmosIO, Enumerable, Kernel, Math, ObjectSpace, QDA, Qt, SNMP Classes: Array, Class, Date, DateTime, Exception, FalseClass, File, Hash, HazardousError, IO, Matrix, NilClass, Numeric, Object, Range, Regexp, RubyLex, RubyLexUtils, Socket, String, StringIO, Struct, Symbol, Time, TrueClass
Constant Summary collapse
- COSMOS_VERSION =
'3.7.1'
Constants included from Cosmos::Script
Cosmos::Script::DEFAULT_TLM_POLLING_RATE
Constants included from Cosmos::Extract
Cosmos::Extract::SCANNING_REGULAR_EXPRESSION
Instance Method Summary collapse
- #gem_installed?(name, version = Gem::Requirement.default) ⇒ Boolean
-
#plot(x = nil, y = nil, legend = "Line 1", *args) ⇒ Object
Create a new graph object and populate plot (x, y, legend, [y,legend], [y,legend], … , [opts]) x - default => [0…y_array.length] y - Y data array to plot legend - Line Legend to describe Y data args - Additional y , legend pairs to plot opts - Hash options at the end of the argument list :width => 400 - default => 800 :height => 300 - default => 600 :x => 100 - default => -1 # Place centered in current screen :y => 100 - default => -1 # Place centered in current screen :winTitle => “Graph 1” - default => “Graph”.
Methods included from Math
#cos_squared, #luma_from_rgb_max_255, #sin_squared, #stddev_population, #stddev_sample, #variance_population, #variance_sample
Instance Method Details
#gem_installed?(name, version = Gem::Requirement.default) ⇒ Boolean
17 18 19 20 |
# File 'ext/mkrf_conf.rb', line 17 def gem_installed?(name, version = Gem::Requirement.default) version = Gem::Requirement.create version unless version.is_a? Gem::Requirement Gem::Specification.each.any? { |spec| name == spec.name and version.satisfied_by? spec.version } end |
#plot(x = nil, y = nil, legend = "Line 1", *args) ⇒ Object
Create a new graph object and populate plot (x, y, legend, [y,legend], [y,legend], … , [opts])
x - default => [0...y_array.length]
y - Y data array to plot
legend - Line Legend to describe Y data
args - Additional y , legend pairs to plot
opts - Hash options at the end of the argument list
:width => 400 - default => 800
:height => 300 - default => 600
:x => 100 - default => -1 # Place centered in current screen
:y => 100 - default => -1 # Place centered in current screen
:winTitle => "Graph 1" - default => "Graph"
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cosmos/gui/line_graph/line_graph_script.rb', line 29 def plot (x = nil, y = nil, legend = "Line 1", *args) my_opts = {:width => 800, :height => 600, :x => -1, :y => -1, :winTitle => "Graph"} # Get the Hash options parameters from the end of the list of arguments arg_idx = -1 while (args[arg_idx].is_a?(Hash)) do my_opts.merge!(args[arg_idx]) arg_idx -= 1 end if y raise "Legend [0] must be a string" unless legend.kind_of? String raise "Y [0] must be an array" unless y.kind_of? Array end # Split out the arguments for the other y arrays & legends y_array = args[0..arg_idx].values_at(* args[0..arg_idx].each_index.select {|i| i.even?}) legend_array = args[0..arg_idx].values_at(* args[0..arg_idx].each_index.select {|i| i.odd?}) raise "Legend Argument List and Y Argument List not the same size" unless legend_array.length == y_array.length (0...y_array.length).each do |i| if y_array[i] raise "Legend [#{i+1}] must be a string" unless legend_array[i].kind_of? String raise "Y [#{i+1}] must be an array" unless y_array[i].kind_of? Array end end my_line_graph = '' Qt.execute_in_main_thread do a = Cosmos::LineGraphDialog.new(my_opts[:winTitle], my_opts[:width], my_opts[:height]) if y a.line_graph.add_line(legend, y, x, nil, nil, nil, nil, 'auto') end (0...y_array.length).each do |i| if y_array[i] a.line_graph.add_line(legend_array[i], y_array[i], x, nil, nil, nil, nil, 'auto') end end a.raise a.show my_line_graph = a.line_graph # Move the window if my_opts[:x] >= 0 && my_opts[:y] >= 0 a.move(my_opts[:x],my_opts[:y]) end end return my_line_graph end |