Class: MotionPlot::Base
- Inherits:
-
Object
- Object
- MotionPlot::Base
- Defined in:
- lib/motion-plot/chart/base.rb
Instance Attribute Summary collapse
-
#axes ⇒ Object
Returns the value of attribute axes.
-
#data_label ⇒ Object
Returns the value of attribute data_label.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#layer_hosting_view ⇒ Object
readonly
Returns the value of attribute layer_hosting_view.
-
#legend ⇒ Object
Returns the value of attribute legend.
-
#major_grid_line_style ⇒ Object
readonly
Returns the value of attribute major_grid_line_style.
-
#plot_options ⇒ Object
Returns the value of attribute plot_options.
-
#plot_space ⇒ Object
readonly
Returns the value of attribute plot_space.
-
#plots ⇒ Object
readonly
Returns the value of attribute plots.
-
#series ⇒ Object
readonly
Returns the value of attribute series.
-
#theme ⇒ Object
Returns the value of attribute theme.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#xaxis ⇒ Object
readonly
Returns the value of attribute xaxis.
-
#yaxis ⇒ Object
readonly
Returns the value of attribute yaxis.
Instance Method Summary collapse
- #add_axis_title(axis, title) ⇒ Object
- #add_chart_title(title) ⇒ Object
- #add_legend ⇒ Object
- #add_plot_space ⇒ Object
- #add_plot_symbol(plot, symbol) ⇒ Object
- #add_xy_range ⇒ Object
- #bootstrap(options) ⇒ Object
- #default_padding ⇒ Object
- #initWithOptions(options, containerView: container) ⇒ Object
Instance Attribute Details
#axes ⇒ Object
Returns the value of attribute axes.
6 7 8 |
# File 'lib/motion-plot/chart/base.rb', line 6 def axes @axes end |
#data_label ⇒ Object
Returns the value of attribute data_label.
6 7 8 |
# File 'lib/motion-plot/chart/base.rb', line 6 def data_label @data_label end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
4 5 6 |
# File 'lib/motion-plot/chart/base.rb', line 4 def graph @graph end |
#layer_hosting_view ⇒ Object (readonly)
Returns the value of attribute layer_hosting_view.
4 5 6 |
# File 'lib/motion-plot/chart/base.rb', line 4 def layer_hosting_view @layer_hosting_view end |
#legend ⇒ Object
Returns the value of attribute legend.
6 7 8 |
# File 'lib/motion-plot/chart/base.rb', line 6 def legend @legend end |
#major_grid_line_style ⇒ Object (readonly)
Returns the value of attribute major_grid_line_style.
4 5 6 |
# File 'lib/motion-plot/chart/base.rb', line 4 def major_grid_line_style @major_grid_line_style end |
#plot_options ⇒ Object
Returns the value of attribute plot_options.
6 7 8 |
# File 'lib/motion-plot/chart/base.rb', line 6 def @plot_options end |
#plot_space ⇒ Object (readonly)
Returns the value of attribute plot_space.
4 5 6 |
# File 'lib/motion-plot/chart/base.rb', line 4 def plot_space @plot_space end |
#plots ⇒ Object (readonly)
Returns the value of attribute plots.
4 5 6 |
# File 'lib/motion-plot/chart/base.rb', line 4 def plots @plots end |
#series ⇒ Object (readonly)
Returns the value of attribute series.
4 5 6 |
# File 'lib/motion-plot/chart/base.rb', line 4 def series @series end |
#theme ⇒ Object
Returns the value of attribute theme.
6 7 8 |
# File 'lib/motion-plot/chart/base.rb', line 6 def theme @theme end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
4 5 6 |
# File 'lib/motion-plot/chart/base.rb', line 4 def title @title end |
#xaxis ⇒ Object (readonly)
Returns the value of attribute xaxis.
4 5 6 |
# File 'lib/motion-plot/chart/base.rb', line 4 def xaxis @xaxis end |
#yaxis ⇒ Object (readonly)
Returns the value of attribute yaxis.
4 5 6 |
# File 'lib/motion-plot/chart/base.rb', line 4 def yaxis @yaxis end |
Instance Method Details
#add_axis_title(axis, title) ⇒ Object
176 177 178 179 180 |
# File 'lib/motion-plot/chart/base.rb', line 176 def add_axis_title(axis, title) axis.title = title.text axis.titleTextStyle = title.text_style axis.titleOffset = title.style.offset end |
#add_chart_title(title) ⇒ Object
170 171 172 173 174 |
# File 'lib/motion-plot/chart/base.rb', line 170 def add_chart_title(title) @graph.title = title.text @graph.titleTextStyle = title.text_style @graph.titlePlotAreaFrameAnchor = title.position end |
#add_legend ⇒ Object
182 183 184 185 186 |
# File 'lib/motion-plot/chart/base.rb', line 182 def add_legend @graph.legend = @legend.cpt_legend(@graph) @graph.legendAnchor = @legend.position @graph.legendDisplacement = @legend.displacement end |
#add_plot_space ⇒ Object
146 147 148 149 150 |
# File 'lib/motion-plot/chart/base.rb', line 146 def add_plot_space @plot_space = @graph.defaultPlotSpace @plot_space.delegate = self @plot_space.allowsUserInteraction = true end |
#add_plot_symbol(plot, symbol) ⇒ Object
152 153 154 155 |
# File 'lib/motion-plot/chart/base.rb', line 152 def add_plot_symbol(plot, symbol) plot.plotSymbol = symbol plot.plotSymbolMarginForHitDetection = 5.0 end |
#add_xy_range ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/motion-plot/chart/base.rb', line 157 def add_xy_range return if(not @axes[:x].enabled? and not @axes[:y].enabled?) @plot_space.scaleToFitPlots(@plots) x_range = @plot_space.xRange.mutableCopy y_range = @plot_space.yRange.mutableCopy x_range.(CPTDecimalFromDouble(1.03)) y_range.(CPTDecimalFromDouble(1.03)) @plot_space.xRange = x_range @plot_space.yRange = y_range end |
#bootstrap(options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 |
# File 'lib/motion-plot/chart/base.rb', line 8 def bootstrap() .each_pair {|key, value| send("#{key}=", value) if(respond_to?("#{key}=")) } if([:title]) @title = Title.new([:title]) end @axes = {} if([:xAxis]) @axes[:x] = Axis.new([:xAxis].merge(type: 'xaxis')) else @axes[:x] = Axis.new(type: 'xaxis', enabled: false) end if([:yAxis]) @axes[:y] = Axis.new([:yAxis].merge(type: 'yaxis')) else @axes[:y] = Axis.new(type: 'yaxis', enabled: false) end if(@plot_options) @plot_options = PlotOptions.new(@plot_options) end @series = {} series = [:series] series && series.each_with_index {|hash, index| hash.reverse_merge!({ index: index, defaults: default_style, plot_options: @plot_options, type: self.plot_type, plot_symbol: (@plot_symbol ? [:plot_symbol] : nil) }) @series[hash[:name]] = Series.new(hash) } if([:legend]) @legend = Legend.new([:legend]) end if([:data_label]) @data_label = DataLabel.new([:data_label]) end @plots = [] end |
#default_padding ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/motion-plot/chart/base.rb', line 188 def default_padding @graph.plotAreaFrame.masksToBorder = false @graph.plotAreaFrame.borderLineStyle = nil @graph.plotAreaFrame.paddingLeft = 50.0 @graph.plotAreaFrame.paddingTop = 10.0 @graph.plotAreaFrame.paddingRight = 20.0 @graph.plotAreaFrame.paddingBottom = 20.0 @graph.paddingLeft = 5.0 @graph.paddingRight = 0.0 @graph.paddingTop = 10.0 @graph.paddingBottom = 10.0 end |
#initWithOptions(options, containerView: container) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/motion-plot/chart/base.rb', line 58 def initWithOptions(, containerView:container) bootstrap() @layer_hosting_view = CPTGraphHostingView.alloc.initWithFrame([[0, 0], [container.frame.size.width, container.frame.size.height]]) bounds = @layer_hosting_view.bounds # create and assign chart to the hosting view. @graph = CPTXYGraph.alloc.initWithFrame(bounds) @layer_hosting_view.hostedGraph = @graph add_chart_title(@title) if(@title) @graph.applyTheme(@theme || Theme.default) default_padding @chart_layers = [NSNumber.numberWithInt(CPTGraphLayerTypePlots), NSNumber.numberWithInt(CPTGraphLayerTypeMajorGridLines), NSNumber.numberWithInt(CPTGraphLayerTypeMinorGridLines), NSNumber.numberWithInt(CPTGraphLayerTypeAxisLines), NSNumber.numberWithInt(CPTGraphLayerTypeAxisLabels), NSNumber.numberWithInt(CPTGraphLayerTypeAxisTitles)] @graph.topDownLayerOrder = @chart_layers # add plot space add_plot_space @major_grid_line_style = CPTMutableLineStyle.lineStyle @major_grid_line_style.lineWidth = 0.75 @major_grid_line_style.lineColor = CPTColor.grayColor.colorWithAlphaComponent(0.25) axisSet = @graph.axisSet # Setting up x-axis if(@axes[:x].enabled?) axis = @axes[:x] @xaxis = axisSet.xAxis @xaxis.majorGridLineStyle = @major_grid_line_style @xaxis.minorTicksPerInterval = 1 add_axis_title(@xaxis, axis.title) if(axis.labels) labels = axis.labels.each_with_index.map do |l, i| @xaxis.labelingPolicy = CPTAxisLabelingPolicyNone label = CPTAxisLabel.alloc.initWithText(l, textStyle: axis.text_style) label.tickLocation = CPTDecimalFromInt(i) label.offset = 3.0 label end @xaxis.axisLabels = NSSet.setWithArray(labels) end end # Setting up y-axis if(@axes[:y].enabled?) @yaxis = axisSet.yAxis @yaxis.majorGridLineStyle = @major_grid_line_style @yaxis.minorTicksPerInterval = 1 @yaxis.labelingPolicy = CPTAxisLabelingPolicyAutomatic axis = @axes[:y] add_axis_title(@yaxis, axis.title) if(axis.labels) labels = axis.labels.each_with_index.map do |l, i| @yaxis.labelingPolicy = CPTAxisLabelingPolicyNone label = CPTAxisLabel.alloc.initWithText(l, textStyle: axis.text_style) label.tickLocation = CPTDecimalFromInt(i) label.offset = 3.0 label end @yaxis.axisLabels = NSSet.setWithArray(labels) end @yaxis.setLabelTextStyle(axis.text_style) end @graph.axisSet = nil if(not @axes[:x].enabled? and not @axes[:y].enabled?) add_series add_legend if(@legend.enabled?) add_xy_range @layer_hosting_view end |