Skip to content

Correct idiom to inject static JSON Data #71

Closed
@schnee

Description

@schnee

I'm attempting to "simply" draw a map using D3 and D3 Projections via htmlwidgets. My question is how to "inject" the shapes data, in the "htmlwidgets" way.

Currently, my renderValue looks like:

  renderValue: function(el, x, instance) {

    var path = d3.geo.path()
    .projection(instance.projection);

    // select the svg element and remove existing childern
    var svg = d3.select(el).select("svg");
    svg.selectAll("*").remove();

    d3.json("htmlwidgets/lib/shapes/world-110m.json", function(error, world) {
      svg.insert("path", ".trip")
          .datum(topojson.feature(world, world.objects.land))
          .attr("class", "land")
          .attr("d", path);

      svg.insert("path", ".trip")
          .datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
          .attr("class", "boundary")
          .attr("d", path);
  });
},

My question centers on this line:

d3.json("htmlwidgets/lib/shapes/world-110m.json", function(error, world) {

What is the idiomatic way to, in general, provide static data like this?

My yaml looks like:

dependencies:
- name: d3-geo-projection
  version: 0.2.12
  src: htmlwidgets/lib/d3-geo-projection
  script: d3-geo-projection.js
- name: d3
  version: 3.5.3
  src: htmlwidgets/lib/d3
  script: d3.min.js
- name: topojson
  version: 1.6.18
  src: htmlwidgets/lib/topojson
  script: topojson.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions