Class: OmfEc::Graph::GraphDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/omf_ec/graph/graph_description.rb

Overview

Describes a graph which can be displayed through the web interface or any other defined graph visualiser.

Constant Summary collapse

@@gds =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(name = nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/omf_ec/graph/graph_description.rb', line 14

def self.create(name = nil)
  if name
    @@gds[name.to_sym] ||= self.new(name)
  else
    self.new("Unknown #{self.object_id}")
  end
end

Instance Method Details

#_reportObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/omf_ec/graph/graph_description.rb', line 72

def _report
  _report_meta
  info "REPORT:START: #{@name}"
  info "REPORT:TYPE: #{@gtype}"
  info "REPORT:POSTFIX: #{URI.encode(@postfix)}" if @postfix
  @ms.each do |ctxt, a|
    a.each do |ms|
      info "REPORT:MS:#{ctxt}: #{URI.encode(ms.sql)}"
    end
  end
  info "REPORT:MAPPING: #{URI.encode(@mapping.to_json)}"
  if @axis
    info "REPORT:AXIS: #{URI.encode(@axis.to_json)}"
  end
  info "REPORT:CAPTION: #{URI.encode(@caption)}" if @caption
  info "REPORT:STOP"
end

#_report_metaObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/omf_ec/graph/graph_description.rb', line 90

def _report_meta
  h = {
    type: @gtype,
    mapping: @mapping,
    caption: @caption
  }
  h[:postfix] = @postfix if @postfix
  dss = h[:dss] = {}
  @ms.each do |ctxt, a|
    a.each do |ms|
      dss[ctxt] = ms.sql
    end
  end
  if @axis
    h[:axis] = @axis
  end
  descr = h.to_json
  OmfEc.experiment.(@name, descr, :graph)
end

#caption(text) ⇒ Object



68
69
70
# File 'lib/omf_ec/graph/graph_description.rb', line 68

def caption(text)
  @caption = text
end

#mapping(mhash) ⇒ Object

Defines the mapping of columns in the measurement tuples to properties of the visualization.

Parameters:

  • mhash

    Hash of mappings specific to the graph ifentified by ‘type’



52
53
54
# File 'lib/omf_ec/graph/graph_description.rb', line 52

def mapping(mhash)
  @mapping = mhash
end

#ms(ms_name, context = :default) ⇒ Object

Define the measurement stream to be visualized in the graph. The optional ‘context’ parameter defines the context in which the MS is used in the graph. This is necessary for graphs, such as ‘networks’ which need more than one MS to describe the visualization.

Parameters:

  • ms_name
  • context (defaults to: :default)


39
40
41
42
43
44
45
46
# File 'lib/omf_ec/graph/graph_description.rb', line 39

def ms(ms_name, context = :default)
  if (table_name = OmfEc.experiment.mp_table_names[ms_name])
    (@ms[context] ||= []) << (msb = MSBuilder.new(@db[table_name.to_sym]))
  else
    warn "Measurement point '#{ms_name}' NOT defined"
  end
  msb
end

#postfix(text) ⇒ Object

Define text to be shown above the graph

Parameters:

  • text


26
27
28
# File 'lib/omf_ec/graph/graph_description.rb', line 26

def postfix(text)
  @postfix = text
end

#type(gtype) ⇒ Object



56
57
58
# File 'lib/omf_ec/graph/graph_description.rb', line 56

def type(gtype)
  @gtype = gtype
end

#xaxis(props) ⇒ Object



60
61
62
# File 'lib/omf_ec/graph/graph_description.rb', line 60

def xaxis(props)
  (@axis ||= {})[:x] = props
end

#yaxis(props) ⇒ Object



64
65
66
# File 'lib/omf_ec/graph/graph_description.rb', line 64

def yaxis(props)
  (@axis ||= {})[:y] = props
end