-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
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. |
Now, user along with format of the chart (in which it has to be exported) can provide the file name.
This will download the chart as: daru.png |
when 'svg' | ||
"\n type: 'image/svg+xml'," | ||
else | ||
raise 'Invalid format' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() {" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check alignments of the lines are correct in web page.
lib/daru/view/adapters/highcharts.rb
Outdated
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't we can find, if user running in IRuby notebook or console or web app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
1efedc4
to
67efe88
Compare
end | ||
|
||
def export_image_iruby(plot, file_name, type='pdf') | ||
def export_type(plot, type='pdf', file_name='chart') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't tab
is easy to read for indentation.
spec/plot_spec.rb
Outdated
end | ||
end # initialize context end | ||
|
||
context '#export_type' do | ||
it "should generate the valid script to export the chart" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better, if you write specs for each export type and check for saved file(png, pdf, ..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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. |
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. |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should throw error saying not implemented yet.
js = '' | ||
js << "\n <script>" | ||
js << "\n (function() {" | ||
js << "\n var onload = window.onload;" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it will not work without internet ? Please document it.
lib/daru/view/plot.rb
Outdated
# @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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write few examples in documentation.
IRuby notebook example link ? Also along with documenting the method, write few example for user to understand the API. |
I have commented out the export method in the examples here. |
700f511
to
53d3845
Compare
@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? |
7b77ff0
to
69a0715
Compare
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
69a0715
to
6d96906
Compare
Pull Request Test Coverage Report for Build 602
💛 - Coveralls |
Pull Request Test Coverage Report for Build 583
💛 - Coveralls |
2 similar comments
Pull Request Test Coverage Report for Build 583
💛 - Coveralls |
Pull Request Test Coverage Report for Build 583
💛 - Coveralls |
@Shekharrajak can you please review the changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document the usage in separate Wiki page as well.
It looks good to go after minor modification as per the comment. 🎊
lib/daru/view/adapters/highcharts.rb
Outdated
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expoting -> Exporting
frameforks -> frameworks
lib/daru/view/adapters/highcharts.rb
Outdated
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can open the issue to track it, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll open it after this PR gets merged.
0cc2975
to
282be2d
Compare
@Shekharrajak I have documented the usage in this wiki page. |
@Prakriti-nith , please resolve the conflicts and run the examples once. |
@Shekharrajak I tried the examples again both in IRuby notebook and rails, everything is working fine. |
Added the methods
export_image
andexport_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.This example will first generate the chart and then download it in svg format like this: