motion-plot 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,22 +1,25 @@
1
1
  # Motion::Plot
2
2
 
3
- Build native charts as you are used with Highcharts/D3. This library is a wrapper on top of [CorePlot](https://code.google.com/p/core-plot/), the iOS plotting framework to build native chart using CoreAnimation, Core Data and Cocoa Bindings
3
+ Build native interactive charts using simple JSON as you are used with Highcharts.
4
+ This library is a wrapper on top of [CorePlot](https://code.google.com/p/core-plot/), the iOS plotting framework to build native chart using CoreAnimation, Core Data and Cocoa Bindings
4
5
 
5
6
  ## Installation
6
7
 
7
- Add this line to your application's Gemfile:
8
+ 1. Add this line to your application's Gemfile:
8
9
 
9
10
  `gem 'motion-plot'`
10
11
 
11
- And then execute:
12
+ And then execute:
12
13
 
13
14
  $ bundle
14
15
 
15
- Or install it yourself as:
16
+ Or install it yourself as:
16
17
 
17
18
  $ gem install motion-plot
18
19
 
19
- And add `require 'motion-plot'` to your `Gemfile`
20
+ And add `require 'motion-plot'` to your `Gemfile`
21
+
22
+ 2. Run 'pod setup' to install core-plot as pod on your local
20
23
 
21
24
  ## Usage
22
25
 
@@ -10,7 +10,7 @@ module MotionPlot
10
10
 
11
11
  bar_x = CPDBarInitialX
12
12
  @data_hash = {}
13
- horizontal_bar = (@plot_options.bar[:orientation] == "vertical") ? true : false
13
+ horizontal_bar = (@plot_options and @plot_options.bar[:orientation] == "vertical") ? true : false
14
14
  @delegate_object = case @stacking
15
15
  when "normal"
16
16
  StackBarDelegate.new(self)
@@ -48,7 +48,7 @@ module MotionPlot
48
48
 
49
49
  def animate(bar)
50
50
  bar.anchorPoint = [0.0, 0.0]
51
- scale_direction = (@plot_options.bar[:orientation] == "vertical") ? "transform.scale.x" : "transform.scale.y"
51
+ scale_direction = (@plot_options and @plot_options.bar[:orientation] == "vertical") ? "transform.scale.x" : "transform.scale.y"
52
52
  scaling = CABasicAnimation.animationWithKeyPath(scale_direction)
53
53
  scaling.fromValue = 0.0
54
54
  scaling.toValue = 1.0
@@ -1,15 +1,5 @@
1
1
  module MotionPlot
2
- class BarDelegate
3
-
4
- # delegate :series, :to => :delegated_to
5
-
6
- def initialize(source)
7
- @delegated_to = source
8
- end
9
-
10
- def numberOfRecordsForPlot(plot)
11
- @delegated_to.series[plot.identifier].data.size
12
- end
2
+ class BarDelegate < BaseDelegate
13
3
 
14
4
  def numberForPlot(plot, field:field_enum, recordIndex:index)
15
5
  data = @delegated_to.series[plot.identifier].data
@@ -0,0 +1,13 @@
1
+ module MotionPlot
2
+ class BaseDelegate
3
+
4
+ def initialize(source)
5
+ @delegated_to = source
6
+ end
7
+
8
+ def numberOfRecordsForPlot(plot)
9
+ @delegated_to.series[plot.identifier].data.size
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,40 @@
1
+ module MotionPlot
2
+ class BeizerCurveDelegate < BaseDelegate
3
+
4
+ def numberOfRecordsForPlot(plot)
5
+ step_size = @delegated_to.plot_options.line[:step_size] || 1
6
+ p @delegated_to.plot_options.line[:data_size] / step_size
7
+ @delegated_to.plot_options.line[:data_size] / step_size
8
+ end
9
+
10
+ # This implementation of this method will put the line graph in a fix position so it won't be scrollable.
11
+ def plotSpace(space, willChangePlotRangeTo:new_range, forCoordinate:coordinate)
12
+ (coordinate == CPTCoordinateY) ? space.yRange : space.xRange
13
+ end
14
+
15
+ def scatterPlot(plot, plotSymbolWasSelectedAtRecordIndex:index)
16
+ if(@delegated_to.data_label and @delegated_to.data_label.annotation)
17
+ @delegated_to.graph.plotAreaFrame.plotArea.removeAnnotation(@delegated_to.data_label.annotation)
18
+ @delegated_to.data_label.annotation = nil
19
+ end
20
+
21
+ y_value = @delegated_to.series[plot.identifier].data[index].round(2)
22
+ @delegated_to.graph.plotAreaFrame.plotArea.addAnnotation(@delegated_to.data_label.annotation_for(y_value, atCoordinate: [index, y_value], plotSpace: @delegated_to.graph.defaultPlotSpace))
23
+ end
24
+
25
+ def numberForPlot(plot, field:field_enum, recordIndex:index)
26
+
27
+ case field_enum
28
+ when CPTScatterPlotFieldY
29
+ num = index
30
+ when CPTScatterPlotFieldX
31
+ p @delegated_to.series[plot.identifier].data
32
+
33
+ num = @delegated_to.series[plot.identifier].data.call(index)
34
+ end
35
+
36
+ num
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ module MotionPlot
2
+ class LineDelegate < BaseDelegate
3
+
4
+ # This implementation of this method will put the line graph in a fix position so it won't be scrollable.
5
+ def plotSpace(space, willChangePlotRangeTo:new_range, forCoordinate:coordinate)
6
+ (coordinate == CPTCoordinateY) ? space.yRange : space.xRange
7
+ end
8
+
9
+ def scatterPlot(plot, plotSymbolWasSelectedAtRecordIndex:index)
10
+ if(@delegated_to.data_label and @delegated_to.data_label.annotation)
11
+ @delegated_to.graph.plotAreaFrame.plotArea.removeAnnotation(@delegated_to.data_label.annotation)
12
+ @delegated_to.data_label.annotation = nil
13
+ end
14
+
15
+ y_value = @delegated_to.series[plot.identifier].data[index].round(2)
16
+ @delegated_to.graph.plotAreaFrame.plotArea.addAnnotation(@delegated_to.data_label.annotation_for(y_value, atCoordinate: [index, y_value], plotSpace: @delegated_to.graph.defaultPlotSpace))
17
+ end
18
+
19
+ def numberForPlot(plot, field:field_enum, recordIndex:index)
20
+ data = @delegated_to.series[plot.identifier].data
21
+
22
+ (field_enum == CPTScatterPlotFieldY) ? data[index] : index
23
+ end
24
+
25
+ end
26
+ end
@@ -1,15 +1,11 @@
1
1
  module MotionPlot
2
- class PercentBarDelegate
2
+ class PercentBarDelegate < BaseDelegate
3
3
 
4
4
  def initialize(source)
5
- @delegated_to = source
5
+ super
6
6
  @number_of_plots = @delegated_to.series.keys.size
7
7
  end
8
8
 
9
- def numberOfRecordsForPlot(plot)
10
- @delegated_to.series[plot.identifier].data.size
11
- end
12
-
13
9
  def numberForPlot(plot, field:field_enum, recordIndex:index)
14
10
  case field_enum
15
11
  when CPTBarPlotFieldBarLocation
@@ -1,16 +1,8 @@
1
1
  module MotionPlot
2
- class StackBarDelegate
2
+ class StackBarDelegate < BaseDelegate
3
3
 
4
4
  # consign :series, :to => :delegated_to
5
-
6
- def initialize(source)
7
- @delegated_to = source
8
- end
9
-
10
- def numberOfRecordsForPlot(plot)
11
- @delegated_to.series[plot.identifier].data.size
12
- end
13
-
5
+
14
6
  def numberForPlot(plot, field:field_enum, recordIndex:index)
15
7
  case field_enum
16
8
  when CPTBarPlotFieldBarLocation
@@ -2,6 +2,12 @@ module MotionPlot
2
2
  class Line < Base
3
3
 
4
4
  def add_series
5
+ @delegate_object = if(@plot_options and @plot_options.line[:beizer])
6
+ BeizerCurveDelegate.new(self)
7
+ else
8
+ LineDelegate.new(self)
9
+ end
10
+
5
11
  @series.keys.each_with_index do |name, index|
6
12
  line = CPTScatterPlot.alloc.initWithFrame(CGRectNull)
7
13
  line.identifier = name
@@ -12,9 +18,9 @@ module MotionPlot
12
18
  line_style.lineColor = @series[name].color
13
19
 
14
20
  line.dataLineStyle = line_style
15
- line.dataSource = self
16
- line.delegate = self
17
- line.interpolation = CPTScatterPlotInterpolationCurved if(@plot_options.line[:curve_inerpolation])
21
+ line.dataSource = @delegate_object
22
+ line.delegate = @delegate_object
23
+ line.interpolation = CPTScatterPlotInterpolationCurved if(@plot_options and @plot_options.line[:curve_inerpolation])
18
24
 
19
25
  add_plot_symbol(line, @series[name].plot_symbol.symbol_for(line)) if(@series[name].plot_symbol)
20
26
 
@@ -23,31 +29,6 @@ module MotionPlot
23
29
  end
24
30
  end
25
31
 
26
- # This implementation of this method will put the line graph in a fix position so it won't be scrollable.
27
- def plotSpace(space, willChangePlotRangeTo:new_range, forCoordinate:coordinate)
28
- (coordinate == CPTCoordinateY) ? space.yRange : space.xRange
29
- end
30
-
31
- def scatterPlot(plot, plotSymbolWasSelectedAtRecordIndex:index)
32
- if(@data_label and @data_label.annotation)
33
- @graph.plotAreaFrame.plotArea.removeAnnotation(@data_label.annotation)
34
- @data_label.annotation = nil
35
- end
36
-
37
- y_value = @series[plot.identifier].data[index].round(2)
38
- @graph.plotAreaFrame.plotArea.addAnnotation(@data_label.annotation_for(y_value, atCoordinate: [index, y_value], plotSpace: @graph.defaultPlotSpace))
39
- end
40
-
41
- def numberOfRecordsForPlot(plot)
42
- @series[plot.identifier].data.size
43
- end
44
-
45
- def numberForPlot(plot, field:field_enum, recordIndex:index)
46
- data = @series[plot.identifier].data
47
-
48
- (field_enum == CPTScatterPlotFieldY) ? data[index] : index
49
- end
50
-
51
32
  protected
52
33
  def default_style
53
34
  {
@@ -18,6 +18,7 @@ module MotionPlot
18
18
 
19
19
  animate(pie)
20
20
  @graph.addPlot(pie)
21
+ @plots << pie
21
22
  end
22
23
 
23
24
  def default_padding
@@ -35,9 +35,7 @@ module MotionPlot
35
35
  legend.cornerRadius = corner_radius
36
36
  legend.swatchSize = swatch_size
37
37
  legend.textStyle = TextStyle.cpt_text_style(@style) if(@style)
38
-
39
- p @style
40
-
38
+
41
39
  legend
42
40
  end
43
41
 
@@ -1,3 +1,3 @@
1
1
  module MotionPlot
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-plot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-22 00:00:00.000000000 Z
12
+ date: 2013-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bubble-wrap
@@ -81,6 +81,9 @@ files:
81
81
  - lib/motion-plot/chart/bar_plot.rb
82
82
  - lib/motion-plot/chart/base.rb
83
83
  - lib/motion-plot/chart/delegates/bar_delegate.rb
84
+ - lib/motion-plot/chart/delegates/base_delegate.rb
85
+ - lib/motion-plot/chart/delegates/beizer_curve_delegate.rb
86
+ - lib/motion-plot/chart/delegates/line_delegate.rb
84
87
  - lib/motion-plot/chart/delegates/percent_bar_delegate.rb
85
88
  - lib/motion-plot/chart/delegates/stack_bar_delegate.rb
86
89
  - lib/motion-plot/chart/line_plot.rb