Skip to content

Commit 96b08d4

Browse files
committed
Merge branch 'gl2d-more-symbols' into booz_2
2 parents 6a6ee44 + fffc702 commit 96b08d4

33 files changed

+1783
-53
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.3.1",
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

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
bwFactor: 0.25
75+
},
76+
'cross-thin': {
77+
unicode: '+',
78+
noBorder: true
79+
},
80+
'asterisk': {
81+
unicode: '✳',
82+
noBorder: true
83+
},
84+
'y-up': {
85+
unicode: '⅄',
86+
noBorder: true
87+
},
88+
'y-down': {
89+
unicode: 'Y',
90+
noBorder: true
91+
},
92+
'line-ew': {
93+
unicode: '─',
94+
noBorder: true
95+
},
96+
'line-ns': {
97+
unicode: '│',
98+
noBorder: true
99+
}
100+
};
101+
102+
var openSymbols = {};
103+
var keys = Object.keys(symbolsWithOpenSupport);
104+
105+
for(var i = 0; i < keys.length; i++) {
106+
var k = keys[i];
107+
openSymbols[k + '-open'] = extendFlat({}, symbolsWithOpenSupport[k]);
108+
}
109+
110+
var otherSymbols = {
111+
'circle-cross-open': {
112+
unicode: '⨁',
113+
noFill: true
114+
},
115+
'circle-x-open': {
116+
unicode: '⨂',
117+
noFill: true
118+
},
119+
'square-cross-open': {
120+
unicode: '⊞',
121+
noFill: true
122+
},
123+
'square-x-open': {
124+
unicode: '⊠',
125+
noFill: true
126+
}
127+
};
128+
129+
module.exports = extendFlat({},
130+
symbolsWithOpenSupport,
131+
openSymbols,
132+
otherSymbols
133+
);
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

+59-22
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ 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'];
3232
var DESELECTDIM = 0.2;
33-
33+
var transparent = [0, 0, 0, 0];
3434

3535
function LineWithMarkers(scene, uid) {
3636
this.scene = scene;
@@ -218,7 +218,7 @@ function _convertArray(convert, data, count) {
218218
var convertNumber = convertArray.bind(null, function(x) { return +x; });
219219
var convertColorBase = convertArray.bind(null, str2RGBArray);
220220
var convertSymbol = convertArray.bind(null, function(x) {
221-
return MARKER_SYMBOLS[x] || '●';
221+
return MARKER_SYMBOLS[x] ? x : 'circle';
222222
});
223223

224224
function convertColor(color, opacity, count) {
@@ -255,6 +255,19 @@ function _convertColor(colors, opacities, count) {
255255
return result;
256256
}
257257

258+
function isSymbolOpen(symbol) {
259+
return symbol.split('-open')[1] === '';
260+
}
261+
262+
function fillColor(colorIn, colorOut, offsetIn, offsetOut, isDimmed) {
263+
var dim = isDimmed ? DESELECTDIM : 1;
264+
265+
for(var j = 0; j < 3; j++) {
266+
colorIn[4 * offsetIn + j] = colorOut[4 * offsetOut + j];
267+
}
268+
colorIn[4 * offsetIn + j] = dim * colorOut[4 * offsetOut + j];
269+
}
270+
258271
proto.update = function(options, cdscatter) {
259272
if(options.visible !== true) {
260273
this.isVisible = false;
@@ -507,7 +520,7 @@ proto.updateFancy = function(options) {
507520
var getX = (xaxis.type === 'log') ? xaxis.d2l : function(x) { return x; };
508521
var getY = (yaxis.type === 'log') ? yaxis.d2l : function(y) { return y; };
509522

510-
var i, j, xx, yy, ex0, ex1, ey0, ey1;
523+
var i, xx, yy, ex0, ex1, ey0, ey1;
511524

512525
for(i = 0; i < len; ++i) {
513526
this.xData[i] = xx = getX(x[i]);
@@ -564,33 +577,57 @@ proto.updateFancy = function(options) {
564577
this.scatter.options.colors = new Array(pId * 4);
565578
this.scatter.options.borderColors = new Array(pId * 4);
566579

567-
var markerSizeFunc = makeBubbleSizeFn(options),
568-
markerOpts = options.marker,
569-
markerOpacity = markerOpts.opacity,
570-
traceOpacity = options.opacity,
571-
colors = convertColorScale(markerOpts, markerOpacity, traceOpacity, len),
572-
glyphs = convertSymbol(markerOpts.symbol, len),
573-
borderWidths = convertNumber(markerOpts.line.width, len),
574-
borderColors = convertColorScale(markerOpts.line, markerOpacity, traceOpacity, len),
575-
index;
580+
var markerSizeFunc = makeBubbleSizeFn(options);
581+
var markerOpts = options.marker;
582+
var markerOpacity = markerOpts.opacity;
583+
var traceOpacity = options.opacity;
584+
var symbols = convertSymbol(markerOpts.symbol, len);
585+
var colors = convertColorScale(markerOpts, markerOpacity, traceOpacity, len);
586+
var borderWidths = convertNumber(markerOpts.line.width, len);
587+
var borderColors = convertColorScale(markerOpts.line, markerOpacity, traceOpacity, len);
588+
var index, symbol, symbolSpec, _colors, _borderColors, bwFactor, isOpen, isDimmed;
576589

577590
sizes = convertArray(markerSizeFunc, markerOpts.size, len);
578591

579592
for(i = 0; i < pId; ++i) {
580593
index = idToIndex[i];
594+
symbol = symbols[index];
595+
symbolSpec = MARKER_SYMBOLS[symbol];
596+
isOpen = isSymbolOpen(symbol);
597+
isDimmed = selIds && !selIds[index];
598+
599+
if(symbolSpec.noBorder && !isOpen) {
600+
_colors = borderColors;
601+
} else {
602+
_colors = colors;
603+
}
604+
605+
if(isOpen) {
606+
_borderColors = colors;
607+
} else {
608+
_borderColors = borderColors;
609+
}
610+
611+
if(symbolSpec.bwFactor) {
612+
bwFactor = symbolSpec.bwFactor;
613+
} else if(symbolSpec.noBorder) {
614+
bwFactor = 0.25;
615+
} else if(symbolSpec.noFill) {
616+
bwFactor = 0.1;
617+
} else {
618+
bwFactor = 0.5;
619+
}
581620

582621
this.scatter.options.sizes[i] = 4.0 * sizes[index];
583-
this.scatter.options.glyphs[i] = glyphs[index];
584-
this.scatter.options.borderWidths[i] = 0.5 * borderWidths[index];
622+
this.scatter.options.glyphs[i] = symbolSpec.unicode;
623+
this.scatter.options.borderWidths[i] = bwFactor * borderWidths[index];
585624

586-
for(j = 0; j < 4; ++j) {
587-
var color = colors[4 * index + j];
588-
if(selIds && !selIds[index] && j === 3) {
589-
color *= DESELECTDIM;
590-
}
591-
this.scatter.options.colors[4 * i + j] = color;
592-
this.scatter.options.borderColors[4 * i + j] = borderColors[4 * index + j];
625+
if(isOpen && !symbolSpec.noBorder && !symbolSpec.noFill) {
626+
fillColor(this.scatter.options.colors, transparent, i, 0);
627+
} else {
628+
fillColor(this.scatter.options.colors, _colors, i, index, isDimmed);
593629
}
630+
fillColor(this.scatter.options.borderColors, _borderColors, i, index, isDimmed);
594631
}
595632

596633
// prevent scatter from resnapping points

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
25.9 KB
Loading
49 Bytes
Loading
Loading
Loading
-7 Bytes
Loading
-110 Bytes
Loading
Loading
-7 Bytes
Loading
8.71 KB
Loading
69.4 KB
Loading

0 commit comments

Comments
 (0)