New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added export method to export highchart in different formats #94

Merged
merged 4 commits into from Jul 14, 2018

Conversation

Projects
None yet
3 participants
@Prakriti-nith
Contributor

Prakriti-nith commented May 28, 2018

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

This comment has been minimized.

Contributor

Prakriti-nith commented May 28, 2018

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

This comment has been minimized.

Contributor

Prakriti-nith commented May 29, 2018

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

when 'svg'
"\n type: 'image/svg+xml',"
else
raise 'Invalid format'

This comment has been minimized.

@Shekharrajak

Shekharrajak May 30, 2018

Collaborator

It's type error right?

def extract_export_code_iruby(placeholder=random_canvas_id, file_name='chart', type='pdf')
js = ''
js << "\n <script>"
js << "\n (function() {"

This comment has been minimized.

@Shekharrajak

Shekharrajak May 30, 2018

Collaborator

Check alignments of the lines are correct in web page.

@@ -64,6 +64,16 @@ def export_html_file(plot, path='./plot.html')
File.write(path, str)
end

# @see #Daru::View::Plot.export_image
def export_image(plot, file_name='chart', type='pdf')

This comment has been minimized.

@Shekharrajak

Shekharrajak May 30, 2018

Collaborator

Isn't we can find, if user running in IRuby notebook or console or web app?

This comment has been minimized.

@Prakriti-nith

Prakriti-nith May 31, 2018

Contributor

Yes, first I thought of creating only the export_image method. I tried to know whether the user is running in web app or IRuby notebook but couldn't do it. So, I created two different methods export_image and export_image_iruby instead

@Prakriti-nith Prakriti-nith force-pushed the Prakriti-nith:export_highchart branch from 1efedc4 to 67efe88 Jun 3, 2018

end

def export_image_iruby(plot, file_name, type='pdf')
def export_type(plot, type='pdf', file_name='chart')

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 4, 2018

Collaborator

I was telling def export(plot, export_type='pdf', file_name='chart').

def append_chart_type(type='pdf')
case type
when 'pdf'
"\n type: 'application/pdf',"

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 4, 2018

Collaborator

Isn't tab is easy to read for indentation.

end
end # initialize context end

context '#export_type' do
it "should generate the valid script to export the chart" do

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 4, 2018

Collaborator

It would be better, if you write specs for each export type and check for saved file(png, pdf, ..)

This comment has been minimized.

@Prakriti-nith

Prakriti-nith Jun 5, 2018

Contributor

This method generates the JS code in String format (or loads it in IRuby) to download the chart. I have updated the documentation of it. It will export the chart when it will run in web frameworks or IRuby notebook. I will write the specs for each export type. Should I write them in the same way or is there any other way possible?

@Prakriti-nith

This comment has been minimized.

Contributor

Prakriti-nith commented Jun 7, 2018

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

This comment has been minimized.

Contributor

Prakriti-nith commented Jun 7, 2018

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

This comment has been minimized.

Contributor

Prakriti-nith commented Jun 8, 2018

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.

@@ -65,6 +65,10 @@ def export_html_file(plot, path='./plot.html')
File.write(path, str)
end

def export(plot, export_type='pdf', file_name='chart')
# TODO

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 10, 2018

Collaborator

Should throw error saying not implemented yet.

js = ''
js << "\n <script>"
js << "\n (function() {"
js << "\n var onload = window.onload;"

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 10, 2018

Collaborator

Isn't it tab is better than space to understand the alignment?

@@ -10,8 +10,7 @@ def self.generate_init_code(dependent_js)
# Enable to show plots on IRuby notebook
def self.init_iruby(
dependent_js=['highstock.js', 'highcharts-more.js', 'modules/exporting.js',
'highcharts-3d.js', 'modules/data.js',
'modules/offline-exporting.js']

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 10, 2018

Collaborator

So it will not work without internet ? Please document it.

# @param file_name [String] The name of the file after exporting the chart
# @return [String, void] js code of chart along with the code to export it
# and loads the js code to export it in IRuby.
def export(export_type='pdf', file_name='chart')

This comment has been minimized.

@Shekharrajak

Shekharrajak Jun 10, 2018

Collaborator

Please write few examples in documentation.

@Shekharrajak

This comment has been minimized.

Collaborator

Shekharrajak commented Jun 10, 2018

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

@Prakriti-nith

This comment has been minimized.

Contributor

Prakriti-nith commented Jun 13, 2018

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 Prakriti-nith force-pushed the Prakriti-nith:export_highchart branch 2 times, most recently from 700f511 to 53d3845 Jun 16, 2018

@Prakriti-nith

This comment has been minimized.

Contributor

Prakriti-nith commented Jun 16, 2018

@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?

@Prakriti-nith Prakriti-nith force-pushed the Prakriti-nith:export_highchart branch from 7b77ff0 to 69a0715 Jun 19, 2018

@Prakriti-nith Prakriti-nith changed the title from Added export_image method to export highchart in different formats to Added export method to export highchart in different formats Jun 23, 2018

Prakriti-nith added some commits May 28, 2018

Added export_image method to export highchart in different formats
Added compatibility for IRuby notebook

Added file_name

Corrected alignment of lines on web page

Remove export_image_iruby from plot.rb

Updated method name to export

Updated documentation

Added more specs

Use exportChartLocal instead of exportChart

Online exporting in IRuby notebook

Added documentation

Updated examples accordingly

Change default type to png

@Prakriti-nith Prakriti-nith force-pushed the Prakriti-nith:export_highchart branch from 69a0715 to 6d96906 Jul 7, 2018

@coveralls

This comment has been minimized.

coveralls commented Jul 7, 2018

Pull Request Test Coverage Report for Build 602

  • 179 of 183 (97.81%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.6%) to 97.126%

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%
Totals Coverage Status
Change from base Build 601: 0.6%
Covered Lines: 1690
Relevant Lines: 1740

💛 - Coveralls
@coveralls

This comment has been minimized.

coveralls commented Jul 7, 2018

Pull Request Test Coverage Report for Build 583

  • 181 of 183 (98.91%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 96.332%

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%
Totals Coverage Status
Change from base Build 578: 0.2%
Covered Lines: 2127
Relevant Lines: 2208

💛 - Coveralls
2 similar comments
@coveralls

This comment has been minimized.

coveralls commented Jul 7, 2018

Pull Request Test Coverage Report for Build 583

  • 181 of 183 (98.91%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 96.332%

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%
Totals Coverage Status
Change from base Build 578: 0.2%
Covered Lines: 2127
Relevant Lines: 2208

💛 - Coveralls
@coveralls

This comment has been minimized.

coveralls commented Jul 7, 2018

Pull Request Test Coverage Report for Build 583

  • 181 of 183 (98.91%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 96.332%

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%
Totals Coverage Status
Change from base Build 578: 0.2%
Covered Lines: 2127
Relevant Lines: 2208

💛 - Coveralls
@Prakriti-nith

This comment has been minimized.

Contributor

Prakriti-nith commented Jul 12, 2018

@Shekharrajak can you please review the changes?

@Shekharrajak

Please document the usage in separate Wiki page as well.
It looks good to go after minor modification as per the comment. 🎊

@@ -70,6 +70,21 @@ def export_html_file(plot, path='./plot.html')
File.write(path, str)
end

# Expoting in web frameforks is completely offline. In IRuby notebook,

This comment has been minimized.

@Shekharrajak

Shekharrajak Jul 12, 2018

Collaborator

Expoting -> Exporting
frameforks -> frameworks

# Expoting in web frameforks is completely offline. 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). So, online exporting is done in IRuby notebook. There is a

This comment has been minimized.

@Shekharrajak

Shekharrajak Jul 12, 2018

Collaborator

We can open the issue to track it, right?

This comment has been minimized.

@Prakriti-nith

Prakriti-nith Jul 12, 2018

Contributor

I'll open it after this PR gets merged.

@Prakriti-nith Prakriti-nith force-pushed the Prakriti-nith:export_highchart branch from 0cc2975 to 282be2d Jul 12, 2018

@Prakriti-nith

This comment has been minimized.

Contributor

Prakriti-nith commented Jul 12, 2018

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

@Shekharrajak

This comment has been minimized.

Collaborator

Shekharrajak commented Jul 13, 2018

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

@Prakriti-nith

This comment has been minimized.

Contributor

Prakriti-nith commented Jul 13, 2018

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

@Shekharrajak Shekharrajak merged commit 8d4f389 into SciRuby:master Jul 14, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.6%) to 97.126%
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment