refactor: main roads

This commit is contained in:
max 2022-08-18 22:10:04 +03:00
parent aff29d9d71
commit 5c2d30c8f0
10 changed files with 169 additions and 34 deletions

View file

@ -0,0 +1,23 @@
import * as d3 from "d3";
import {round} from "utils/stringUtils";
export function drawRoutes() {
routes.selectAll("path").remove();
const lineGen = d3.line().curve(d3.curveBasis);
const routePaths: Dict<string[]> = {};
for (const {i, type, cells: routeCells} of pack.routes) {
const points = routeCells.map(cellId => pack.cells.p[cellId]);
const path = round(lineGen(points)!);
if (!routePaths[type]) routePaths[type] = [];
routePaths[type].push(`<path id="${type}${i}" d="${path}"/>`);
}
for (const type in routePaths) {
routes.select(`[data-type=${type}]`).html(routePaths[type].join(""));
}
}

View file

@ -16,6 +16,7 @@ import {drawPrecipitation} from "./drawPrecipitation";
import {drawProvinces} from "./drawProvinces";
import {drawReligions} from "./drawReligions";
import {drawRivers} from "./drawRivers";
import {drawRoutes} from "./drawRoutes";
import {drawStates} from "./drawStates";
import {drawTemperature} from "./drawTemperature";
@ -37,6 +38,7 @@ const layerRenderersMap = {
provinces: drawProvinces,
religions: drawReligions,
rivers: drawRivers,
routes: drawRoutes,
states: drawStates,
temperature: drawTemperature
};