Skip to content
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

Merged
merged 26 commits into from
Jul 31, 2017
Merged

Conversation

ede0m
Copy link

@ede0m ede0m commented Jul 25, 2017

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:

npm install jsdom --save
npm install svg2png --save

Note: the flask freeze or python run command must be executed with THUMBNAIL=True in config.py before running the below command.

Usage:

node floodviz/thumbnail/thumbnail.js 

Copy link
Contributor

@skaymen skaymen left a 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 @@

Copy link
Contributor

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

Copy link
Contributor

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');
Copy link
Contributor

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) {
Copy link
Contributor

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

@ede0m
Copy link
Author

ede0m commented Jul 26, 2017

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:

<--- Last few GCs --->

   31767 ms: Mark-sweep 1394.2 (1439.2) -> 1394.1 (1439.2) MB, 1274.7 / 0.0 ms (+ 0.9 ms in 6 steps since start of marking, biggest step 0.6 ms) [allocation failure] [scavenge might not succeed].
   33054 ms: Mark-sweep 1394.2 (1439.2) -> 1394.2 (1439.2) MB, 1285.4 / 0.0 ms (+ 0.6 ms in 1 steps since start of marking, biggest step 0.6 ms) [allocation failure] [scavenge might not succeed].


<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory

EDIT

This heap memory error is a known issue in node:
see here
and here

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

@ede0m
Copy link
Author

ede0m commented Jul 27, 2017

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.

Copy link
Collaborator

@mbucknell mbucknell left a 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 @@

Copy link
Collaborator

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

Copy link
Author

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) {
Copy link
Collaborator

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

Copy link
Author

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.

Copy link
Collaborator

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.

Copy link
Author

@ede0m ede0m Jul 28, 2017

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?

Copy link
Author

@ede0m ede0m Jul 28, 2017

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.

Copy link
Collaborator

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',
Copy link
Collaborator

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',
Copy link
Collaborator

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?

@@ -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:
Copy link
Collaborator

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.

Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

@@ -94,4 +98,8 @@ def _map_helper():
]
}
})

with open('floodviz/static/data/map_data.json', 'w') as f:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as above.

Copy link
Collaborator

@mbucknell mbucknell left a 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.

@@ -0,0 +1,8 @@
.hydro-inactive{
Copy link
Collaborator

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.


'use strict';
/**
* @param {Object} options - holds options for the configuration of the map.
Copy link
Collaborator

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
Copy link
Collaborator

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/static/bower_components/d3/d3.js',
'./floodviz/static/bower_components/proj4/dist/proj4.js',
'./floodviz/thumbnail/hydro_thumbnail.js',
'./floodviz/thumbnail/map_thumbnail.js'
Copy link
Collaborator

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

// 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');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be spaces after ','


// Wrapper around svg2png that injects custom css to inline svg before conversion
function convert(figure, window, css_path, filename) {
figure.init(undefined);
Copy link
Collaborator

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().

@@ -91,4 +96,9 @@ def _map_helper():
]
}
})

if thumbnail:
Copy link
Collaborator

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",
Copy link
Collaborator

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.

@mbucknell mbucknell merged commit eed3755 into USGS-VIZLAB:master Jul 31, 2017
@ede0m ede0m mentioned this pull request Jul 31, 2017
@ede0m ede0m deleted the thumbnail_FV_34 branch August 1, 2017 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants