-
Notifications
You must be signed in to change notification settings - Fork 4
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
successfully inject map d3 into target/index.html (correct branch this time!) #35
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3274405
testing out js
650ed74
merge upstream, resolve conflicts
01de7d4
add js as publisher + move js files
6a81e59
complete move of js file
fb89adc
inject js file into body of index
028755c
add d3 library as resource
5a73080
use built-in d3 lib
29c341a
fixing floating mimetype line
597b287
nevermind - it was accidentally commited
d56e040
floating dash
303f205
add map js + process map data to geojson, not svg
afe5509
remove svg creation code
7f4f7d9
increase chart width
59c4e21
remove commented code + edit comments
dc632c1
change spatial projection
9fbb718
reinstate as_svg.R
6b40412
hack to get geojson in target
cf79e4c
remake won't allow duplication location tags
d41f258
revert attempt to export geojson to target
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Width and height | ||
var chart_width = 1000; | ||
var chart_height = 600; | ||
|
||
// Projection | ||
var projection = d3.geoMercator() //changing to geoAlbers makes the map disappear | ||
.scale(1500) | ||
.center([-91.34397, 32.25196]) | ||
.translate([chart_width / 2, chart_height / 2]); | ||
var path = d3.geoPath() | ||
.projection(projection); | ||
|
||
// Create SVG | ||
var svg = d3.select("body") | ||
.append("svg") | ||
.attr("width", chart_width) | ||
.attr("height", chart_height); | ||
|
||
var map = svg.append( 'g' ) | ||
.attr( 'id', 'map' ); | ||
|
||
// Add map features | ||
d3.json('../cache/state_map.geojson', function(us_data){ | ||
|
||
map.selectAll( 'path' ) | ||
.data(us_data.features) | ||
.enter() | ||
.append('path') | ||
.attr('d', path) | ||
.attr('fill', "cornflowerblue") | ||
.attr('stroke', '#fff') | ||
.attr('stroke-width', 0.5) | ||
.on("mouseover", mouseover) | ||
.on("mouseout", mouseout); | ||
|
||
}); | ||
|
||
function mouseover(d){ | ||
d3.select(this).style('fill', 'orange'); | ||
} | ||
|
||
function mouseout(d){ | ||
d3.select(this).style('fill', "cornflowerblue"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
fetchTimestamp.save_map <- vizlab::alwaysCurrent | ||
|
||
#' Saves sf data as geojson. | ||
#' @description Converts sf data to sp, then saves as geojson for use in d3. | ||
#' | ||
#' @param viz a vizlab object including \code{viewbox_limits} and \code{fetch_args} | ||
#' @details | ||
#' Depends on: \code{map_data}: an sf representation of the x and y | ||
#' (geographic coordinates) values of map_data shapes (counties, states, countries, etc). | ||
#' | ||
process.save_map <- function(viz){ | ||
deps <- readDepends(viz) | ||
checkRequired(deps, "map_data") | ||
map_data <- deps[["map_data"]] | ||
|
||
# spatial data needs to be sp to use writeOGR | ||
# saves empty file if there is not any map features | ||
if(nrow(map_data) > 0){ | ||
map_data_sp <- as(map_data, "Spatial") | ||
rgdal::writeOGR(map_data_sp, viz[['location']], | ||
layer="map_data_sp", driver="GeoJSON") | ||
} else { | ||
write.table(data.frame(), viz[["location"]]) | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
../cache
isn't going to be available on CHSThere 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.
.....WUT 🤦♀️ been operating under that assumption with this code.
Do you think I can push them to a
target/data
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 think data that you want access to in target needs to be
publish
or otherwise exported.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.
see #37