Sha256: 6daa838cd0ce97795e0db1d43e8799299cc6906eb160ad397d5029ced1e025ee

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'rbplotly'
require 'daru'

module Daru
  module Plotly
    # exports #plot and #generate_data for Vector
    module Vector
      class << self
        include Daru::Plotly

        def generate_data(vector, opts)
          type = extract_type opts[:type]

          case type
          when :histogram
            generate_data_for_histogram(vector, opts)
          when :scatter, :bar
            generate_data_for_scatter_and_bar(vector, opts)
          when :pie
            generate_data_for_pie(vector, opts)
          end.map { |trace| trace.merge(opts[:opts] || {}) }
        end

        def generate_data_for_histogram(vector, _opts)
          [{ x: vector.to_a, type: :histogram }]
        end

        def generate_data_for_scatter_and_bar(vector, opts)
          [
            {
              x: vector.index.to_a, y: vector.to_a,
              type: opts[:type], mode: extract_mode_string(opts[:model])
            }
          ]
        end

        def generate_data_for_pie(vector, _opts)
          [{ labels: vector.index.to_a, values: vector.to_a, type: :pie }]
        end

        def supported_types
          %i[scatter bar histogram pie]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
daru-plotly-0.2.0 lib/daru/plotly/vector.rb