michelson / lazy_high_charts

Make highcharts a la ruby , works in rails 5.X / 4.X / 3.X, and other ruby web frameworks
http://www.suipit.com
MIT License
1.05k stars 243 forks source link

defined `show` and `show_in_iruby` methods #236

Open Shekharrajak opened 7 years ago

Shekharrajak commented 7 years ago

Fixes https://github.com/michelson/lazy_high_charts/issues/235

e.g. in iruby notebook :

chart = LazyHighCharts::HighChart.new('graph') do |f|
      f.title({ :text=>"Combination chart"})
      f.options[:xAxis][:categories] = ['Apples', 'Oranges', 'Pears', 'Bananas', 'Plums']
      f.labels(:items=>[:html=>"Total fruit consumption", :style=>{:left=>"40px", :top=>"8px", :color=>"black"} ])      
      f.series(:type=> 'column',:name=> 'Jane',:data=> [3, 2, 1, 3, 4])
      f.series(:type=> 'column',:name=> 'John',:data=> [2, 3, 5, 7, 6])
      f.series(:type=> 'column', :name=> 'Joe',:data=> [4, 3, 3, 9, 0])
      f.series(:type=> 'spline',:name=> 'Average', :data=> [3, 2.67, 3, 6.33, 3.33])
      f.series(:type=> 'pie',:name=> 'Total consumption', 
        :data=> [
          {:name=> 'Jane', :y=> 13, :color=> 'red'}, 
          {:name=> 'John', :y=> 23,:color=> 'green'},
          {:name=> 'Joe', :y=> 19,:color=> 'blue'}
        ],
        :center=> [100, 80], :size=> 100, :showInLegend=> false)
    end

include LazyHighCharts::LayoutHelper
IRuby.display high_chart("some_id", chart), mime: 'text/html'
# or
IRuby.html high_chart("some_id", chart).to_s

I am not able to understand why high_chart_iruby("some_id1", chart) not working.

Shekharrajak commented 7 years ago

Ping @michelson

Shekharrajak commented 7 years ago

@michelson , if this PR is merged, then it will be very helpful for me to use it in Daru gem and plugin gem daru-view. So please try to review it as soon as possible.

michelson commented 7 years ago

Hi @Shekharrajak , this looks good!. Could you provide an example in spec/dummy for iruby in order to do some integration tests?

best!

Shekharrajak commented 7 years ago

@michelson , I hope, now it is good to go.

Shekharrajak commented 7 years ago

Using show and show_in_iruby method use don't need to run these lines :

include LazyHighCharts::LayoutHelper
IRuby.display high_chart("some_id", chart), mime: 'text/html'
Shekharrajak commented 7 years ago

Most of the time developers and users try their code in iruby notebook. So it will be very helpful if lazy_high_charts is usable in iruby notebook. I have tried one example and pushed in this branch. You can check it in this link : http://nbviewer.jupyter.org/github/Shekharrajak/lazy_high_charts/blob/iruby_setup/examples/notebook/lazy_high_charts.ipynb

It will be helpful for me to continue my work on daru-view, if this PR is merged as soon as possible. Thanks.

michelson commented 7 years ago

Hi Shekhar, thanks for this contribution , I guess this will be very helpful for iruby users. Let me check this out , do some tests and merge this PR asap

regards from Chile

Atte. Miguel Michelson Martinez www.vadb.org http://vadb.org

On Mon, Jun 5, 2017 at 6:26 AM, Shekhar Prasad Rajak < notifications@github.com> wrote:

Most of the time developers and users try their code in iruby notebook. So it will be very helpful if lazy_high_charts is usable in iruby notebook. I have tried one example and pushed in this branch. You can check it in this link : http://nbviewer.jupyter.org/github/Shekharrajak/lazy_high_ charts/blob/iruby_setup/examples/notebook/lazy_high_charts.ipynb

It will be helpful for me to continue my work on daru-view, if this PR is merged as soon as possible. Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/michelson/lazy_high_charts/pull/236#issuecomment-306143844, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAuyKXd68HkcJqs2QMs_9rjKPEmlqOWks5sA8m1gaJpZM4NvB8A .

michelson commented 7 years ago

Hi @Shekharrajak , The example should be moved to spec/dummy_iruby in order to merge this the example should contain all the dependences in a Gemfile , and the iRuby dep should be removed from gemspec. The Gemfile from the example project should be something like:

source "http://rubygems.org"
gem "iruby"
gem "cztop"
gemspec  :path => '../../'

btw I'm having troubles to run the notebook, all the output is turned to text, so is no chart. but I can see the example you pointed on jupyter.org correctly

regards

Shekharrajak commented 7 years ago

Thanks for review . @michelson are you getting nothing in output cell of the notebook, when you run show_in_iruby ?

Shekharrajak commented 7 years ago

I have added more examples in spec/dummy_iruby : http://nbviewer.jupyter.org/github/Shekharrajak/lazy_high_charts/blob/iruby_setup/spec/dummy_iruby/lazy_high_charts_basics.ipynb

Please check the last example, why it is failing. I think that is other issue.

michelson commented 7 years ago

yup , I'm not seeing any html output for the graph

i'm doing bundle exec iruby notebook inside spec/dummy_iruby

image

I've updated the gemfile as follows:

source "http://rubygems.org"
gem "iruby"
gem "cztop"
#gem 'rbczmq' <- this is not compiling on ruby 2.4.0 (osx)
gem 'actionview', '~> 4.2'
gemspec  :path => '../../'

is this working for you on local environment ? I get some errors just after notebook starts , FATAL -- : Kernel died: uninitialized constant IRuby::Kernel::Session

Shekharrajak commented 7 years ago
gem 'rbczmq' # or 'ffi-rzmq'

is needed for iruby notebook. You can try it with 2.3 ruby

see : https://stackoverflow.com/questions/35999925/kernel-dies-when-creating-iruby-notebook

yup , I'm not seeing any html output for the graph'

When you do print preview in iruby notebook you will be able to see the chart. I also got the same problem I didn't understand why.

Shekharrajak commented 7 years ago

@michelson , I think for 3d charts need to use <script src="/https://code.highcharts.com/highcharts-3d.js"><script>. But previously I thought 3d charts is usable with highcharts.js only. Is there any dependency in 3d plotting?

Shekharrajak commented 7 years ago

Problem is onload method used here . I will update the PR soon