~ubuntu-branches/ubuntu/utopic/ctioga2/utopic-proposed

« back to all changes in this revision

Viewing changes to lib/ctioga2/graphics/styles/axes.rb

  • Committer: Package Import Robot
  • Author(s): Vincent Fourmond
  • Date: 2014-03-17 22:29:58 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140317222958-mo23o3mhmblq1yyc
Tags: 0.10-1
New upstream release (yeah, I should package intermediate versions)

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
        # * a transform is set
82
82
        # * ticks are set
83
83
 
 
84
        @@text_size_index = 0
84
85
 
85
86
        # Creates a new AxisStyle object at the given location with
86
87
        # the given style.
90
91
 
91
92
          @tick_label_style = FullTextStyle.new
92
93
          @tick_label_style.scale = Types::Dimension.new(:dy, 0.8)
 
94
 
93
95
          @axis_label = TextLabel.new(label)
94
96
          @log = false
95
97
          @ticks_side = {}
96
98
          @ticks = AxisTicks.new
 
99
 
 
100
          @index = @@text_size_index
 
101
          @@text_size_index += 1
97
102
        end
98
103
 
99
104
        # Draws the axis within the current plot. Boundaries are the
105
110
        #   where it should be...
106
111
        # * non-linear axes (or linear, for that matter, but with
107
112
        #   a transformation)
108
 
        def draw_axis(t)
 
113
        #
 
114
        # _watcher_ is a TextSizeWatcher object.
 
115
        def draw_axis(t, watcher = nil)
109
116
          spec = get_axis_specification(t)
110
117
 
111
118
          info = t.axis_information(spec)
126
133
          end
127
134
 
128
135
          spec.update(@ticks_side)
 
136
 
 
137
          # We don't allow Tioga to draw tick labels by itself
 
138
          type = spec['type']
 
139
          spec['type'] = case spec['type']
 
140
                         when Tioga::FigureConstants::AXIS_WITH_MAJOR_TICKS_AND_NUMERIC_LABELS
 
141
                           Tioga::FigureConstants::AXIS_WITH_MAJOR_TICKS_ONLY
 
142
                         when Tioga::FigureConstants::AXIS_WITH_TICKS_AND_NUMERIC_LABELS
 
143
                           Tioga::FigureConstants::AXIS_WITH_TICKS_ONLY
 
144
                         else
 
145
                           spec['type']
 
146
                         end
129
147
          t.show_axis(spec)
 
148
          # Now, we draw axis ticks
 
149
          if type == Tioga::FigureConstants::AXIS_WITH_MAJOR_TICKS_AND_NUMERIC_LABELS || type == Tioga::FigureConstants::AXIS_WITH_TICKS_AND_NUMERIC_LABELS
 
150
 
 
151
            fnc = info['vertical'] ? :convert_figure_to_frame_y : :convert_figure_to_frame_x
 
152
            stl = @tick_label_style.dup
 
153
            
 
154
            
 
155
            stl.shift ||= Types::Dimension.new(:dy, info['shift'])
 
156
 
 
157
 
 
158
            # @todo integrate to the 
 
159
            shift_def = ( 
 
160
                         @location.base_location == :bottom ||
 
161
                         @location.base_location == :at_y_origin ||
 
162
                         @location.base_location == :right 
 
163
                         ) ? 0.3 : 0.4
 
164
            stl.shift = Types::Dimension.new(:dy, stl.shift.to_dy(t) + shift_def)
 
165
 
 
166
            stl.valign ||= ( 
 
167
                            @location.base_location == :bottom ||
 
168
                            @location.base_location == :at_y_origin ||
 
169
                            @location.base_location == :right 
 
170
                            ) ? Tioga::FigureConstants::ALIGNED_AT_TOP : Tioga::FigureConstants::ALIGNED_AT_BOTTOM
 
171
            
 
172
            spec['labels'].size.times do |i|
 
173
              pos = spec['major_ticks'][i]
 
174
              label = spec['labels'][i]
 
175
              pos = t.send(fnc, pos)
 
176
              
 
177
              next unless label
 
178
 
 
179
 
 
180
              nm = "axis-tick#{@index}-#{i}"
 
181
 
 
182
              stl.draw_text(t, label, spec['location'], 
 
183
                            [:pos, pos], nm)
 
184
              if watcher
 
185
                watcher.watch(nm)
 
186
              end
 
187
            end
 
188
          end
 
189
 
130
190
          @axis_label.loc = @location
131
191
          default = vertical? ? 'ylabel' : 'xlabel'
132
 
          @axis_label.draw(t, default)
 
192
          nm = "axis-label#{@index}"
 
193
 
 
194
          # stl = @axis_label.dup
 
195
          # # Default to aligning the label where it counts.
 
196
          # stl.valign ||= ( 
 
197
          #                 @location.base_location == :bottom ||
 
198
          #                 @location.base_location == :at_y_origin ||
 
199
          #                 @location.base_location == :right 
 
200
          #                 ) ? Tioga::FigureConstants::ALIGNED_AT_MIDHEIGHT : Tioga::FigureConstants::ALIGNED_AT_BOTTOM
 
201
 
 
202
          @axis_label.draw(t, default, nm)
 
203
          if watcher
 
204
            watcher.watch(nm)
 
205
          end
133
206
        end
134
207
 
135
208
        # Sets the current boundaries of the _t_ object to the _range_