Skip to content

Commit 96c9eb3

Browse files
authored
Merge pull request #8071 from Lexachoc/fix-scattergl-marker-symbol-display
Fix numeric and numeric-string marker symbol variant detection in `scattergl`
2 parents c7aefae + 88cbefd commit 96c9eb3

4 files changed

Lines changed: 36 additions & 14 deletions

File tree

‎draftlogs/8071_fix.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix numeric and numeric-string marker symbol variant detection in `scattergl` [[#8071](https://github.com/plotly/plotly.js/pull/8071)]

‎src/traces/scattergl/constants.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ export const SYMBOL_SDF_SIZE = 200;
66
export const SYMBOL_SIZE = 20;
77
export const SYMBOL_STROKE = SYMBOL_SIZE / 20;
88

9-
export const DOT_RE = /-dot/;
10-
export const OPEN_RE = /-open/;
11-
129
export const DASHES = {
1310
solid: [1],
1411
dot: [1, 1],

‎src/traces/scattergl/helpers.js‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
'use strict';
22

3-
var constants = require('./constants');
3+
const { symbolNumber } = require('../../components/drawing');
44

5-
exports.isOpenSymbol = function(symbol) {
6-
return (typeof symbol === 'string') ?
7-
constants.OPEN_RE.test(symbol) :
8-
symbol % 200 > 100;
9-
};
5+
exports.isOpenSymbol = (symbol) => symbolNumber(symbol) % 200 >= 100;
106

11-
exports.isDotSymbol = function(symbol) {
12-
return (typeof symbol === 'string') ?
13-
constants.DOT_RE.test(symbol) :
14-
symbol > 200;
15-
};
7+
exports.isDotSymbol = (symbol) => symbolNumber(symbol) >= 200;

‎test/jasmine/tests/scattergl_test.js‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var Plotly = require('../../../lib/index');
22
var Lib = require('../../../src/lib');
33

44
var ScatterGl = require('../../../src/traces/scattergl');
5+
var ScatterGlHelpers = require('../../../src/traces/scattergl/helpers');
56
var TOO_MANY_POINTS = require('../../../src/traces/scattergl/constants').TOO_MANY_POINTS;
67

78
var createGraphDiv = require('../assets/create_graph_div');
@@ -11,6 +12,37 @@ var delay = require('../assets/delay');
1112
var readPixel = require('../assets/read_pixel');
1213
var checkTextTemplate = require('../assets/check_texttemplate');
1314

15+
describe('scattergl marker symbol variants', function() {
16+
var symbolCases = [
17+
{symbols: ['circle', 0, '0'], isOpen: false, isDot: false},
18+
{symbols: ['circle-open', 100, '100'], isOpen: true, isDot: false},
19+
{symbols: ['circle-dot', 200, '200'], isOpen: false, isDot: true},
20+
{symbols: ['circle-open-dot', 300, '300'], isOpen: true, isDot: true}
21+
];
22+
23+
it('should detect open symbol variants', function() {
24+
symbolCases.forEach(function(symbolCase) {
25+
symbolCase.symbols.forEach(function(symbol) {
26+
expect(ScatterGlHelpers.isOpenSymbol(symbol)).toBe(
27+
symbolCase.isOpen,
28+
'symbol: ' + JSON.stringify(symbol)
29+
);
30+
});
31+
});
32+
});
33+
34+
it('should detect dot symbol variants', function() {
35+
symbolCases.forEach(function(symbolCase) {
36+
symbolCase.symbols.forEach(function(symbol) {
37+
expect(ScatterGlHelpers.isDotSymbol(symbol)).toBe(
38+
symbolCase.isDot,
39+
'symbol: ' + JSON.stringify(symbol)
40+
);
41+
});
42+
});
43+
});
44+
});
45+
1446
describe('end-to-end scattergl tests', function() {
1547
var gd;
1648

0 commit comments

Comments
 (0)