SciRuby / daru-view

daru-view is for easy and interactive plotting in web application & IRuby notebook. daru-view is a plugin gem to the existing daru gem.
https://sciruby.github.io/daru-view/
MIT License
95 stars 20 forks source link

Added export method to export highchart in different formats #94

Closed Prakriti-nith closed 6 years ago

Prakriti-nith commented 6 years ago

Added the methods export_image and export_image_iruby to export the Highchart in four formats: pdf, png, jpg and svg with the default format being pdf. This is working fine in rails app but I can't understand why it is not working in IRuby notebook. Still searching some way to make it work. I will add the example of rails app to demonstrate this feature.

Example: hchart = Daru::View::Plot.new(data, options) hchart.export_image('svg')

This example will first generate the chart and then download it in svg format like this: image

Prakriti-nith commented 6 years ago

I was using JQuery to get the Highchart object and then download it. For this, I was using jquery.min.js dependency. This dependency was not properly loaded in IRuby notebook (maybe conflicting with the existing dependencies of the jupyter notebook) and was creating problems. I have replaced the code to get the instance of HighCharts' object with the pure js code. It is now working fine in both IRuby notebook as well as in web frameworks.

Prakriti-nith commented 6 years ago

Now, user along with format of the chart (in which it has to be exported) can provide the file name. For example,

hchart = Daru::View::Plot.new(data, options) hchart.export_image('daru', 'png')

This will download the chart as: daru.png

Prakriti-nith commented 6 years ago

I just found that while exporting multiple highcharts simultaneously in web frameworks, it is exporting only the last one. I am trying to find a solution to resolve this issue.

Prakriti-nith commented 6 years ago

By using exportChartLocal (useful link), not only the issue has been resolved but also the exporting works offline (export button in highcharts works online). In IRuby notebook, online exporting asks to leave the page and after that that jupyter notebook does not work (try exporting using exporting button) but this method (export) resolves all.

Prakriti-nith commented 6 years ago

In IRuby notebook, offline-export supports only the exporting to png, jpeg and svg format. Export to PDF is not working (not even through the exporting button in highchart). Also, in IRuby notebook, online exporting asks to leave the page and after that that jupyter notebook does not work (try exporting using exporting button). Still, I am keeping the online exporting for the IRuby notebook so that at least chart can be exported to all the formats and offline-exporting for the web frameworks.

Shekharrajak commented 6 years ago

IRuby notebook example link ? Also along with documenting the method, write few example for user to understand the API.

Prakriti-nith commented 6 years ago

I have commented out the export method in the examples here. I also tried running it in console, it is generating the correct script to download the chart.

Prakriti-nith commented 6 years ago

@Shekharrajak The tests of updating the js files runs sometimes perfectly and sometimes doesn't (maybe because the highcharts js doesn't get loaded fully and network error occurs). I don't understand the exact reason. Can you please check this?

coveralls commented 6 years ago

Pull Request Test Coverage Report for Build 602


Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/daru/view/adapters/googlecharts.rb 1 2 50.0%
lib/daru/view/adapters/nyaplot.rb 1 2 50.0%
lib/daru/view/adapters/highcharts/display.rb 48 50 96.0%
<!-- Total: 179 183 97.81% -->
Totals Coverage Status
Change from base Build 601: 0.6%
Covered Lines: 1690
Relevant Lines: 1740

💛 - Coveralls
coveralls commented 6 years ago

Pull Request Test Coverage Report for Build 583


Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/daru/view/adapters/googlecharts.rb 1 2 50.0%
lib/daru/view/adapters/nyaplot.rb 1 2 50.0%
<!-- Total: 181 183 98.91% -->
Totals Coverage Status
Change from base Build 578: 0.2%
Covered Lines: 2127
Relevant Lines: 2208

💛 - Coveralls
coveralls commented 6 years ago

Pull Request Test Coverage Report for Build 583


Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/daru/view/adapters/googlecharts.rb 1 2 50.0%
lib/daru/view/adapters/nyaplot.rb 1 2 50.0%
<!-- Total: 181 183 98.91% -->
Totals Coverage Status
Change from base Build 578: 0.2%
Covered Lines: 2127
Relevant Lines: 2208

💛 - Coveralls
coveralls commented 6 years ago

Pull Request Test Coverage Report for Build 583


Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/daru/view/adapters/googlecharts.rb 1 2 50.0%
lib/daru/view/adapters/nyaplot.rb 1 2 50.0%
<!-- Total: 181 183 98.91% -->
Totals Coverage Status
Change from base Build 578: 0.2%
Covered Lines: 2127
Relevant Lines: 2208

💛 - Coveralls
Prakriti-nith commented 6 years ago

@Shekharrajak can you please review the changes?

Prakriti-nith commented 6 years ago

@Shekharrajak I have documented the usage in this wiki page.

Shekharrajak commented 6 years ago

@Prakriti-nith , please resolve the conflicts and run the examples once.

Prakriti-nith commented 6 years ago

@Shekharrajak I tried the examples again both in IRuby notebook and rails, everything is working fine.