Sha256: e7363c0e1d48ee4d6dacfc9e9f24bd1532783afbe95e3ecc061ce4548b40ec60

Contents?: true

Size: 1.5 KB

Versions: 14

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module Gruff
  class Store
    # @private
    class XYPointsizeData < Struct.new(:label, :x_points, :y_points, :point_sizes, :color)
      def initialize(label, x_points, y_points, point_sizes, color)
        y_points = Array(y_points)
        x_points = x_points ? Array(x_points) : Array.new(y_points.length)
        raise ArgumentError, 'x_points.length != y_points.length!'    if x_points.length != y_points.length
        raise ArgumentError, 'x_points.length != point_sizes.length!' if x_points.length != point_sizes.length

        super(label.to_s, x_points, y_points, point_sizes, color)
      end

      alias points y_points

      def coordinate_and_pointsizes
        x_points.zip(y_points, point_sizes)
      end

      def empty?
        y_points.empty?
      end

      def columns
        y_points.length
      end

      def min
        y_points.compact.min
      end
      alias min_y min

      def max
        y_points.compact.max
      end
      alias max_y max

      def min_x
        x_points.compact.min
      end

      def max_x
        x_points.compact.max
      end

      def normalize(minimum_x:, minimum_y:, spread_x:, spread_y:)
        norm_x_points = x_points.map do |x|
          x.nil? ? nil : (x.to_f - minimum_x.to_f) / spread_x
        end
        norm_y_points = y_points.map do |y|
          y.nil? ? nil : (y.to_f - minimum_y.to_f) / spread_y
        end

        self.class.new(label, norm_x_points, norm_y_points, point_sizes, color)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
gruff-0.24.0-java lib/gruff/store/xy_pointsizes_data.rb
gruff-0.24.0 lib/gruff/store/xy_pointsizes_data.rb
gruff-0.23.0 lib/gruff/store/xy_pointsizes_data.rb
gruff-0.23.0-java lib/gruff/store/xy_pointsizes_data.rb
gruff-0.22.0 lib/gruff/store/xy_pointsizes_data.rb
gruff-0.22.0-java lib/gruff/store/xy_pointsizes_data.rb
gruff-0.21.0-java lib/gruff/store/xy_pointsizes_data.rb
gruff-0.21.0 lib/gruff/store/xy_pointsizes_data.rb
gruff-0.20.0-java lib/gruff/store/xy_pointsizes_data.rb
gruff-0.20.0 lib/gruff/store/xy_pointsizes_data.rb
gruff-0.19.0 lib/gruff/store/xy_pointsizes_data.rb
gruff-0.19.0-java lib/gruff/store/xy_pointsizes_data.rb
gruff-0.18.0-java lib/gruff/store/xy_pointsizes_data.rb
gruff-0.18.0 lib/gruff/store/xy_pointsizes_data.rb