Skip to content

Commit 91c0b8d

Browse files
authored
Merge pull request #1781 from plotly/gl2d-more-symbols
More gl2d symbols!
2 parents 52271e9 + 4444c36 commit 91c0b8d

37 files changed

+2959
-51
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"delaunay-triangulate": "^1.1.6",
6565
"es6-promise": "^3.0.2",
6666
"fast-isnumeric": "^1.1.1",
67+
"font-atlas-sdf": "^1.3.3",
6768
"gl-contour2d": "^1.1.2",
6869
"gl-error2d": "^1.2.1",
6970
"gl-error3d": "^1.0.6",
@@ -76,7 +77,7 @@
7677
"gl-plot3d": "^1.5.4",
7778
"gl-pointcloud2d": "^1.0.0",
7879
"gl-scatter2d": "^1.2.2",
79-
"gl-scatter2d-sdf": "^1.3.9",
80+
"gl-scatter2d-sdf": "^1.3.10",
8081
"gl-scatter3d": "^1.0.4",
8182
"gl-select-box": "^1.0.1",
8283
"gl-shader": "4.2.0",

src/constants/gl2d_markers.js

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* Copyright 2012-2017, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
10+
'use strict';
11+
12+
var extendFlat = require('../lib/extend').extendFlat;
13+
14+
var symbolsWithOpenSupport = {
15+
'circle': {
16+
unicode: '●'
17+
},
18+
'square': {
19+
unicode: '■'
20+
},
21+
'diamond': {
22+
unicode: '◆'
23+
},
24+
'cross': {
25+
unicode: '✚'
26+
},
27+
'x': {
28+
unicode: '❌'
29+
},
30+
'triangle-up': {
31+
unicode: '▲'
32+
},
33+
'triangle-down': {
34+
unicode: '▼'
35+
},
36+
'triangle-left': {
37+
unicode: '◄'
38+
},
39+
'triangle-right': {
40+
unicode: '►'
41+
},
42+
'triangle-ne': {
43+
unicode: '◥'
44+
},
45+
'triangle-nw': {
46+
unicode: '◤'
47+
},
48+
'triangle-se': {
49+
unicode: '◢'
50+
},
51+
'triangle-sw': {
52+
unicode: '◣'
53+
},
54+
'pentagon': {
55+
unicode: '⬟'
56+
},
57+
'hexagon': {
58+
unicode: '⬢'
59+
},
60+
'hexagon2': {
61+
unicode: '⬣'
62+
},
63+
'star': {
64+
unicode: '★'
65+
},
66+
'diamond-tall': {
67+
unicode: '♦'
68+
},
69+
'bowtie': {
70+
unicode: '⧓'
71+
},
72+
'diamond-x': {
73+
unicode: '❖'
74+
},
75+
'cross-thin': {
76+
unicode: '+',
77+
noBorder: true
78+
},
79+
'asterisk': {
80+
unicode: '✳',
81+
noBorder: true
82+
},
83+
'y-up': {
84+
unicode: '⅄',
85+
noBorder: true
86+
},
87+
'y-down': {
88+
unicode: 'Y',
89+
noBorder: true
90+
},
91+
'line-ew': {
92+
unicode: '─',
93+
noBorder: true
94+
},
95+
'line-ns': {
96+
unicode: '│',
97+
noBorder: true
98+
}
99+
};
100+
101+
var openSymbols = {};
102+
var keys = Object.keys(symbolsWithOpenSupport);
103+
104+
for(var i = 0; i < keys.length; i++) {
105+
var k = keys[i];
106+
openSymbols[k + '-open'] = extendFlat({}, symbolsWithOpenSupport[k]);
107+
}
108+
109+
var otherSymbols = {
110+
'circle-cross-open': {
111+
unicode: '⨁',
112+
noFill: true
113+
},
114+
'circle-x-open': {
115+
unicode: '⨂',
116+
noFill: true
117+
},
118+
'square-cross-open': {
119+
unicode: '⊞',
120+
noFill: true
121+
},
122+
'square-x-open': {
123+
unicode: '⊠',
124+
noFill: true
125+
}
126+
};
127+
128+
module.exports = extendFlat({},
129+
symbolsWithOpenSupport,
130+
openSymbols,
131+
otherSymbols
132+
);
File renamed without changes.

src/traces/scatter3d/attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var colorAttributes = require('../../components/colorscale/color_attributes');
1313
var errorBarAttrs = require('../../components/errorbars/attributes');
1414
var DASHES = require('../../constants/gl3d_dashes');
1515

16-
var MARKER_SYMBOLS = require('../../constants/gl_markers');
16+
var MARKER_SYMBOLS = require('../../constants/gl3d_markers');
1717
var extendFlat = require('../../lib/extend').extendFlat;
1818

1919
var scatterLineAttrs = scatterAttrs.line,

src/traces/scatter3d/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var str2RgbaArray = require('../../lib/str2rgbarray');
2020
var formatColor = require('../../lib/gl_format_color');
2121
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
2222
var DASH_PATTERNS = require('../../constants/gl3d_dashes');
23-
var MARKER_SYMBOLS = require('../../constants/gl_markers');
23+
var MARKER_SYMBOLS = require('../../constants/gl3d_markers');
2424

2525
var calculateError = require('./calc_errors');
2626

src/traces/scatter3d/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var Scatter3D = {};
1212

1313
Scatter3D.plot = require('./convert');
1414
Scatter3D.attributes = require('./attributes');
15-
Scatter3D.markerSymbols = require('../../constants/gl_markers');
15+
Scatter3D.markerSymbols = require('../../constants/gl3d_markers');
1616
Scatter3D.supplyDefaults = require('./defaults');
1717
Scatter3D.colorbar = require('../scatter/colorbar');
1818
Scatter3D.calc = require('./calc');

src/traces/scattergl/attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var scatterAttrs = require('../scatter/attributes');
1212
var colorAttributes = require('../../components/colorscale/color_attributes');
1313

1414
var DASHES = require('../../constants/gl2d_dashes');
15-
var MARKERS = require('../../constants/gl_markers');
15+
var MARKERS = require('../../constants/gl2d_markers');
1616
var extendFlat = require('../../lib/extend').extendFlat;
1717
var extendDeep = require('../../lib/extend').extendDeep;
1818

src/traces/scattergl/convert.js

+53-20
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ var formatColor = require('../../lib/gl_format_color');
2525
var subTypes = require('../scatter/subtypes');
2626
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
2727
var getTraceColor = require('../scatter/get_trace_color');
28-
var MARKER_SYMBOLS = require('../../constants/gl_markers');
28+
var MARKER_SYMBOLS = require('../../constants/gl2d_markers');
2929
var DASHES = require('../../constants/gl2d_dashes');
3030

3131
var AXES = ['xaxis', 'yaxis'];
32-
32+
var transparent = [0, 0, 0, 0];
3333

3434
function LineWithMarkers(scene, uid) {
3535
this.scene = scene;
@@ -214,7 +214,7 @@ function _convertArray(convert, data, count) {
214214
var convertNumber = convertArray.bind(null, function(x) { return +x; });
215215
var convertColorBase = convertArray.bind(null, str2RGBArray);
216216
var convertSymbol = convertArray.bind(null, function(x) {
217-
return MARKER_SYMBOLS[x] || '●';
217+
return MARKER_SYMBOLS[x] ? x : 'circle';
218218
});
219219

220220
function convertColor(color, opacity, count) {
@@ -251,8 +251,17 @@ function _convertColor(colors, opacities, count) {
251251
return result;
252252
}
253253

254-
proto.update = function(options) {
254+
function isSymbolOpen(symbol) {
255+
return symbol.split('-open')[1] === '';
256+
}
255257

258+
function fillColor(colorIn, colorOut, offsetIn, offsetOut) {
259+
for(var j = 0; j < 4; j++) {
260+
colorIn[4 * offsetIn + j] = colorOut[4 * offsetOut + j];
261+
}
262+
}
263+
264+
proto.update = function(options) {
256265
if(options.visible !== true) {
257266
this.isVisible = false;
258267
this.hasLines = false;
@@ -441,7 +450,7 @@ proto.updateFancy = function(options) {
441450
var getX = (xaxis.type === 'log') ? xaxis.d2l : function(x) { return x; };
442451
var getY = (yaxis.type === 'log') ? yaxis.d2l : function(y) { return y; };
443452

444-
var i, j, xx, yy, ex0, ex1, ey0, ey1;
453+
var i, xx, yy, ex0, ex1, ey0, ey1;
445454

446455
for(i = 0; i < len; ++i) {
447456
this.xData[i] = xx = getX(x[i]);
@@ -491,29 +500,53 @@ proto.updateFancy = function(options) {
491500
this.scatter.options.colors = new Array(pId * 4);
492501
this.scatter.options.borderColors = new Array(pId * 4);
493502

494-
var markerSizeFunc = makeBubbleSizeFn(options),
495-
markerOpts = options.marker,
496-
markerOpacity = markerOpts.opacity,
497-
traceOpacity = options.opacity,
498-
colors = convertColorScale(markerOpts, markerOpacity, traceOpacity, len),
499-
glyphs = convertSymbol(markerOpts.symbol, len),
500-
borderWidths = convertNumber(markerOpts.line.width, len),
501-
borderColors = convertColorScale(markerOpts.line, markerOpacity, traceOpacity, len),
502-
index;
503+
var markerSizeFunc = makeBubbleSizeFn(options);
504+
var markerOpts = options.marker;
505+
var markerOpacity = markerOpts.opacity;
506+
var traceOpacity = options.opacity;
507+
var symbols = convertSymbol(markerOpts.symbol, len);
508+
var colors = convertColorScale(markerOpts, markerOpacity, traceOpacity, len);
509+
var borderWidths = convertNumber(markerOpts.line.width, len);
510+
var borderColors = convertColorScale(markerOpts.line, markerOpacity, traceOpacity, len);
511+
var index, size, symbol, symbolSpec, isOpen, _colors, _borderColors, bw, minBorderWidth;
503512

504513
sizes = convertArray(markerSizeFunc, markerOpts.size, len);
505514

506515
for(i = 0; i < pId; ++i) {
507516
index = idToIndex[i];
508517

509-
this.scatter.options.sizes[i] = 4.0 * sizes[index];
510-
this.scatter.options.glyphs[i] = glyphs[index];
511-
this.scatter.options.borderWidths[i] = 0.5 * borderWidths[index];
518+
symbol = symbols[index];
519+
symbolSpec = MARKER_SYMBOLS[symbol];
520+
isOpen = isSymbolOpen(symbol);
521+
522+
if(symbolSpec.noBorder && !isOpen) {
523+
_colors = borderColors;
524+
} else {
525+
_colors = colors;
526+
}
527+
528+
if(isOpen) {
529+
_borderColors = colors;
530+
} else {
531+
_borderColors = borderColors;
532+
}
533+
534+
// See https://github.com/plotly/plotly.js/pull/1781#discussion_r121820798
535+
// for more info on this logic
536+
size = sizes[index];
537+
bw = borderWidths[index];
538+
minBorderWidth = (symbolSpec.noBorder || symbolSpec.noFill) ? 0.1 * size : 0;
539+
540+
this.scatter.options.sizes[i] = 4.0 * size;
541+
this.scatter.options.glyphs[i] = symbolSpec.unicode;
542+
this.scatter.options.borderWidths[i] = 0.5 * ((bw > minBorderWidth) ? bw - minBorderWidth : 0);
512543

513-
for(j = 0; j < 4; ++j) {
514-
this.scatter.options.colors[4 * i + j] = colors[4 * index + j];
515-
this.scatter.options.borderColors[4 * i + j] = borderColors[4 * index + j];
544+
if(isOpen && !symbolSpec.noBorder && !symbolSpec.noFill) {
545+
fillColor(this.scatter.options.colors, transparent, i, 0);
546+
} else {
547+
fillColor(this.scatter.options.colors, _colors, i, index);
516548
}
549+
fillColor(this.scatter.options.borderColors, _borderColors, i, index);
517550
}
518551

519552
this.fancyScatter.update();

test/image/baselines/gl2d_10.png

22 Bytes
Loading

test/image/baselines/gl2d_12.png

254 Bytes
Loading

test/image/baselines/gl2d_14.png

-155 Bytes
Loading

test/image/baselines/gl2d_17.png

364 Bytes
Loading
75 Bytes
Loading
77 Bytes
Loading
47 Bytes
Loading
-5 Bytes
Loading
-35 Bytes
Loading
-29 Bytes
Loading
0 Bytes
Loading
9 Bytes
Loading
51.1 KB
Loading
25.1 KB
Loading
49 Bytes
Loading
Loading
Loading
-7 Bytes
Loading
-110 Bytes
Loading
Loading
-7 Bytes
Loading
8.71 KB
Loading
45.7 KB
Loading
69.4 KB
Loading

0 commit comments

Comments
 (0)