class Charty::Plotters::StyleMapper
Constants
- MARKER_NAMES
Attributes
levels[R]
lookup_table[R]
norm[R]
order[R]
palette[R]
Public Instance Methods
inverse_lookup_table(attr)
click to toggle source
# File lib/charty/plotters/relational_plotter.rb, line 409 def inverse_lookup_table(attr) lookup_table.map { |k, v| [v[attr], k] }.to_h end
lookup_single_value(key, attr=nil)
click to toggle source
# File lib/charty/plotters/relational_plotter.rb, line 413 def lookup_single_value(key, attr=nil) case attr when nil @lookup_table[key] else @lookup_table[key][attr] end end
Private Instance Methods
initialize_mapping(markers, dashes, order)
click to toggle source
# File lib/charty/plotters/relational_plotter.rb, line 340 def initialize_mapping(markers, dashes, order) @markers = markers @dashes = dashes @order = order return unless plotter.variables.key?(:style) data = plotter.plot_data[:style] return unless data.notnull.any? @levels = data.categorical_order(order) markers = map_attributes(markers, @levels, unique_markers(@levels.length), :markers) dashes = map_attributes(dashes, @levels, unique_dashes(@levels.length), :dashes) @lookup_table = @levels.map {|key| record = { marker: markers[key], dashes: dashes[key] } record.compact! [key, record] }.to_h end
map_attributes(vals, levels, defaults, attr)
click to toggle source
# File lib/charty/plotters/relational_plotter.rb, line 382 def map_attributes(vals, levels, defaults, attr) case vals when true return levels.zip(defaults).to_h when Hash missing_keys = lavels - vals.keys unless missing_keys.empty? raise ArgumentError, "The `%s` levels are missing values: %p" % [attr, missing_keys] end return vals when Array, Enumerable if levels.length != vals.length raise ArgumentError, "%he `%s` argument has the wrong number of values" % attr end return levels.zip(vals).to_h when nil, false return {} else raise ArgumentError, "Unable to recognize the value for `%s`: %p" % [attr, vals] end end
unique_dashes(n)
click to toggle source
# File lib/charty/plotters/relational_plotter.rb, line 378 def unique_dashes(n) DashPatternGenerator.take(n) end
unique_markers(n)
click to toggle source
# File lib/charty/plotters/relational_plotter.rb, line 370 def unique_markers(n) if n > MARKER_NAMES.length raise ArgumentError, "Too many markers are required (%p for %p)" % [n, MARKER_NAMES.length] end MARKER_NAMES[0, n] end