github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/scripts/topo.js (about) 1 #!/usr/bin/env node 2 // Copyright 2019 The Cockroach Authors. 3 // 4 // Use of this software is governed by the Business Source License 5 // included in the file licenses/BSL.txt. 6 // 7 // As of the Change Date specified in that file, in accordance with 8 // the Business Source License, use of this software will be governed 9 // by the Apache License, Version 2.0, included in the file 10 // licenses/APL.txt. 11 12 13 const fs = require('fs'); 14 const path = require('path'); 15 16 const d3geo = require('d3-geo'); 17 const d3geoProjection = require('d3-geo-projection'); 18 const topojson = require('topojson'); 19 20 const usOrig = require('../node_modules/us-atlas/us/10m.json'); 21 const worldOrig = require('../node_modules/world-atlas/world/50m.json'); 22 23 const projection = d3geo.geoAlbersUsa().scale(1280).translate([480, 300]); 24 const invert = d3geo.geoTransform({ 25 point: function(x, y) { 26 const inverted = projection.invert([x, y]); 27 this.stream.point(inverted[0], inverted[1]); 28 } 29 }); 30 31 const usFeatProjected = topojson.feature(usOrig, { 32 type: "GeometryCollection", 33 geometries: usOrig.objects.states.geometries, 34 }); 35 const usFeat = d3geoProjection.geoProject(usFeatProjected, invert); 36 const worldFeat = topojson.feature(worldOrig, { 37 type: "GeometryCollection", 38 geometries: worldOrig.objects.countries.geometries.filter(c => c.id != "840"), 39 }); 40 41 const combinedFeats = { 42 type: "FeatureCollection", 43 features: usFeat.features.concat(worldFeat.features), 44 }; 45 46 const combinedTopo = topojson.topology({all: combinedFeats}, 1e3); 47 48 let combinedSimpl = topojson.presimplify(combinedTopo); 49 combinedSimpl = topojson.simplify(combinedSimpl, 0.25); 50 51 const combinedResult = topojson.feature(combinedSimpl, combinedSimpl.objects.all); 52 const combinedSerialized = JSON.stringify(combinedResult); 53 54 const outfile = path.join(__dirname, '..', 'ccl', 'src', 'views', 'clusterviz', 'containers', 'map', 'world.json'); 55 fs.writeFileSync(outfile, combinedSerialized);