From 31f80f5761df57f53d0059f4867917f1748eaacb Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Mon, 19 Jun 2023 21:28:05 -0400 Subject: [PATCH 01/14] Add JSON output and use source layer --- scripts/stats.js | 55 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/scripts/stats.js b/scripts/stats.js index 26662d65e..eaff052b5 100644 --- a/scripts/stats.js +++ b/scripts/stats.js @@ -10,6 +10,7 @@ program .option("-l, --layer ", "stats about one layer") .option("-loc, --locales ", "language codes", ["mul"]) .option("-pp, --pretty", "pretty-print JSON output") + .option("-j, --json", "output JSON") .option( "-pg, --print-group ", "print a list of the layers in a group" @@ -42,7 +43,7 @@ for (let i = 0; i < layers.length; i++) { let layer = layers[i]; layerMap.set(layer.id, layers[i]); let layerSize = JSON.stringify(layer).length; - let layerGroup = layer.id.split("_", 1)[0]; + let layerGroup = layer["source-layer"] || layer.source || layer.type; layerSizeStats.set(layer.id, JSON.stringify(layer).length); if (!layerGroupSizeStats.has(layerGroup)) { layerGroupSizeStats.set(layerGroup, layerSize); @@ -62,32 +63,58 @@ for (let i = 0; i < layers.length; i++) { } if (opts.layerCount) { - console.log(`${layerCount} layers`); + if (opts.json) { + process.stdout.write(JSON.stringify({ layerCount }) + '\n'); + } else { + console.log(`${layerCount} layers`); + } } if (opts.layerSize) { - console.log(`Total layer size ${layerSize.toLocaleString("en-US")} bytes`); + if (opts.json) { + process.stdout.write(JSON.stringify({ layerSize }) + '\n'); + } else { + console.log(`Total layer size ${layerSize.toLocaleString("en-US")} bytes`); + } } if (opts.allLayers) { - console.log(`${layerCount} layers, grouped as follows:`); - layerGroupSizeStats.forEach((v, k) => { - let layerCount = layerGroupCountStats.get(k); - let layerString = `${k}(${layerCount})`.padEnd(30, "."); - console.log( - `${layerString}${v.toLocaleString("en-US").padStart(10, ".")} bytes` - ); - }); + if (opts.json) { + let allLayers = { + layerCount, + layers: {}, + }; + layerGroupSizeStats.forEach((v, k) => { + let layerCount = layerGroupCountStats.get(k); + allLayers.layers[k] = layerCount; + }); + process.stdout.write(JSON.stringify(allLayers) + '\n'); + } else { + layerGroupSizeStats.forEach((v, k) => { + let layerCount = layerGroupCountStats.get(k); + let layerString = `${k}(${layerCount})`.padEnd(30, "."); + console.log( + `${layerString}${v.toLocaleString("en-US").padStart(10, ".")} bytes` + ); + }); + } } if (opts.printGroup) { - layerGroupMap.get(opts.printGroup).forEach((lyr) => console.log(lyr)); + let group = layerGroupMap.get(opts.printGroup); + if (opts.json) { + let layers = []; + group.forEach((lyr) => layers.push(lyr)); + process.stdout.write(JSON.stringify(layers) + '\n'); + } else { + group.forEach((lyr) => console.log(lyr)); + } } if (opts.printLayer) { if (opts.pretty) { - console.log(JSON.stringify(layerMap.get(opts.printLayer), null, 2)); + process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer), null, 2) + '\n'); } else { - console.log(JSON.stringify(layerMap.get(opts.printLayer))); + process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer)) + '\n'); } } From da373dfd1c5a34b5e2cf4deba7d2d08fd4a08276 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Mon, 19 Jun 2023 21:39:40 -0400 Subject: [PATCH 02/14] Prettier --- scripts/stats.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/stats.js b/scripts/stats.js index eaff052b5..c5d7ef9bf 100644 --- a/scripts/stats.js +++ b/scripts/stats.js @@ -64,7 +64,7 @@ for (let i = 0; i < layers.length; i++) { if (opts.layerCount) { if (opts.json) { - process.stdout.write(JSON.stringify({ layerCount }) + '\n'); + process.stdout.write(JSON.stringify({ layerCount }) + "\n"); } else { console.log(`${layerCount} layers`); } @@ -72,7 +72,7 @@ if (opts.layerCount) { if (opts.layerSize) { if (opts.json) { - process.stdout.write(JSON.stringify({ layerSize }) + '\n'); + process.stdout.write(JSON.stringify({ layerSize }) + "\n"); } else { console.log(`Total layer size ${layerSize.toLocaleString("en-US")} bytes`); } @@ -88,7 +88,7 @@ if (opts.allLayers) { let layerCount = layerGroupCountStats.get(k); allLayers.layers[k] = layerCount; }); - process.stdout.write(JSON.stringify(allLayers) + '\n'); + process.stdout.write(JSON.stringify(allLayers) + "\n"); } else { layerGroupSizeStats.forEach((v, k) => { let layerCount = layerGroupCountStats.get(k); @@ -105,7 +105,7 @@ if (opts.printGroup) { if (opts.json) { let layers = []; group.forEach((lyr) => layers.push(lyr)); - process.stdout.write(JSON.stringify(layers) + '\n'); + process.stdout.write(JSON.stringify(layers) + "\n"); } else { group.forEach((lyr) => console.log(lyr)); } @@ -113,8 +113,10 @@ if (opts.printGroup) { if (opts.printLayer) { if (opts.pretty) { - process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer), null, 2) + '\n'); + process.stdout.write( + JSON.stringify(layerMap.get(opts.printLayer), null, 2) + "\n" + ); } else { - process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer)) + '\n'); + process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer)) + "\n"); } } From 6cade2690a57fc28f13f9ed3a802e6783ee85e98 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Tue, 20 Jun 2023 21:40:41 -0400 Subject: [PATCH 03/14] WIP --- scripts/layer.js | 43 +++++++++++++++++++++++++++++++++++++++++++ scripts/stats.js | 21 ++++++++++++++------- 2 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 scripts/layer.js diff --git a/scripts/layer.js b/scripts/layer.js new file mode 100644 index 000000000..6df45ff1b --- /dev/null +++ b/scripts/layer.js @@ -0,0 +1,43 @@ +import * as Style from "../src/js/style.js"; +import config from "../src/config.js"; +import { Command } from "commander"; + +const program = new Command(); +program + .option("-loc, --locales ", "language codes", ["mul"]) + .option("-pp, --pretty", "pretty-print JSON output") + .option("-pl, --print-layer ", "print the JSON of a layer"); +program.parse(process.argv); + +let opts = program.opts(); + +if (Object.keys(opts).length === 1 || !opts.printLayer) { + program.help(); + process.exit(); +} + +let style = Style.build( + config.OPENMAPTILES_URL, + "https://zelonewolf.github.io/openstreetmap-americana/sprites/sprite", + "https://osm-americana.github.io/fontstack66/{fontstack}/{range}.pbf", + opts.locales +); + +const layers = style.layers; +const layerMap = new Map(); + +for (let i = 0; i < layers.length; i++) { + let layer = layers[i]; + layerMap.set(layer.id, layers[i]); +} + +if(!layerMap.has(opts.printLayer)) { + console.log({}); + process.exit(); +} + +if (opts.pretty) { + process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer), null, 2)); +} else { + process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer))); +} diff --git a/scripts/stats.js b/scripts/stats.js index c5d7ef9bf..8544de880 100644 --- a/scripts/stats.js +++ b/scripts/stats.js @@ -31,7 +31,7 @@ let style = Style.build( const layers = style.layers; const layerCount = layers.length; -const layerSize = JSON.stringify(layers).length; +const styleSize = JSON.stringify(layers).length; const layerMap = new Map(); const layerGroupMap = new Map(); @@ -39,6 +39,13 @@ const layerSizeStats = new Map(); const layerGroupSizeStats = new Map(); const layerGroupCountStats = new Map(); +const stats = { + layerCount, + styleSize, + layer: {}, + layerGroup: {} +}; + for (let i = 0; i < layers.length; i++) { let layer = layers[i]; layerMap.set(layer.id, layers[i]); @@ -64,7 +71,7 @@ for (let i = 0; i < layers.length; i++) { if (opts.layerCount) { if (opts.json) { - process.stdout.write(JSON.stringify({ layerCount }) + "\n"); + process.stdout.write(JSON.stringify({ layerCount })); } else { console.log(`${layerCount} layers`); } @@ -72,7 +79,7 @@ if (opts.layerCount) { if (opts.layerSize) { if (opts.json) { - process.stdout.write(JSON.stringify({ layerSize }) + "\n"); + process.stdout.write(JSON.stringify({ layerSize })); } else { console.log(`Total layer size ${layerSize.toLocaleString("en-US")} bytes`); } @@ -88,7 +95,7 @@ if (opts.allLayers) { let layerCount = layerGroupCountStats.get(k); allLayers.layers[k] = layerCount; }); - process.stdout.write(JSON.stringify(allLayers) + "\n"); + process.stdout.write(JSON.stringify(allLayers)); } else { layerGroupSizeStats.forEach((v, k) => { let layerCount = layerGroupCountStats.get(k); @@ -105,7 +112,7 @@ if (opts.printGroup) { if (opts.json) { let layers = []; group.forEach((lyr) => layers.push(lyr)); - process.stdout.write(JSON.stringify(layers) + "\n"); + process.stdout.write(JSON.stringify(layers)); } else { group.forEach((lyr) => console.log(lyr)); } @@ -114,9 +121,9 @@ if (opts.printGroup) { if (opts.printLayer) { if (opts.pretty) { process.stdout.write( - JSON.stringify(layerMap.get(opts.printLayer), null, 2) + "\n" + JSON.stringify(layerMap.get(opts.printLayer), null, 2) ); } else { - process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer)) + "\n"); + process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer))); } } From 081fb046fc1c02b4463d23ee0b5137b18708c73f Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Wed, 21 Jun 2023 21:42:21 -0400 Subject: [PATCH 04/14] Update stats scripts --- CONTRIBUTING.md | 6 +++ scripts/layer.js | 43 ----------------- scripts/stats.js | 118 +++++++++++++++-------------------------------- scripts/util.js | 62 +++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 123 deletions(-) delete mode 100644 scripts/layer.js create mode 100644 scripts/util.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea878665e..34fbe7f5b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -194,6 +194,12 @@ There is a "stats" script that will generate various statistics about layer comp - `npm run stats -- -c` - total layer count - `npm run stats -- -h` - list all options +There is a "util" script that will extract layer style data: + +- `node scripts/util -pl ` - JSON contents of a specified layer +- `node scripts/util -pg ` - list of layers from a specified source +- `node scripts/util -h` - list all options + ## Layers 1. Layers should be named as followed: `_`, wher the "group" should match the file name that the layer is contained in. This naming convention is needed by the layer statistic script. diff --git a/scripts/layer.js b/scripts/layer.js deleted file mode 100644 index 6df45ff1b..000000000 --- a/scripts/layer.js +++ /dev/null @@ -1,43 +0,0 @@ -import * as Style from "../src/js/style.js"; -import config from "../src/config.js"; -import { Command } from "commander"; - -const program = new Command(); -program - .option("-loc, --locales ", "language codes", ["mul"]) - .option("-pp, --pretty", "pretty-print JSON output") - .option("-pl, --print-layer ", "print the JSON of a layer"); -program.parse(process.argv); - -let opts = program.opts(); - -if (Object.keys(opts).length === 1 || !opts.printLayer) { - program.help(); - process.exit(); -} - -let style = Style.build( - config.OPENMAPTILES_URL, - "https://zelonewolf.github.io/openstreetmap-americana/sprites/sprite", - "https://osm-americana.github.io/fontstack66/{fontstack}/{range}.pbf", - opts.locales -); - -const layers = style.layers; -const layerMap = new Map(); - -for (let i = 0; i < layers.length; i++) { - let layer = layers[i]; - layerMap.set(layer.id, layers[i]); -} - -if(!layerMap.has(opts.printLayer)) { - console.log({}); - process.exit(); -} - -if (opts.pretty) { - process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer), null, 2)); -} else { - process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer))); -} diff --git a/scripts/stats.js b/scripts/stats.js index 8544de880..f7258661a 100644 --- a/scripts/stats.js +++ b/scripts/stats.js @@ -7,123 +7,81 @@ program .option("-a, --all-layers", "summary layer stats") .option("-c, --layer-count", "count number of layers") .option("-s, --layer-size", "size of all layers") - .option("-l, --layer ", "stats about one layer") .option("-loc, --locales ", "language codes", ["mul"]) - .option("-pp, --pretty", "pretty-print JSON output") - .option("-j, --json", "output JSON") - .option( - "-pg, --print-group ", - "print a list of the layers in a group" - ) - .option("-pl, --print-layer ", "print the JSON of a layer"); + .option("-j, --all-json", "output all stats in JSON") + .option("-pp, --pretty", "pretty-print JSON output"); + program.parse(process.argv); let opts = program.opts(); if (Object.keys(opts).length === 1) program.help(); +let locales = opts.locales[0].split(","); + let style = Style.build( config.OPENMAPTILES_URL, "https://zelonewolf.github.io/openstreetmap-americana/sprites/sprite", "https://osm-americana.github.io/fontstack66/{fontstack}/{range}.pbf", - opts.locales + locales ); const layers = style.layers; const layerCount = layers.length; + +if (opts.layerCount) { + console.log(layerCount); + process.exit(); +} + const styleSize = JSON.stringify(layers).length; +if (opts.layerSize) { + console.log(styleSize); + process.exit(); +} + const layerMap = new Map(); -const layerGroupMap = new Map(); -const layerSizeStats = new Map(); -const layerGroupSizeStats = new Map(); -const layerGroupCountStats = new Map(); const stats = { layerCount, styleSize, - layer: {}, - layerGroup: {} + layerGroup: {}, }; -for (let i = 0; i < layers.length; i++) { +for (let i = 0; i < layerCount; i++) { let layer = layers[i]; layerMap.set(layer.id, layers[i]); let layerSize = JSON.stringify(layer).length; let layerGroup = layer["source-layer"] || layer.source || layer.type; - layerSizeStats.set(layer.id, JSON.stringify(layer).length); - if (!layerGroupSizeStats.has(layerGroup)) { - layerGroupSizeStats.set(layerGroup, layerSize); - layerGroupCountStats.set(layerGroup, 1); - layerGroupMap.set(layerGroup, [layer.id]); - } else { - layerGroupSizeStats.set( - layerGroup, - layerGroupSizeStats.get(layerGroup) + layerSize - ); - layerGroupCountStats.set( - layerGroup, - layerGroupCountStats.get(layerGroup) + 1 - ); - layerGroupMap.get(layerGroup).push(layer.id); - } -} - -if (opts.layerCount) { - if (opts.json) { - process.stdout.write(JSON.stringify({ layerCount })); - } else { - console.log(`${layerCount} layers`); - } -} - -if (opts.layerSize) { - if (opts.json) { - process.stdout.write(JSON.stringify({ layerSize })); + if (stats.layerGroup[layerGroup]) { + stats.layerGroup[layerGroup].size += layerSize; + stats.layerGroup[layerGroup].count++; } else { - console.log(`Total layer size ${layerSize.toLocaleString("en-US")} bytes`); - } -} - -if (opts.allLayers) { - if (opts.json) { - let allLayers = { - layerCount, - layers: {}, + stats.layerGroup[layerGroup] = { + size: layerSize, + count: 1, }; - layerGroupSizeStats.forEach((v, k) => { - let layerCount = layerGroupCountStats.get(k); - allLayers.layers[k] = layerCount; - }); - process.stdout.write(JSON.stringify(allLayers)); - } else { - layerGroupSizeStats.forEach((v, k) => { - let layerCount = layerGroupCountStats.get(k); - let layerString = `${k}(${layerCount})`.padEnd(30, "."); - console.log( - `${layerString}${v.toLocaleString("en-US").padStart(10, ".")} bytes` - ); - }); } } -if (opts.printGroup) { - let group = layerGroupMap.get(opts.printGroup); - if (opts.json) { - let layers = []; - group.forEach((lyr) => layers.push(lyr)); - process.stdout.write(JSON.stringify(layers)); +if (opts.allJson) { + if (opts.pretty) { + process.stdout.write(JSON.stringify(stats, null, 2)); } else { - group.forEach((lyr) => console.log(lyr)); + process.stdout.write(JSON.stringify(stats)); } + process.exit(); } -if (opts.printLayer) { - if (opts.pretty) { - process.stdout.write( - JSON.stringify(layerMap.get(opts.printLayer), null, 2) +if (opts.allLayers) { + for (const layerGroup in stats.layerGroup) { + let layerStats = stats.layerGroup[layerGroup]; + let layerString = `${layerGroup}(${layerStats.count})`.padEnd(30, "."); + console.log( + `${layerString}${layerStats.size + .toLocaleString("en-US") + .padStart(10, ".")} bytes` ); - } else { - process.stdout.write(JSON.stringify(layerMap.get(opts.printLayer))); } } diff --git a/scripts/util.js b/scripts/util.js new file mode 100644 index 000000000..7f291df37 --- /dev/null +++ b/scripts/util.js @@ -0,0 +1,62 @@ +import * as Style from "../src/js/style.js"; +import config from "../src/config.js"; +import { Command } from "commander"; + +const program = new Command(); +program + .option("-pp, --pretty", "pretty-print JSON output") + .option( + "-pg, --print-group ", + "print a list of the layers in a group" + ) + .option("-pl, --print-layer ", "print the JSON of a layer") + .option("-loc, --locales ", "language codes", ["mul"]); +program.parse(process.argv); + +let opts = program.opts(); + +if (Object.keys(opts).length === 1) program.help(); + +let locales = opts.locales[0].split(","); + +let style = Style.build( + config.OPENMAPTILES_URL, + "https://zelonewolf.github.io/openstreetmap-americana/sprites/sprite", + "https://osm-americana.github.io/fontstack66/{fontstack}/{range}.pbf", + locales +); + +const layers = style.layers; +const layerMap = new Map(); +const layerGroupMap = new Map(); + +for (let i = 0; i < layers.length; i++) { + let layer = layers[i]; + layerMap.set(layer.id, layers[i]); + let layerGroup = layer["source-layer"] || layer.source || layer.type; + if (!layerGroupMap.has(layerGroup)) { + layerGroupMap.set(layerGroup, [layer.id]); + } else { + layerGroupMap.get(layerGroup).push(layer.id); + } +} + +let outputObj; + +if (opts.printGroup) { + let group = layerGroupMap.get(opts.printGroup); + let layers = []; + group.forEach((lyr) => layers.push(lyr)); + outputObj = layers; +} + +if (opts.printLayer) { + console.log(layerMap); + outputObj = layerMap.get(opts.printLayer) ?? {}; +} + +if (opts.pretty) { + process.stdout.write(JSON.stringify(outputObj, null, 2)); +} else { + process.stdout.write(JSON.stringify(outputObj)); +} From 39570bd89aa31b1fbc88bea376e7f954bf1c2890 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 22 Jun 2023 19:25:58 -0400 Subject: [PATCH 05/14] Update scripts/util.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Minh Nguyễn --- scripts/util.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/util.js b/scripts/util.js index 7f291df37..2efd3fe14 100644 --- a/scripts/util.js +++ b/scripts/util.js @@ -55,8 +55,4 @@ if (opts.printLayer) { outputObj = layerMap.get(opts.printLayer) ?? {}; } -if (opts.pretty) { - process.stdout.write(JSON.stringify(outputObj, null, 2)); -} else { - process.stdout.write(JSON.stringify(outputObj)); -} +process.stdout.write(JSON.stringify(outputObj, null, opts.pretty ? 2 : null)); From 8f522eef97913113e540045bd4114e0341e9f2f4 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 22 Jun 2023 19:29:18 -0400 Subject: [PATCH 06/14] Rename to extract_layers --- CONTRIBUTING.md | 8 ++++---- scripts/{util.js => extract_layer.js} | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename scripts/{util.js => extract_layer.js} (100%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 34fbe7f5b..51be9721a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -194,11 +194,11 @@ There is a "stats" script that will generate various statistics about layer comp - `npm run stats -- -c` - total layer count - `npm run stats -- -h` - list all options -There is a "util" script that will extract layer style data: +There is an "extract_layers" script that will extract layer style data: -- `node scripts/util -pl ` - JSON contents of a specified layer -- `node scripts/util -pg ` - list of layers from a specified source -- `node scripts/util -h` - list all options +- `node scripts/extract_layers -pl ` - JSON contents of a specified layer +- `node scripts/extract_layers -pg ` - list of layers from a specified source +- `node scripts/extract_layers -h` - list all options ## Layers diff --git a/scripts/util.js b/scripts/extract_layer.js similarity index 100% rename from scripts/util.js rename to scripts/extract_layer.js From 56379419b99c5e75190fd837bc9c4ef6da481d33 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 22 Jun 2023 19:57:46 -0400 Subject: [PATCH 07/14] Mutex options --- scripts/extract_layer.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scripts/extract_layer.js b/scripts/extract_layer.js index 2efd3fe14..729327282 100644 --- a/scripts/extract_layer.js +++ b/scripts/extract_layer.js @@ -1,13 +1,15 @@ import * as Style from "../src/js/style.js"; import config from "../src/config.js"; -import { Command } from "commander"; +import { Command, Option } from "commander"; const program = new Command(); program .option("-pp, --pretty", "pretty-print JSON output") - .option( - "-pg, --print-group ", - "print a list of the layers in a group" + .addOption( + new Option( + "-pg, --print-group ", + "print a list of the layers in a group" + ).conflicts("printLayer") ) .option("-pl, --print-layer ", "print the JSON of a layer") .option("-loc, --locales ", "language codes", ["mul"]); @@ -44,14 +46,10 @@ for (let i = 0; i < layers.length; i++) { let outputObj; if (opts.printGroup) { - let group = layerGroupMap.get(opts.printGroup); - let layers = []; - group.forEach((lyr) => layers.push(lyr)); - outputObj = layers; + outputObj = layerGroupMap.get(opts.printGroup); } if (opts.printLayer) { - console.log(layerMap); outputObj = layerMap.get(opts.printLayer) ?? {}; } From 67312c08a96cae2740d92ed7a197bafbb82a3f23 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 22 Jun 2023 20:01:15 -0400 Subject: [PATCH 08/14] Update docs --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 51be9721a..155b8088d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -202,7 +202,7 @@ There is an "extract_layers" script that will extract layer style data: ## Layers -1. Layers should be named as followed: `_`, wher the "group" should match the file name that the layer is contained in. This naming convention is needed by the layer statistic script. +1. Layers must be uniquely named. 2. For performance reasons, it is better to have fewer layers with filters than multiple, simpler layers. 3. Layers are drawn in the order specified in `layer/index.js` using the [Painter's Algorithm](https://en.wikipedia.org/wiki/Painter%27s_algorithm). From 90ca7947092e0d672ab224e87e0e90967e813000 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 22 Jun 2023 20:30:21 -0400 Subject: [PATCH 09/14] Fix npm scripts --- CONTRIBUTING.md | 12 ++++++------ package.json | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 155b8088d..ed45bf9e6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -190,15 +190,15 @@ When adding or changing style layer code, it can be helpful to assess the change There is a "stats" script that will generate various statistics about layer composition and complexity: -- `npm run stats -- -a -s` - overall size and breakdown of layers -- `npm run stats -- -c` - total layer count -- `npm run stats -- -h` - list all options +- `npm run -s stats -- -a -s` - overall size and breakdown of layers +- `npm run -s stats -- -c` - total layer count +- `npm run -s stats -- -h` - list all options There is an "extract_layers" script that will extract layer style data: -- `node scripts/extract_layers -pl ` - JSON contents of a specified layer -- `node scripts/extract_layers -pg ` - list of layers from a specified source -- `node scripts/extract_layers -h` - list all options +- `npm run -s extract_layers -pl ` - JSON contents of a specified layer +- `npm run -s extract_layers -pg ` - list of layers from a specified source +- `npm run -s extract_layers -h` - list all options ## Layers diff --git a/package.json b/package.json index d82733cd3..813895eec 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "code_format": "run-s code_format:prettier code_format:svgo", "code_format:prettier": "prettier --write --list-different .", "code_format:svgo": "svgo -q -f icons/", + "extract_layer": "node scripts/extract_layer", "presprites": "shx rm -rf dist/sprites", "serve": "ts-node scripts/serve", "shields": "node scripts/generate_shield_defs.js -o dist/shields.json", From b230b564ac245e1f7f060b142cba48c7dc3b7e68 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 22 Jun 2023 20:33:32 -0400 Subject: [PATCH 10/14] Change to const --- scripts/extract_layer.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/extract_layer.js b/scripts/extract_layer.js index 729327282..e6eb4cc3b 100644 --- a/scripts/extract_layer.js +++ b/scripts/extract_layer.js @@ -15,13 +15,13 @@ program .option("-loc, --locales ", "language codes", ["mul"]); program.parse(process.argv); -let opts = program.opts(); +const opts = program.opts(); if (Object.keys(opts).length === 1) program.help(); -let locales = opts.locales[0].split(","); +const locales = opts.locales[0].split(","); -let style = Style.build( +const style = Style.build( config.OPENMAPTILES_URL, "https://zelonewolf.github.io/openstreetmap-americana/sprites/sprite", "https://osm-americana.github.io/fontstack66/{fontstack}/{range}.pbf", @@ -33,9 +33,9 @@ const layerMap = new Map(); const layerGroupMap = new Map(); for (let i = 0; i < layers.length; i++) { - let layer = layers[i]; + const layer = layers[i]; layerMap.set(layer.id, layers[i]); - let layerGroup = layer["source-layer"] || layer.source || layer.type; + const layerGroup = layer["source-layer"] || layer.source || layer.type; if (!layerGroupMap.has(layerGroup)) { layerGroupMap.set(layerGroup, [layer.id]); } else { From fc881fc46f983328f4c9cb2b8b1df78d317ca7f2 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 22 Jun 2023 20:38:02 -0400 Subject: [PATCH 11/14] Code cleanup --- scripts/stats.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/scripts/stats.js b/scripts/stats.js index f7258661a..df58f2b46 100644 --- a/scripts/stats.js +++ b/scripts/stats.js @@ -13,13 +13,13 @@ program program.parse(process.argv); -let opts = program.opts(); +const opts = program.opts(); if (Object.keys(opts).length === 1) program.help(); -let locales = opts.locales[0].split(","); +const locales = opts.locales[0].split(","); -let style = Style.build( +const style = Style.build( config.OPENMAPTILES_URL, "https://zelonewolf.github.io/openstreetmap-americana/sprites/sprite", "https://osm-americana.github.io/fontstack66/{fontstack}/{range}.pbf", @@ -50,10 +50,10 @@ const stats = { }; for (let i = 0; i < layerCount; i++) { - let layer = layers[i]; + const layer = layers[i]; layerMap.set(layer.id, layers[i]); - let layerSize = JSON.stringify(layer).length; - let layerGroup = layer["source-layer"] || layer.source || layer.type; + const layerSize = JSON.stringify(layer).length; + const layerGroup = layer["source-layer"] || layer.source || layer.type; if (stats.layerGroup[layerGroup]) { stats.layerGroup[layerGroup].size += layerSize; stats.layerGroup[layerGroup].count++; @@ -66,11 +66,7 @@ for (let i = 0; i < layerCount; i++) { } if (opts.allJson) { - if (opts.pretty) { - process.stdout.write(JSON.stringify(stats, null, 2)); - } else { - process.stdout.write(JSON.stringify(stats)); - } + process.stdout.write(JSON.stringify(stats, null, opts.pretty ? 2 : null)); process.exit(); } From b1813c0487ebd61ad0919f90bb386cb6b72a8bbd Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 22 Jun 2023 20:44:09 -0400 Subject: [PATCH 12/14] Set mutex options --- scripts/stats.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/stats.js b/scripts/stats.js index df58f2b46..04b4fd8da 100644 --- a/scripts/stats.js +++ b/scripts/stats.js @@ -1,12 +1,23 @@ import * as Style from "../src/js/style.js"; import config from "../src/config.js"; -import { Command } from "commander"; +import { Command, Option } from "commander"; const program = new Command(); program - .option("-a, --all-layers", "summary layer stats") - .option("-c, --layer-count", "count number of layers") - .option("-s, --layer-size", "size of all layers") + .addOption( + new Option("-a, --all-layers", "summary layer stats") + .conflicts("layerCount") + .conflicts("layerSize") + .conflicts("allJson") + ) + .addOption( + new Option("-c, --layer-count", "count number of layers") + .conflicts("layerSize") + .conflicts("allJson") + ) + .addOption( + new Option("-s, --layer-size", "size of all layers").conflicts("allJson") + ) .option("-loc, --locales ", "language codes", ["mul"]) .option("-j, --all-json", "output all stats in JSON") .option("-pp, --pretty", "pretty-print JSON output"); From 0c9803f7b923035f0348d39236176803c1b46c49 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 22 Jun 2023 20:46:17 -0400 Subject: [PATCH 13/14] Rename to layerCount --- scripts/stats.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/stats.js b/scripts/stats.js index 04b4fd8da..b75ef7f01 100644 --- a/scripts/stats.js +++ b/scripts/stats.js @@ -67,11 +67,11 @@ for (let i = 0; i < layerCount; i++) { const layerGroup = layer["source-layer"] || layer.source || layer.type; if (stats.layerGroup[layerGroup]) { stats.layerGroup[layerGroup].size += layerSize; - stats.layerGroup[layerGroup].count++; + stats.layerGroup[layerGroup].layerCount++; } else { stats.layerGroup[layerGroup] = { size: layerSize, - count: 1, + layerCount: 1, }; } } @@ -84,7 +84,7 @@ if (opts.allJson) { if (opts.allLayers) { for (const layerGroup in stats.layerGroup) { let layerStats = stats.layerGroup[layerGroup]; - let layerString = `${layerGroup}(${layerStats.count})`.padEnd(30, "."); + let layerString = `${layerGroup}(${layerStats.layerCount})`.padEnd(30, "."); console.log( `${layerString}${layerStats.size .toLocaleString("en-US") From a728705a1f2c96cf13925c4765c87241e7adf419 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Thu, 22 Jun 2023 21:44:46 -0400 Subject: [PATCH 14/14] Update CONTRIBUTING.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Minh Nguyễn --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ed45bf9e6..62a22b609 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -196,9 +196,9 @@ There is a "stats" script that will generate various statistics about layer comp There is an "extract_layers" script that will extract layer style data: -- `npm run -s extract_layers -pl ` - JSON contents of a specified layer -- `npm run -s extract_layers -pg ` - list of layers from a specified source -- `npm run -s extract_layers -h` - list all options +- `npm run -s extract_layer -pl ` - JSON contents of a specified layer +- `npm run -s extract_layer -pg ` - list of layers from a specified source +- `npm run -s extract_layer -h` - list all options ## Layers