lib/ctioga2/graphics/styles/ticks.rb in ctioga2-0.10.1 vs lib/ctioga2/graphics/styles/ticks.rb in ctioga2-0.11
- old
+ new
@@ -24,10 +24,13 @@
module Styles
# This class describes where to place ticks on the target axis
# and how to label them.
+ #
+ # I really should drop the call to Tioga altogether. It makes
+ # everything too complicated.
class AxisTicks < BasicStyle
include Log
# The format of the tick labels.
@@ -49,10 +52,15 @@
typed_attribute :major, 'float-list'
# Separation between major ticks. Overriden by the major list
typed_attribute :major_delta, "float"
+ # Or physical separation between ticks
+ #
+ # @todo Make a major_min_sep ?
+ typed_attribute :major_sep, 'dimension'
+
# Approximate number of major ticks
typed_attribute :major_number, "integer"
# The list of the position of minor ticks
typed_attribute :minor, 'float-list'
@@ -61,11 +69,16 @@
typed_attribute :minor_delta, "float"
# Number of minor ticks between major ticks
typed_attribute :minor_number, "integer"
+ # This needs a little more careful thinking. Or just a min
+ # separation ?
+ # Physical separation between the minor ticks
+ typed_attribute :minor_sep_min, 'dimension'
+
# The list of labels
typed_attribute :labels, 'text-list'
def self.tweak_format_string(str)
@@ -94,25 +107,52 @@
if xl > xr
xl, xr = xr, xl
end
+ mn = if @major_number
+ @major_number
+ elsif @major_sep
+ dx = @major_sep.to_figure(t, info['vertical'] ? :y : :x)
+ mn = (xr - xl)/dx
+ else
+ nil
+ end
+
if @major
ret['minor_ticks'] = Dobjects::Dvector.new
ret['major_ticks'] = Dobjects::Dvector.new(@major)
fmt ||= "$%g$"
- elsif @major_delta || @major_number
- delta = @major_delta || Utils::closest_subdivision(( (xr - xl)/@major_number))
+ elsif @major_delta || mn
+ delta = @major_delta || Utils::closest_subdivision(( (xr - xl)/mn))
ret['major_ticks'] = Utils::integer_subdivisions(xl, xr,
delta)
fmt ||= "$%g$"
end
if @minor
ret['minor_ticks'] = Dobjects::Dvector.new(@minor)
- elsif @minor_delta || delta
- dt = @minor_delta || delta/((@minor_number || 3)+1)
+ elsif @minor_delta || @minor_sep || delta
+
+ dt = if @minor_delta
+ @minor_delta
+ else
+ nb = if @minor_number
+ @minor_number
+ elsif @minor_sep_min
+ dx = @minor_sep_min.to_figure(t, info['vertical'] ? :y : :x)
+ mx = ((delta/dx).round - 1)
+ if mx > 3
+ 3
+ else
+ mx
+ end
+ else
+ 3
+ end
+ delta/(nb+1)
+ end
ret['minor_ticks'] = Utils::integer_subdivisions(xl, xr,
dt)
end
fmt_last = @format_last || fmt