Skip to content

Commit

Permalink
update projection system
Browse files Browse the repository at this point in the history
  • Loading branch information
neocarto committed Dec 4, 2024
1 parent 6ca10b4 commit d96e6fb
Show file tree
Hide file tree
Showing 82 changed files with 338 additions and 168 deletions.
10 changes: 7 additions & 3 deletions docs/container_create.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/container_draw.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/container_render.js.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/data/search.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/effect_blur.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/effect_clippath.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/effect_radialgradient.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/effect_shadow.js.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/global.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/grid_arbitrary.js.html

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions docs/grid_count.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/grid_diamond.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/grid_dot.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/grid_h3.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/grid_hexbin.js.html

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions docs/grid_intersect.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/grid_make.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/grid_square.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/grid_triangle.js.html

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions docs/helpers_tooltip.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_box.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_choro-horizontal.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_choro-vertical.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_circles-half.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_circles-nested.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_circles.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_mushrooms.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_spikes.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_squares-nested.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_squares.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_symbol-horizontal.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_symbol-vertical.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_typo-horizontal.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/legend_typo-vertical.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_circle.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_footer.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_graticule.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_halfcircle.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_header.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_north.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_outline.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_path.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_scalebar.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_spike.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_square.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_symbol.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_text.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/mark_tile.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/plot_plot.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/plot_plot_choro.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/plot_plot_prop.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/plot_plot_propchoro.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/plot_plot_proptypo.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/plot_plot_symbol.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/plot_plot_typo.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_addfonts.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_centroid.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_choro.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_dissolve.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_dodge.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_dotstogrid.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_featurecollection.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_geotable.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_height.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_merge.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_proj4d3.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_project.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_radius.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_random.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_replicate.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_rewind.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_ridge.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_symbols.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_typo.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tool_unproject.js.html

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"d3-force": "^3.0.0",
"d3-format": "^3.1.0",
"d3-geo": "^3.1.0",
"d3-geo-polygon": "^2.0.1",
"d3-geo-projection": "^4.0.0",
"d3-geo-scale-bar": "^1.2.5",
"d3-interpolate": "^3.0.1",
Expand Down
6 changes: 5 additions & 1 deletion src/container/create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { extent } from "../helpers/extent";
import { unique } from "../helpers/utils";
import { getproj } from "../projection/getproj";
import { create as create2 } from "d3-selection";
import {
geoPath,
Expand Down Expand Up @@ -61,7 +62,7 @@ import { plot as addplot } from "../plot/plot.js";
* @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")
* @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) & [d3-geo-polygon](https://github.com/d3/d3-geo-polygon). All theses functions are available in geoviz like this: viz.proj.geoSomething(). You can alse use a String. E.g: d3.geoMercator() <=> viz.proj.geoMercator() <=> "Mercator" <=> "mercator". Null or “none” allows you to display geometries as they are, without reprojecting them. In this case, you must specify the domain.
* @property {number[]} [pos] - position of the container (if contained in another svg container)
* @property {string} [background] - background color
* @property {string} [fontFamily] - font-family for the entire map
Expand Down Expand Up @@ -93,6 +94,9 @@ export function create({
warning_message = [],
} = {}) {
// projection

projection = getproj(projection);

const initproj = projection;
switch (projection) {
case "mercator":
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,9 @@ export { symbol } from "./mark/symbol.js";

// Plot
export { plot } from "./plot/plot.js";

// Proj
import * as d3geo from "d3-geo";
import * as d3geoprojection from "d3-geo-projection";
import * as d3geoppolygon from "d3-geo-polygon";
export let proj = Object.assign({}, d3geo, d3geoprojection, d3geoppolygon);
25 changes: 14 additions & 11 deletions src/projection/getproj.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { geoEquirectangular } from "d3-geo";
const d3 = Object.assign({}, { geoEquirectangular });
import { stringtod3proj } from "./stringtod3proj";
import { Polar } from "./polar";
import { HoaXiaoguang } from "./hoaxiaoguang";
import { Spilhaus } from "./spilhaus";

export function getproj(projection) {
/* DEFAULT - the projection is not defined.
The default projection is d3.geoEquirectangular().
*/

if (projection === null || projection === undefined || projection === "") {
return d3.geoEquirectangular();
}

/* FUNCTION - if the projection is a d3.js function (outside bertin.js).
if (
projection === null ||
projection === undefined ||
projection === "" ||
projection === "none"
) {
return "none";
} else if (typeof projection === "function") {
/* FUNCTION - if the projection is a d3.js.
then, the function is used directly.*/

if (typeof projection === "function") {
return projection;
}

// STRINGS
if (typeof projection === "string") {
else if (typeof projection === "string" && projection !== "none") {
projection = projection.replace(/\s/g, "");

/* CUSTOM projections*/
Expand Down
5 changes: 3 additions & 2 deletions src/projection/stringtod3proj.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as d3geo from "d3-geo";
import * as d3geoprojection from "d3-geo-projection";
const d3 = Object.assign({}, d3geo, d3geoprojection);
import * as d3geoppolygon from "d3-geo-polygon";
const d3 = Object.assign({}, d3geo, d3geoprojection, d3geoppolygon);

export function stringtod3proj(string) {
let str = string;
Expand All @@ -12,7 +13,7 @@ export function stringtod3proj(string) {
} else {
str = str.replace(".", "().");
}
str = "d3.geo" + str;
str = "d3.geo" + str.charAt(0).toUpperCase() + str.slice(1);
}

const createProjection = new Function("d3", `return (${str})`);
Expand Down

0 comments on commit d96e6fb

Please sign in to comment.