Skip to content

Commit

Permalink
Added point styles by monkey-patching plotly
Browse files Browse the repository at this point in the history
  • Loading branch information
ceriottm committed Oct 17, 2024
1 parent 6a2a75d commit a7a0e46
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/map/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Check failure on line 24 in src/map/options.ts

View workflow job for this annotation

GitHub Actions / npm-test

Unsafe assignment of an `any` value

Check failure on line 24 in src/map/options.ts

View workflow job for this annotation

GitHub Actions / npm-test

A `require()` style import is forbidden
const POSSIBLE_SYMBOLS_IN_3D = Object.keys(markers3d.default);

Check failure on line 25 in src/map/options.ts

View workflow job for this annotation

GitHub Actions / npm-test

Unsafe argument of type `any` assigned to a parameter of type `{}`

Check failure on line 25 in src/map/options.ts

View workflow job for this annotation

GitHub Actions / npm-test

Unsafe member access .default on an `any` value
export function get3DSymbol(i: number): string {
return POSSIBLE_SYMBOLS_IN_3D[i % POSSIBLE_SYMBOLS_IN_3D.length];
}
Expand Down
26 changes: 26 additions & 0 deletions src/map/plotly/markers3d.js
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 12 additions & 1 deletion src/map/plotly/plotly-scatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit a7a0e46

Please sign in to comment.