Class: CTioga2::Graphics::Styles::AxisTicks
- Inherits:
-
BasicStyle
- Object
- BasicStyle
- CTioga2::Graphics::Styles::AxisTicks
- Includes:
- Log
- Defined in:
- lib/ctioga2/graphics/styles/ticks.rb
Overview
This class describes where to place ticks on the target axis and how to label them.
Constant Summary
Constants inherited from BasicStyle
BasicStyle::AllStyles, BasicStyle::OldAttrAccessor
Class Method Summary collapse
Instance Method Summary collapse
-
#ticks_specs(t, info, transform) ⇒ Object
Returns the specifications that should be added to the information.
Methods included from Log
context, debug, error, fatal, #format_exception, #identify, info, init_logger, log_to, logger, set_level, #spawn, warn
Methods inherited from BasicStyle
alias_for, attr_accessor, attribute_type, attribute_types, attributes, deprecated_attribute, from_hash, inherited, #instance_variable_defined?, options_hash, #set_from_hash, sub_style, sub_styles, #to_hash, typed_attribute, #update_from_other
Class Method Details
.tweak_format_string(str) ⇒ Object
71 72 73 |
# File 'lib/ctioga2/graphics/styles/ticks.rb', line 71 def self.tweak_format_string(str) return str.gsub("%b", "%2$").gsub("%p", "%3$d") end |
Instance Method Details
#ticks_specs(t, info, transform) ⇒ Object
Returns the specifications that should be added to the information
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ctioga2/graphics/styles/ticks.rb', line 77 def ticks_specs(t, info, transform) ret = {} for k in %w{major_ticks minor_ticks labels} ret[k] = info[k] end if info['major'] ret['minor_ticks'] = info['minor'] ret['major_ticks'] = info['major'] end fmt = @format # beginning or end of the axis. Not specifically x xl, xr = * (if info['vertical'] [info['y0'], info['y1']] else [info['x0'], info['x1']] end) if xl > xr xl, xr = xr, xl 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)) 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) ret['minor_ticks'] = Utils::integer_subdivisions(xl, xr, dt) end fmt_last = @format_last || fmt if @labels ret['labels'] = @labels elsif fmt ret['labels'] = [] fmt = AxisTicks.tweak_format_string(fmt) fmt_last = AxisTicks.tweak_format_string(fmt_last) i = ret['major_ticks'].size common = Utils::common_pow10(ret['major_ticks']) fact = 10**(-common) for v in ret['major_ticks'] i -= 1 ret['labels'] << (i > 0 ? fmt : fmt_last) % [v, v*fact, common] end end return ret end |