diff --git a/docs/container_create.js.html b/docs/container_create.js.html index 66d9b30..4a6d7b7 100644 --- a/docs/container_create.js.html +++ b/docs/container_create.js.html @@ -1,6 +1,6 @@ Source: container/create.js
On this page

container_create.js

import { extent } from "../helpers/extent";
+    
On this page

container_create.js

import { extent } from "../helpers/extent";
 import { unique } from "../helpers/utils";
 import { create as create2 } from "d3-selection";
 import {
@@ -34,6 +34,8 @@
 import { shadow as addshadow } from "../effect/shadow.js";
 import { radialGradient as addradialGradient } from "../effect/radialgradient.js";
 
+import { make as addgrid } from "../grid/make.js";
+
 import { circles_nested as addcircles_nested } from "../legend/circles-nested";
 import { circles as addcircles } from "../legend/circles";
 import { squares as addsquares } from "../legend/squares";
@@ -58,6 +60,7 @@
  * @see {@link https://observablehq.com/@neocartocnrs/geoviz}
  *
  * @property {number} [width = 1000] - width of the container.
+ * @property {number} [id = "map"] - id of the svg container.
  * @property {number} [height] - height of the container. This value is automatically calculated according to `domain`. But it can be forced by entering a value.
  * @property {object|object[]} [domain] - the domain corresponds to the geographical area to be displayed. It is defined by a geoJSON or an array containing geoJSONs.
  * @property {function|string} [projection] - d3 function of projection. See [d3-geo](https://github.com/d3/d3-geo) & [d3-geo-projection](https://github.com/d3/d3-geo-projection). You can aslo write "mercator" to use tiles. (default: "none")
@@ -76,6 +79,7 @@
 
 export function create({
   height = null,
+  id = "map",
   //projection = d3.geoEquirectangular(),
   projection = "none",
   domain,
@@ -142,6 +146,13 @@
       zoomablelayers: [],
       zoom: { k: 1, x: 0, y: 0 },
       bbox: d3.geoBounds(ref),
+      // bbox:
+      //   domain == undefined
+      //     ? [
+      //         [-180, 90],
+      //         [180, -90],
+      //       ]
+      //     : d3.geoBounds(ref),
       inset: parent ? true : false,
       warning,
       warning_message,
@@ -154,6 +165,7 @@
       .create2("svg")
       .attr("width", width)
       .attr("height", height)
+      .attr("id", id)
       .attr("viewBox", [0, 0, width, height])
       .style("background-color", background);
     svg.append("defs").attr("id", "defs");
@@ -203,6 +215,14 @@
       })
   );
 
+  let grid = {};
+  [{ id: "make", func: addgrid }].forEach(
+    (d) =>
+      (grid[d.id] = function () {
+        return d.func(output, arguments[0]);
+      })
+  );
+
   let legend = {};
   [
     { id: "circles_nested", func: addcircles_nested },
@@ -245,10 +265,11 @@
   return Object.assign(output, {
     ...mark,
     legend,
+    grid,
     effect,
     render: function () {
       return addrender(output, arguments[0]);
     },
   });
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/container_draw.js.html b/docs/container_draw.js.html index 431e094..276aa92 100644 --- a/docs/container_draw.js.html +++ b/docs/container_draw.js.html @@ -1,6 +1,6 @@ Source: container/draw.js
On this page

container_draw.js

import { create } from "./create";
+    
On this page

container_draw.js

import { create } from "./create";
 import { geoEquirectangular } from "d3-geo";
 const d3 = Object.assign({}, { geoEquirectangular });
 
@@ -69,4 +69,4 @@
   });
   return svg.render();
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/container_render.js.html b/docs/container_render.js.html index 45d2c95..6991a62 100644 --- a/docs/container_render.js.html +++ b/docs/container_render.js.html @@ -1,6 +1,6 @@ Source: container/render.js
On this page

container_render.js

import { getDOMids } from "../helpers/getDOMids";
+    
On this page

container_render.js

import { getDOMids } from "../helpers/getDOMids";
 import { zoomandpan } from "../helpers/zoomandpan";
 import { zoomversor } from "../helpers/zoomversor";
 import { select, pointers } from "d3-selection";
@@ -131,4 +131,4 @@
   // render
   return svg.node();
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/data/search.json b/docs/data/search.json index 4afc1cc..c2a47f3 100644 --- a/docs/data/search.json +++ b/docs/data/search.json @@ -1 +1 @@ -{"list":[{"title":"circle","link":"circle","description":"

The circle function allows to add circles on a map. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"create","link":"create","description":"

The create function is the first step in map construction. It creates an svg container + some information about this container:projection, margin, width, height and bbox.

"},{"title":"draw","link":"draw","description":"

The draw() function is inspired by the bertin library. It allows you to draw the entire map using a single function. All the necessary information is stored in a single JSON, containing general parameters and an array of objects describing the layers to be displayed and overlaid. Under the wood, the function draw() use the viz.plot() function. The types available are the same.

"},{"title":"effect/blur","link":"effect/blur","description":"

The blur function allows to create a svg blur filter. It adds a filter to the defs and returns the id like "url(#id)".

"},{"title":"effect/clipPath","link":"effect/clipPath","description":"

The clipPath function allows to create a clip layer. The function adds a clip layer to the SVG container and returns the id like "url(#id)". WARNING - the clip is valid for the entireweb page, not just the map

"},{"title":"effect/radialGradient","link":"effect/radialGradient","description":"

The radialGradient function allows to create a radialGradient. The function adds a filter to the defs and returns the id like "url(#id)".

"},{"title":"effect/shadow","link":"effect/shadow","description":"

The shadow function allows to create a svg filter. It can be use ta add a shadow effect. The function adds a filter to the defs and returns the id like "url(#id)".

"},{"title":"footer","link":"footer","description":"

The footer function allows add a source below the map. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"graticule","link":"graticule","description":"

The graticule function allows to create a layer with lat/long lines. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"halfcircle","link":"halfcircle","description":"

The halfcircle function allows to create a layer with rotable half-circles from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"header","link":"header","description":"

The header function allows add a title above the map. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/box","link":"legend/box","description":"

The legend.box function allows to add a box legend on a map. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/choro_horizontal","link":"legend/choro_horizontal","description":"

The legend.choro_horizontal function allows to add an horizontal legend on a map for choropleth layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/choro_vertical","link":"legend/choro_vertical","description":"

The legend.choro_vertical function allows to add a vertical legend on a map for choropleth layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/circles","link":"legend/circles","description":"

The legend.circles function allows to add an legend for proportional circles. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/circles_half","link":"legend/circles_half","description":"

The legend.circles_half function allows to add an legend for mushroom maps. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/circles_nested","link":"legend/circles_nested","description":"

The legend.circles_nested function allows to add an legend for proportional circles. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/mushrooms","link":"legend/mushrooms","description":"

The legend.mushrooms function allows to add an legend for proportional half-circles. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/spikes","link":"legend/spikes","description":"

The legend.spikes function allows to add an legend for spike marks. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/squares","link":"legend/squares","description":"

The legend.squares function allows to add an legend for proportional squares. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/squares_nested","link":"legend/squares_nested","description":"

The legend.squares_nested function allows to add an legend for proportional squares. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/symbol_horizontal","link":"legend/symbol_horizontal","description":"

The legend.symbol_horizontal function allows to add an vertical legend on a map for symbol layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/symbol_vertical","link":"legend/symbol_vertical","description":"

The legend.symbol_vertical function allows to add an vertical legend on a map for symbol layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/typo_horizontal","link":"legend/typo_horizontal","description":"

The legend.typo_horizontal function allows to add an horizontal legend on a map for typo layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/typo_vertical","link":"legend/typo_vertical","description":"

The legend.typo_vertical function allows to add an vertical legend on a map for typo layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"north","link":"north","description":"

The north function allows add a North arrow. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"outline","link":"outline","description":"

The outline function allows to create a layer with Earth outline in the projection. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"path","link":"path","description":"

The path function generates SVG paths from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"plot","link":"plot","description":"

The plot() function in geoviz allows you to call up all the layer types available in the library via a single function. To do this, you need to define the type in the parameter.\n

For example: geoviz.plot({type: "graticule", step: 30})

"},{"title":"plot/choro","link":"plot/choro","description":"

With the plot({type = "choro"}) function, you can quickly draw a choropleth map.

\n\"choro\"

"},{"title":"plot/prop","link":"plot/prop","description":"

With the plot({type = "prop"}) function, you can quickly draw a choropleth map.

"},{"title":"plot/propchoro","link":"plot/propchoro","description":"

With the plot({type = "propchoro"}) function, you can quickly draw a proportional symbols with a color gradation/

"},{"title":"plot/proptypo","link":"plot/proptypo","description":"

With the plot({type = "proptypo"}) function, you can quickly draw a proportional symbols with qualitative colors (hues)

"},{"title":"plot/symbol","link":"plot/symbol","description":"

With the plot({type = "symbol"}) function, you can quickly draw a layer with symbols.

\n\"choro\"

"},{"title":"plot/typo","link":"plot/typo","description":"

With the plot({type = "typo"}) function, you can quickly draw a typlogy from qualitative data.

\n\"choro\"

"},{"title":"render","link":"render","description":"

The render function returns the svg document. It returns a pretty map in SVG format :-)

"},{"title":"scalebar","link":"scalebar","description":"

The scalebar function allows add a scalebar. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"spike","link":"spike","description":"

The spike function allows to create a layer with spikes from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"square","link":"square","description":"

The square function allows to create a layer with rotable squares from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"symbol","link":"symbol","description":"

The symbol function allows to create a layer with symbols from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"text","link":"text","description":"

The text function allows to add a text on the map. It allow also to create a layer with labels from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"tile","link":"tile","description":"

The tile function allows to display raster tiles. To use this mark, you must use the projection d3.geoMercator() (or directly "mercator"). The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"tip","link":"tip","description":"

The tip parameter allows to add tooltips on map layers

"},{"title":"tool/addonts","link":"tool/addonts","description":"

The tool.addonts function allows add font to the document from an url.

"},{"title":"tool/centroid","link":"tool/centroid","description":"

The tool.centroid function calculate the centroid of all the geometries given in a GeoJSON FeatureCollection. It returns a GeoJSON FeatureCollection (points)

"},{"title":"tool/choro","link":"tool/choro","description":"

The tool.choro function discretizes an array of numbers. It returns an object containing breaks, colors, the color of the missing value and a function.

"},{"title":"tool/dissolve","link":"tool/dissolve","description":"

The tool.dissolve function aims to transform multi part features into single parts feature. It a GeoJSON FeatureCollection (without multi part features)

"},{"title":"tool/dodge","link":"tool/dodge","description":"

The tool.dodge function use d3.forceSimulation to spread dots or circles of given in a GeoJSON FeatureCollection (points). It returns the coordinates in the page map. It can be used to create a dorling cartogram. The function returns a GeoJSON FeatureCollection (points) with coordinates in the page map.

"},{"title":"tool/dotstogrid","link":"tool/dotstogrid","description":"

dotstogrid is a function to create a regular grid in the SVG plan count the number of dots inside

"},{"title":"tool/featurecollection","link":"tool/featurecollection","description":"

tool.featurecollection is a function to create a valid GeoJSON FeatureCollection, from geometries, features or coordinates. It returns a GeoJSON FeatureCollection.

"},{"title":"tool/geotable","link":"tool/geotable","description":"

geotable is a function to create an array on objects containing properties and geomeytries, froam a GeoJSON FeatureCollection. This makes it easy to sort, extract data, etc. tool.featurecollection(geotable, { geometry: "geometry" }) can be used to rebuild a valid geoJSON. The function returns an array of an array of FeatureCollections.

"},{"title":"tool/height","link":"tool/height","description":"

This function return a function to calculate radius of circles from data. It returns an object containing a radius function.

"},{"title":"tool/merge","link":"tool/merge","description":"

tool.merge is a function to join a geoJSON and a data file. It returns a GeoJSON FeatureCollection.

"},{"title":"tool/proj4d3","link":"tool/proj4d3","description":"

proj4d3 is a function developped by Philippe Rivière to allow tu use proj4js projections with d3. It returns a d3js projection function. See https://observablehq.com/@fil/proj4js-d3

"},{"title":"tool/project","link":"tool/project","description":"

The function tool.project use geoproject from d3-geo-projection to project a geoJSON. It returns a GeoJSON FeatureCollection with coordinates in the page map.

"},{"title":"tool/radius","link":"tool/radius","description":"

The tool.radius function return a function to calculate radius of circles from data

"},{"title":"tool/random","link":"tool/random","description":"

The tool.random function returns a random color among 20 predefined colors.

"},{"title":"tool/replicate","link":"tool/replicate","description":"

Data-driven features replication. This function can be used to create "dots cartograms". The function returns a GeoJSON FeatureCollection with overlapping features

"},{"title":"tool/rewind","link":"tool/rewind","description":"

The tool.rewind function allows to generate compliant Polygon and MultiPolygon geometries. Adapted from MapBox geojson-rewind code (https://github.com/mapbox/grojson-rewind) under ISC license

"},{"title":"tool/ridge","link":"tool/ridge","description":"

The tool.ridge function convert a regular grid (x,y,z) to a GeoJSON FeatureCollection (LineString). The aim is to draw a rideline map.

"},{"title":"tool/symbols","link":"tool/symbols","description":"

Display symbols available in geoviz

"},{"title":"tool/typo","link":"tool/typo","description":"

The tool.typo function allows you to assign colors to qualitative data. It can be used to create typology maps. It returs an object containing types, colors, the color of the missing value and a function.

"},{"title":"tool/unproject","link":"tool/unproject","description":"

The tool.unproject function allow to unproject geometries. It returns a GeoJSON FeatureCollection with wgs84 coordinates

"}]} \ No newline at end of file +{"list":[{"title":"circle","link":"circle","description":"

The circle function allows to add circles on a map. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"create","link":"create","description":"

The create function is the first step in map construction. It creates an svg container + some information about this container:projection, margin, width, height and bbox.

"},{"title":"draw","link":"draw","description":"

The draw() function is inspired by the bertin library. It allows you to draw the entire map using a single function. All the necessary information is stored in a single JSON, containing general parameters and an array of objects describing the layers to be displayed and overlaid. Under the wood, the function draw() use the viz.plot() function. The types available are the same.

"},{"title":"effect/blur","link":"effect/blur","description":"

The blur function allows to create a svg blur filter. It adds a filter to the defs and returns the id like "url(#id)".

"},{"title":"effect/clipPath","link":"effect/clipPath","description":"

The clipPath function allows to create a clip layer. The function adds a clip layer to the SVG container and returns the id like "url(#id)". WARNING - the clip is valid for the entireweb page, not just the map

"},{"title":"effect/radialGradient","link":"effect/radialGradient","description":"

The radialGradient function allows to create a radialGradient. The function adds a filter to the defs and returns the id like "url(#id)".

"},{"title":"effect/shadow","link":"effect/shadow","description":"

The shadow function allows to create a svg filter. It can be use ta add a shadow effect. The function adds a filter to the defs and returns the id like "url(#id)".

"},{"title":"footer","link":"footer","description":"

The footer function allows add a source below the map. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"graticule","link":"graticule","description":"

The graticule function allows to create a layer with lat/long lines. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"grid/arbitrary","link":"grid/arbitrary","description":"

The grid.arbitrary function allows to create an arbitrary geoJSON grid in SVG coordinates.

"},{"title":"grid/diamond","link":"grid/diamond","description":"

The grid.diamond function allows to create a diamond geoJSON grid in SVG coordinates.

"},{"title":"grid/dot","link":"grid/dot","description":"

The grid.dot function allows to create a geoJSON vith regular dots in SVG coordinates.

"},{"title":"grid/h3","link":"grid/h3","description":"

The grid.h3 function allows to create a hexbin geoJSON grid in geographical coordinates.

"},{"title":"grid/hexbin","link":"grid/hexbin","description":"

The grid.hexbin function allows to create a hexbin geoJSON grid in SVG coordinates.

"},{"title":"grid/make","link":"grid/make","description":"

The grid.make function allows to create a regular grid geoJSON. For all types, For all grid types (except "h3"), the function returns a geojson with svg coordinates in the layout of the page. For type "h3", the function returns geographic coordinates in latitude and longitude.

"},{"title":"grid/square","link":"grid/square","description":"

The grid.square function allows to create a square geoJSON grid in SVG coordinates.

"},{"title":"grid/triangle","link":"grid/triangle","description":"

The grid.triangle function allows to create a triangle geoJSON grid in SVG coordinates.

"},{"title":"halfcircle","link":"halfcircle","description":"

The halfcircle function allows to create a layer with rotable half-circles from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"header","link":"header","description":"

The header function allows add a title above the map. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/box","link":"legend/box","description":"

The legend.box function allows to add a box legend on a map. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/choro_horizontal","link":"legend/choro_horizontal","description":"

The legend.choro_horizontal function allows to add an horizontal legend on a map for choropleth layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/choro_vertical","link":"legend/choro_vertical","description":"

The legend.choro_vertical function allows to add a vertical legend on a map for choropleth layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/circles","link":"legend/circles","description":"

The legend.circles function allows to add an legend for proportional circles. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/circles_half","link":"legend/circles_half","description":"

The legend.circles_half function allows to add an legend for mushroom maps. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/circles_nested","link":"legend/circles_nested","description":"

The legend.circles_nested function allows to add an legend for proportional circles. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/mushrooms","link":"legend/mushrooms","description":"

The legend.mushrooms function allows to add an legend for proportional half-circles. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/spikes","link":"legend/spikes","description":"

The legend.spikes function allows to add an legend for spike marks. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/squares","link":"legend/squares","description":"

The legend.squares function allows to add an legend for proportional squares. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/squares_nested","link":"legend/squares_nested","description":"

The legend.squares_nested function allows to add an legend for proportional squares. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/symbol_horizontal","link":"legend/symbol_horizontal","description":"

The legend.symbol_horizontal function allows to add an vertical legend on a map for symbol layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/symbol_vertical","link":"legend/symbol_vertical","description":"

The legend.symbol_vertical function allows to add an vertical legend on a map for symbol layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/typo_horizontal","link":"legend/typo_horizontal","description":"

The legend.typo_horizontal function allows to add an horizontal legend on a map for typo layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"legend/typo_vertical","link":"legend/typo_vertical","description":"

The legend.typo_vertical function allows to add an vertical legend on a map for typo layers. The function adds a legend layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"north","link":"north","description":"

The north function allows add a North arrow. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"outline","link":"outline","description":"

The outline function allows to create a layer with Earth outline in the projection. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"path","link":"path","description":"

The path function generates SVG paths from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"plot","link":"plot","description":"

The plot() function in geoviz allows you to call up all the layer types available in the library via a single function. To do this, you need to define the type in the parameter.\n

For example: geoviz.plot({type: "graticule", step: 30})

"},{"title":"plot/choro","link":"plot/choro","description":"

With the plot({type = "choro"}) function, you can quickly draw a choropleth map.

\n\"choro\"

"},{"title":"plot/prop","link":"plot/prop","description":"

With the plot({type = "prop"}) function, you can quickly draw a choropleth map.

"},{"title":"plot/propchoro","link":"plot/propchoro","description":"

With the plot({type = "propchoro"}) function, you can quickly draw a proportional symbols with a color gradation/

"},{"title":"plot/proptypo","link":"plot/proptypo","description":"

With the plot({type = "proptypo"}) function, you can quickly draw a proportional symbols with qualitative colors (hues)

"},{"title":"plot/symbol","link":"plot/symbol","description":"

With the plot({type = "symbol"}) function, you can quickly draw a layer with symbols.

\n\"choro\"

"},{"title":"plot/typo","link":"plot/typo","description":"

With the plot({type = "typo"}) function, you can quickly draw a typlogy from qualitative data.

\n\"choro\"

"},{"title":"render","link":"render","description":"

The render function returns the svg document. It returns a pretty map in SVG format :-)

"},{"title":"scalebar","link":"scalebar","description":"

The scalebar function allows add a scalebar. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"spike","link":"spike","description":"

The spike function allows to create a layer with spikes from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"square","link":"square","description":"

The square function allows to create a layer with rotable squares from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"symbol","link":"symbol","description":"

The symbol function allows to create a layer with symbols from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"text","link":"text","description":"

The text function allows to add a text on the map. It allow also to create a layer with labels from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"tile","link":"tile","description":"

The tile function allows to display raster tiles. To use this mark, you must use the projection d3.geoMercator() (or directly "mercator"). The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

"},{"title":"tip","link":"tip","description":"

The tip parameter allows to add tooltips on map layers

"},{"title":"tool/addonts","link":"tool/addonts","description":"

The tool.addonts function allows add font to the document from an url.

"},{"title":"tool/centroid","link":"tool/centroid","description":"

The tool.centroid function calculate the centroid of all the geometries given in a GeoJSON FeatureCollection. It returns a GeoJSON FeatureCollection (points)

"},{"title":"tool/choro","link":"tool/choro","description":"

The tool.choro function discretizes an array of numbers. It returns an object containing breaks, colors, the color of the missing value and a function.

"},{"title":"tool/dissolve","link":"tool/dissolve","description":"

The tool.dissolve function aims to transform multi part features into single parts feature. It a GeoJSON FeatureCollection (without multi part features)

"},{"title":"tool/dodge","link":"tool/dodge","description":"

The tool.dodge function use d3.forceSimulation to spread dots or circles of given in a GeoJSON FeatureCollection (points). It returns the coordinates in the page map. It can be used to create a dorling cartogram. The function returns a GeoJSON FeatureCollection (points) with coordinates in the page map.

"},{"title":"tool/dotstogrid","link":"tool/dotstogrid","description":"

dotstogrid is a function to create a regular grid in the SVG plan count the number of dots inside

"},{"title":"tool/featurecollection","link":"tool/featurecollection","description":"

tool.featurecollection is a function to create a valid GeoJSON FeatureCollection, from geometries, features or coordinates. It returns a GeoJSON FeatureCollection.

"},{"title":"tool/geotable","link":"tool/geotable","description":"

geotable is a function to create an array on objects containing properties and geomeytries, froam a GeoJSON FeatureCollection. This makes it easy to sort, extract data, etc. tool.featurecollection(geotable, { geometry: "geometry" }) can be used to rebuild a valid geoJSON. The function returns an array of an array of FeatureCollections.

"},{"title":"tool/height","link":"tool/height","description":"

This function return a function to calculate radius of circles from data. It returns an object containing a radius function.

"},{"title":"tool/merge","link":"tool/merge","description":"

tool.merge is a function to join a geoJSON and a data file. It returns a GeoJSON FeatureCollection.

"},{"title":"tool/proj4d3","link":"tool/proj4d3","description":"

proj4d3 is a function developped by Philippe Rivière to allow tu use proj4js projections with d3. It returns a d3js projection function. See https://observablehq.com/@fil/proj4js-d3

"},{"title":"tool/project","link":"tool/project","description":"

The function tool.project use geoproject from d3-geo-projection to project a geoJSON. It returns a GeoJSON FeatureCollection with coordinates in the page map.

"},{"title":"tool/radius","link":"tool/radius","description":"

The tool.radius function return a function to calculate radius of circles from data

"},{"title":"tool/random","link":"tool/random","description":"

The tool.random function returns a random color among 20 predefined colors.

"},{"title":"tool/replicate","link":"tool/replicate","description":"

Data-driven features replication. This function can be used to create "dots cartograms". The function returns a GeoJSON FeatureCollection with overlapping features

"},{"title":"tool/rewind","link":"tool/rewind","description":"

The tool.rewind function allows to generate compliant Polygon and MultiPolygon geometries. Adapted from MapBox geojson-rewind code (https://github.com/mapbox/grojson-rewind) under ISC license

"},{"title":"tool/ridge","link":"tool/ridge","description":"

The tool.ridge function convert a regular grid (x,y,z) to a GeoJSON FeatureCollection (LineString). The aim is to draw a rideline map.

"},{"title":"tool/symbols","link":"tool/symbols","description":"

Display symbols available in geoviz

"},{"title":"tool/typo","link":"tool/typo","description":"

The tool.typo function allows you to assign colors to qualitative data. It can be used to create typology maps. It returs an object containing types, colors, the color of the missing value and a function.

"},{"title":"tool/unproject","link":"tool/unproject","description":"

The tool.unproject function allow to unproject geometries. It returns a GeoJSON FeatureCollection with wgs84 coordinates

"}]} \ No newline at end of file diff --git a/docs/effect_blur.js.html b/docs/effect_blur.js.html index cc55eab..490e355 100644 --- a/docs/effect_blur.js.html +++ b/docs/effect_blur.js.html @@ -1,6 +1,6 @@ Source: effect/blur.js
On this page

effect_blur.js

import { unique } from "../helpers/utils";
+    
On this page

effect_blur.js

import { unique } from "../helpers/utils";
 
 /**
  * @function effect/blur
@@ -29,4 +29,4 @@
 
   return `url(#${id})`;
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/effect_clippath.js.html b/docs/effect_clippath.js.html index 04927e0..41f17ac 100644 --- a/docs/effect_clippath.js.html +++ b/docs/effect_clippath.js.html @@ -1,6 +1,6 @@ Source: effect/clippath.js
On this page

effect_clippath.js

import { unique } from "../helpers/utils";
+    
On this page

effect_clippath.js

import { unique } from "../helpers/utils";
 import { geoPath } from "d3-geo";
 const d3 = Object.assign({}, { geoPath });
 
@@ -45,4 +45,4 @@
 
   return `url(#${id})`;
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/effect_radialgradient.js.html b/docs/effect_radialgradient.js.html index cb84dbe..8f94433 100644 --- a/docs/effect_radialgradient.js.html +++ b/docs/effect_radialgradient.js.html @@ -1,6 +1,6 @@ Source: effect/radialgradient.js
On this page

effect_radialgradient.js

import { unique } from "../helpers/utils";
+    
On this page

effect_radialgradient.js

import { unique } from "../helpers/utils";
 
 /**
  * @function effect/radialGradient
@@ -52,4 +52,4 @@
 
   return `url(#${id})`;
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/effect_shadow.js.html b/docs/effect_shadow.js.html index 7496791..d33f9e6 100644 --- a/docs/effect_shadow.js.html +++ b/docs/effect_shadow.js.html @@ -1,6 +1,6 @@ Source: effect/shadow.js
On this page

effect_shadow.js

import { unique } from "../helpers/utils";
+    
On this page

effect_shadow.js

import { unique } from "../helpers/utils";
 
 /**
  * @function effect/shadow
@@ -50,4 +50,4 @@
 
   return `url(#${id})`;
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/global.html b/docs/global.html index 80dc416..53adf31 100644 --- a/docs/global.html +++ b/docs/global.html @@ -1,6 +1,6 @@ Global
On this page

Members

tip

The tip parameter allows to add tooltips on map layers

Properties
NameTypeDescription
tipstring | boolean | function

You can display a simple text like "foo". But in most cases, tooltips are used to display information related to the elements hovered over. To do this, use the $ prefix with the field name.With true, all fidls are displayed. Finally, you can pass a function to build a customized tooltip.

tipstyleobject

An object to configure the "appearance of the tooltip. fontSize, fill, background, stroke, strokeWidth, fontFamily, fontWeight, fontStyle, textDecoration. See also tool.addonts

Examples
// Simple text
+    
On this page

Members

tip

The tip parameter allows to add tooltips on map layers

Properties
NameTypeDescription
tipstring | boolean | function

You can display a simple text like "foo". But in most cases, tooltips are used to display information related to the elements hovered over. To do this, use the $ prefix with the field name.With true, all fidls are displayed. Finally, you can pass a function to build a customized tooltip.

tipstyleobject

An object to configure the "appearance of the tooltip. fontSize, fill, background, stroke, strokeWidth, fontFamily, fontWeight, fontStyle, textDecoration. See also tool.addonts

Examples
// Simple text
 viz.path({ data: world, tip: "hello" })
// A field to display
 viz.path({ data: world, tip: "$pop" })
// To display all fields
 viz.path({ data: world, tip: true })
// A tooltip on several lines
@@ -40,7 +40,7 @@
 svg.circle({ data: cities, r: "population" }) // where svg is the container
 svg.plot({ type: "circle", data: cities, r: "population" }) // where svg is the container
 geoviz.circle({ data: cities, r: "population" }) // no container
-geoviz.plot({ type = "circle", data: cities, r: "population" }) // no container

create()

The create function is the first step in map construction. It creates an svg container + some information about this container:projection, margin, width, height and bbox.

Properties
NameTypeAttributesDefaultDescription
widthnumber<optional>
1000

width of the container.

heightnumber<optional>

height of the container. This value is automatically calculated according to domain. But it can be forced by entering a value.

domainobject | Array.<object><optional>

the domain corresponds to the geographical area to be displayed. It is defined by a geoJSON or an array containing geoJSONs.

projectionfunction | string<optional>

d3 function of projection. See d3-geo & d3-geo-projection. You can aslo write "mercator" to use tiles. (default: "none")

posArray.<number><optional>

position of the container (if contained in another svg container)

backgroundstring<optional>

background color

fontFamilystring<optional>

font-family for the entire map

marginnumber | Array.<number><optional>
0

margins around the map. A number to set the same margin everywhere or an array [top, right, bottom, left] to set different margins.

parentobject<optional>

name of parent container into which this child container is to be included. In this case, the options.pos parameter is also used.

zoomableboolean | number | string<optional>

activates the map zoom function. If you set an array of 2 values, it defines the scaleExtent (default: [1,8]). Use "versor" to activate versor zoom. "versor" is only available for vector geometries in wgs84.

controlboolean | Array.<number><optional>

If zoomable is enabled, set the control parameter as true displays control buttons to zoom on the map. You can also define an array of 2 values to locate the panel in the position you want (e.g. [100, 200]). This setting is not available with the Versor zoom.

warningboolean<optional>
true

display or not warnings on the map

Example
let svg = geoviz.create({width: 500, background: "lightblue"})

draw()

The draw() function is inspired by the bertin library. It allows you to draw the entire map using a single function. All the necessary information is stored in a single JSON, containing general parameters and an array of objects describing the layers to be displayed and overlaid. Under the wood, the function draw() use the viz.plot() function. The types available are the same.

Properties
NameTypeDescription
jsonobject

an object containing container parameters and an array for layers description. See example below.

Example
geoviz.draw({
+geoviz.plot({ type = "circle", data: cities, r: "population" }) // no container

create()

The create function is the first step in map construction. It creates an svg container + some information about this container:projection, margin, width, height and bbox.

Properties
NameTypeAttributesDefaultDescription
widthnumber<optional>
1000

width of the container.

idnumber<optional>
"map"

id of the svg container.

heightnumber<optional>

height of the container. This value is automatically calculated according to domain. But it can be forced by entering a value.

domainobject | Array.<object><optional>

the domain corresponds to the geographical area to be displayed. It is defined by a geoJSON or an array containing geoJSONs.

projectionfunction | string<optional>

d3 function of projection. See d3-geo & d3-geo-projection. You can aslo write "mercator" to use tiles. (default: "none")

posArray.<number><optional>

position of the container (if contained in another svg container)

backgroundstring<optional>

background color

fontFamilystring<optional>

font-family for the entire map

marginnumber | Array.<number><optional>
0

margins around the map. A number to set the same margin everywhere or an array [top, right, bottom, left] to set different margins.

parentobject<optional>

name of parent container into which this child container is to be included. In this case, the options.pos parameter is also used.

zoomableboolean | number | string<optional>

activates the map zoom function. If you set an array of 2 values, it defines the scaleExtent (default: [1,8]). Use "versor" to activate versor zoom. "versor" is only available for vector geometries in wgs84.

controlboolean | Array.<number><optional>

If zoomable is enabled, set the control parameter as true displays control buttons to zoom on the map. You can also define an array of 2 values to locate the panel in the position you want (e.g. [100, 200]). This setting is not available with the Versor zoom.

warningboolean<optional>
true

display or not warnings on the map

Example
let svg = geoviz.create({width: 500, background: "lightblue"})

draw()

The draw() function is inspired by the bertin library. It allows you to draw the entire map using a single function. All the necessary information is stored in a single JSON, containing general parameters and an array of objects describing the layers to be displayed and overlaid. Under the wood, the function draw() use the viz.plot() function. The types available are the same.

Properties
NameTypeDescription
jsonobject

an object containing container parameters and an array for layers description. See example below.

Example
geoviz.draw({
  // SVG container parameters
   params: {
     zoomable: true,
@@ -83,7 +83,9 @@
 geoviz.graticule(svg, { step: 2 }) // where svg is the container
 svg.graticule({ step: [10,2] }) // where svg is the container
 svg.plot({ type: "graticule", step: [10,2] }) // where svg is the container
-geoviz.graticule({ step: 2 }) // no container

halfcircle()

The halfcircle function allows to create a layer with rotable half-circles from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

Properties
NameTypeAttributesDefaultDescription
dataobject

GeoJSON FeatureCollection

idstring<optional>

id of the layer

posArray.<number><optional>
[0,0]

position of the half-circle to display a single circle

dxnumber<optional>
0

shift in x

dynumber<optional>
0

shift in y

anglenumber<optional>
0

angle of the half circle

rnumber | string<optional>
10

a number or the name of a property containing numerical values

innerRadiusnumber<optional>
10

inner radius

cornerRadiusnumber<optional>
2

corner radius

knumber<optional>
50

radius of the largest half-circle (or corresponding to the value defined by fixmax)

fixmaxnumber<optional>

value matching the half-circle with radius k. Setting this value is useful for making maps comparable with each other

sortstring | function<optional>

the field to sort circles or a sort function

descendingboolean<optional>

circle sorting order

coordsstring<optional>
"geo"

use "svg" if the coordinates are already in the plan of the svg document

fillstring | function<optional>

fill color. To create choropleth maps or typologies, use the tool.choro and tool.typo functions

strokestring | function<optional>

stroke color. To create choropleth maps or typologies, use the tool.choro and tool.typo functions

tipboolean | function<optional>
false

a function to display the tip. Use true tu display all fields

viewboolean<optional>
false

use true and viewof in Observable for this layer to act as Input

tipstyleobject<optional>

tooltip style

**<optional>

other SVG attributes that can be applied (strokeDasharray, strokeWidth, opacity, strokeLinecap...)

svg_**<optional>

parameters of the svg container created if the layer is not called inside a container (e.g svg_width)

Example
// There are several ways to use this function
+geoviz.graticule({ step: 2 }) // no container

grid/arbitrary()

The grid.arbitrary function allows to create an arbitrary geoJSON grid in SVG coordinates.

Properties
NameTypeAttributesDefaultDescription
stepnumber<optional>
50

step of the grid

widthnumber<optional>
1000

width of the grid

heightnumber<optional>
500

height of the grid

Example
geoviz.grid.arbitrary(50, 1000, 500)

grid/diamond()

The grid.diamond function allows to create a diamond geoJSON grid in SVG coordinates.

Properties
NameTypeAttributesDefaultDescription
stepnumber<optional>
50

step of the grid

widthnumber<optional>
1000

width of the grid

heightnumber<optional>
500

height of the grid

Example
geoviz.grid.diamond(50, 1000, 500)

grid/dot()

The grid.dot function allows to create a geoJSON vith regular dots in SVG coordinates.

Properties
NameTypeAttributesDefaultDescription
stepnumber<optional>
50

step of the grid

widthnumber<optional>
1000

width of the grid

heightnumber<optional>
500

height of the grid

Example
geoviz.grid.dot(50, 1000, 500)

grid/h3()

The grid.h3 function allows to create a hexbin geoJSON grid in geographical coordinates.

Properties
NameTypeAttributesDefaultDescription
levelnumber<optional>
0

level of the grid. Form 0 (large hexagons) to 4 (small hexagons). See: https://h3geo.org

Example
geoviz.grid.h3(1)

grid/hexbin()

The grid.hexbin function allows to create a hexbin geoJSON grid in SVG coordinates.

Properties
NameTypeAttributesDefaultDescription
stepnumber<optional>
50

step of the grid

widthnumber<optional>
1000

width of the grid

heightnumber<optional>
500

height of the grid

Example
geoviz.grid.hexbin(50, 1000, 500)

grid/make()

The grid.make function allows to create a regular grid geoJSON. For all types, For all grid types (except "h3"), the function returns a geojson with svg coordinates in the layout of the page. For type "h3", the function returns geographic coordinates in latitude and longitude.

Properties
NameTypeAttributesDefaultDescription
typestring<optional>
"square"

Type of grid ("square", "dot", "diamond", "hexbin" (or "hex"), "trangle", "arbitrary" (or "randmon"), "h3" (or "h3geo", "hexgeo", "hexbingeo"))

stepnumber<optional>
50

step of grids (except for "h3" type)

levelnumber<optional>
0

level oh geographical hexbin grids ("h3" type only). Form 0 (large hexagons) to 4 (small hexagons). See: https://h3geo.org

Example
// There are several ways to use this function
+geoviz.grid.make(svg, { type:"diamond", step:100 })  // where svg is the container
+svg.grid.make({ type:"diamond", step:100 })  // where svg is the container

grid/square()

The grid.square function allows to create a square geoJSON grid in SVG coordinates.

Properties
NameTypeAttributesDefaultDescription
stepnumber<optional>
50

step of the grid

widthnumber<optional>
1000

width of the grid

heightnumber<optional>
500

height of the grid

Example
geoviz.grid.square(50, 1000, 500)

grid/triangle()

The grid.triangle function allows to create a triangle geoJSON grid in SVG coordinates.

Properties
NameTypeAttributesDefaultDescription
stepnumber<optional>
50

step of the grid

widthnumber<optional>
1000

width of the grid

heightnumber<optional>
500

height of the grid

Example
geoviz.grid.triangle(50, 1000, 500)

halfcircle()

The halfcircle function allows to create a layer with rotable half-circles from a geoJSON. The function adds a layer to the SVG container and returns the layer identifier. If the container is not defined, then the layer is displayed directly.

Properties
NameTypeAttributesDefaultDescription
dataobject

GeoJSON FeatureCollection

idstring<optional>

id of the layer

posArray.<number><optional>
[0,0]

position of the half-circle to display a single circle

dxnumber<optional>
0

shift in x

dynumber<optional>
0

shift in y

anglenumber<optional>
0

angle of the half circle

rnumber | string<optional>
10

a number or the name of a property containing numerical values

innerRadiusnumber<optional>
10

inner radius

cornerRadiusnumber<optional>
2

corner radius

knumber<optional>
50

radius of the largest half-circle (or corresponding to the value defined by fixmax)

fixmaxnumber<optional>

value matching the half-circle with radius k. Setting this value is useful for making maps comparable with each other

sortstring | function<optional>

the field to sort circles or a sort function

descendingboolean<optional>

circle sorting order

coordsstring<optional>
"geo"

use "svg" if the coordinates are already in the plan of the svg document

fillstring | function<optional>

fill color. To create choropleth maps or typologies, use the tool.choro and tool.typo functions

strokestring | function<optional>

stroke color. To create choropleth maps or typologies, use the tool.choro and tool.typo functions

tipboolean | function<optional>
false

a function to display the tip. Use true tu display all fields

viewboolean<optional>
false

use true and viewof in Observable for this layer to act as Input

tipstyleobject<optional>

tooltip style

**<optional>

other SVG attributes that can be applied (strokeDasharray, strokeWidth, opacity, strokeLinecap...)

svg_**<optional>

parameters of the svg container created if the layer is not called inside a container (e.g svg_width)

Example
// There are several ways to use this function
 geoviz.halfcircle(svg, { pos: [10,20], r: 15 }) // a single half-circle
 geoviz.halfcircle(svg, { data: cities, r: "population" }) // where svg is the container
 svg.halfcircle({ data: cities, r: "population" }) // where svg is the container
@@ -195,4 +197,4 @@
 geoviz.tile() // no container
 geoviz.tile(svg, {url: "worldterrain"}) // where svg is the container
 svg.tile({url: "worldterrain"}) // where svg is the container
-svg.plot({type: "tile", url: "worldterrain"}) // where svg is the container

tool/addonts()

The tool.addonts function allows add font to the document from an url.

Properties
NameTypeDescription
fontFamilystring

font family name

urlstring

tff- file url

tool/centroid()

The tool.centroid function calculate the centroid of all the geometries given in a GeoJSON FeatureCollection. It returns a GeoJSON FeatureCollection (points)

Properties
NameTypeAttributesDefaultDescription
dataobject

a GeoJSON FeatureCollection

options.largestboolean<optional>
true

place the centroid in the largest polygon.

options.latlongboolean<optional>
true

use true if input coordinates are in latitude ans longitude. Use false if the coordinates are already defined in the page plan

Example
let dots = geoviz.tool.centroid(world, { largest: true })

tool/choro()

The tool.choro function discretizes an array of numbers. It returns an object containing breaks, colors, the color of the missing value and a function.

Properties
NameTypeAttributesDefaultDescription
dataArray.<number>

an array of numerical values.

options.breaksArray.<number><optional>

class breaks including min and max

options.colorsstring | Array.<string><optional>
"Algae"

an array of colors or name of a color palette available in dicopal

options.reverseboolean<optional>
false

reverse colors

options.missingstring<optional>
"white"

a color for missings values

options.methodstring<optional>
"quantile"

classification method ('quantile', 'q6', 'equal', 'jenks', 'msd', 'geometric', 'headtail', 'pretty', 'arithmetic' or 'nestedmeans')

options.nbnumber<optional>
6

number of classes desired

options.precisionnumber<optional>
2

number of digits

options.minmaxboolean<optional>

to keep or delete min and max

options.knumber<optional>
1

number of standard deviations taken into account (msd method only)

options.middleboolean<optional>

to have the average as a class center (msd method only)

Example
geoviz.tool.choro(world.features.map((d) => d.properties.gdppc), {method: "equal", nb: 4})

tool/dissolve()

The tool.dissolve function aims to transform multi part features into single parts feature. It a GeoJSON FeatureCollection (without multi part features)

Properties
NameTypeAttributesDefaultDescription
dataobject

a GeoJSON FeatureCollection

options.areashareboolean<optional>
"_share"

name of the field containing the share area of the part

Example
let dots = geoviz.tool.dissolve(world)

tool/dodge()

The tool.dodge function use d3.forceSimulation to spread dots or circles of given in a GeoJSON FeatureCollection (points). It returns the coordinates in the page map. It can be used to create a dorling cartogram. The function returns a GeoJSON FeatureCollection (points) with coordinates in the page map.

Properties
NameTypeAttributesDefaultDescription
dataobject

a GeoJSON FeatureCollection

options.projectionfunction<optional>
d => d

d3 projection function

options.rnumber | string<optional>
10

a number or the name of a property containing numerical values.

options.knumber<optional>
50

radius of the largest circle (or corresponding to the value defined by fixmax)

options.fixmaxnumber<optional>
null

value matching the circle with radius k. Setting this value is useful for making maps comparable with each other

options.iterationnumber<optional>
200

number of iterations

options.gapnumber<optional>
0

space between points/circles

Example
let dots = geoviz.tool.dodge(world, { projection: d3.geoOrthographic(), r: "population", k: 40 })

tool/dotstogrid()

dotstogrid is a function to create a regular grid in the SVG plan count the number of dots inside

Properties
NameTypeAttributesDefaultDescription
svgobject

A geoviz SVG container

options.typestring<optional>
"hex"

type of grid ("hex", "square", "triangle","random")

options.stepnumber<optional>
50

grid resolution (in pixels)

options.datageoJSON<optional>

dots to count in the grid

options.varstring<optional>

field to sum

Example
geoviz.tool.dotstogrid(svg, {type:"triangle", step:30, data: dots, var: "mayvar"})

tool/featurecollection()

tool.featurecollection is a function to create a valid GeoJSON FeatureCollection, from geometries, features or coordinates. It returns a GeoJSON FeatureCollection.

Properties
NameTypeDescription
dataobject | Array

A GeoJSON FeatureCollection, an array of GeoJSON features, a single feature, an array of geometries, a single geometry or a array defining a bbox. You can also use an array of properties containing latitude and longitude coordinates. In this case, you need to specify the field names in the options.

options.latitudestring

name of field containing latitudes. You can also use lat

options.longitudestring

name of field containing longitudes. You can also use lon

options.coordinatesstring

name of field containing géographic coordinates. You can also use coords

options.geometrystring

name of field containing geoJSON geometries

tool/geotable()

geotable is a function to create an array on objects containing properties and geomeytries, froam a GeoJSON FeatureCollection. This makes it easy to sort, extract data, etc. tool.featurecollection(geotable, { geometry: "geometry" }) can be used to rebuild a valid geoJSON. The function returns an array of an array of FeatureCollections.

Properties
NameTypeDescription
dataobject

A GeoJSON FeatureCollection

options.geometrystring

name of field containing GEOJSON geometries

tool/height()

This function return a function to calculate radius of circles from data. It returns an object containing a radius function.

Properties
NameTypeAttributesDefaultDescription
dataArray.<number>

an array of numerical values.

options.fixmaxArray.<string><optional>

to fix the value corresponding to the circle with radius = k

options.kArray.<string><optional>
50

radius if the greater circle

tool/merge()

tool.merge is a function to join a geoJSON and a data file. It returns a GeoJSON FeatureCollection.

Properties
NameTypeAttributesDescription
geomArray

a GeoJSON FeatureCollection

geom_idstring

geom id

dataArray

array containg data

data_idstring

data id

idstring<optional>

id (if ids are the same in data and geometries)

tool/proj4d3()

proj4d3 is a function developped by Philippe Rivière to allow tu use proj4js projections with d3. It returns a d3js projection function. See https://observablehq.com/@fil/proj4js-d3

Properties
NameTypeDescription
proj4library

the proj4 lib that you have to load

proj4stringstring

a proj4 projection

Example
geoviz.tool.proj4d3(proj4, `+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs` )

tool/project()

The function tool.project use geoproject from d3-geo-projection to project a geoJSON. It returns a GeoJSON FeatureCollection with coordinates in the page map.

Properties
NameTypeDescription
dataobject

a GeoJSON FeatureCollection

options.projectionfunction

projection definition. See d3-geo & d3-geo-projection

Example
let newGeoJSON = geoviz.tool.project(world, { projection: d3.geoOrthographic()})

tool/radius()

The tool.radius function return a function to calculate radius of circles from data

Properties
NameTypeAttributesDefaultDescription
dataArray.<number>

an array of numerical values.

options.fixmaxArray.<string><optional>

to fix the value corresponding to the circle with radius = k

option.kArray.<string><optional>
50

radius if the greater circle

tool/random()

The tool.random function returns a random color among 20 predefined colors.

tool/replicate()

Data-driven features replication. This function can be used to create "dots cartograms". The function returns a GeoJSON FeatureCollection with overlapping features

Properties
NameTypeDescription
dataobject

a GeoJSON FeatureCollection

options.fieldstring

property name containing numeric data

options.targetvaluenumber

Feature target value

Example
let dots = geoviz.tool.replicate(world, { field: "population", targetvalue: 10000 })

tool/rewind()

The tool.rewind function allows to generate compliant Polygon and MultiPolygon geometries. Adapted from MapBox geojson-rewind code (https://github.com/mapbox/grojson-rewind) under ISC license

Properties
NameTypeAttributesDefaultDescription
dataobject

a GeoJSON FeatureCollection

options.outerboolean<optional>
false

rewind Rings Outer

options.mutateboolean<optional>
false

mutate the Input geoJSON

tool/ridge()

The tool.ridge function convert a regular grid (x,y,z) to a GeoJSON FeatureCollection (LineString). The aim is to draw a rideline map.

Properties
NameTypeAttributesDefaultDescription
gridarray

an array of object containig x,y,z values

options.xstring<optional>
"x"

field containg x values

options.ystring<optional>
"y"

field containg y values

options.zstring<optional>
"z"

field containg z values

options.knumber<optional>
100

height of highest peak

options.fixmaxnumber<optional>
null

a fixed value corresponding to the k

options.projectionboolean<optional>
d => d

projection

tool/symbols()

Display symbols available in geoviz

Properties
NameTypeAttributesDefaultDescription
options.widthnumber<optional>
800

width

Example
geoviz.tool.symbols({ width: 500 })

tool/typo()

The tool.typo function allows you to assign colors to qualitative data. It can be used to create typology maps. It returs an object containing types, colors, the color of the missing value and a function.

Properties
NameTypeAttributesDefaultDescription
dataArray.<number>

an array of numerical values.

options.colorsArray.<string><optional>
"Set3"

an array of colors or name of a color palette available in dicopal

options.missingstring<optional>
"white"

a color for missings values

Example
geoviz.tool.typo(world.features.map((d) => d.properties.region), {palette: "Pastel"})

tool/unproject()

The tool.unproject function allow to unproject geometries. It returns a GeoJSON FeatureCollection with wgs84 coordinates

Properties
NameTypeDescription
dataobject

a GeoJSON FeatureCollection

options.projectionfunction

projection definition. See d3-geo & d3-geo-projection

Example
let newGeoJSON = geoviz.tool.unproject(world, { projection: d3.geoOrthographic()})
Home
\ No newline at end of file +svg.plot({type: "tile", url: "worldterrain"}) // where svg is the container

tool/addonts()

The tool.addonts function allows add font to the document from an url.

Properties
NameTypeDescription
fontFamilystring

font family name

urlstring

tff- file url

Source

tool/centroid()

The tool.centroid function calculate the centroid of all the geometries given in a GeoJSON FeatureCollection. It returns a GeoJSON FeatureCollection (points)

Properties
NameTypeAttributesDefaultDescription
dataobject

a GeoJSON FeatureCollection

options.largestboolean<optional>
true

place the centroid in the largest polygon.

options.latlongboolean<optional>
true

use true if input coordinates are in latitude ans longitude. Use false if the coordinates are already defined in the page plan

Source
See
Example
let dots = geoviz.tool.centroid(world, { largest: true })

tool/choro()

The tool.choro function discretizes an array of numbers. It returns an object containing breaks, colors, the color of the missing value and a function.

Properties
NameTypeAttributesDefaultDescription
dataArray.<number>

an array of numerical values.

options.breaksArray.<number><optional>

class breaks including min and max

options.colorsstring | Array.<string><optional>
"Algae"

an array of colors or name of a color palette available in dicopal

options.reverseboolean<optional>
false

reverse colors

options.missingstring<optional>
"white"

a color for missings values

options.methodstring<optional>
"quantile"

classification method ('quantile', 'q6', 'equal', 'jenks', 'msd', 'geometric', 'headtail', 'pretty', 'arithmetic' or 'nestedmeans')

options.nbnumber<optional>
6

number of classes desired

options.precisionnumber<optional>
2

number of digits

options.minmaxboolean<optional>

to keep or delete min and max

options.knumber<optional>
1

number of standard deviations taken into account (msd method only)

options.middleboolean<optional>

to have the average as a class center (msd method only)

Source
Example
geoviz.tool.choro(world.features.map((d) => d.properties.gdppc), {method: "equal", nb: 4})

tool/dissolve()

The tool.dissolve function aims to transform multi part features into single parts feature. It a GeoJSON FeatureCollection (without multi part features)

Properties
NameTypeAttributesDefaultDescription
dataobject

a GeoJSON FeatureCollection

options.areashareboolean<optional>
"_share"

name of the field containing the share area of the part

Source
See
Example
let dots = geoviz.tool.dissolve(world)

tool/dodge()

The tool.dodge function use d3.forceSimulation to spread dots or circles of given in a GeoJSON FeatureCollection (points). It returns the coordinates in the page map. It can be used to create a dorling cartogram. The function returns a GeoJSON FeatureCollection (points) with coordinates in the page map.

Properties
NameTypeAttributesDefaultDescription
dataobject

a GeoJSON FeatureCollection

options.projectionfunction<optional>
d => d

d3 projection function

options.rnumber | string<optional>
10

a number or the name of a property containing numerical values.

options.knumber<optional>
50

radius of the largest circle (or corresponding to the value defined by fixmax)

options.fixmaxnumber<optional>
null

value matching the circle with radius k. Setting this value is useful for making maps comparable with each other

options.iterationnumber<optional>
200

number of iterations

options.gapnumber<optional>
0

space between points/circles

Source
See
Example
let dots = geoviz.tool.dodge(world, { projection: d3.geoOrthographic(), r: "population", k: 40 })

tool/dotstogrid()

dotstogrid is a function to create a regular grid in the SVG plan count the number of dots inside

Properties
NameTypeAttributesDefaultDescription
svgobject

A geoviz SVG container

options.typestring<optional>
"hex"

type of grid ("hex", "square", "triangle","random")

options.stepnumber<optional>
50

grid resolution (in pixels)

options.datageoJSON<optional>

dots to count in the grid

options.varstring<optional>

field to sum

Source
See
Example
geoviz.tool.dotstogrid(svg, {type:"triangle", step:30, data: dots, var: "mayvar"})

tool/featurecollection()

tool.featurecollection is a function to create a valid GeoJSON FeatureCollection, from geometries, features or coordinates. It returns a GeoJSON FeatureCollection.

Properties
NameTypeDescription
dataobject | Array

A GeoJSON FeatureCollection, an array of GeoJSON features, a single feature, an array of geometries, a single geometry or a array defining a bbox. You can also use an array of properties containing latitude and longitude coordinates. In this case, you need to specify the field names in the options.

options.latitudestring

name of field containing latitudes. You can also use lat

options.longitudestring

name of field containing longitudes. You can also use lon

options.coordinatesstring

name of field containing géographic coordinates. You can also use coords

options.geometrystring

name of field containing geoJSON geometries

Source
See

tool/geotable()

geotable is a function to create an array on objects containing properties and geomeytries, froam a GeoJSON FeatureCollection. This makes it easy to sort, extract data, etc. tool.featurecollection(geotable, { geometry: "geometry" }) can be used to rebuild a valid geoJSON. The function returns an array of an array of FeatureCollections.

Properties
NameTypeDescription
dataobject

A GeoJSON FeatureCollection

options.geometrystring

name of field containing GEOJSON geometries

Source
See

tool/height()

This function return a function to calculate radius of circles from data. It returns an object containing a radius function.

Properties
NameTypeAttributesDefaultDescription
dataArray.<number>

an array of numerical values.

options.fixmaxArray.<string><optional>

to fix the value corresponding to the circle with radius = k

options.kArray.<string><optional>
50

radius if the greater circle

Source

tool/merge()

tool.merge is a function to join a geoJSON and a data file. It returns a GeoJSON FeatureCollection.

Properties
NameTypeAttributesDescription
geomArray

a GeoJSON FeatureCollection

geom_idstring

geom id

dataArray

array containg data

data_idstring

data id

idstring<optional>

id (if ids are the same in data and geometries)

Source
See

tool/proj4d3()

proj4d3 is a function developped by Philippe Rivière to allow tu use proj4js projections with d3. It returns a d3js projection function. See https://observablehq.com/@fil/proj4js-d3

Properties
NameTypeDescription
proj4library

the proj4 lib that you have to load

proj4stringstring

a proj4 projection

Source
See
Example
geoviz.tool.proj4d3(proj4, `+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs` )

tool/project()

The function tool.project use geoproject from d3-geo-projection to project a geoJSON. It returns a GeoJSON FeatureCollection with coordinates in the page map.

Properties
NameTypeDescription
dataobject

a GeoJSON FeatureCollection

options.projectionfunction

projection definition. See d3-geo & d3-geo-projection

Source
See
Example
let newGeoJSON = geoviz.tool.project(world, { projection: d3.geoOrthographic()})

tool/radius()

The tool.radius function return a function to calculate radius of circles from data

Properties
NameTypeAttributesDefaultDescription
dataArray.<number>

an array of numerical values.

options.fixmaxArray.<string><optional>

to fix the value corresponding to the circle with radius = k

option.kArray.<string><optional>
50

radius if the greater circle

Source

tool/random()

The tool.random function returns a random color among 20 predefined colors.

Source

tool/replicate()

Data-driven features replication. This function can be used to create "dots cartograms". The function returns a GeoJSON FeatureCollection with overlapping features

Properties
NameTypeDescription
dataobject

a GeoJSON FeatureCollection

options.fieldstring

property name containing numeric data

options.targetvaluenumber

Feature target value

Source
See
Example
let dots = geoviz.tool.replicate(world, { field: "population", targetvalue: 10000 })

tool/rewind()

The tool.rewind function allows to generate compliant Polygon and MultiPolygon geometries. Adapted from MapBox geojson-rewind code (https://github.com/mapbox/grojson-rewind) under ISC license

Properties
NameTypeAttributesDefaultDescription
dataobject

a GeoJSON FeatureCollection

options.outerboolean<optional>
false

rewind Rings Outer

options.mutateboolean<optional>
false

mutate the Input geoJSON

Source
See

tool/ridge()

The tool.ridge function convert a regular grid (x,y,z) to a GeoJSON FeatureCollection (LineString). The aim is to draw a rideline map.

Properties
NameTypeAttributesDefaultDescription
gridarray

an array of object containig x,y,z values

options.xstring<optional>
"x"

field containg x values

options.ystring<optional>
"y"

field containg y values

options.zstring<optional>
"z"

field containg z values

options.knumber<optional>
100

height of highest peak

options.fixmaxnumber<optional>
null

a fixed value corresponding to the k

options.projectionboolean<optional>
d => d

projection

Source
See

tool/symbols()

Display symbols available in geoviz

Properties
NameTypeAttributesDefaultDescription
options.widthnumber<optional>
800

width

Source
See
Example
geoviz.tool.symbols({ width: 500 })

tool/typo()

The tool.typo function allows you to assign colors to qualitative data. It can be used to create typology maps. It returs an object containing types, colors, the color of the missing value and a function.

Properties
NameTypeAttributesDefaultDescription
dataArray.<number>

an array of numerical values.

options.colorsArray.<string><optional>
"Set3"

an array of colors or name of a color palette available in dicopal

options.missingstring<optional>
"white"

a color for missings values

Source
Example
geoviz.tool.typo(world.features.map((d) => d.properties.region), {palette: "Pastel"})

tool/unproject()

The tool.unproject function allow to unproject geometries. It returns a GeoJSON FeatureCollection with wgs84 coordinates

Properties
NameTypeDescription
dataobject

a GeoJSON FeatureCollection

options.projectionfunction

projection definition. See d3-geo & d3-geo-projection

Source
See
Example
let newGeoJSON = geoviz.tool.unproject(world, { projection: d3.geoOrthographic()})
Home
\ No newline at end of file diff --git a/docs/grid_arbitrary.js.html b/docs/grid_arbitrary.js.html new file mode 100644 index 0000000..25a984f --- /dev/null +++ b/docs/grid_arbitrary.js.html @@ -0,0 +1,45 @@ +Source: grid/arbitrary.js
On this page

grid_arbitrary.js

import { Delaunay } from "d3-delaunay";
+const d3 = Object.assign({}, { Delaunay });
+
+/**
+ * @function grid/arbitrary
+ * @description The `grid.arbitrary` function allows to create an arbitrary geoJSON grid in SVG coordinates.
+ * @see {@link https://observablehq.com/@neocartocnrs/regular-grids}
+ * @property {number} [step = 50] - step of the grid
+ * @property {number} [width = 1000] - width of the grid
+ * @property {number} [height = 500] - height of the grid
+ * @example
+ * geoviz.grid.arbitrary(50, 1000, 500)
+ */
+
+export function arbitrary(step = 50, width = 1000, height = 500) {
+  let grid = [];
+  let nb = Math.round((width / step) * (height / step));
+  for (let i = 0; i < nb; i++) {
+    grid.push([Math.random() * width, Math.random() * height]);
+  }
+
+  let voronoi = d3.Delaunay.from(
+    grid,
+    (d) => d[0],
+    (d) => d[1]
+  ).voronoi([0, 0, width, height]);
+
+  // build object
+  let result = grid.map((d, i) => {
+    return {
+      type: "Feature",
+      geometry: {
+        type: "Polygon",
+        coordinates: [voronoi.cellPolygon(i)],
+      },
+      properties: {
+        index: i,
+      },
+    };
+  });
+  return { type: "FeatureCollection", features: result };
+}
+
Home
\ No newline at end of file diff --git a/docs/grid_diamond.js.html b/docs/grid_diamond.js.html new file mode 100644 index 0000000..ef8f459 --- /dev/null +++ b/docs/grid_diamond.js.html @@ -0,0 +1,51 @@ +Source: grid/diamond.js
On this page

grid_diamond.js

import { range } from "d3-array";
+const d3 = Object.assign({}, { range });
+
+/**
+ * @function grid/diamond
+ * @description The `grid.diamond` function allows to create a diamond geoJSON grid in SVG coordinates.
+ * @see {@link https://observablehq.com/@neocartocnrs/regular-grids}
+ * @property {number} [step = 50] - step of the grid
+ * @property {number} [width = 1000] - width of the grid
+ * @property {number} [height = 500] - height of the grid
+ * @example
+ * geoviz.grid.diamond(50, 1000, 500)
+ */
+export function diamond(step = 50, width = 1000, height = 500) {
+  let size = step * Math.sqrt(2);
+
+  // build grid
+  let x = d3.range(0, width + size, size);
+  let y = d3.range(0, height + size, size / 2).reverse();
+  let grid = x.map((x) => y.map((y, j) => [x, y, j % 2])).flat();
+  grid = grid.map((d) => {
+    return d[2] == 1 ? [d[0] + size / 2, d[1]] : [d[0], d[1]];
+  });
+
+  let s = size / 2;
+  // build object
+  let result = grid.map((d, i) => {
+    return {
+      type: "Feature",
+      geometry: {
+        type: "Polygon",
+        coordinates: [
+          [
+            [d[0] - s, d[1]],
+            [d[0], d[1] + s],
+            [d[0] + s, d[1]],
+            [d[0], d[1] - s],
+            [d[0] - s, d[1]],
+          ],
+        ],
+      },
+      properties: {
+        index: i,
+      },
+    };
+  });
+  return { type: "FeatureCollection", features: result };
+}
+
Home
\ No newline at end of file diff --git a/docs/grid_dot.js.html b/docs/grid_dot.js.html new file mode 100644 index 0000000..acc7865 --- /dev/null +++ b/docs/grid_dot.js.html @@ -0,0 +1,37 @@ +Source: grid/dot.js
On this page

grid_dot.js

import { range } from "d3-array";
+const d3 = Object.assign({}, { range });
+
+/**
+ * @function grid/dot
+ * @description The `grid.dot` function allows to create a geoJSON vith regular dots in SVG coordinates.
+ * @see {@link https://observablehq.com/@neocartocnrs/regular-grids}
+ * @property {number} [step = 50] - step of the grid
+ * @property {number} [width = 1000] - width of the grid
+ * @property {number} [height = 500] - height of the grid
+ * @example
+ * geoviz.grid.dot(50, 1000, 500)
+ */
+export function dot(step = 30, width = 1000, height = 500) {
+  // build grid
+  let y = d3.range(0 + step / 2, height, step).reverse();
+  let x = d3.range(0 + step / 2, width, step);
+  let grid = x.map((x) => y.map((y) => [x, y])).flat();
+  let s = step / 2;
+  // build object
+  let result = grid.map((d, i) => {
+    return {
+      type: "Feature",
+      geometry: {
+        type: "Point",
+        coordinates: d,
+      },
+      properties: {
+        index: i,
+      },
+    };
+  });
+  return { type: "FeatureCollection", features: result };
+}
+
Home
\ No newline at end of file diff --git a/docs/grid_h3.js.html b/docs/grid_h3.js.html new file mode 100644 index 0000000..08009d0 --- /dev/null +++ b/docs/grid_h3.js.html @@ -0,0 +1,34 @@ +Source: grid/h3.js
On this page

grid_h3.js

import {
+  getRes0Cells,
+  cellToChildren,
+  isPentagon,
+  cellToBoundary,
+} from "h3-js";
+
+/**
+ * @function grid/h3
+ * @description The `grid.h3` function allows to create a hexbin geoJSON grid in geographical coordinates.
+ * @see {@link https://observablehq.com/@neocartocnrs/regular-grids}
+ * @property {number} [level = 0] - level of the grid. Form 0 (large hexagons) to 4 (small hexagons). See:  https://h3geo.org
+ * @example
+ * geoviz.grid.h3(1)
+ */
+export function h3(level = 0) {
+  return {
+    type: "FeatureCollection",
+    features: getRes0Cells()
+      .map((i) => cellToChildren(i, level))
+      .flat()
+      .map((d) => ({
+        type: "Feature",
+        properties: { id: d, pentagon: isPentagon(d) },
+        geometry: {
+          type: "Polygon",
+          coordinates: [cellToBoundary(d, true).reverse()],
+        },
+      })),
+  };
+}
+
Home
\ No newline at end of file diff --git a/docs/grid_hexbin.js.html b/docs/grid_hexbin.js.html new file mode 100644 index 0000000..81abe22 --- /dev/null +++ b/docs/grid_hexbin.js.html @@ -0,0 +1,53 @@ +Source: grid/hexbin.js
On this page

grid_hexbin.js

import { range, max } from "d3-array";
+const d3 = Object.assign({}, { range, max });
+
+/**
+ * @function grid/hexbin
+ * @description The `grid.hexbin` function allows to create a hexbin geoJSON grid in SVG coordinates.
+ * @see {@link https://observablehq.com/@neocartocnrs/regular-grids}
+ * @property {number} [step = 50] - step of the grid
+ * @property {number} [width = 1000] - width of the grid
+ * @property {number} [height = 500] - height of the grid
+ * @example
+ * geoviz.grid.hexbin(50, 1000, 500)
+ */
+export function hexbin(step = 50, width = 1000, height = 500) {
+  let w = step;
+  let size = w / Math.sqrt(3);
+  let h = 2 * size * (3 / 4);
+
+  // build grid
+  let y = d3.range(0, height + size, h).reverse();
+  if (y.length % 2) {
+    y.unshift(d3.max(y) + h);
+  }
+  let x = d3.range(0, width + size, w);
+  let grid = x.map((x) => y.map((y) => [x, y])).flat();
+  grid = grid.map((d, i) => {
+    return i % 2 == 1 ? [d[0] + w / 2, d[1]] : d;
+  });
+  let s = step / 2;
+  // build object
+  let result = grid.map((d, i) => {
+    let hex = [];
+    for (let i = 0; i < 6; i++) {
+      let ang = (Math.PI / 180) * (60 * i - 30);
+      hex.push([d[0] + size * Math.cos(ang), d[1] + size * Math.sin(ang)]);
+    }
+
+    return {
+      type: "Feature",
+      geometry: {
+        type: "Polygon",
+        coordinates: [[hex[0], hex[1], hex[2], hex[3], hex[4], hex[5], hex[0]]],
+      },
+      properties: {
+        index: i,
+      },
+    };
+  });
+  return { type: "FeatureCollection", features: result };
+}
+
Home
\ No newline at end of file diff --git a/docs/grid_make.js.html b/docs/grid_make.js.html new file mode 100644 index 0000000..dce6f6d --- /dev/null +++ b/docs/grid_make.js.html @@ -0,0 +1,55 @@ +Source: grid/make.js
On this page

grid_make.js

import { square } from "./square.js";
+import { dot } from "./dot.js";
+import { diamond } from "./diamond.js";
+import { arbitrary } from "./arbitrary.js";
+import { hexbin } from "./hexbin.js";
+import { triangle } from "./triangle.js";
+import { h3 } from "./h3.js";
+
+/**
+ * @function grid/make
+ * @description The `grid.make` function allows to create a regular grid geoJSON. For all types, For all grid types (except "h3"), the function returns a geojson with svg coordinates in the layout of the page. For type "h3", the function returns geographic coordinates in latitude and longitude.
+ * @see {@link https://observablehq.com/@neocartocnrs/regular-grids}
+ *
+ * @property {string} [type = "square"] - Type of grid ("square", "dot", "diamond", "hexbin" (or "hex"), "trangle", "arbitrary" (or "randmon"), "h3" (or "h3geo", "hexgeo", "hexbingeo"))
+ * @property {number} [step = 50] - step of grids (except for "h3" type)
+ * @property {number} [level = 0] - level oh geographical hexbin grids ("h3" type only). Form 0 (large hexagons) to 4 (small hexagons). See:  https://h3geo.org
+ * @example
+ * // There are several ways to use this function
+ * geoviz.grid.make(svg, { type:"diamond", step:100 })  // where svg is the container
+ * svg.grid.make({ type:"diamond", step:100 })  // where svg is the container
+ */
+
+export function make(svg, { step = 50, type = "square", level = 0 } = {}) {
+  switch (type) {
+    case "square":
+      return square(step, svg.width, svg.height);
+      break;
+    case "arbitrary":
+    case "random":
+      return arbitrary(step, svg.width, svg.height);
+      break;
+    case "dot":
+      return dot(step, svg.width, svg.height);
+      break;
+    case "diamond":
+      return diamond(step, svg.width, svg.height);
+      break;
+    case "hexbin":
+    case "hex":
+      return hexbin(step, svg.width, svg.height);
+      break;
+    case "triangle":
+      return triangle(step, svg.width, svg.height);
+      break;
+    case "h3":
+    case "h3geo":
+    case "hexgeo":
+    case "hexbingeo":
+      return h3(level);
+      break;
+  }
+}
+
Home
\ No newline at end of file diff --git a/docs/grid_square.js.html b/docs/grid_square.js.html new file mode 100644 index 0000000..be005c1 --- /dev/null +++ b/docs/grid_square.js.html @@ -0,0 +1,46 @@ +Source: grid/square.js
On this page

grid_square.js

import { range } from "d3-array";
+const d3 = Object.assign({}, { range });
+
+/**
+ * @function grid/square
+ * @description The `grid.square` function allows to create a square geoJSON grid in SVG coordinates.
+ * @see {@link https://observablehq.com/@neocartocnrs/regular-grids}
+ * @property {number} [step = 50] - step of the grid
+ * @property {number} [width = 1000] - width of the grid
+ * @property {number} [height = 500] - height of the grid
+ * @example
+ * geoviz.grid.square(50, 1000, 500)
+ */
+export function square(step = 50, width = 1000, height = 500) {
+  // build grid
+  let y = d3.range(0 + step / 2, height, step).reverse();
+  let x = d3.range(0 + step / 2, width, step);
+  let grid = x.map((x) => y.map((y) => [x, y])).flat();
+
+  let s = step / 2;
+  // build object
+  let result = grid.map((d, i) => {
+    return {
+      type: "Feature",
+      geometry: {
+        type: "Polygon",
+        coordinates: [
+          [
+            [d[0] - s, d[1] + s],
+            [d[0] + s, d[1] + s],
+            [d[0] + s, d[1] - s],
+            [d[0] - s, d[1] - s],
+            [d[0] - s, d[1] + s],
+          ],
+        ],
+      },
+      properties: {
+        index: i,
+      },
+    };
+  });
+  return { type: "FeatureCollection", features: result };
+}
+
Home
\ No newline at end of file diff --git a/docs/grid_triangle.js.html b/docs/grid_triangle.js.html new file mode 100644 index 0000000..0fa87e4 --- /dev/null +++ b/docs/grid_triangle.js.html @@ -0,0 +1,67 @@ +Source: grid/triangle.js
On this page

grid_triangle.js

import { range, max } from "d3-array";
+const d3 = Object.assign({}, { range, max });
+
+/**
+ * @function grid/triangle
+ * @description The `grid.triangle` function allows to create a triangle geoJSON grid in SVG coordinates.
+ * @see {@link https://observablehq.com/@neocartocnrs/regular-grids}
+ * @property {number} [step = 50] - step of the grid
+ * @property {number} [width = 1000] - width of the grid
+ * @property {number} [height = 500] - height of the grid
+ * @example
+ * geoviz.grid.triangle(50, 1000, 500)
+ */
+export function triangle(step = 50, width = 1000, height = 500) {
+  let triangletop = (p, size) => {
+    let h = (Math.sqrt(3) / 2) * size;
+    let p1 = [p[0] + size / 2, p[1]];
+    let p2 = [p[0], p[1] - h];
+    let p3 = [p[0] - size / 2, p[1]];
+    return [p1, p2, p3, p1];
+  };
+
+  let trianglebottom = (p, size) => {
+    let h = (Math.sqrt(3) / 2) * size;
+    let p1 = [p[0] + size / 2, p[1]];
+    let p2 = [p[0], p[1] + h];
+    let p3 = [p[0] - size / 2, p[1]];
+    return [p1, p2, p3, p1];
+  };
+
+  let size = step / Math.sqrt(3);
+  let h = (Math.sqrt(3) / 2) * step;
+
+  // build grid
+
+  let y = d3.range(0, height + size, h).reverse();
+  if (y.length % 2) {
+    y.unshift(d3.max(y) + h);
+  }
+  let x = d3.range(0, width + size, step);
+  let grid = x.map((x, i) => y.map((y) => [x, y])).flat();
+  grid = grid.map((d, i) => {
+    return i % 2 == 1 ? [d[0] + step / 2, d[1]] : d;
+  });
+
+  let nb = grid.length;
+  grid = grid.concat(grid);
+
+  // build object
+  let result = grid.map((d, i) => {
+    return {
+      type: "Feature",
+      geometry: {
+        type: "Polygon",
+        coordinates:
+          i < nb ? [triangletop(d, step)] : [trianglebottom(d, step)],
+      },
+      properties: {
+        index: i,
+      },
+    };
+  });
+  return { type: "FeatureCollection", features: result };
+}
+
Home
\ No newline at end of file diff --git a/docs/helpers_tooltip.js.html b/docs/helpers_tooltip.js.html index e29626e..c61a9f4 100644 --- a/docs/helpers_tooltip.js.html +++ b/docs/helpers_tooltip.js.html @@ -1,6 +1,6 @@ Source: helpers/tooltip.js
On this page

helpers_tooltip.js

import { select, pointers } from "d3-selection";
+    
On this page

helpers_tooltip.js

import { select, pointers } from "d3-selection";
 const d3 = Object.assign({}, { select, pointers });
 
 /**
@@ -274,4 +274,4 @@
     });
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/index.html b/docs/index.html index b300708..a11c649 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,6 +1,6 @@ Geoviz
On this page

npm jsdeliver license code size github stars

Geoviz JavaScript library

Tags #cartography #maps #geoviz #dataviz #JSspatial #Observable #FrontEndCartography

geoviz is a JavaScript library for designing thematic maps. The library provides a set of d3 compatible functions that you can mix with the usual d3 syntax. The library is designed to be intuitive and concise. It allow to manage different geographic layers (points, lines, polygons) and marks (circles, labels, scale bar, title, north arrow, etc.) to design pretty maps. Its use is particularly well suited to Observable notebooks. Maps deigned with geoviz are:

🌏 live demo Observable notebook simple map choropleth typology bubble dorling Mercator tiles

💻 Source code github

💡 Suggestions/bugs issues

Installation

In the browser

<script src="https://cdn.jsdelivr.net/npm/geoviz" charset="utf-8"></script>
+    
On this page

npm jsdeliver license code size github stars

Geoviz JavaScript library

Tags #cartography #maps #geoviz #dataviz #JSspatial #Observable #FrontEndCartography

geoviz is a JavaScript library for designing thematic maps. The library provides a set of d3 compatible functions that you can mix with the usual d3 syntax. The library is designed to be intuitive and concise. It allow to manage different geographic layers (points, lines, polygons) and marks (circles, labels, scale bar, title, north arrow, etc.) to design pretty maps. Its use is particularly well suited to Observable notebooks. Maps deigned with geoviz are:

🌏 live demo Observable notebook simple map choropleth typology bubble dorling Mercator tiles

💻 Source code github

💡 Suggestions/bugs issues

Installation

In the browser

<script src="https://cdn.jsdelivr.net/npm/geoviz" charset="utf-8"></script>
 

In Observable notebooks

geoviz = require("geoviz")
 

Marks

The geoviz library provides several graphic marks that will allow you to draw your maps. circles, semi-circles, graticules, paths, scale, legends... Each mark has a specific function.

📚 Map marks path() circle() square() halfcircle() spike() tile()

📚 Layout marks header() footer() graticule() outline() north() scalebar() text()

📚 Legend marks legend.box() legend.choro_horizontal() legend.choro_vertical() legend.circles_half() legend.circles_nested() legend.circles() legend.squares() legend.squares_nested() legend.mushrooms() legend.spikes() legend.typo_horizontal() legend.typo_vertical()

For example:

// To display a geoJSON
 viz.path({data: *a geoJSON*})
@@ -48,4 +48,4 @@
 

📚 plot/choro()

🌏 live demo choropleth

Typology

By using type = "typo", you can design a qualitative typo map. Find below a minimal example.

geoviz.plot({type = "typo", data = *a geoJSON*, var = *a field*})
 

📚 plot/typo()

🌏 live demo typology

Proportional symbols + choropleth

By using type = "propchoro", you can design a map with proportionnal symbols with graduated colors. Find below a minimal example.

geoviz.plot({type = "propchoro", data = *a geoJSON*, var1 = *a field*, var2 = *a field*})
 

📚 plot/propchoro()

🌏 live demo prop

Proportional symbols + typology

By using type = "proptypo", you can design a map with proportionnal symbols with qualitative colors. Find below a minimal example.

geoviz.plot({type = "proptypo", data = *a geoJSON*, var1 = *a field*, var2 = *a field*})
-

📚 plot/proptypo()

🌏 live demo prop

Interactivity

Maps created by geoviz are zoomable and interactive.

🌏 live demo tooltip pan and zoom interactivity

Helpers

Finally, geoviz provides a toolbox of useful functions for cartography.

📚 tool.addfonts() tool/centroid() tool.choro() tool.typo() tool.dissolve() tool.dodge() tool.featurecollection() tool.geotable() tool.rewind() tool.merge() tool.proj4d3() tool.project() tool.unproject() tool.replicate() tool.ridge() tool.random() tool.radius()

🌏 live demo Handle geometries

Nicolas Lambert 2024 - MIT License
\ No newline at end of file +

📚 plot/proptypo()

🌏 live demo prop

Interactivity

Maps created by geoviz are zoomable and interactive.

🌏 live demo tooltip pan and zoom interactivity

Helpers

Finally, geoviz provides a toolbox of useful functions for cartography.

📚 tool.addfonts() tool/centroid() tool.choro() tool.typo() tool.dissolve() tool.dodge() tool.featurecollection() tool.geotable() tool.rewind() tool.merge() tool.proj4d3() tool.project() tool.unproject() tool.replicate() tool.ridge() tool.random() tool.radius()

🌏 live demo Handle geometries

Home
\ No newline at end of file diff --git a/docs/legend_box.js.html b/docs/legend_box.js.html index 875dc33..22a82d1 100644 --- a/docs/legend_box.js.html +++ b/docs/legend_box.js.html @@ -1,6 +1,6 @@ Source: legend/box.js
On this page

legend_box.js

import { create } from "../container/create";
+    
On this page

legend_box.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash } from "../helpers/camelcase";
 import { getsize } from "../helpers/getsize";
@@ -140,4 +140,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_choro-horizontal.js.html b/docs/legend_choro-horizontal.js.html index d2413ca..c8650b1 100644 --- a/docs/legend_choro-horizontal.js.html +++ b/docs/legend_choro-horizontal.js.html @@ -1,6 +1,6 @@ Source: legend/choro-horizontal.js
On this page

legend_choro-horizontal.js

import { create } from "../container/create";
+    
On this page

legend_choro-horizontal.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash } from "../helpers/camelcase";
 import { roundarray } from "../helpers/rounding";
@@ -218,4 +218,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_choro-vertical.js.html b/docs/legend_choro-vertical.js.html index 447a279..98893bc 100644 --- a/docs/legend_choro-vertical.js.html +++ b/docs/legend_choro-vertical.js.html @@ -1,6 +1,6 @@ Source: legend/choro-vertical.js
On this page

legend_choro-vertical.js

import { create } from "../container/create";
+    
On this page

legend_choro-vertical.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash } from "../helpers/camelcase";
 import { roundarray } from "../helpers/rounding";
@@ -224,4 +224,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_circles-half.js.html b/docs/legend_circles-half.js.html index 29e38c1..62031ed 100644 --- a/docs/legend_circles-half.js.html +++ b/docs/legend_circles-half.js.html @@ -1,6 +1,6 @@ Source: legend/circles-half.js
On this page

legend_circles-half.js

import { create } from "../container/create.js";
+    
On this page

legend_circles-half.js

import { create } from "../container/create.js";
 import { render } from "../container/render.js";
 import { camelcasetodash } from "../helpers/camelcase.js";
 import { datatoradius } from "../helpers/datatoradius.js";
@@ -253,4 +253,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_circles-nested.js.html b/docs/legend_circles-nested.js.html index 8724620..d3f1788 100644 --- a/docs/legend_circles-nested.js.html +++ b/docs/legend_circles-nested.js.html @@ -1,6 +1,6 @@ Source: legend/circles-nested.js
On this page

legend_circles-nested.js

import { create } from "../container/create";
+    
On this page

legend_circles-nested.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash } from "../helpers/camelcase";
 import { datatoradius } from "../helpers/datatoradius";
@@ -240,4 +240,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_circles.js.html b/docs/legend_circles.js.html index b2ca690..beadea2 100644 --- a/docs/legend_circles.js.html +++ b/docs/legend_circles.js.html @@ -1,6 +1,6 @@ Source: legend/circles.js
On this page

legend_circles.js

import { create } from "../container/create";
+    
On this page

legend_circles.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash } from "../helpers/camelcase";
 import { datatoradius } from "../helpers/datatoradius";
@@ -249,4 +249,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_mushrooms.js.html b/docs/legend_mushrooms.js.html index aa572eb..dd33f21 100644 --- a/docs/legend_mushrooms.js.html +++ b/docs/legend_mushrooms.js.html @@ -1,6 +1,6 @@ Source: legend/mushrooms.js
On this page

legend_mushrooms.js

import { create } from "../container/create.js";
+    
On this page

legend_mushrooms.js

import { create } from "../container/create.js";
 import { render } from "../container/render.js";
 import { camelcasetodash } from "../helpers/camelcase.js";
 import { datatoradius } from "../helpers/datatoradius.js";
@@ -427,4 +427,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_spikes.js.html b/docs/legend_spikes.js.html index 6a5f0b9..f97f2b5 100644 --- a/docs/legend_spikes.js.html +++ b/docs/legend_spikes.js.html @@ -1,6 +1,6 @@ Source: legend/spikes.js
On this page

legend_spikes.js

import { create } from "../container/create.js";
+    
On this page

legend_spikes.js

import { create } from "../container/create.js";
 import { render } from "../container/render.js";
 import { camelcasetodash } from "../helpers/camelcase.js";
 import { datatoheight } from "../helpers/datatoheight.js";
@@ -204,4 +204,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_squares-nested.js.html b/docs/legend_squares-nested.js.html index e72481a..167b1f1 100644 --- a/docs/legend_squares-nested.js.html +++ b/docs/legend_squares-nested.js.html @@ -1,6 +1,6 @@ Source: legend/squares-nested.js
On this page

legend_squares-nested.js

import { create } from "../container/create";
+    
On this page

legend_squares-nested.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash } from "../helpers/camelcase";
 import { datatoradius } from "../helpers/datatoradius";
@@ -244,4 +244,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_squares.js.html b/docs/legend_squares.js.html index ced8895..1e8d4f8 100644 --- a/docs/legend_squares.js.html +++ b/docs/legend_squares.js.html @@ -1,6 +1,6 @@ Source: legend/squares.js
On this page

legend_squares.js

import { create } from "../container/create";
+    
On this page

legend_squares.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash } from "../helpers/camelcase";
 import { datatoradius } from "../helpers/datatoradius";
@@ -256,4 +256,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_symbol-horizontal.js.html b/docs/legend_symbol-horizontal.js.html index 974441d..eb70342 100644 --- a/docs/legend_symbol-horizontal.js.html +++ b/docs/legend_symbol-horizontal.js.html @@ -1,6 +1,6 @@ Source: legend/symbol-horizontal.js
On this page

legend_symbol-horizontal.js

import { create } from "../container/create";
+    
On this page

legend_symbol-horizontal.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash } from "../helpers/camelcase";
 import { getsize } from "../helpers/getsize";
@@ -244,4 +244,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_symbol-vertical.js.html b/docs/legend_symbol-vertical.js.html index 9c74b4d..e671484 100644 --- a/docs/legend_symbol-vertical.js.html +++ b/docs/legend_symbol-vertical.js.html @@ -1,6 +1,6 @@ Source: legend/symbol-vertical.js
On this page

legend_symbol-vertical.js

import { create } from "../container/create";
+    
On this page

legend_symbol-vertical.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash } from "../helpers/camelcase";
 import { getsize } from "../helpers/getsize";
@@ -241,4 +241,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_typo-horizontal.js.html b/docs/legend_typo-horizontal.js.html index 4f23310..f63bd07 100644 --- a/docs/legend_typo-horizontal.js.html +++ b/docs/legend_typo-horizontal.js.html @@ -1,6 +1,6 @@ Source: legend/typo-horizontal.js
On this page

legend_typo-horizontal.js

import { create } from "../container/create";
+    
On this page

legend_typo-horizontal.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash } from "../helpers/camelcase";
 import { getsize } from "../helpers/getsize";
@@ -208,4 +208,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/legend_typo-vertical.js.html b/docs/legend_typo-vertical.js.html index f7adbb2..612a966 100644 --- a/docs/legend_typo-vertical.js.html +++ b/docs/legend_typo-vertical.js.html @@ -1,6 +1,6 @@ Source: legend/typo-vertical.js
On this page

legend_typo-vertical.js

import { create } from "../container/create";
+    
On this page

legend_typo-vertical.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash } from "../helpers/camelcase";
 import { getsize } from "../helpers/getsize";
@@ -209,4 +209,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_circle.js.html b/docs/mark_circle.js.html index 219f708..5911124 100644 --- a/docs/mark_circle.js.html +++ b/docs/mark_circle.js.html @@ -1,6 +1,6 @@ Source: mark/circle.js
On this page

mark_circle.js

import { scaleSqrt } from "d3-scale";
+    
On this page

mark_circle.js

import { scaleSqrt } from "d3-scale";
 import { max, descending } from "d3-array";
 import { geoPath, geoIdentity } from "d3-geo";
 const d3 = Object.assign(
@@ -319,9 +319,9 @@
           k,
         }
       );
-      return (d, rr) => radius.r(d.properties[rr]);
+      return (d, rr) => radius.r(Math.abs(d.properties[rr]));
     case "value":
       return (d) => attr;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_footer.js.html b/docs/mark_footer.js.html index adee4d2..6af61c5 100644 --- a/docs/mark_footer.js.html +++ b/docs/mark_footer.js.html @@ -1,6 +1,6 @@ Source: mark/footer.js
On this page

mark_footer.js

import { create } from "../container/create";
+    
On this page

mark_footer.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash, getsize, unique } from "../helpers/utils";
 
@@ -171,4 +171,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_graticule.js.html b/docs/mark_graticule.js.html index a6439e1..a6aa08f 100644 --- a/docs/mark_graticule.js.html +++ b/docs/mark_graticule.js.html @@ -1,6 +1,6 @@ Source: mark/graticule.js
On this page

mark_graticule.js

import { create } from "../container/create";
+    
On this page

mark_graticule.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash, unique } from "../helpers/utils";
 import { geoGraticule, geoPath, geoNaturalEarth1 } from "d3-geo";
@@ -131,4 +131,4 @@
     }
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_halfcircle.js.html b/docs/mark_halfcircle.js.html index f8d9e96..26f6e21 100644 --- a/docs/mark_halfcircle.js.html +++ b/docs/mark_halfcircle.js.html @@ -1,6 +1,6 @@ Source: mark/halfcircle.js
On this page

mark_halfcircle.js

import { scaleSqrt } from "d3-scale";
+    
On this page

mark_halfcircle.js

import { scaleSqrt } from "d3-scale";
 import { arc } from "d3-shape";
 import { max, descending } from "d3-array";
 import { geoPath, geoIdentity } from "d3-geo";
@@ -339,4 +339,4 @@
       return (d) => attr;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_header.js.html b/docs/mark_header.js.html index ec61bc8..1f0f887 100644 --- a/docs/mark_header.js.html +++ b/docs/mark_header.js.html @@ -1,6 +1,6 @@ Source: mark/header.js
On this page

mark_header.js

import { create } from "../container/create";
+    
On this page

mark_header.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash, getsize, unique } from "../helpers/utils";
 
@@ -171,4 +171,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_north.js.html b/docs/mark_north.js.html index 666b9d9..fea7194 100644 --- a/docs/mark_north.js.html +++ b/docs/mark_north.js.html @@ -1,6 +1,6 @@ Source: mark/north.js
On this page

mark_north.js

import { create } from "../container/create";
+    
On this page

mark_north.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { camelcasetodash, unique, northangle } from "../helpers/utils";
 import { geoNaturalEarth1 } from "d3-geo";
@@ -123,4 +123,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_outline.js.html b/docs/mark_outline.js.html index f2f377f..62376a6 100644 --- a/docs/mark_outline.js.html +++ b/docs/mark_outline.js.html @@ -1,6 +1,6 @@ Source: mark/outline.js
On this page

mark_outline.js

import { geoPath, geoNaturalEarth1 } from "d3-geo";
+    
On this page

mark_outline.js

import { geoPath, geoNaturalEarth1 } from "d3-geo";
 const d3 = Object.assign({}, { geoPath, geoNaturalEarth1 });
 import { create } from "../container/create";
 import { render } from "../container/render";
@@ -110,4 +110,4 @@
     }
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_path.js.html b/docs/mark_path.js.html index b056591..a76abb8 100644 --- a/docs/mark_path.js.html +++ b/docs/mark_path.js.html @@ -1,6 +1,6 @@ Source: mark/path.js
On this page

mark_path.js

import { geoPath, geoIdentity } from "d3-geo";
+    
On this page

mark_path.js

import { geoPath, geoIdentity } from "d3-geo";
 const d3 = Object.assign({}, { geoPath, geoIdentity });
 import { create } from "../container/create";
 import { render } from "../container/render";
@@ -61,6 +61,7 @@
     coords: "geo",
     clip: true,
     strokeWidth: 1,
+    clipPath: undefined,
   };
   let opts = { ...options, ...(newcontainer ? arg1 : arg2) };
 
@@ -137,11 +138,26 @@
       : svg.projection;
   let path = d3.geoPath(projection);
 
+  // ClipPath
+  if (opts.clipPath) {
+    layer.attr("clip-path", opts.clipPath);
+    opts.clip = false;
+  }
+
   // Specific attributes
   let entries = Object.entries(opts).map((d) => d[0]);
   const notspecificattr = entries.filter(
     (d) =>
-      !["mark", "id", "datum", "data", "coords", "tip", "tipstyle"].includes(d)
+      ![
+        "mark",
+        "id",
+        "datum",
+        "data",
+        "coords",
+        "tip",
+        "tipstyle",
+        "clipPath",
+      ].includes(d)
   );
 
   // layer attributes
@@ -225,4 +241,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_scalebar.js.html b/docs/mark_scalebar.js.html index f1eacf6..82dbce5 100644 --- a/docs/mark_scalebar.js.html +++ b/docs/mark_scalebar.js.html @@ -1,6 +1,6 @@ Source: mark/scalebar.js
On this page

mark_scalebar.js

import * as geoScaleBar from "d3-geo-scale-bar";
+    
On this page

mark_scalebar.js

import * as geoScaleBar from "d3-geo-scale-bar";
 import { geoNaturalEarth1 } from "d3-geo";
 const d3 = Object.assign({ geoNaturalEarth1 }, geoScaleBar);
 import { create } from "../container/create";
@@ -155,4 +155,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_spike.js.html b/docs/mark_spike.js.html index f067792..6332052 100644 --- a/docs/mark_spike.js.html +++ b/docs/mark_spike.js.html @@ -1,6 +1,6 @@ Source: mark/spike.js
On this page

mark_spike.js

import { scaleSqrt } from "d3-scale";
+    
On this page

mark_spike.js

import { scaleSqrt } from "d3-scale";
 import { max, descending } from "d3-array";
 import { geoPath, geoIdentity } from "d3-geo";
 const d3 = Object.assign(
@@ -319,4 +319,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_square.js.html b/docs/mark_square.js.html index dc786d0..ea2b3ea 100644 --- a/docs/mark_square.js.html +++ b/docs/mark_square.js.html @@ -1,6 +1,6 @@ Source: mark/square.js
On this page

mark_square.js

import { scaleSqrt } from "d3-scale";
+    
On this page

mark_square.js

import { scaleSqrt } from "d3-scale";
 import { arc } from "d3-shape";
 import { radius as computeradius } from "../tool/radius";
 import { max, descending } from "d3-array";
@@ -320,9 +320,9 @@
           k,
         }
       );
-      return (d, rr) => radius.r(d.properties[rr]);
+      return (d, rr) => radius.r(Math.abs(d.properties[rr]));
     case "value":
       return (d) => attr;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_symbol.js.html b/docs/mark_symbol.js.html index 3926698..54e551f 100644 --- a/docs/mark_symbol.js.html +++ b/docs/mark_symbol.js.html @@ -1,6 +1,6 @@ Source: mark/symbol.js
On this page

mark_symbol.js

import { scaleSqrt } from "d3-scale";
+    
On this page

mark_symbol.js

import { scaleSqrt } from "d3-scale";
 import { max, descending } from "d3-array";
 import { geoPath, geoIdentity } from "d3-geo";
 const d3 = Object.assign(
@@ -485,4 +485,4 @@
     }
   };
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_text.js.html b/docs/mark_text.js.html index e32eeb5..4327ff5 100644 --- a/docs/mark_text.js.html +++ b/docs/mark_text.js.html @@ -1,6 +1,6 @@ Source: mark/text.js
On this page

mark_text.js

import { geoPath, geoIdentity, geoCentroid } from "d3-geo";
+    
On this page

mark_text.js

import { geoPath, geoIdentity, geoCentroid } from "d3-geo";
 const d3 = Object.assign({}, { geoPath, geoIdentity, geoCentroid });
 import { create } from "../container/create";
 import { render } from "../container/render";
@@ -275,4 +275,4 @@
     return `#${opts.id}`;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/mark_tile.js.html b/docs/mark_tile.js.html index 16d9b21..df2b602 100644 --- a/docs/mark_tile.js.html +++ b/docs/mark_tile.js.html @@ -1,6 +1,6 @@ Source: mark/tile.js
On this page

mark_tile.js

import { tile as d3tile } from "d3-tile";
+    
On this page

mark_tile.js

import { tile as d3tile } from "d3-tile";
 import { geoMercator } from "d3-geo";
 import { create } from "../container/create";
 import { render } from "../container/render";
@@ -254,4 +254,4 @@
       `  https://server.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer/tile/${z}/${y}/${x}`,
   },
 ];
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/plot_plot.js.html b/docs/plot_plot.js.html index 07a0718..087d9f4 100644 --- a/docs/plot_plot.js.html +++ b/docs/plot_plot.js.html @@ -1,6 +1,6 @@ Source: plot/plot.js
On this page

plot_plot.js

// Marks
+    
On this page

plot_plot.js

// Marks
 import { graticule } from "../mark/graticule";
 import { outline } from "../mark/outline";
 import { path } from "../mark/path";
@@ -231,4 +231,4 @@
       break;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/plot_plot_choro.js.html b/docs/plot_plot_choro.js.html index 1caa31f..a18c6c7 100644 --- a/docs/plot_plot_choro.js.html +++ b/docs/plot_plot_choro.js.html @@ -1,6 +1,6 @@ Source: plot/plot_choro.js
On this page

plot_plot_choro.js

import { choro } from "../tool/choro";
+    
On this page

plot_plot_choro.js

import { choro } from "../tool/choro";
 import { create } from "../container/create";
 import { path } from "../mark/path";
 import { render } from "../container/render";
@@ -171,4 +171,4 @@
     return ids;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/plot_plot_prop.js.html b/docs/plot_plot_prop.js.html index 4eb5ed3..c8473c3 100644 --- a/docs/plot_plot_prop.js.html +++ b/docs/plot_plot_prop.js.html @@ -1,6 +1,6 @@ Source: plot/plot_prop.js
On this page

plot_plot_prop.js

import { create } from "../container/create";
+    
On this page

plot_plot_prop.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { implantation, unique } from "../helpers/utils";
 
@@ -165,4 +165,4 @@
     return ids;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/plot_plot_propchoro.js.html b/docs/plot_plot_propchoro.js.html index 1a783a8..6620543 100644 --- a/docs/plot_plot_propchoro.js.html +++ b/docs/plot_plot_propchoro.js.html @@ -1,6 +1,6 @@ Source: plot/plot_propchoro.js
On this page

plot_plot_propchoro.js

import { create } from "../container/create";
+    
On this page

plot_plot_propchoro.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { choro } from "../tool/choro";
 import { choro_vertical } from "../legend/choro-vertical";
@@ -244,4 +244,4 @@
     return ids;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/plot_plot_proptypo.js.html b/docs/plot_plot_proptypo.js.html index 6c0be80..7894008 100644 --- a/docs/plot_plot_proptypo.js.html +++ b/docs/plot_plot_proptypo.js.html @@ -1,6 +1,6 @@ Source: plot/plot_proptypo.js
On this page

plot_plot_proptypo.js

import { create } from "../container/create";
+    
On this page

plot_plot_proptypo.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { typo } from "../tool/typo";
 import { typo_vertical } from "../legend/typo-vertical";
@@ -232,4 +232,4 @@
     return ids;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/plot_plot_symbol.js.html b/docs/plot_plot_symbol.js.html index c665517..8d49bc5 100644 --- a/docs/plot_plot_symbol.js.html +++ b/docs/plot_plot_symbol.js.html @@ -1,6 +1,6 @@ Source: plot/plot_symbol.js
On this page

plot_plot_symbol.js

import { create } from "../container/create";
+    
On this page

plot_plot_symbol.js

import { create } from "../container/create";
 import { render } from "../container/render";
 import { implantation, propertiesentries } from "../helpers/utils";
 import { picto } from "../helpers/picto";
@@ -175,4 +175,4 @@
     }
   };
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/plot_plot_typo.js.html b/docs/plot_plot_typo.js.html index 48e18a1..c7ae844 100644 --- a/docs/plot_plot_typo.js.html +++ b/docs/plot_plot_typo.js.html @@ -1,6 +1,6 @@ Source: plot/plot_typo.js
On this page

plot_plot_typo.js

import { typo } from "../tool/typo";
+    
On this page

plot_plot_typo.js

import { typo } from "../tool/typo";
 import { create } from "../container/create";
 import { path } from "../mark/path";
 import { render } from "../container/render";
@@ -159,4 +159,4 @@
     return ids;
   }
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_addfonts.js.html b/docs/tool_addfonts.js.html index 3facb44..2619282 100644 --- a/docs/tool_addfonts.js.html +++ b/docs/tool_addfonts.js.html @@ -1,6 +1,6 @@ Source: tool/addfonts.js
On this page

tool_addfonts.js

/**
+    
On this page

tool_addfonts.js

/**
  * @function tool/addonts
  * @description The `tool.addonts` function allows add font to the document from an url.
  * @property {string} fontFamily - font family name
@@ -21,4 +21,4 @@
   });
   return fontNames;
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_centroid.js.html b/docs/tool_centroid.js.html index bfb6499..9df4f5c 100644 --- a/docs/tool_centroid.js.html +++ b/docs/tool_centroid.js.html @@ -1,6 +1,6 @@ Source: tool/centroid.js
On this page

tool_centroid.js

// Imports
+    
On this page

tool_centroid.js

// Imports
 import { geoArea, geoCentroid, geoIdentity, geoPath } from "d3-geo";
 const d3 = Object.assign({}, { geoArea, geoCentroid, geoIdentity, geoPath });
 
@@ -61,4 +61,4 @@
 
   return geojson;
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_choro.js.html b/docs/tool_choro.js.html index 8b0d4f4..6737b8a 100644 --- a/docs/tool_choro.js.html +++ b/docs/tool_choro.js.html @@ -1,6 +1,6 @@ Source: tool/choro.js
On this page

tool_choro.js

import { isNumber } from "../helpers/isnuber";
+    
On this page

tool_choro.js

import { isNumber } from "../helpers/isnuber";
 import * as discr from "statsbreaks";
 import { getColors, getPalettes } from "dicopal";
 // import { getColors } from "dicopal";
@@ -106,4 +106,4 @@
 
   return cols;
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_dissolve.js.html b/docs/tool_dissolve.js.html index 6cbd293..2cd34ce 100644 --- a/docs/tool_dissolve.js.html +++ b/docs/tool_dissolve.js.html @@ -1,6 +1,6 @@ Source: tool/dissolve.js
On this page

tool_dissolve.js

import { geoArea } from "d3-geo";
+    
On this page

tool_dissolve.js

import { geoArea } from "d3-geo";
 const d3 = Object.assign({}, { geoArea });
 
 /**
@@ -57,4 +57,4 @@
 
   return JSON.parse(JSON.stringify(result));
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_dodge.js.html b/docs/tool_dodge.js.html index 546e747..4552072 100644 --- a/docs/tool_dodge.js.html +++ b/docs/tool_dodge.js.html @@ -1,6 +1,6 @@ Source: tool/dodge.js
On this page

tool_dodge.js

import { forceX, forceY, forceCollide, forceSimulation } from "d3-force";
+    
On this page

tool_dodge.js

import { forceX, forceY, forceCollide, forceSimulation } from "d3-force";
 import { max } from "d3-array";
 import { scaleSqrt } from "d3-scale";
 const d3 = Object.assign(
@@ -107,4 +107,4 @@
 
   return { type: "FeatureCollection", crs: null, features: rawfeatures };
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_dotstogrid.js.html b/docs/tool_dotstogrid.js.html index 37652ed..8668de3 100644 --- a/docs/tool_dotstogrid.js.html +++ b/docs/tool_dotstogrid.js.html @@ -1,6 +1,6 @@ Source: tool/dotstogrid.js
On this page

tool_dotstogrid.js

// Imports
+    
On this page

tool_dotstogrid.js

// Imports
 import { range, max } from "d3-array";
 import { Delaunay } from "d3-delaunay";
 import { geoProject } from "d3-geo-projection";
@@ -246,4 +246,4 @@
   });
   return result;
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_featurecollection.js.html b/docs/tool_featurecollection.js.html index 762def3..e99272a 100644 --- a/docs/tool_featurecollection.js.html +++ b/docs/tool_featurecollection.js.html @@ -1,6 +1,6 @@ Source: tool/featurecollection.js
On this page

tool_featurecollection.js

import { whatisit } from "../helpers/whatisit";
+    
On this page

tool_featurecollection.js

import { whatisit } from "../helpers/whatisit";
 import { coords2geo } from "../helpers/coords2geo";
 import { bbox } from "../helpers/bbox";
 
@@ -99,4 +99,4 @@
 
   return { type: "FeatureCollection", features };
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_geotable.js.html b/docs/tool_geotable.js.html index ce0fa78..ab11056 100644 --- a/docs/tool_geotable.js.html +++ b/docs/tool_geotable.js.html @@ -1,6 +1,6 @@ Source: tool/geotable.js
On this page

tool_geotable.js

/**
+    
On this page

tool_geotable.js

/**
  * @function tool/geotable
  * @description `geotable` is a function to create an array on objects containing properties and geomeytries, froam a GeoJSON FeatureCollection. This makes it easy to sort, extract data, etc. tool.featurecollection(geotable, { geometry: "geometry" }) can be used to rebuild a valid geoJSON. The function returns an array of an array of FeatureCollections.
  * @see {@link https://observablehq.com/@neocartocnrs/handle-geometries}
@@ -15,4 +15,4 @@
   );
   return table;
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_height.js.html b/docs/tool_height.js.html index 1fbfa22..8f9885b 100644 --- a/docs/tool_height.js.html +++ b/docs/tool_height.js.html @@ -1,6 +1,6 @@ Source: tool/height.js
On this page

tool_height.js

import { isNumber } from "../helpers/utils";
+    
On this page

tool_height.js

import { isNumber } from "../helpers/utils";
 import { max, extent } from "d3-array";
 import { scaleLinear } from "d3-scale";
 const d3 = Object.assign({}, { scaleLinear, max, extent });
@@ -26,4 +26,4 @@
     h: d3.scaleLinear().domain([0, valmax]).range([0, k]).unknown(0),
   };
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_merge.js.html b/docs/tool_merge.js.html index 624c07c..816d8a7 100644 --- a/docs/tool_merge.js.html +++ b/docs/tool_merge.js.html @@ -1,6 +1,6 @@ Source: tool/merge.js
On this page

tool_merge.js

import { columns } from "../helpers/utils";
+    
On this page

tool_merge.js

import { columns } from "../helpers/utils";
 
 /**
  * @function tool/merge
@@ -111,4 +111,4 @@
 
   return [newArray, accessor.get(id)];
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_proj4d3.js.html b/docs/tool_proj4d3.js.html index 56dadc9..e80a111 100644 --- a/docs/tool_proj4d3.js.html +++ b/docs/tool_proj4d3.js.html @@ -1,6 +1,6 @@ Source: tool/proj4d3.js
On this page

tool_proj4d3.js

import { geoProjection } from "d3-geo";
+    
On this page

tool_proj4d3.js

import { geoProjection } from "d3-geo";
 const d3 = Object.assign({}, { geoProjection });
 
 /**
@@ -30,4 +30,4 @@
   projection.raw = raw;
   return projection;
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_project.js.html b/docs/tool_project.js.html index 71ac748..0f38268 100644 --- a/docs/tool_project.js.html +++ b/docs/tool_project.js.html @@ -1,6 +1,6 @@ Source: tool/project.js
On this page

tool_project.js

import { geoProject } from "d3-geo-projection";
+    
On this page

tool_project.js

import { geoProject } from "d3-geo-projection";
 const d3 = Object.assign({}, { geoProject });
 
 /**
@@ -15,4 +15,4 @@
 export function project(data, { projection = null } = {}) {
   return projection == null ? data : d3.geoProject(data, projection);
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_radius.js.html b/docs/tool_radius.js.html index ea256a1..2a78fcd 100644 --- a/docs/tool_radius.js.html +++ b/docs/tool_radius.js.html @@ -1,6 +1,6 @@ Source: tool/radius.js
On this page

tool_radius.js

import { isNumber } from "../helpers/utils";
+    
On this page

tool_radius.js

import { isNumber } from "../helpers/utils";
 import { max, extent } from "d3-array";
 import { scaleSqrt } from "d3-scale";
 const d3 = Object.assign({}, { scaleSqrt, max, extent });
@@ -13,17 +13,29 @@
  * @property {string[]} [option.k = 50] - radius if the greater circle
  */
 
+// export function radius(data, { fixmax = undefined, k = 50 } = {}) {
+//   const valmax =
+//     fixmax != undefined ? fixmax : d3.max(data.map((d) => Math.abs(+d)));
+
+//   return {
+//     data: d3.extent(
+//       data.filter((d) => isNumber(d)).map((d) => Math.abs(Number(d)))
+//     ),
+//     k,
+//     fixmax,
+//     r: d3.scaleSqrt([0, valmax], [0, k]),
+//   };
+// }
+
 export function radius(data, { fixmax = undefined, k = 50 } = {}) {
-  const valmax =
-    fixmax != undefined ? fixmax : d3.max(data.map((d) => Math.abs(+d)));
+  let databs = data.map((d) => Math.abs(parseFloat(d)));
+  const valmax = fixmax != undefined ? fixmax : d3.max(databs);
 
   return {
-    data: d3.extent(
-      data.filter((d) => isNumber(d)).map((d) => Math.abs(Number(d)))
-    ),
+    data: d3.extent(databs.filter((d) => isNumber(d))),
     k,
     fixmax,
     r: d3.scaleSqrt([0, valmax], [0, k]),
   };
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_random.js.html b/docs/tool_random.js.html index 4e7f304..b1bdeb4 100644 --- a/docs/tool_random.js.html +++ b/docs/tool_random.js.html @@ -1,6 +1,6 @@ Source: tool/random.js
On this page

tool_random.js

/**
+    
On this page

tool_random.js

/**
  * @function tool/random
  * @description The `tool.random` function returns a random color among 20 predefined colors.
  */
@@ -29,4 +29,4 @@
   ];
   return cols[Math.floor(Math.random() * cols.length)];
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_replicate.js.html b/docs/tool_replicate.js.html index 165be60..a72a21a 100644 --- a/docs/tool_replicate.js.html +++ b/docs/tool_replicate.js.html @@ -1,6 +1,6 @@ Source: tool/replicate.js
On this page

tool_replicate.js

import { sum } from "d3-array";
+    
On this page

tool_replicate.js

import { sum } from "d3-array";
 const d3 = Object.assign({}, { sum });
 
 /**
@@ -31,4 +31,4 @@
   x.features = output;
   return x;
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_rewind.js.html b/docs/tool_rewind.js.html index 3211646..b3019ea 100644 --- a/docs/tool_rewind.js.html +++ b/docs/tool_rewind.js.html @@ -1,6 +1,6 @@ Source: tool/rewind.js
On this page

tool_rewind.js

/**
+    
On this page

tool_rewind.js

/**
  * @function tool/rewind
  * @description The `tool.rewind` function allows to generate compliant Polygon and MultiPolygon geometries. Adapted from MapBox geojson-rewind code (https://github.com/mapbox/grojson-rewind) under ISC license
  * @see {@link https://observablehq.com/@neocartocnrs/handle-geometries}
@@ -45,4 +45,4 @@
   }
   if (tArea + err >= 0 !== !!dir) ring.reverse();
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_ridge.js.html b/docs/tool_ridge.js.html index 746f41e..011fab1 100644 --- a/docs/tool_ridge.js.html +++ b/docs/tool_ridge.js.html @@ -1,6 +1,6 @@ Source: tool/ridge.js
On this page

tool_ridge.js

import { scaleLinear } from "d3-scale";
+    
On this page

tool_ridge.js

import { scaleLinear } from "d3-scale";
 import { min, max, mean, mode } from "d3-array";
 const d3 = Object.assign({}, { scaleLinear, min, max, mean, mode });
 
@@ -123,4 +123,4 @@
   }
   return d3.mode(arr);
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_symbols.js.html b/docs/tool_symbols.js.html index 54f1801..03e3416 100644 --- a/docs/tool_symbols.js.html +++ b/docs/tool_symbols.js.html @@ -1,6 +1,6 @@ Source: tool/symbols.js
On this page

tool_symbols.js

import { picto } from "../helpers/picto";
+    
On this page

tool_symbols.js

import { picto } from "../helpers/picto";
 import { create } from "d3-selection";
 const d3 = Object.assign({}, { create });
 
@@ -60,4 +60,4 @@
 
   return svg.node();
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_typo.js.html b/docs/tool_typo.js.html index dac2fb0..5f9b3c4 100644 --- a/docs/tool_typo.js.html +++ b/docs/tool_typo.js.html @@ -1,6 +1,6 @@ Source: tool/typo.js
On this page

tool_typo.js

import { getColors } from "dicopal";
+    
On this page

tool_typo.js

import { getColors } from "dicopal";
 import { scaleOrdinal } from "d3-scale";
 const d3 = Object.assign({}, { scaleOrdinal });
 
@@ -45,4 +45,4 @@
     colorize,
   };
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/docs/tool_unproject.js.html b/docs/tool_unproject.js.html index 25cfc01..f55cdfa 100644 --- a/docs/tool_unproject.js.html +++ b/docs/tool_unproject.js.html @@ -1,6 +1,6 @@ Source: tool/unproject.js
On this page

tool_unproject.js

/**
+    
On this page

tool_unproject.js

/**
  * @function tool/unproject
  * @description The `tool.unproject` function allow to unproject geometries. It returns a GeoJSON FeatureCollection with wgs84 coordinates
  * @see {@link https://observablehq.com/@neocartocnrs/handle-geometries}
@@ -27,4 +27,4 @@
     return unprojectCoords(coord, proj);
   });
 }
-
Nicolas Lambert 2024 - MIT License
\ No newline at end of file +
Home
\ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 94f74d5..135a742 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "dicopal": "^0.6.4", "docs": "^0.3.2-canary.0", "documentation": "^14.0.3", + "h3-js": "^4.1.0", "rollup": "^4.10.0", "statsbreaks": "^1.0.6", "versor": "^0.2.0" @@ -2431,6 +2432,16 @@ "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", "dev": true }, + "node_modules/h3-js": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/h3-js/-/h3-js-4.1.0.tgz", + "integrity": "sha512-LQhmMl1dRQQjMXPzJc7MpZ/CqPOWWuAvVEoVJM9n/s7vHypj+c3Pd5rLQCkAsOgAoAYKbNCsYFE++LF7MvSfCQ==", + "engines": { + "node": ">=4", + "npm": ">=3", + "yarn": ">=1.3.0" + } + }, "node_modules/handlebars": { "version": "4.7.8", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz", @@ -7543,6 +7554,11 @@ "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", "dev": true }, + "h3-js": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/h3-js/-/h3-js-4.1.0.tgz", + "integrity": "sha512-LQhmMl1dRQQjMXPzJc7MpZ/CqPOWWuAvVEoVJM9n/s7vHypj+c3Pd5rLQCkAsOgAoAYKbNCsYFE++LF7MvSfCQ==" + }, "handlebars": { "version": "4.7.8", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz", diff --git a/package.json b/package.json index af16a0e..0d9e099 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "dicopal": "^0.6.4", "docs": "^0.3.2-canary.0", "documentation": "^14.0.3", + "h3-js": "^4.1.0", "rollup": "^4.10.0", "statsbreaks": "^1.0.6", "versor": "^0.2.0" diff --git a/src/container/create.js b/src/container/create.js index d01e1a0..89dba3f 100644 --- a/src/container/create.js +++ b/src/container/create.js @@ -32,6 +32,8 @@ import { blur as addblur } from "../effect/blur.js"; import { shadow as addshadow } from "../effect/shadow.js"; import { radialGradient as addradialGradient } from "../effect/radialgradient.js"; +import { make as addgrid } from "../grid/make.js"; + import { circles_nested as addcircles_nested } from "../legend/circles-nested"; import { circles as addcircles } from "../legend/circles"; import { squares as addsquares } from "../legend/squares"; @@ -56,6 +58,7 @@ import { plot as addplot } from "../plot/plot.js"; * @see {@link https://observablehq.com/@neocartocnrs/geoviz} * * @property {number} [width = 1000] - width of the container. + * @property {number} [id = "map"] - id of the svg container. * @property {number} [height] - height of the container. This value is automatically calculated according to `domain`. But it can be forced by entering a value. * @property {object|object[]} [domain] - the domain corresponds to the geographical area to be displayed. It is defined by a geoJSON or an array containing geoJSONs. * @property {function|string} [projection] - d3 function of projection. See [d3-geo](https://github.com/d3/d3-geo) & [d3-geo-projection](https://github.com/d3/d3-geo-projection). You can aslo write "mercator" to use tiles. (default: "none") @@ -74,6 +77,7 @@ import { plot as addplot } from "../plot/plot.js"; export function create({ height = null, + id = "map", //projection = d3.geoEquirectangular(), projection = "none", domain, @@ -159,6 +163,7 @@ export function create({ .create2("svg") .attr("width", width) .attr("height", height) + .attr("id", id) .attr("viewBox", [0, 0, width, height]) .style("background-color", background); svg.append("defs").attr("id", "defs"); @@ -208,6 +213,14 @@ export function create({ }) ); + let grid = {}; + [{ id: "make", func: addgrid }].forEach( + (d) => + (grid[d.id] = function () { + return d.func(output, arguments[0]); + }) + ); + let legend = {}; [ { id: "circles_nested", func: addcircles_nested }, @@ -250,6 +263,7 @@ export function create({ return Object.assign(output, { ...mark, legend, + grid, effect, render: function () { return addrender(output, arguments[0]); diff --git a/src/grid/arbitrary.js b/src/grid/arbitrary.js index 5d5e40e..3bdf5d8 100644 --- a/src/grid/arbitrary.js +++ b/src/grid/arbitrary.js @@ -1,6 +1,17 @@ import { Delaunay } from "d3-delaunay"; const d3 = Object.assign({}, { Delaunay }); +/** + * @function grid/arbitrary + * @description The `grid.arbitrary` function allows to create an arbitrary geoJSON grid in SVG coordinates. + * @see {@link https://observablehq.com/@neocartocnrs/regular-grids} + * @property {number} [step = 50] - step of the grid + * @property {number} [width = 1000] - width of the grid + * @property {number} [height = 500] - height of the grid + * @example + * geoviz.grid.arbitrary(50, 1000, 500) + */ + export function arbitrary(step = 50, width = 1000, height = 500) { let grid = []; let nb = Math.round((width / step) * (height / step)); diff --git a/src/grid/diamond.js b/src/grid/diamond.js index bbb06db..54a4540 100644 --- a/src/grid/diamond.js +++ b/src/grid/diamond.js @@ -1,6 +1,16 @@ import { range } from "d3-array"; const d3 = Object.assign({}, { range }); +/** + * @function grid/diamond + * @description The `grid.diamond` function allows to create a diamond geoJSON grid in SVG coordinates. + * @see {@link https://observablehq.com/@neocartocnrs/regular-grids} + * @property {number} [step = 50] - step of the grid + * @property {number} [width = 1000] - width of the grid + * @property {number} [height = 500] - height of the grid + * @example + * geoviz.grid.diamond(50, 1000, 500) + */ export function diamond(step = 50, width = 1000, height = 500) { let size = step * Math.sqrt(2); diff --git a/src/grid/diamondgeo.js b/src/grid/diamondgeo.js deleted file mode 100644 index 371401d..0000000 --- a/src/grid/diamondgeo.js +++ /dev/null @@ -1,53 +0,0 @@ -import { bbox } from "../helpers/bbox"; -import { booleanIntersects } from "@turf/boolean-intersects"; -import { range } from "d3-array"; -const d3 = Object.assign({}, { range }); - -export function diamondgeo(step, domain) { - let size = step * Math.sqrt(2); - - // build grid - let y = d3.range(-90 + size / 2, 90, size / 2).reverse(); - let x = d3.range(-180 + size / 2, 180, size); - let grid = x.map((x) => y.map((y, j) => [x, y, j % 2])).flat(); - grid = grid.map((d) => { - return d[2] == 1 ? [d[0] + size / 2, d[1]] : [d[0], d[1]]; - }); - - let s = size / 2; - // build object - let result = grid.map((d, i) => { - return { - type: "Feature", - geometry: { - type: "Polygon", - coordinates: [ - [ - [d[0] - s, d[1]], - [d[0], d[1] + s], - [d[0] + s, d[1]], - [d[0], d[1] - s], - [d[0] - s, d[1]], - ], - ], - }, - properties: { - index: i, - }, - }; - }); - let final = []; - - if (domain) { - let bb = bbox(domain); - result.forEach((d) => { - if (booleanIntersects(d, bb.features[0])) { - final.push(d); - } - }); - } else { - final = result; - } - - return { type: "FeatureCollection", features: final }; -} diff --git a/src/grid/dot.js b/src/grid/dot.js index 772da8d..1fb9619 100644 --- a/src/grid/dot.js +++ b/src/grid/dot.js @@ -1,6 +1,16 @@ import { range } from "d3-array"; const d3 = Object.assign({}, { range }); +/** + * @function grid/dot + * @description The `grid.dot` function allows to create a geoJSON vith regular dots in SVG coordinates. + * @see {@link https://observablehq.com/@neocartocnrs/regular-grids} + * @property {number} [step = 50] - step of the grid + * @property {number} [width = 1000] - width of the grid + * @property {number} [height = 500] - height of the grid + * @example + * geoviz.grid.dot(50, 1000, 500) + */ export function dot(step = 30, width = 1000, height = 500) { // build grid let y = d3.range(0 + step / 2, height, step).reverse(); diff --git a/src/grid/dotgeo.js b/src/grid/dotgeo.js deleted file mode 100644 index c83d6b3..0000000 --- a/src/grid/dotgeo.js +++ /dev/null @@ -1,46 +0,0 @@ -import { range } from "d3-array"; -const d3 = Object.assign({}, { range }); -import { booleanIntersects } from "@turf/boolean-intersects"; -import { project } from "../tool/project.js"; -import { bbox } from "../helpers/bbox"; - -export function dotgeo(step = 5, domain = undefined, projection = undefined) { - // build grid - let x = d3.range(-180 + step / 2, 180, step); - let y = d3.range(-90 + step / 2, 90, step).reverse(); - let grid = x.map((x) => y.map((y) => [x, y])).flat(); - let s = step / 2; - // build object - let result = grid.map((d, i) => { - return { - type: "Feature", - geometry: { - type: "Point", - coordinates: d, - }, - properties: { - index: i, - }, - }; - }); - - if (domain == undefined) { - return { type: "FeatureCollection", features: result }; - } else { - let final = []; - let resultproj = project( - { type: "FeatureCollection", features: result }, - { projection: projection } - ).features.filter((d) => d.geometry !== null); - let bb = project(bbox(domain), { projection: projection }); - resultproj.forEach((d) => { - if (booleanIntersects(d, bb.features[0])) { - final.push(d.properties.index); - } - }); - return { - type: "FeatureCollection", - features: result.filter((d) => final.includes(d.properties.index)), - }; - } -} diff --git a/src/grid/h3.js b/src/grid/h3.js new file mode 100644 index 0000000..48418b6 --- /dev/null +++ b/src/grid/h3.js @@ -0,0 +1,31 @@ +import { + getRes0Cells, + cellToChildren, + isPentagon, + cellToBoundary, +} from "h3-js"; + +/** + * @function grid/h3 + * @description The `grid.h3` function allows to create a hexbin geoJSON grid in geographical coordinates. + * @see {@link https://observablehq.com/@neocartocnrs/regular-grids} + * @property {number} [level = 0] - level of the grid. Form 0 (large hexagons) to 4 (small hexagons). See: https://h3geo.org + * @example + * geoviz.grid.h3(1) + */ +export function h3(level = 0) { + return { + type: "FeatureCollection", + features: getRes0Cells() + .map((i) => cellToChildren(i, level)) + .flat() + .map((d) => ({ + type: "Feature", + properties: { id: d, pentagon: isPentagon(d) }, + geometry: { + type: "Polygon", + coordinates: [cellToBoundary(d, true).reverse()], + }, + })), + }; +} diff --git a/src/grid/hexbin.js b/src/grid/hexbin.js index bfe727d..a3855a3 100644 --- a/src/grid/hexbin.js +++ b/src/grid/hexbin.js @@ -1,6 +1,16 @@ import { range, max } from "d3-array"; const d3 = Object.assign({}, { range, max }); +/** + * @function grid/hexbin + * @description The `grid.hexbin` function allows to create a hexbin geoJSON grid in SVG coordinates. + * @see {@link https://observablehq.com/@neocartocnrs/regular-grids} + * @property {number} [step = 50] - step of the grid + * @property {number} [width = 1000] - width of the grid + * @property {number} [height = 500] - height of the grid + * @example + * geoviz.grid.hexbin(50, 1000, 500) + */ export function hexbin(step = 50, width = 1000, height = 500) { let w = step; let size = w / Math.sqrt(3); diff --git a/src/grid/make.js b/src/grid/make.js index 0120772..d582632 100644 --- a/src/grid/make.js +++ b/src/grid/make.js @@ -1,21 +1,52 @@ import { square } from "./square.js"; import { dot } from "./dot.js"; -import { dotgeo } from "./dotgeo.js"; -import { squaregeo } from "./squaregeo.js"; +import { diamond } from "./diamond.js"; +import { arbitrary } from "./arbitrary.js"; +import { hexbin } from "./hexbin.js"; +import { triangle } from "./triangle.js"; +import { h3 } from "./h3.js"; -export function make(svg, { step, type = "square" } = {}) { +/** + * @function grid/make + * @description The `grid.make` function allows to create a regular grid geoJSON. For all types, For all grid types (except "h3"), the function returns a geojson with svg coordinates in the layout of the page. For type "h3", the function returns geographic coordinates in latitude and longitude. + * @see {@link https://observablehq.com/@neocartocnrs/regular-grids} + * + * @property {string} [type = "square"] - Type of grid ("square", "dot", "diamond", "hexbin" (or "hex"), "trangle", "arbitrary" (or "randmon"), "h3" (or "h3geo", "hexgeo", "hexbingeo")) + * @property {number} [step = 50] - step of grids (except for "h3" type) + * @property {number} [level = 0] - level oh geographical hexbin grids ("h3" type only). Form 0 (large hexagons) to 4 (small hexagons). See: https://h3geo.org + * @example + * // There are several ways to use this function + * geoviz.grid.make(svg, { type:"diamond", step:100 }) // where svg is the container + * svg.grid.make({ type:"diamond", step:100 }) // where svg is the container + */ + +export function make(svg, { step = 50, type = "square", level = 0 } = {}) { switch (type) { case "square": return square(step, svg.width, svg.height); break; + case "arbitrary": + case "random": + return arbitrary(step, svg.width, svg.height); + break; case "dot": return dot(step, svg.width, svg.height); break; - case "dotgeo": - return dotgeo(step, svg.domain, svg.projection); + case "diamond": + return diamond(step, svg.width, svg.height); + break; + case "hexbin": + case "hex": + return hexbin(step, svg.width, svg.height); + break; + case "triangle": + return triangle(step, svg.width, svg.height); break; - case "squaregeo": - return squaregeo(step, svg.domain, svg.projection); + case "h3": + case "h3geo": + case "hexgeo": + case "hexbingeo": + return h3(level); break; } } diff --git a/src/grid/square.js b/src/grid/square.js index 9260b3f..86f370e 100644 --- a/src/grid/square.js +++ b/src/grid/square.js @@ -1,6 +1,16 @@ import { range } from "d3-array"; const d3 = Object.assign({}, { range }); +/** + * @function grid/square + * @description The `grid.square` function allows to create a square geoJSON grid in SVG coordinates. + * @see {@link https://observablehq.com/@neocartocnrs/regular-grids} + * @property {number} [step = 50] - step of the grid + * @property {number} [width = 1000] - width of the grid + * @property {number} [height = 500] - height of the grid + * @example + * geoviz.grid.square(50, 1000, 500) + */ export function square(step = 50, width = 1000, height = 500) { // build grid let y = d3.range(0 + step / 2, height, step).reverse(); diff --git a/src/grid/squaregeo.js b/src/grid/squaregeo.js deleted file mode 100644 index 5eb1a88..0000000 --- a/src/grid/squaregeo.js +++ /dev/null @@ -1,47 +0,0 @@ -import { bbox } from "../helpers/bbox"; -import { booleanIntersects } from "@turf/boolean-intersects"; -import { range } from "d3-array"; -const d3 = Object.assign({}, { range }); - -export function squaregeo(step = 1, domain = undefined) { - let y = d3.range(-90 + step / 2, 90, step).reverse(); - let x = d3.range(-180 + step / 2, 180, step); - let grid = x.map((x, i) => y.map((y) => [x, y])).flat(); - - let s = step / 2; - // build object - let result = grid.map((d, i) => { - return { - type: "Feature", - geometry: { - type: "Polygon", - coordinates: [ - [ - [d[0] - s, d[1] + s], - [d[0] + s, d[1] + s], - [d[0] + s, d[1] - s], - [d[0] - s, d[1] - s], - [d[0] - s, d[1] + s], - ], - ], - }, - properties: { - index: i, - }, - }; - }); - let final = []; - - if (domain) { - let bb = bbox(domain); - result.forEach((d) => { - if (booleanIntersects(d, bb.features[0])) { - final.push(d); - } - }); - } else { - final = result; - } - - return { type: "FeatureCollection", features: final }; -} diff --git a/src/grid/triangle.js b/src/grid/triangle.js index 402eac4..3d0ca63 100644 --- a/src/grid/triangle.js +++ b/src/grid/triangle.js @@ -1,6 +1,16 @@ import { range, max } from "d3-array"; const d3 = Object.assign({}, { range, max }); +/** + * @function grid/triangle + * @description The `grid.triangle` function allows to create a triangle geoJSON grid in SVG coordinates. + * @see {@link https://observablehq.com/@neocartocnrs/regular-grids} + * @property {number} [step = 50] - step of the grid + * @property {number} [width = 1000] - width of the grid + * @property {number} [height = 500] - height of the grid + * @example + * geoviz.grid.triangle(50, 1000, 500) + */ export function triangle(step = 50, width = 1000, height = 500) { let triangletop = (p, size) => { let h = (Math.sqrt(3) / 2) * size; diff --git a/src/grid/trianglegeo.js b/src/grid/trianglegeo.js deleted file mode 100644 index 545f855..0000000 --- a/src/grid/trianglegeo.js +++ /dev/null @@ -1,71 +0,0 @@ -import { bbox } from "../helpers/bbox"; -import { rewind } from "../tool/rewind"; -import { booleanIntersects } from "@turf/boolean-intersects"; -import { range, max } from "d3-array"; -const d3 = Object.assign({}, { range, max }); - -export function trianglegeo(step = 1, domain = undefined) { - let size = step / Math.sqrt(3); - let h = (Math.sqrt(3) / 2) * step; - - let triangletop = (p, size) => { - let h = (Math.sqrt(3) / 2) * size; - let p1 = [p[0] + size / 2, p[1]]; - let p2 = [p[0], p[1] - h]; - let p3 = [p[0] - size / 2, p[1]]; - return [p1, p2, p3, p1]; - }; - - let trianglebottom = (p, size) => { - let h = (Math.sqrt(3) / 2) * size; - let p1 = [p[0] + size / 2, p[1]]; - let p2 = [p[0], p[1] + h]; - let p3 = [p[0] - size / 2, p[1]]; - return [p1, p2, p3, p1]; - }; - - let y = d3.range(-90 + h / 2, 90, h).reverse(); - if (y.length % 2) { - y.unshift(d3.max(y) + h); - } - - let x = d3.range(-180 + step / 2, 180, step); - - let grid = x.map((x) => y.map((y) => [x, y])).flat(); - grid = grid.map((d, i) => { - return i % 2 == 1 ? [d[0] + step / 2, d[1]] : d; - }); - - let nb = grid.length; - grid = grid.concat(grid); - - // build object - let result = grid.map((d, i) => { - return { - type: "Feature", - geometry: { - type: "Polygon", - coordinates: - i < nb ? [triangletop(d, step)] : [trianglebottom(d, step)], - }, - properties: { - index: i, - }, - }; - }); - - let final = []; - - if (domain) { - let bb = bbox(domain); - result.forEach((d) => { - if (booleanIntersects(d, bb.features[0])) { - final.push(d); - } - }); - } else { - final = result; - } - - return rewind({ type: "FeatureCollection", features: final }); -} diff --git a/src/index.js b/src/index.js index fac1e03..52fd438 100644 --- a/src/index.js +++ b/src/index.js @@ -82,32 +82,6 @@ export let legend = { symbol_horizontal, }; -// grid -import { square } from "./grid/square.js"; -import { hexbin } from "./grid/hexbin.js"; -import { diamond } from "./grid/diamond.js"; -import { triangle } from "./grid/triangle.js"; -import { trianglegeo } from "./grid/trianglegeo.js"; -import { arbitrary } from "./grid/arbitrary.js"; -import { dot } from "./grid/dot.js"; -import { dotgeo } from "./grid/dotgeo.js"; -import { squaregeo } from "./grid/squaregeo.js"; -import { diamondgeo } from "./grid/diamondgeo.js"; -import { make } from "./grid/make.js"; -export let grid = { - make, - dot, - dotgeo, - square, - squaregeo, - triangle, - trianglegeo, - diamond, - diamondgeo, - hexbin, - arbitrary, -}; - // effects import { blur } from "./effect/blur.js"; import { shadow } from "./effect/shadow.js"; @@ -120,6 +94,26 @@ export let effect = { clipPath, }; +// grid +import { make } from "./grid/make.js"; +import { arbitrary } from "./grid/arbitrary.js"; +import { diamond } from "./grid/diamond.js"; +import { dot } from "./grid/dot.js"; +import { h3 } from "./grid/h3.js"; +import { hexbin } from "./grid/hexbin.js"; +import { square } from "./grid/square.js"; +import { triangle } from "./grid/triangle.js"; +export let grid = { + make, + arbitrary, + diamond, + dot, + h3, + hexbin, + square, + triangle, +}; + // main export { draw } from "./container/draw"; export { create } from "./container/create";