Giter VIP home page Giter VIP logo

d3plus-geomap's Introduction

d3plus-geomap

A reusable geo map built on D3 and Topojson

Installing

If using npm, npm install d3plus-geomap. Otherwise, you can download the latest release from GitHub or load from a CDN.

import modules from "d3plus-geomap";

d3plus-geomap can be loaded as a standalone library or bundled as part of D3plus. ES modules, AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3plus global is exported:

<script src="https://cdn.jsdelivr.net/npm/d3plus-geomap@1"></script>
<script>
  console.log(d3plus);
</script>

Examples

Live examples can be found on d3plus.org, which includes a collection of example visualizations using d3plus-react. These examples are powered by the d3plus-storybook repo, and PRs are always welcome. 🍻

API Reference


Geomap <>

This is a global class, and extends all of the methods and functionality of Viz.

# new Geomap()

Creates a geographical map with zooming, panning, image tiles, and the ability to layer choropleth paths and coordinate points. See this example for help getting started.

# Geomap.fitFilter([value]) <>

Topojson files sometimes include small geographies that negatively impact how the library determines the default zoom level (for example, a small island or territory far off the coast that is barely visible to the eye). The fitFilter method can be used to remove specific geographies from the logic used to determine the zooming.

The value passed can be a single id to remove, an array of ids, or a filter function. Take a look at the Choropleth Example to see it in action.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.fitKey(value) <>

If the topojson being used to determine the zoom fit (either the main topojson object or the fitObject) contains multiple geographical sets (for example, a file containing state and county boundaries), use this method to indentify which set to use for the zoom fit.

If not specified, the first key in the Array returned from using Object.keys on the topojson will be used.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.fitObject(data, [formatter]) <>

The topojson to be used for the initial projection fit extent. The value passed should either be a valid Topojson Object or a String representing a filepath or URL to be loaded.

Additionally, a custom formatting function can be passed as a second argument to this method. This custom function will be passed the data that has been loaded, as long as there are no errors. This function needs to return the final Topojson Object.

This is a static method of Geomap, and is chainable with other methods of this Class.

Param Type Description
data Object | String = undefined
[formatter] function

# Geomap.ocean([value]) <>

The color visible behind any shapes drawn on the map projection. By default, a color value matching the color used in the map tiles is used to help mask the loading time needed to render the tiles. Any value CSS color value may be used, including hexidecimal, rgb, rgba, and color strings like "blue" and "transparent".

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.point([value]) <>

The accessor to be used when detecting coordinate points in the objects passed to the data method. Values are expected to be in the format [longitude, latitude], which is in-line with d3's expected coordinate mapping.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.pointSize([value]) <>

The accessor or static value to be used for sizing coordinate points.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.pointSizeMax([value]) <>

The maximum pixel radius used in the scale for sizing coordinate points.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.pointSizeMin([value]) <>

The minimum pixel radius used in the scale for sizing coordinate points.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.projection(projection) <>

Sets the map projection used when displaying topojson and coordinate points. All of the projections exported from d3-geo, d3-geo-projection, and d3-composite-projections are accepted, whether as the string name (ie. "geoMercator") or the generator function itself. Map tiles are only usable when the projection is set to Mercator (which is also the default value).

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.projectionPadding([value]) <>

The outer padding between the edge of the visualization and the shapes drawn. The value passed can be either a single number to be used on all sides, or a CSS string pattern (ie. "20px 0 10px").

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.projectionRotate([value]) <>

An array that corresponds to the value passed to the projection's rotate function. Use this method to shift the centerpoint of a map.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.tiles([value]) <>

Toggles the visibility of the map tiles.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.tileUrl([url]) <>

By default, d3plus uses the light_all style provided by CARTO for it's map tiles. The tileUrl method changes the base URL used for fetching the tiles, as long as the string passed contains {x}, {y}, and {z} variables enclosed in curly brackets for the zoom logic to load the correct tiles.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.topojson(data, [formatter]) <>

The topojson to be used for drawing geographical paths. The value passed should either be a valid Topojson Object or a String representing a filepath or URL to be loaded.

Additionally, a custom formatting function can be passed as a second argument to this method. This custom function will be passed the data that has been loaded, as long as there are no errors. This function should return the final Topojson Obejct.

This is a static method of Geomap, and is chainable with other methods of this Class.

Param Type Description
data Object | String = []
[formatter] function

# Geomap.topojsonFill(value) <>

The function is used to set default color of the map.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.topojsonFilter([value]) <>

If the topojson being used contains boundaries that should not be shown, this method can be used to filter them out of the final output. The value passed can be a single id to remove, an array of ids, or a filter function.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.topojsonKey(value) <>

If the topojson contains multiple geographical sets (for example, a file containing state and county boundaries), use this method to indentify which set to use.

If not specified, the first key in the Array returned from using Object.keys on the topojson will be used.

This is a static method of Geomap, and is chainable with other methods of this Class.

# Geomap.topojsonId(value) <>

The accessor used to map each topojson geometry to it's corresponding data point.

This is a static method of Geomap, and is chainable with other methods of this Class.


Documentation generated on Wed, 25 Jan 2023 18:32:14 GMT

d3plus-geomap's People

Contributors

cnavarreteliz avatar davelandry avatar greenkeeper[bot] avatar nbond211 avatar rbaheti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

d3plus-geomap's Issues

when a geomap is provided an empty array for data an error occurs

d3plus-legend.js:161 Uncaught TypeError: Cannot read property 'length' of undefined
    at fillMatrices (d3plus-legend.js:161)
    at ckmeans (d3plus-legend.js:237)
    at ColorScale.render (d3plus-legend.js:354)
    at Geomap.drawColorScale (d3plus-viz.js:150)
    at Geomap._draw (d3plus-viz.js:875)
    at Geomap._draw (d3plus-geomap.js:222)
    at Queue.eval [as _call] (d3plus-viz.js:995)
    at maybeNotify (queue.js:115)
    at Queue.awaitAll (queue.js:46)
    at Geomap.render (d3plus-viz.js:994)

hook up brush to zoom

Logic was implemented manually in Data USA, and the code exists in d3plus but is just commented out.

color scale does not work when there is only 1 value

Expected Behavior

When using the colorScale method, and there is only 1 data point available, the scale gets rendered with no values and the topojson is rendered as black.

Current Behavior

The color scale should not appear, and the topojson should be colored the max color in the scale.

Steps to Reproduce (for bugs)

https://jsfiddle.net/2zb6retc/9/

Your Environment

  • Browser Name: Chrome
  • Operating System and Version: macOS Sierra

error in resetting colorScale

Seems to be a bug in resetting the colorScale back to nothing, here's my config:

    shapeConfig: {
      Path: {
        fill: d => colorScale(d[val])
      }
    },
    colorScale: false
  };

And here's the console error:

ckmeans.js:149 Uncaught TypeError: Cannot read property 'length' of undefined
    at fillMatrices (ckmeans.js:149)
    at __webpack_exports__.a (ckmeans.js:225)
    at ColorScale.render (ColorScale.js:118)
    at Geomap.__webpack_exports__.a (_drawColorScale.js:50)
    at Geomap._draw (Viz.js:336)
    at Geomap._draw (Geomap.js:159)
    at Queue.eval [as _call] (Viz.js:486)
    at maybeNotify (queue.js:115)
    at eval (queue.js:86)
    at eval (load.js:50)

Issue with d3plus-geomap.v0.4 and IE 11 (as well as others)

Hi,
I am having issues with Internet Explorer (e.g. IE11) and probably all others post IE 8 with the map not rendering and only "Loading Visualization Powered by D3plus" displaying. The debugged error is " Object doesn't support property or method 'includes' File: d3plus-geomap.v0.4.full.min.js, Line: 7, Column: 105644". Having a quick look through the JS, there are a significant number if includes that are involved rather than the odd one and IE doesn't understand includes

Expected Behavior

The map should display in IE like it does in Chrome, FF or any other real browser

Current Behavior

"Loading Visualization Powered by D3plus" and the map does not load

Steps to Reproduce (for bugs)

  1. Attempt this is Chorme/FF etc https://jsfiddle.net/ozn3s2f6/ and it should work
  2. Attempt the same in IE https://jsfiddle.net/ozn3s2f6/ and it fails to fully load

Your Environment

IE11 in a SOE environment as an example however it appears to affect all IE later environments

changing data and colorScale causes error

Expected Behavior

I should be able to change the data provided to .data( ) and the associated variable passed to .colorScale( ) to update the map.

Current Behavior

Currently, certain combinations will make the map empty.

Steps to Reproduce (for bugs)

http://jsfiddle.net/14L2qn89/17/

Your Environment

  • Browser Name: Chrome
  • Operating System and Version: macOS High Sierra

map that has single place with data doesnt render properly

Expected Behavior

Map renders, but with only 1 place (colored as either the highest or lowest value in the scale)

Current Behavior

Map renders black and gets stuck saying "Loading visualization / powered by d3plus"

screen shot 2018-08-02 at 4 15 29 pm

Geomap.js:76 Uncaught TypeError: this$1._colorScaleClass._colorScale is not a function
    at Geomap.fill (Geomap.js:76)
    at eval (configPrep.js:23)
    at Function.styleLogic (Shape.js:208)
    at SVGPathElement.eval (attr.js:30)
    at Selection.__webpack_exports__.a [as each] (each.js:5)
    at Selection.__webpack_exports__.a [as attr] (attr.js:54)
    at Path._applyStyle (Shape.js:212)
    at Selection.__webpack_exports__.a [as call] (call.js:4)
    at Path.render (Path.js:61)
    at Geomap._draw (Geomap.js:364)

Steps to Reproduce (for bugs)

  1. https://jsfiddle.net/jonathan_dw/cedntuxj/1/
  2. Note error in javascript console

I tried both the uniform and jenks scales.

Your Environment

  • Browser Name: Chrome 67
  • Operating System and Version: OS X 10.13.6

bug with using both topojson and points

I'm using the geomap to display a choropleth, and it's working great. Since the choropleth overlays the geography below, it's difficult to orient where you are on the map. I'd love to be able to put a marker on the map that represents a point of interest, and that marker should overlay the choropleth. I tried doing same w/ points on a map, but it seems that points and choropleth are mutually exclusive -- you can have one or the other.

Bonus: support arbitrary marker images.

attribution for OpenStreetMap

Hi all,

I noticed that in many pages using this library, default CARTO tiles are used, which are based on OpenStreetMap data, without giving proper attribution. Is it possible to have an easy way to add attribution within this library?

Thanks,

labels for jenks breaks overlap with some narrow maps

The legend labels for some maps using jenks breaks overlap with each other which can make the legend hard to read.

Expected Behavior

To have labels avoid overlapping. Either,

  1. increased vertical spacing if insufficient horizontal space available or
  2. perhaps if too narrow, some labels could only appear on hover?

just some ideas

Current Behavior

screen shot 2017-10-10 at 3 56 04 pm

Steps to Reproduce (for bugs)

  1. https://jsfiddle.net/neuyy41a/

Your Environment

OSX / Chrome

add an option to only draw topojson paths for areas with data

Feature request: add an option to only draw boundaries for areas with data. This could be helpful when visualizing a map in conjunction with dynamic API calls for variables that may only cover certain tracts for example, and instead of showing many empty tracts it could be nice to simply hide those without data.

include a shortcut for largestRect label placement

.shapeConfig({
    label: d => d.id,
    labelBounds: (d, i, s) => {

        const poly = d3plus.largestRect(s.points);

        return poly ? {
            x: poly.cx - poly.width / 2,
            y: poly.cy - poly.height / 2,
            width: poly.width,
            height: poly.height
        } : null;

    }
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.