-
Notifications
You must be signed in to change notification settings - Fork 7
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
Refac thumbnail fv 73 #93
Conversation
… floodviz_onready
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.
Refactored code looks good besides the single comment I made.
PNG generation works correctly, although the old instructions for running it need to be updated.
floodviz/thumbnail/thumbnail.js
Outdated
@@ -82,7 +83,7 @@ function convert(figure, window, css_path, filename) { | |||
svg_string = inject_style(style_default, null, svg, window); | |||
} | |||
// Takes care of canvas conversion and encodes base64 | |||
svg2png(svg_string) | |||
svg2png(svg_string, {height: 300, width: 560}) |
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.
The numbers for height and width are used twice in this file-- maybe we could make them vars?
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.
There was refactoring done to height and width within the figure module while I was working on implementing the thumbnail script. When jumping on this current ticket, height and width had been removed from hydrograph.js during svg initialization (lines 116-122). This required me to specify height in width in svg2png because it could not be interpreted from the svg itself.
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 did however, take your suggestion and declare vars at the top for height and width instead of using the actual integers.
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.
Some minor things and some suggestions for a little reorganization of thumbnail.js
'div_id': '#hydrograph' | ||
}; | ||
|
||
var map_figure = FV.mapmodule(map_options); | ||
var hydro_figure = FV.hydromodule(hydro_options); | ||
var hydro_figure = hydromodule(hydro_options); | ||
|
||
// Use frames to link interactions | ||
var map_to_hydro = { |
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 is actually for https://github.com/ede0m/active-flood-viz/blob/33e572dbf2ce36d182ebeab1ea5311b601928a64/floodviz/static/js/floodviz_onready.js#L45. I would like to see the data passed directly into the init function. It's more explicit to pass it directly in and is not used before init() is called anyways.
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 agree with this refactor. But I think it fits in better with a new ticket that would encapsulate the FV.default_display_id changes that still need to be made in map, for the sake of consistency across these figure modules. I would happily pick this new ticket up and make those changes tomorrow.
floodviz/static/js/hydrograph.js
Outdated
* Non-optional Keys include: | ||
* @prop 'height' v(int) - height of the graph | ||
* @prop 'width' v(int) - width of the graph | ||
* @prop 'data' v(list) - A list of objects representing data points |
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 is the one that I would like to see removed and instead passed in through the init() function. Please add a comment for the new display_ids property.
floodviz/thumbnail/thumbnail.js
Outdated
@@ -15,6 +15,7 @@ var jsdom = require('jsdom/lib/old-api.js'); | |||
var svg2png = require('svg2png'); | |||
// Data imports | |||
var data_hydro = require('../thumbnail/hydrograph_data.json'); | |||
var reference = require('../../examples/reference.json'); |
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 location needs instance/reference.json as that is where we are putting it in the dockerfile process.
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.
Gotcha!
floodviz/thumbnail/thumbnail.js
Outdated
if (args[0] === '-css') { | ||
style_path = args[1]; | ||
} else { | ||
console.log('\nUnrecognized argument: ' + args[0] + '\n'); |
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.
Let's show the usage here too.
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.
For sure
floodviz/thumbnail/thumbnail.js
Outdated
@@ -44,19 +51,17 @@ jsdom.env( | |||
[ | |||
'./floodviz/static/bower_components/d3/d3.js', | |||
'./floodviz/static/bower_components/proj4/dist/proj4.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.
We don't need proj4 for the hydrograph, so this can be removed. Also remove the map div since we are only doing the hydrograph (that's above this on line 47).
floodviz/thumbnail/thumbnail.js
Outdated
@@ -82,7 +87,7 @@ function convert(figure, window, css_path, filename) { | |||
svg_string = inject_style(style_default, null, svg, window); |
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 comment is for line 78 where the additional css file is read in. Can this be done after line 30.? This gets the reading of the file done where the config parameter is read. You should be able to assign the value to style_ext and then you only need a single line to inject_style(style_default, style_ext, svg, window).
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.
Good Idea! Thanks
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.
Just need to add the one comment.
* Pass null if there are no such interactions to link. | ||
* @prop 'hover_in' - linked interaction function for hover_in events on this figure. | ||
* @prop 'hover_out' - linked interaction function for hover_out events on this figure. | ||
* @prop 'click' - linked interaction function for click events on this figure. |
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.
Add comment for @param data
Mostly involved adding reading in default_display_ids from examples into thumbnail.js
Can run and test the node script with the same command used in this pull request