Sha256: 48a2d6a5c8aa400218df191a2b849553dc2cea6bd1554b6ed8563f1e47fb07a7

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

require 'chartkick'

module Arql
  module Chart
    include Chartkick::Helper

    def line_chart(data_source, **options)
      html_chart "LineChart", data_source, **options
    end

    def pie_chart(data_source, **options)
      html_chart "PieChart", data_source, **options
    end

    def column_chart(data_source, **options)
      html_chart "ColumnChart", data_source, **options
    end

    def bar_chart(data_source, **options)
      html_chart "BarChart", data_source, **options
    end

    def area_chart(data_source, **options)
      html_chart "AreaChart", data_source, **options
    end

    def scatter_chart(data_source, **options)
      html_chart "ScatterChart", data_source, **options
    end

    def geo_chart(data_source, **options)
      html_chart "GeoChart", data_source, **options
    end

    def timeline(data_source, **options)
      html_chart "Timeline", data_source, **options
    end

    def html_chart(klass, data_source, **options)
      chart = chartkick_chart(klass, data_source, **options)

      html = <<~HTML
        <html>
          <head>
            <script src="https://www.hackit.fun/js/Chart.bundle.js"></script>
            <script src="https://www.hackit.fun/js/chartkick.js"></script>
          </head>
          <body style="color: red">
            #{chart}
          </body>
        </html>
      HTML
      html = html.lines.reject {|line| line =~ /(data-turbo)|(Chartkick" in window)|(^\s*\}\s*else\s*\{\s*$)|(chartkick:load)|(^\s*\}\s*$)/}.join("\n")
      IRuby.display(html, mime: 'text/html')
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
arql-0.4.12 lib/arql/chart.rb
arql-0.4.11 lib/arql/chart.rb
arql-0.4.10 lib/arql/chart.rb
arql-0.4.8 lib/arql/chart.rb
arql-0.4.7 lib/arql/chart.rb
arql-0.4.6 lib/arql/chart.rb