Charty - Visualizing your data in Ruby

Charty - Visualizing your data in Ruby

Charty - Visualizing your data in Ruby at RubyConf Taiwan 2019

7ef4ab70ee295c821f8b77fab3aa87cf?s=128

秒速284km

July 27, 2019
Tweet

Transcript

  1. 1.
  2. 2.

    I came to Taiwan and spent 3 days Taiwan is

    a excellent place. Everything I ate was delicious I love taiwan
  3. 4.

    I went to ⿓⼭寺 There are many other places I

    would like to go, but I will not calm down until the presentation is over :) I'm looking forward to it. 九份 象⼭ 猫空 etc ...
  4. 6.
  5. 7.

    I came from asakusa.rb I'm a member of Asakusa.rb If

    you ever come to Japan, come to Asakusa.rb
  6. 8.

    Bubble tea Recently very popular in Japan. But I drank

    bubble tea for the first time in Taiwan Thank you Stan(@_st0012). He is very kind. He guided me to bubble tea I drink different taste every day It's taste terrific. I love it. I love this tea.
  7. 9.

    Tea I'm interested in teas other than "Bubble" tea. I

    wanna go to 猫空. and I wanna get delicious tea. By the way, tea is pronounce in Chinese and Japanese. 茶(cha)
  8. 10.
  9. 12.
  10. 15.
  11. 18.

    About Charty Charty is a open-source Ruby library for visualizing

    your data in a simple way. For example such a graph, such a graph, or such a graph or something like this, etc. We can easily plot with Charty
  12. 19.

    Characteristics of Charty Charty has 2 abstract layer Data Abstraction

    Layer Plotting Abstraction Layer (I will explain later)
  13. 22.

    Pyplot require 'charty' charty = Charty::Plotter.new(:pyplot) scatter = charty.scatter do

    iris.group_by(:label).groups.each do |label, index| records = iris.row[*index] series records[:petal_length].to_a, records[:petal_width].to_a, label: label[0] end xlabel "Petal Length" ylabel "Petal Width" end scatter.render('pyplot.png')
  14. 23.

    Gruff require 'charty' charty = Charty::Plotter.new(:gruff) scatter = charty.scatter do

    iris.group_by(:label).groups.each do |label, index| records = iris.row[*index] series records[:petal_length].to_a, records[:petal_width].to_a, label: label[0] end xlabel "Petal Length" ylabel "Petal Width" end scatter.render('gruff.png')
  15. 24.

    Plotting Abstraction Layer The difference is one line. Here is

    one of the features of Charty We can easily switch back-end libraries with almost the same code e.g.) left: Pyplot, right: Gruff
  16. 25.

    More about Plotting Abstraction Layer Currently supported backends pyplot gruff

    Rubyplot google-chart bokeh plotly plotly.js chart.js
  17. 26.

    About each backend I feel that Pyplot has the largest

    number of graph types that can be output. When we want to add a graph to support, we often implement Pyplot first as a reference implementation. After that, we will implement other libraries.
  18. 27.

    Other cases about backend For example, google-charts, bokeh, plotly These

    were implemented by a pull request that "I'd like to use if this library is supported by the back end of Charty" If there is a real User and Real-world use case exists, it depends on the priority with other work, but consider support for a new backend. At the moment we are developing that way
  19. 29.

    Ruby Association Grant Charty is a project of Ruby Association

    Grant 2018 this is my proposal at the time If you are interested, You may wish to apply for the Ruby Association Grant 2019 :) (Application for 2019 has not started yet)
  20. 30.

    Data Abstraction Layer daru numo/narray nmatrix ActiveRecord (demo) Thus, it

    can respond to various data structures. That's because Charty::Table is abstracted.
  21. 31.

    Feature summary of Charty Charty has two abstraction layers. Data

    Abstraction Layer Plotting Abstraction Layer. So we can use the data structures we need We can use output libraries we want to use.
  22. 32.

    Introduction of various use cases The examples so far have

    mainly introduced back-ends that output graph images. Recently, we introduced Charty in our production environment of Web Application, which is our job. This Web Application is a common Rails Application. At that time, we were asking for Charty to output json, not the image. Here is an example using plotly.js (demo)
  23. 33.

    Code # controller plotlyjs = Charty::Plotter.new(:plotlyjs) plotlyjs.table = DataModel.new(params[:foo]) json_data

    = plotlyjs.to_json layout_data = plotlyjs.layout # view <div id="sample"></div> # javascript import * as Plotly from 'plotly.js-dist'; Plotly.newPlot("sample", json_data, layout_data);
  24. 34.

    Another sample Chart.js this is another sample application using Chart.js

    as a Charty backend. this case, Charty returns HTML includes javascript code to need. This is an experimental implementation, but I would like to have features abstracted according to the use case.
  25. 36.

    benchmark-driver ruby/csv benchmark-driver $ gem install $ benchmark-driver examples/parse.yaml Calculating

    ------------------------------------- csv 3.1.1 csv 3.0.1 unquoted 61.332 38.149 i/s - 100.000 times in 1.630461s 2.621311s quoted 30.558 17.023 i/s - 100.000 times in 3.272469s 5.874313s mixed 40.932 23.047 i/s - 100.000 times in 2.443082s 4.339030s include_col_sep 11.167 10.657 i/s - 100.000 times in 8.955275s 9.383878s include_row_sep 11.180 4.339 i/s - 100.000 times in 8.944608s 23.044523s encode_utf-8 39.129 31.525 i/s - 100.000 times in 2.555671s 3.172112s encode_sjis 49.982 31.289 i/s - 100.000 times in 2.000736s 3.196026s Comparison: unquoted csv 3.1.1: 61.3 i/s csv 3.0.1: 38.1 i/s - 1.61x slower quoted csv 3.1.1: 30.6 i/s csv 3.0.1: 17.0 i/s - 1.80x slower mixed csv 3.1.1: 40.9 i/s csv 3.0.1: 23.0 i/s - 1.78x slower include_col_sep csv 3.1.1: 11.2 i/s csv 3.0.1: 10.7 i/s - 1.05x slower include_row_sep csv 3.1.1: 11.2 i/s csv 3.0.1: 4.3 i/s - 2.58x slower
  26. 38.

    Data Abstraction Layer (currently supports) Array Hash daru numo-narray nmatrix

    ActiveRecord benchmark_driver (Charty Adapter) It can Output: image, HTML, JSON
  27. 40.

    Future plan Interface Release stable version Support red-arrow Improve iruby

    more faster csv Add supported dataset (red-datasets) (e.g. titanic)