Class: Wads::VisibleRange
- Inherits:
-
Object
- Object
- Wads::VisibleRange
- Defined in:
- lib/wads/data_structures.rb
Overview
A two dimensional range used by Plot to determine the visible area which can be a subset of the total data range(s)
Instance Attribute Summary collapse
-
#bottom_y ⇒ Object
Returns the value of attribute bottom_y.
-
#is_time_based ⇒ Object
Returns the value of attribute is_time_based.
-
#left_x ⇒ Object
Returns the value of attribute left_x.
-
#right_x ⇒ Object
Returns the value of attribute right_x.
-
#top_y ⇒ Object
Returns the value of attribute top_y.
-
#x_range ⇒ Object
Returns the value of attribute x_range.
-
#y_range ⇒ Object
Returns the value of attribute y_range.
Instance Method Summary collapse
- #calc_x_values ⇒ Object
- #clear_cache ⇒ Object
-
#divide_range_into_values(range_size, start_value, end_value, is_derived_values = true) ⇒ Object
This method determines what are equidistant points along the x-axis that we can use to draw gridlines and calculate derived values from functions.
- #grid_line_x_values ⇒ Object
- #grid_line_y_values ⇒ Object
-
#initialize(l, r, b, t, is_time_based = false) ⇒ VisibleRange
constructor
A new instance of VisibleRange.
- #plus(other_range) ⇒ Object
- #scale(zoom_level) ⇒ Object
- #scroll_down ⇒ Object
- #scroll_left ⇒ Object
- #scroll_right ⇒ Object
- #scroll_up ⇒ Object
- #x_ten_percent ⇒ Object
- #y_ten_percent ⇒ Object
Constructor Details
#initialize(l, r, b, t, is_time_based = false) ⇒ VisibleRange
Returns a new instance of VisibleRange.
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
# File 'lib/wads/data_structures.rb', line 795 def initialize(l, r, b, t, is_time_based = false) if l < r @left_x = l @right_x = r else @left_x = r @right_x = l end if b < t @bottom_y = b @top_y = t else @bottom_y = t @top_y = b end @x_range = @right_x - @left_x @y_range = @top_y - @bottom_y @is_time_based = is_time_based @orig_left_x = @left_x @orig_right_x = @right_x @orig_bottom_y = @bottom_y @orig_top_y = @top_y @orig_range_x = @x_range @orig_range_y = @y_range end |
Instance Attribute Details
#bottom_y ⇒ Object
Returns the value of attribute bottom_y.
789 790 791 |
# File 'lib/wads/data_structures.rb', line 789 def bottom_y @bottom_y end |
#is_time_based ⇒ Object
Returns the value of attribute is_time_based.
793 794 795 |
# File 'lib/wads/data_structures.rb', line 793 def is_time_based @is_time_based end |
#left_x ⇒ Object
Returns the value of attribute left_x.
787 788 789 |
# File 'lib/wads/data_structures.rb', line 787 def left_x @left_x end |
#right_x ⇒ Object
Returns the value of attribute right_x.
788 789 790 |
# File 'lib/wads/data_structures.rb', line 788 def right_x @right_x end |
#top_y ⇒ Object
Returns the value of attribute top_y.
790 791 792 |
# File 'lib/wads/data_structures.rb', line 790 def top_y @top_y end |
#x_range ⇒ Object
Returns the value of attribute x_range.
791 792 793 |
# File 'lib/wads/data_structures.rb', line 791 def x_range @x_range end |
#y_range ⇒ Object
Returns the value of attribute y_range.
792 793 794 |
# File 'lib/wads/data_structures.rb', line 792 def y_range @y_range end |
Instance Method Details
#calc_x_values ⇒ Object
893 894 895 896 897 898 899 900 |
# File 'lib/wads/data_structures.rb', line 893 def calc_x_values if @cached_calc_x_values return @cached_calc_x_values end @cached_calc_x_values = divide_range_into_values(@x_range, @left_x, @right_x) #puts "The x_axis value to calculate are: #{@cached_calc_x_values}" @cached_calc_x_values end |
#clear_cache ⇒ Object
902 903 904 905 906 |
# File 'lib/wads/data_structures.rb', line 902 def clear_cache @cached_grid_line_x_values = nil @cached_grid_line_y_values = nil @cached_calc_x_values = nil end |
#divide_range_into_values(range_size, start_value, end_value, is_derived_values = true) ⇒ Object
This method determines what are equidistant points along the x-axis that we can use to draw gridlines and calculate derived values from functions
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 |
# File 'lib/wads/data_structures.rb', line 911 def divide_range_into_values(range_size, start_value, end_value, is_derived_values = true) values = [] # How big is x-range? What should the step size be? # Generally we want a hundred display points. Let's start there. if range_size < 1.1 step_size = is_derived_values ? 0.01 : 0.1 elsif range_size < 11 step_size = is_derived_values ? 0.1 : 1 elsif range_size < 111 step_size = is_derived_values ? 1 : 10 elsif range_size < 1111 step_size = is_derived_values ? 10 : 100 elsif range_size < 11111 step_size = is_derived_values ? 100 : 1000 elsif range_size < 111111 step_size = is_derived_values ? 1000 : 10000 else step_size = is_derived_values ? 10000 : 100000 end grid_x = start_value while grid_x < end_value values << grid_x grid_x = grid_x + step_size end values end |
#grid_line_x_values ⇒ Object
877 878 879 880 881 882 883 |
# File 'lib/wads/data_structures.rb', line 877 def grid_line_x_values if @cached_grid_line_x_values return @cached_grid_line_x_values end @cached_grid_line_x_values = divide_range_into_values(@x_range, @left_x, @right_x, false) @cached_grid_line_x_values end |
#grid_line_y_values ⇒ Object
885 886 887 888 889 890 891 |
# File 'lib/wads/data_structures.rb', line 885 def grid_line_y_values if @cached_grid_line_y_values return @cached_grid_line_y_values end @cached_grid_line_y_values = divide_range_into_values(@y_range, @bottom_y, @top_y, false) @cached_grid_line_y_values end |
#plus(other_range) ⇒ Object
822 823 824 825 826 827 828 |
# File 'lib/wads/data_structures.rb', line 822 def plus(other_range) l = @left_x < other_range.left_x ? @left_x : other_range.left_x r = @right_x > other_range.right_x ? @right_x : other_range.right_x b = @bottom_y < other_range.bottom_y ? @bottom_y : other_range.bottom_y t = @top_y > other_range.top_y ? @top_y : other_range.top_y VisibleRange.new(l, r, b, t, (@is_time_based or other_range.is_time_based)) end |
#scale(zoom_level) ⇒ Object
838 839 840 841 842 843 844 845 846 847 848 849 850 851 |
# File 'lib/wads/data_structures.rb', line 838 def scale(zoom_level) x_mid_point = @orig_left_x + (@orig_range_x.to_f / 2) x_extension = (@orig_range_x.to_f * zoom_level) / 2 @left_x = x_mid_point - x_extension @right_x = x_mid_point + x_extension y_mid_point = @orig_bottom_y + (@orig_range_y.to_f / 2) y_extension = (@orig_range_y.to_f * zoom_level) / 2 @bottom_y = y_mid_point - y_extension @top_y = y_mid_point + y_extension @x_range = @right_x - @left_x @y_range = @top_y - @bottom_y end |
#scroll_down ⇒ Object
859 860 861 862 863 |
# File 'lib/wads/data_structures.rb', line 859 def scroll_down @bottom_y = @bottom_y - y_ten_percent @top_y = @top_y - y_ten_percent @y_range = @top_y - @bottom_y end |
#scroll_left ⇒ Object
871 872 873 874 875 |
# File 'lib/wads/data_structures.rb', line 871 def scroll_left @left_x = @left_x - x_ten_percent @right_x = @right_x - x_ten_percent @x_range = @right_x - @left_x end |
#scroll_right ⇒ Object
865 866 867 868 869 |
# File 'lib/wads/data_structures.rb', line 865 def scroll_right @left_x = @left_x + x_ten_percent @right_x = @right_x + x_ten_percent @x_range = @right_x - @left_x end |
#scroll_up ⇒ Object
853 854 855 856 857 |
# File 'lib/wads/data_structures.rb', line 853 def scroll_up @bottom_y = @bottom_y + y_ten_percent @top_y = @top_y + y_ten_percent @y_range = @top_y - @bottom_y end |
#x_ten_percent ⇒ Object
830 831 832 |
# File 'lib/wads/data_structures.rb', line 830 def x_ten_percent @x_range.to_f / 10 end |
#y_ten_percent ⇒ Object
834 835 836 |
# File 'lib/wads/data_structures.rb', line 834 def y_ten_percent @y_range.to_f / 10 end |