From a7a0e46a7b31c19742f470add6fd77f5ca0e4cea Mon Sep 17 00:00:00 2001 From: Michele Ceriotti Date: Thu, 17 Oct 2024 22:17:31 +0200 Subject: [PATCH] Added point styles by monkey-patching plotly --- src/map/options.ts | 8 +++----- src/map/plotly/markers3d.js | 26 ++++++++++++++++++++++++++ src/map/plotly/plotly-scatter.js | 13 ++++++++++++- 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 src/map/plotly/markers3d.js diff --git a/src/map/options.ts b/src/map/options.ts index fd10c43d0..2511f538a 100644 --- a/src/map/options.ts +++ b/src/map/options.ts @@ -20,11 +20,9 @@ import { COLOR_MAPS } from './colorscales'; import BARS_SVG from '../static/bars.svg'; import HTML_OPTIONS from './options.html.in'; -// in 3D mode, only strings are supported for 'marker.symbol', and only very few -// of them. See https://github.com/plotly/plotly.js/issues/4205 as the plotly -// issue tracking more symbols in 3D mode. -const POSSIBLE_SYMBOLS_IN_3D = ['circle', 'square', 'diamond', 'cross']; - +// in 3D mode, only strings are supported for 'marker.symbol'. +const markers3d = require('./plotly/markers3d'); +const POSSIBLE_SYMBOLS_IN_3D = Object.keys(markers3d.default); export function get3DSymbol(i: number): string { return POSSIBLE_SYMBOLS_IN_3D[i % POSSIBLE_SYMBOLS_IN_3D.length]; } diff --git a/src/map/plotly/markers3d.js b/src/map/plotly/markers3d.js new file mode 100644 index 000000000..06c123916 --- /dev/null +++ b/src/map/plotly/markers3d.js @@ -0,0 +1,26 @@ +/** @type {{ [key: string]: string }} */ +const markers3d_dict = { + circle: '●', + square: '■', + diamond: '◆', + cross: '✚', + x: '✖', + 'triangle-up': '▲', + 'triangle-down': '▼', + 'triangle-left': '◀', + 'triangle-right': '▶', + 'triangle-ne': '◥', + 'triangle-se': '◢', + 'triangle-sw': '◣', + 'triangle-nw': '◤', + pentagon: '⬟', + hexagon: '⬢', + hexagon2: '⬣', + octagon: '⯃', + star: '🟊', + hexagram: '🟌', + hourglass: '⧗', + bowtie: '⧓', +}; + +export default markers3d_dict; diff --git a/src/map/plotly/plotly-scatter.js b/src/map/plotly/plotly-scatter.js index 95d0e8710..6b60e1434 100644 --- a/src/map/plotly/plotly-scatter.js +++ b/src/map/plotly/plotly-scatter.js @@ -10,8 +10,19 @@ 'use strict'; +const markers3d = require('./markers3d.js'); + +// Require the module +const scatter3d = require('plotly.js/lib/scatter3d'); +// monkey patch scatter3d to include more (and better!) symbols for 3d plots +// see https://github.com/plotly/plotly.js/issues/4205 in case this ever gets +// patched upstream and becomes unnecessary +for (const [k, v] of Object.entries(markers3d.default)) { + scatter3d.markerSymbols[k] = v; +} + const Plotly = require('plotly.js/lib/core'); -Plotly.register([require('plotly.js/lib/scattergl'), require('plotly.js/lib/scatter3d')]); +Plotly.register([require('plotly.js/lib/scattergl'), scatter3d]); module.exports = Plotly;