Coder Social home page Coder Social logo

yaph / d3-geomap Goto Github PK

View Code? Open in Web Editor NEW
132.0 8.0 45.0 7.29 MB

A library for creating geographical maps based on D3.js

Home Page: https://d3-geomap.github.io/

License: MIT License

Makefile 6.26% Python 7.65% JavaScript 83.94% Sass 2.15%
javascript map mapping d3 d3js choropleth choropleth-map geography geo svg

d3-geomap's Introduction

d3-geomap

npm package version npm package license

d3-geomap is designed to be a reusable geographic map for D3. In its current stage it consists of a class to create plain maps d3.geomap() and one for choropleth maps d3.choropleth().

Refer to the documentation on how to use d3-geomap and to download a bundle that contains minified versions of d3-geomap and its dependencies as well as TopoJSON files for creating world and individual country maps.

Install

$ npm install d3-geomap

Usage

ES6:

import { select } from 'd3-selection';
import { geomap } from 'd3-geomap';

const worldMap = geomap();
worldMap.geofile('./node_modules/d3-geomap/src/world/countries.json');

worldMap.draw(select('#map'));

Otherwise, see examples in the /examples directory.

Develop

Clone the repo & install dependencies:

$ git clone https://github.com/yaph/d3-geomap.git
$ cd d3-geomap
$ npm install

Start the development server:

$ npm run serve

A browser should open pointed to http://localhost:8000/examples/. Choose to view one of the example maps.

Map Showcase

World Cup 2014 Players' Birth Countries

The map above, showing birth countries of Football World Cup 2014 players, was created with d3-geomap. You can find more example maps here.

d3-geomap's People

Contributors

dpraul avatar geraldo avatar oskario avatar yaph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

d3-geomap's Issues

RTL support for d3 geomap - choropleth

When i try to add dir="rtl" in HTML tag, As per observation d3 geomap does not have RTL processing, Is there any RTL related config or how to add RTL support in D3 geomap library?

d3.geomap.dependencies.min.js Error

I get this error in the console (chrome) when using the d3.geomap libraries. I've tried both with the 0.1 release and master, same deal.

d3.geomap.dependencies.min.js:1 Error: Invalid value for attribute transform="translate(0, 0"

any ideas?

Deprecate columnVal function

  • Replace code with: self.extent = d3Array.extent(self.data, d => d[self.column()]);
  • Mark as deprecated and to be removed in the next major release
  • Update docs

Add support for US counties map

Current USA.json file only supports states map. For counties I need a different data source. Also a new directory structure for topojson files would make sense, examples

US specific

  • /topojson/counties/USA/states.json
  • /topojson/counties/USA/counties.json

vs.

More generic

  • /topojson/counties/USA.json
  • /topojson/counties/USA/counties.json

onClick event in d3-geomap

0
down vote
favorite
I'm trying to change onclick event in d3-geomap from zoom to another function. How can I do this ?

Thanks

my code is here :

var map = d3.geomap.choropleth()
            .geofile('json/IRN2.json')
            .unitId('fips')
            .projection(function(){return d3.geo.albers().center([51,35]);})
            .column('point')
            .scale(2000)
            .rotate([-40, 0])
            .translate([1.25*width ,-200 ])
            .colors(['green','yellow' , 'pink' ,'red'])
            .domain([0, 20 , 50,100])
            //.clicked(function(){console.log("hiiiiiiiiiiiiiiii");})
            .legend(true);


          d3.select('#map')
            .datum(mydata)
            .call(map.draw, map);

Missing lakes make some maps look awkward

Especially the US map without the great lakes. So find a way to incorporate lakes at least in country level maps, even better in all maps, i. e. the topojson sources.

Getting Error when trying to draw map: geomap.properties.projection is not a function

I am trying to draw the map (with no data) and I am receiving two errors.

  1. Unexpected token ILLEGAL (in D3 dependencies โ€” not too worried about this)
  2. geomap.properties.projection is not a function.
    When I click on error in Chrome dev tools):
    Geomap.draw @ d3.geomap.js:444
    _a.call @ d3.v3.min.js:3
    (anonymous function) @ app.js:5

I am using the code from: http://d3-geomap.github.io/ just trying to get the basics.

Here is the repository: https://github.com/zreitano/h_campaign

This is my app.js file

var map = d3.geomap()
    .geofile('d3-geomap/topojson/countries/USA.json');

d3.select('#map')
    .call(map.draw, map);

This is my index.html file

<!DOCTYPE html>

<html >

    <head>
        <title>H Campaign</title>

        <link rel="stylesheet" type="text/css" href="style.css">
      <link rel="stylesheet" type="text/css" href="styles/usa.css">

      <!-- Latest compiled and minified CSS -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

      <!-- Optional theme -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
      <!-- D3 Styling -->
      <link rel="stylesheet" href="d3-geomap/css/d3.geomap.css">
    </head>

    <body>

      <div class="container">
        <h1>Header</h1>
      </div>


      <div id="map">
      </div>

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
      <!-- Latest compiled and minified JavaScript -->
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
      <!-- D3 with geomap -->
      <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
      <script type="text/javascript" src="d3-geomap/vendor/d3.geomap.dependencies.min.js"></script>
      <script type="text/javascript" src="d3-geomap/js/d3.geomap.js"></script>
      <!-- My JS -->
      <script type="text/javascript" src="js/app.js"></script>

    </body>
</html>

Please let me know if I can help with any more information.

Legend is affected by values that don't map to a country

Example: the population data from the World Bank includes a row for the world (id: WLD) that causes the legend to go up to the total world population thus rendering the map useless.

How to handle such data in d3.geomap? Leave it to the user or remove values that don't map to countries?

Rename geo files and map units

Create directory structure for geo files and rename them accordingly, e. g.

geo/
    world/
        countries.topojson
        continents.topojson
    countries/
        usa/
            states.topojson

Give map units a generic term, e. g. units or subunits instead of countries.

Better default legend

  • Set fixed height to 250.
  • Set fixed width to 120.
  • Add rectangle around legend with medium opacity white background.

Documentation

Add documentation so that d3.geomap can be used by others.

No distributable provided for import/require

Usually, a library delivered over npm provides a built version that another module can directly consume with import or require. This is usually done by pointing main in package.json to a file within the source bundle. If I'm understanding #44, this is the same problem they are facing - although jsDelivr is not a standard key in package.json so is not the proper solution.

To fix this, either (a) the distributable needs to be included in the source bundle uploaded to npm, (b) the package needs to be built by import/require instead of concatenation, or - ideally - (c) both!

(a) is the easiest and requires the least restructuring, and the simplicity of this library means (b) probably isn't too far off as well. If you're looking for assistance, happy to make a PR (although it may seem drastic)

Make map responsive

Set width, height, scale and translate to null as defaults and calculate in draw function if not given. Check each accessor individually, to not overrider user settings.

map callback

Currently callback is only called in draw, rather move to map initialization and call automatically at the end of update.

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.