refactor: import d3

This commit is contained in:
Azgaar 2022-07-05 21:12:55 +03:00
parent 1847772d74
commit 98ae3292fc
83 changed files with 709 additions and 69 deletions

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {rn} from "utils/numberUtils";
import {round} from "utils/stringUtils";
import {byId} from "utils/shorthands";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {getProvincesVertices} from "./drawProvinces";
import {minmax, rn} from "utils/numberUtils";
import {byId} from "utils/shorthands";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
export function drawGrid() {
gridOverlay.selectAll("*").remove();
const pattern = "#pattern_" + (gridOverlay.attr("type") || "pointyHex");

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {getColorScheme, getHeightColor} from "utils/colorUtils";
export function drawHeightmap() {

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
export function drawPopulation(event) {
population.selectAll("line").remove();

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
export function drawPrecipitation() {
prec.selectAll("circle").remove();
const {cells, points} = grid;

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import polylabel from "polylabel";
export function drawStates() {

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {convertTemperature} from "utils/unitUtils";
export function drawTemperature() {

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {tip} from "scripts/tooltips";
import {getBase64} from "utils/functionUtils";
import {isCtrlPressed} from "utils/keyboardUtils";
@ -139,14 +141,14 @@ function togglePopulation(event?: MouseEvent) {
.select("#rural")
.selectAll("line")
.transition(hide)
.attr("y2", d => d[1])
.attr("y2", (d: any[]) => d[1])
.remove();
population
.select("#urban")
.selectAll("line")
.transition(hide)
.delay(1000)
.attr("y2", d => d[1])
.attr("y2", (d: any[]) => d[1])
.remove();
}
}
@ -473,8 +475,8 @@ function toggleScaleBar(event?: MouseEvent) {
}
async function openUnitsEditor() {
// @ts-ignore fix dynamic import
const {editUnits} = await import("./../modules/ui/unitsEditor.js");
// @ts-ignore untyped module
const {editUnits} = await import("../modules/ui/units-editor.js");
editUnits();
}
}

2
src/libs/d3.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -3,6 +3,8 @@
import "./components";
// @ts-expect-error js-module
import {defineSvg} from "./modules/define-svg";
// @ts-expect-error js-module
import {clearLegend} from "./modules/legend";
// @ts-expect-error js-module
import {Rulers} from "./modules/measurers";
@ -37,8 +39,8 @@ statesNeutral = 1; // statesEditor growth parameter
applyStoredOptions();
rulers = new Rulers();
biomesData = Biomes.getDefault();
nameBases = Names.getNameBases(); // cultures-related data
biomesData = window.Biomes.getDefault();
nameBases = window.Names.getNameBases(); // cultures-related data
// voronoi graph extension, cannot be changed after generation
graphWidth = getInputNumber("mapWidthInput");

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {TIME} from "config/logging";
import {isLand} from "utils/graphUtils";
import {rn} from "utils/numberUtils";

View file

@ -1,3 +1,4 @@
import * as d3 from "d3";
import FlatQueue from "flatqueue";
import Delaunator from "delaunator";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {ERROR, TIME} from "config/logging";
import {reMarkFeatures} from "modules/markup";
import {clipPoly} from "utils/lineUtils";

View file

@ -1,3 +1,4 @@
import * as d3 from "d3";
import FlatQueue from "flatqueue";
import {TIME} from "config/logging";

View file

@ -29,3 +29,54 @@ let distanceScale;
let urbanization;
let urbanDensity;
let statesNeutral;
// svg d3 selections
let svg,
defs,
viewbox,
scaleBar,
legend,
ocean,
oceanLayers,
oceanPattern,
lakes,
landmass,
texture,
terrs,
biomes,
cells,
gridOverlay,
coordinates,
compass,
rivers,
terrain,
relig,
cults,
regions,
statesBody,
statesHalo,
provs,
zones,
borders,
stateBorders,
provinceBorders,
routes,
roads,
trails,
searoutes,
temperature,
coastline,
ice,
prec,
population,
emblems,
labels,
icons,
burgLabels,
burgIcons,
anchors,
armies,
markers,
fogging,
ruler,
debug;

View file

@ -1,57 +1,6 @@
"use strict";
// temporary define svg elements as globals
import * as d3 from "d3";
let svg,
defs,
viewbox,
scaleBar,
legend,
ocean,
oceanLayers,
oceanPattern,
lakes,
landmass,
texture,
terrs,
biomes,
cells,
gridOverlay,
coordinates,
compass,
rivers,
terrain,
relig,
cults,
regions,
statesBody,
statesHalo,
provs,
zones,
borders,
stateBorders,
provinceBorders,
routes,
roads,
trails,
searoutes,
temperature,
coastline,
ice,
prec,
population,
emblems,
labels,
icons,
burgLabels,
burgIcons,
anchors,
armies,
markers,
fogging,
ruler,
debug;
function defineSvg(width, height) {
export function defineSvg(width, height) {
// append svg layers (in default order)
svg = d3.select("#map");
defs = svg.select("#deftemp");

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {findCell} from "utils/graphUtils";
import {rn} from "utils/numberUtils";
import {rand, P, rw} from "utils/probabilityUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findAll, findCell, getPackPolygon, isLand} from "utils/graphUtils";
import {tip, showMainTip, clearMainTip} from "scripts/tooltips";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findAll, findCell, getPackPolygon, isLand} from "utils/graphUtils";
import {tip, showMainTip, clearMainTip} from "scripts/tooltips";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findAll, findCell, getPackPolygon, isLand} from "utils/graphUtils";
import {byId} from "utils/shorthands";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {heightmapTemplates} from "config/heightmap-templates";
import {precreatedHeightmaps} from "config/precreated-heightmaps";
import {shouldRegenerateGrid, generateGrid} from "utils/graphUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {byId} from "utils/shorthands";
import {tip} from "scripts/tooltips";
import {capitalize} from "utils/stringUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {isWater} from "utils/graphUtils";
import {tip} from "scripts/tooltips";
import {byId} from "utils/shorthands";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {heightmapTemplates} from "config/heightmap-templates";
import {TIME} from "config/logging";
import {createTypedArray} from "utils/arrayUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {getGridPolygon} from "utils/graphUtils";
import {unique} from "utils/arrayUtils";
import {tip} from "scripts/tooltips";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {updatePresetInput} from "layers";
import {restoreDefaultEvents} from "scripts/events";
import {ldb} from "scripts/indexedDB";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {TIME} from "config/logging";
import {rn} from "utils/numberUtils";
import {aleaPRNG} from "scripts/aleaPRNG";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {rn} from "../utils/numberUtils";
import {parseTransform} from "utils/stringUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {TIME} from "config/logging";
import {last} from "utils/arrayUtils";
import {rn} from "utils/numberUtils";

View file

@ -1,3 +1,4 @@
import * as d3 from "d3";
import polylabel from "polylabel";
import {last} from "utils/arrayUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {TIME} from "config/logging";
import {rn, minmax} from "utils/numberUtils";
import {rand, gauss, ra} from "utils/probabilityUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {TIME} from "config/logging";
import {clipPoly} from "utils/lineUtils";
import {rn} from "utils/numberUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {TIME} from "config/logging";
import {minmax} from "utils/numberUtils";
import {rand} from "utils/probabilityUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {getPackPolygon} from "utils/graphUtils";
import {rn, minmax} from "utils/numberUtils";
import {rand} from "utils/probabilityUtils";

View file

@ -1,3 +1,4 @@
import * as d3 from "d3";
import FlatQueue from "flatqueue";
import {TIME} from "config/logging";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {TIME, WARN} from "config/logging";
import {last} from "utils/arrayUtils";
import {rn} from "utils/numberUtils";

View file

@ -1,3 +1,4 @@
import * as d3 from "d3";
import FlatQueue from "flatqueue";
import {TIME} from "config/logging";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {findCell} from "utils/graphUtils";
import {getMiddlePoint} from "utils/lineUtils";
import {rn} from "utils/numberUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {TIME} from "config/logging";
import {minmax, rn} from "utils/numberUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {last} from "utils/arrayUtils";
import {tip} from "scripts/tooltips";
import {wiki} from "utils/linkUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findAll, findCell, getPackPolygon, isLand} from "utils/graphUtils";
import {tip, showMainTip, clearMainTip} from "scripts/tooltips";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {findCell} from "utils/graphUtils";
import {tip, clearMainTip} from "scripts/tooltips";
import {rn} from "utils/numberUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findCell} from "utils/graphUtils";
import {tip, clearMainTip} from "scripts/tooltips";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {getPackPolygon} from "utils/graphUtils";
import {tip} from "scripts/tooltips";
import {clipPoly} from "utils/lineUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findCell} from "utils/graphUtils";
import {tip, clearMainTip} from "scripts/tooltips";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findCell} from "utils/graphUtils";
import {byId} from "utils/shorthands";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {findCell} from "utils/graphUtils";
import {rn} from "utils/numberUtils";
import {getColorScheme, getHeightColor} from "utils/colorUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {clearMainTip} from "scripts/tooltips";
import {tip} from "scripts/tooltips";
import {openURL} from "utils/linkUtils";

View file

@ -1,3 +1,4 @@
import * as d3 from "d3";
import RgbQuant from "rgbquant";
import {heightmapTemplates} from "config/heightmap-templates";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {findGridCell, getGridPolygon} from "utils/graphUtils";
import {tip, clearMainTip} from "scripts/tooltips";
import {rn} from "utils/numberUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {getPackPolygon} from "utils/graphUtils";
import {tip} from "scripts/tooltips";
import {rn} from "utils/numberUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findCell} from "utils/graphUtils";
import {clearMainTip} from "scripts/tooltips";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {tip} from "scripts/tooltips";
import {wiki} from "utils/linkUtils";
import {rn} from "utils/numberUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {unique} from "utils/arrayUtils";
import {tip} from "scripts/tooltips";
import {openURL} from "utils/linkUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {heightmapTemplates} from "config/heightmap-templates";
import {precreatedHeightmaps} from "config/precreated-heightmaps";
import {lock, locked} from "scripts/options/lock";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findAll, findCell, getPackPolygon, isLand} from "utils/graphUtils";
import {unique} from "utils/arrayUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findCell} from "utils/graphUtils";
import {last} from "utils/arrayUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {findCell} from "utils/graphUtils";
import {last} from "utils/arrayUtils";
import {tip, clearMainTip} from "scripts/tooltips";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findCell} from "utils/graphUtils";
import {tip, showMainTip, clearMainTip} from "scripts/tooltips";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {getPackPolygon, findCell} from "utils/graphUtils";
import {last} from "utils/arrayUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {findCell, getPackPolygon} from "utils/graphUtils";
import {tip, clearMainTip} from "scripts/tooltips";
import {getSegmentId} from "utils/lineUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {rn} from "utils/numberUtils";
export function overviewRivers() {

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {tip, showMainTip, clearMainTip} from "scripts/tooltips";
import {getSegmentId} from "utils/lineUtils";
import {rn} from "utils/numberUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {tip} from "scripts/tooltips";
import {rn} from "utils/numberUtils";
import {parseTransform} from "utils/stringUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {tip} from "scripts/tooltips";
import {rn} from "utils/numberUtils";
import {round} from "utils/stringUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findCell} from "utils/graphUtils";
import {last} from "utils/arrayUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findCell} from "utils/graphUtils";
import {tip} from "scripts/tooltips";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {tip} from "scripts/tooltips";
import {rn} from "utils/numberUtils";
import {round, parseTransform} from "utils/stringUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {restoreDefaultEvents} from "scripts/events";
import {findAll, findCell, getPackPolygon} from "utils/graphUtils";
import {unique} from "utils/arrayUtils";

View file

@ -1,3 +1,4 @@
import * as d3 from "d3";
import FlatQueue from "flatqueue";
import {TIME} from "config/logging";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {debounce} from "utils/functionUtils";
import {handleZoom, invokeActiveZooming} from "/src/modules/activeZooming";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {dragLegendBox} from "modules/legend";
import {debounce} from "utils/functionUtils";
import {findCell, findGridCell} from "utils/graphUtils";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {ERROR, INFO, WARN} from "config/logging";
import {initLayers, renderLayer, restoreLayers} from "layers";
import {drawCoastline} from "modules/coastline";

View file

@ -1,3 +1,5 @@
import * as d3 from "d3";
import {ERROR, WARN} from "config/logging";
import {generateMapOnLoad} from "./generation";
import {loadMapFromURL} from "modules/io/load";

View file

@ -1,4 +1,5 @@
// @ts-nocheck global variables
import * as d3 from "d3";
import {TIME} from "config/logging";
import {normalize} from "utils/numberUtils";

View file

@ -1,4 +1,5 @@
// @ts-nocheck global variables
import * as d3 from "d3";
import {TIME} from "config/logging";
import {UINT16_MAX} from "constants";
import {createTypedArray} from "utils/arrayUtils";

View file

@ -1,4 +1,4 @@
const d3 = window.d3;
import * as d3 from "d3";
const c12: Hex[] = [
"#dababf",

View file

@ -1,4 +1,5 @@
// @ts-nocheck
import * as d3 from "d3";
import Delaunator from "delaunator";
import {TIME} from "../config/logging";

View file

@ -1,8 +1,8 @@
import * as d3 from "d3";
import {ERROR} from "../config/logging";
import {minmax, rn} from "./numberUtils";
const d3 = window.d3;
// random number in range
export function rand(min: number, max: number) {
if (min === undefined && max === undefined) return Math.random();