diff --git a/package-lock.json b/package-lock.json index a160df1d5..f0f98926e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,6 @@ "d3-timer": "^3.0.1", "d3-transition": "^3.0.1", "d3-zoom": "^3.0.0", - "deepscatter": "^3.0.0-next.23", "glsl-easings": "^1.0.0", "glsl-fast-gaussian-blur": "^1.0.2", "glsl-read-float": "^1.1.0", @@ -33,6 +32,7 @@ "@sveltejs/vite-plugin-svelte": "^3.0.2", "@types/d3": "^7.4.3", "@types/d3-geo": "^3.1.0", + "@types/d3-scale-chromatic": "^3.0.3", "@types/d3-selection": "^3.0.10", "@types/geojson": "^7946.0.14", "@types/lodash.merge": "^4.6.9", @@ -1134,9 +1134,10 @@ } }, "node_modules/@types/d3-scale-chromatic": { - "version": "3.0.0", - "dev": true, - "license": "MIT" + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/d3-scale-chromatic/-/d3-scale-chromatic-3.0.3.tgz", + "integrity": "sha512-laXM4+1o5ImZv3RpFAsTRn3TEkzqkytiOY0Dz0sq5cnd1dtNlk6sHLon4OvqaiJb28T0S/TdsBI3Sjsy+keJrw==", + "dev": true }, "node_modules/@types/d3-selection": { "version": "3.0.10", @@ -2419,34 +2420,6 @@ "node": ">=0.10.0" } }, - "node_modules/deepscatter": { - "version": "3.0.0-next.23", - "resolved": "https://registry.npmjs.org/deepscatter/-/deepscatter-3.0.0-next.23.tgz", - "integrity": "sha512-AuQ4fPvMZMgeUh1KVJFVUhExkiSYOYm0XyY3bSxCuYO7651mbRY//N0JSvi7D2L8OHfTVa0omJ0KeyNyTflcgQ==", - "dependencies": { - "d3-array": "^3.2.4", - "d3-color": "^3.1.0", - "d3-ease": "^3.0.1", - "d3-interpolate": "^3.0.1", - "d3-random": "^3.0.1", - "d3-scale": "^4.0.2", - "d3-scale-chromatic": "^3.0.0", - "d3-selection": "^3.0.0", - "d3-timer": "^3.0.1", - "d3-transition": "^3.0.1", - "d3-zoom": "^3.0.0", - "deepscatter": "^3.0.0-next.6", - "glsl-easings": "^1.0.0", - "glsl-fast-gaussian-blur": "^1.0.2", - "glsl-read-float": "^1.1.0", - "lodash.merge": "^4.6.2", - "rbush-3d": "^0.0.4", - "regl": "^2.1.0" - }, - "peerDependencies": { - "apache-arrow": ">=11.0.0 <17.0.0" - } - }, "node_modules/define-data-property": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", @@ -7367,7 +7340,9 @@ } }, "@types/d3-scale-chromatic": { - "version": "3.0.0", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/d3-scale-chromatic/-/d3-scale-chromatic-3.0.3.tgz", + "integrity": "sha512-laXM4+1o5ImZv3RpFAsTRn3TEkzqkytiOY0Dz0sq5cnd1dtNlk6sHLon4OvqaiJb28T0S/TdsBI3Sjsy+keJrw==", "dev": true }, "@types/d3-selection": { @@ -8239,31 +8214,6 @@ "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", "dev": true }, - "deepscatter": { - "version": "3.0.0-next.23", - "resolved": "https://registry.npmjs.org/deepscatter/-/deepscatter-3.0.0-next.23.tgz", - "integrity": "sha512-AuQ4fPvMZMgeUh1KVJFVUhExkiSYOYm0XyY3bSxCuYO7651mbRY//N0JSvi7D2L8OHfTVa0omJ0KeyNyTflcgQ==", - "requires": { - "d3-array": "^3.2.4", - "d3-color": "^3.1.0", - "d3-ease": "^3.0.1", - "d3-interpolate": "^3.0.1", - "d3-random": "^3.0.1", - "d3-scale": "^4.0.2", - "d3-scale-chromatic": "^3.0.0", - "d3-selection": "^3.0.0", - "d3-timer": "^3.0.1", - "d3-transition": "^3.0.1", - "d3-zoom": "^3.0.0", - "deepscatter": "^3.0.0-next.6", - "glsl-easings": "^1.0.0", - "glsl-fast-gaussian-blur": "^1.0.2", - "glsl-read-float": "^1.1.0", - "lodash.merge": "^4.6.2", - "rbush-3d": "^0.0.4", - "regl": "^2.1.0" - } - }, "define-data-property": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", diff --git a/package.json b/package.json index 38931115b..73bc766fd 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "@sveltejs/vite-plugin-svelte": "^3.0.2", "@types/d3": "^7.4.3", "@types/d3-geo": "^3.1.0", + "@types/d3-scale-chromatic": "^3.0.3", "@types/d3-selection": "^3.0.10", "@types/geojson": "^7946.0.14", "@types/lodash.merge": "^4.6.9", diff --git a/src/aesthetics/ColorAesthetic.ts b/src/aesthetics/ColorAesthetic.ts index 24c586d8f..b45124898 100644 --- a/src/aesthetics/ColorAesthetic.ts +++ b/src/aesthetics/ColorAesthetic.ts @@ -35,6 +35,7 @@ const color_palettes: Record = { }; const schemes: Record = {}; +const interpolators: Record = {}; function palette_from_color_strings(colors: readonly string[]): Uint8Array { // Fills a large Uint8Array by decomposing the colors and repeating over them. @@ -69,7 +70,6 @@ for (const schemename of [ 'schemeSet2', 'schemeSet3', 'schemeTableau10', - 'schemeObservable10', ] as const) { const colors = d3Chromatic[schemename]; @@ -133,15 +133,25 @@ const d3Interpolators = [ ] as const; for (const interpolator of d3Interpolators) { - const name = interpolator.replace('interpolate', '').toLowerCase(); + const nickname = interpolator.replace('interpolate', ''); + const v = d3Chromatic[interpolator]; + + // First store the d3 type for scale-building in javascript. + interpolators[nickname] = v; + interpolators[nickname.toLowerCase()] = v; + interpolators[nickname.toLowerCase()[0] + nickname.slice(1)] = v; + + // Then store an underlying block of colors for webGL work. const materialized = materialize_color_interpolator(v); - color_palettes[name] = materialized; - color_palettes[name.toLowerCase()] = materialized; - if (name === 'rainbow') { + color_palettes[nickname] = materialized; + color_palettes[nickname.toLowerCase()] = materialized; + color_palettes[nickname.toLowerCase()[0] + nickname.slice(1)] = materialized; + + if (nickname === 'Rainbow') { // Deterministic random shuffle orders const shuffle = shuffler(randomLcg(1)); - color_palettes.shufbow = shuffle(color_palettes[name]); + color_palettes.shufbow = shuffle(color_palettes[nickname]); } } @@ -152,10 +162,9 @@ function getSequentialScale( let interpolator: typeof d3Chromatic.interpolateViridis; if (typeof range === 'string') { // So we have to write `puOr`, `viridis`, etc. instead of `PuOr`, `Viridis` - const k = 'interpolate' + range.charAt(0).toUpperCase() + range.slice(1); - interpolator = d3Chromatic[k] as typeof d3Chromatic.interpolateViridis; + interpolator = interpolators[range]; if (interpolator === undefined) { - throw new Error(`Unknown interpolator ${k}`); + throw new Error(`Unknown interpolator ${range}`); } } else { interpolator = interpolateHsl(...range);