Permalink
Browse files

Cleaner UI and zoom integration

  • Loading branch information...
Amit Kumar Amit Kumar
Amit Kumar authored and Amit Kumar committed Jan 18, 2013
1 parent 2a3d350 commit 6d2d01e747a0fba9ea268622ea96acbdde920434
@@ -2,23 +2,26 @@ class CurvePlotController < UIViewController
attr_accessor :curve_hosting_view, :plot, :horizontal_zoom, :legend_view, :vertical_zoom
+ attr_reader :horizontal_zoom_value, :vertical_zoom_value
+
def viewDidLoad
super
theme = CPTTheme.themeNamed KCPTPlainWhiteTheme
@plot = CurvePlot.alloc.init
@plot.delegate = self
@plot.renderInLayer(@curve_hosting_view, withTheme:theme, andCurves:curves)
- @horizontal_zoom.value = 0
+ @horizontal_zoom.value = @horizontal_zoom_value = 0
@curve_hosting_view.round_corners(8)
@legend_view.add(lever_names)
@legend_view.round_corners(8)
self.view.addSubview(@legend)
trans = CGAffineTransformMakeRotation(Math::PI * 0.5)
- # @vertical_zoom.value = 0
- # @vertical_zoom.transform = trans
+ @vertical_zoom.value = @vertical_zoom_value = 1
+ @vertical_zoom.transform = trans
+ @vertical_zoom.setFrame([[16, 200], [23, 500]])
end
def shouldAutorotateToInterfaceOrientation(toInterfaceOrientation)
@@ -27,8 +30,17 @@ def shouldAutorotateToInterfaceOrientation(toInterfaceOrientation)
def zoom_x(sender)
- @horizontal_zoom.value = sender.value
- @plot.zoom_x_by(sender.value)
+ return if(@horizontal_zoom_value == sender.value)
+
+ @horizontal_zoom.value = sender.value
+
+ (@horizontal_zoom_value < sender.value) ? @plot.zoom_in_x_by(sender.value) : @plot.zoom_out_x_by(sender.value)
+
+ @horizontal_zoom_value = @horizontal_zoom.value
+ end
+
+ def zoom_y(sender)
+ p sender
end
def curves
View
@@ -22,17 +22,17 @@ def curves
when 1
lambda {|p| 0.5 * p * p}
when 2
- lambda {|p| 1.5 * p * p}
+ lambda {|p| 5 * p * p}
when 3
lambda {|p| 3.0 * p * p}
when 4
- lambda {|p| 4.5 * p * p}
+ lambda {|p| 7 * p * p}
when 5
- lambda {|p| 6.0 * p * p}
+ lambda {|p| p * p}
when 6
- lambda {|p| 7.5 * p * p}
+ lambda {|p| 0.1 * p * p}
when 7
- lambda {|p| 9.0 * p * p}
+ lambda {|p| 1}
when 8
lambda {|p| 10.5 * p * p}
end
View
@@ -57,11 +57,24 @@ def renderInLayer(hosting_view, withTheme:theme, andCurves:curves)
create_and_add_draggable_point
end
- def zoom_x_by(percent)
+ def zoom_in_x_by(percent)
+ space = @graph.defaultPlotSpace
+ new_x_range = space.xRange.mutableCopy
+ # p new_x_range.lengthDouble
+ p percent
+ p (new_x_range.lengthDouble - (new_x_range.lengthDouble * percent))
+ new_x_range.setLength(CPTDecimalFromDouble(new_x_range.lengthDouble - (new_x_range.lengthDouble * percent)))
+ # p new_x_range.lengthDouble
+ space.xRange = new_x_range
+ end
+
+ def zoom_out_x_by(percent)
space = @graph.defaultPlotSpace
new_x_range = space.xRange.mutableCopy
p new_x_range.lengthDouble
- new_x_range.setLength(CPTDecimalFromDouble(new_x_range.lengthDouble - percent))
+ p percent
+ p (new_x_range.lengthDouble + (new_x_range.lengthDouble * percent))
+ new_x_range.setLength(CPTDecimalFromDouble(p (new_x_range.lengthDouble + (new_x_range.lengthDouble * percent))))
p new_x_range.lengthDouble
space.xRange = new_x_range
end
@@ -185,7 +198,7 @@ def add_padding
def add_plot_space
plot_space = @graph.defaultPlotSpace
plot_space.yRange = plot_space_range(0, 6)
- plot_space.xRange = plot_space_range(0, 100)
+ plot_space.xRange = plot_space_range(0, 10)
plot_space.allowsUserInteraction = true
plot_space.delegate = self
end
Oops, something went wrong.

0 comments on commit 6d2d01e

Please sign in to comment.