-
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
Thumbnail fv_34 with JSDOM #79
Conversation
…d to refactor the figure modules a bit to clean up this code
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.
Code could use additional commenting as mentioned in specific places.
Does not work correctly on my machine, but does work on two other machines. Possibly due to using an older version of node on my machine.
Overlapping PNGs is an issue but already being worked on.
@@ -0,0 +1,248 @@ | |||
|
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.
Could use comments indicating this is same as hydrograph code and what differences are.
@@ -0,0 +1,363 @@ | |||
|
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.
Could use similar comment to hydrograph.
@@ -0,0 +1,92 @@ | |||
var fs = require('fs'); |
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.
A comment here would help explain what these variables will be used for.
'./floodviz/posterioir_build/map_thumbnail.js' | ||
], | ||
|
||
function (err, 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.
Function comments would be helpful here
I verified that this does not work with Node version 6.11.0. If we want to use this or a variant of this implementation, we will have to use node >= 7.5. Below is the console error from using v6.11:
EDIT This heap memory error is a known issue in node: EDIT-2 I believe I have isolated the problem to be hydrograph specific. The map png is outputted just fine when using v6.11.0. I believe it has something to do with the data file size when being passed to hydromodule. EDIT-3 using a smaller hydrograph_data.json file lets the process go through. hmmmm |
Was just thinking that adding an optional argument for external css files may be useful. Let me know what you guys think and I can add this if desired. |
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.
Things to do before the code is merged.
The png's should not be committed and the other comments should be addressed. I think we could merge this than and then talk about next steps which might mean new tickets. For instance we need a ticket to address the Heap memory error. We need a ticket to actually code the build process in the Dockerfiles. There may be other things too. We should talk about this at sprint planning.
@@ -0,0 +1,248 @@ | |||
|
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.
How about calling the directory thumbnail
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.
agreed
* interaction functions for other figures should be passed to init in and object. | ||
* | ||
*/ | ||
var hydromodule = function (options) { |
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.
Could we change hydrograph.js not to be wrapped in a function? I'm not sure why we are doing that anyways. Then I think you could use it directly here
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.
Are you saying change the original hydrograph.js to not be wrapped in a function, and then we wont have to replicate this file? I will definitely try this, but I am still thinking we will have to battle the FV.hydromodule issue with the original file.
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.
Maybe. The alternate is to not use global namepsace of FV in the original module. I would rather do that the duplicate code.
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.
Wondering if we could make another ticket for this and attack it once the reference.json changes are merged?
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.
Actually, it looks like they are already merged. But a separate ticket for this would still be helpful IMO. There may be a decent amount of refactoring. Something to talk about at sprint planning I guess.
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 talk about at sprint planning. I'm okay with putting in a separate ticket though.
'width': 560, | ||
'div_id': '#hydrograph', | ||
'data': data_hydro, | ||
"display_ids": ['05471200', '05476750', '05411850', '05454220', |
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.
These will have to be parameterized eventually.
// load local assets into window environment | ||
[ | ||
'./floodviz/static/bower_components/d3/d3.js', | ||
'./floodviz/static/bower_components/jquery/dist/jquery.min.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.
Does any of this use jquery?
floodviz/views.py
Outdated
@@ -34,6 +34,10 @@ def timeseries_data(): | |||
# Hydrodata data clean and write | |||
j = hydrograph_utils.req_hydrodata(sites, hydro_start_date, hydro_end_date, url_nwis_prefix) | |||
timeseries_data = hydrograph_utils.parse_hydrodata(j) | |||
|
|||
# Write data to file for post build thumbnail | |||
with open('floodviz/static/data/hydrograph_data.json', 'w') as f: |
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 should not be written to the static directory because it is not data used by the web site. For now let's write it to the new floodviz/thumbnail directory.
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'd also like this to happen only when we ask it to be generated. maybe through a config.py variable
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.
floodviz/views.py
Outdated
@@ -94,4 +98,8 @@ def _map_helper(): | |||
] | |||
} | |||
}) | |||
|
|||
with open('floodviz/static/data/map_data.json', 'w') as f: |
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.
Same comments as above.
…od-viz into thumbnail_FV_34
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 address comments. In particular, remove code for the map and the css file in the thumbnail directory.
floodviz/thumbnail/hydro_thumb.css
Outdated
@@ -0,0 +1,8 @@ | |||
.hydro-inactive{ |
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.
Is this to prove that a secondary css file can be brought in? If so, it should not be committed.
floodviz/thumbnail/map_thumbnail.js
Outdated
|
||
'use strict'; | ||
/** | ||
* @param {Object} options - holds options for the configuration of the map. |
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'd like to limit the scope to only the hydrograph. This should be removed.
@@ -0,0 +1,90 @@ | |||
// Dependency Import |
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.
Could you start with a brief comment describing what this script does
floodviz/thumbnail/thumbnail.js
Outdated
'./floodviz/static/bower_components/d3/d3.js', | ||
'./floodviz/static/bower_components/proj4/dist/proj4.js', | ||
'./floodviz/thumbnail/hydro_thumbnail.js', | ||
'./floodviz/thumbnail/map_thumbnail.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.
Please remove the map_thumbnail.js
floodviz/thumbnail/thumbnail.js
Outdated
// Refactor Later. I'm assuming this will change with references.json | ||
} | ||
); | ||
convert(hydro_figure,window,'floodviz/static/css/hydrograph.css','floodviz/thumbnail/thumbnail_hydro.png'); |
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 be spaces after ','
floodviz/thumbnail/thumbnail.js
Outdated
|
||
// Wrapper around svg2png that injects custom css to inline svg before conversion | ||
function convert(figure, window, css_path, filename) { | ||
figure.init(undefined); |
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 better style to put this after the variable declarations. You can write this as figure.init().
floodviz/views.py
Outdated
@@ -91,4 +96,9 @@ def _map_helper(): | |||
] | |||
} | |||
}) | |||
|
|||
if thumbnail: |
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 remove. Let's stick to just the hydrograph.
package.json
Outdated
@@ -18,5 +18,9 @@ | |||
"homepage": "https://github.com/USGS-VIZLAB/active-flood-viz#readme", | |||
"devDependencies": { | |||
"bower": "1.8.0" | |||
}, | |||
"dependencies": { | |||
"jsdom": "11.1.0", |
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.
These are actually dev dependencies since they are only used in the build process.
There is still plenty to do with this ticket. Namely, lots of refactoring once we start using reference.json. Right now we are using almost a direct copy of hydromodule, with a few minor differences to make this work post build. Ideally we would like to not have a duplicate file like this.
New dependencies:
Note: the flask freeze or python run command must be executed with THUMBNAIL=True in config.py before running the below command.
Usage: