Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More gl2d symbols! #1781

Merged
merged 19 commits into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^3.0.2",
"fast-isnumeric": "^1.1.1",
"font-atlas-sdf": "^1.3.3",
"gl-contour2d": "^1.1.2",
"gl-error2d": "^1.2.1",
"gl-error3d": "^1.0.6",
Expand All @@ -76,7 +77,7 @@
"gl-plot3d": "^1.5.4",
"gl-pointcloud2d": "^1.0.0",
"gl-scatter2d": "^1.2.2",
"gl-scatter2d-sdf": "^1.3.9",
"gl-scatter2d-sdf": "^1.3.10",
"gl-scatter3d": "^1.0.4",
"gl-select-box": "^1.0.1",
"gl-shader": "4.2.0",
Expand Down
132 changes: 132 additions & 0 deletions src/constants/gl2d_markers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var extendFlat = require('../lib/extend').extendFlat;

var symbolsWithOpenSupport = {
'circle': {
unicode: '●'
},
'square': {
unicode: '■'
},
'diamond': {
unicode: '◆'
},
'cross': {
unicode: '✚'
},
'x': {
unicode: '❌'
},
'triangle-up': {
unicode: '▲'
},
'triangle-down': {
unicode: '▼'
},
'triangle-left': {
unicode: '◄'
},
'triangle-right': {
unicode: '►'
},
'triangle-ne': {
unicode: '◥'
},
'triangle-nw': {
unicode: '◤'
},
'triangle-se': {
unicode: '◢'
},
'triangle-sw': {
unicode: '◣'
},
'pentagon': {
unicode: '⬟'
},
'hexagon': {
unicode: '⬢'
},
'hexagon2': {
unicode: '⬣'
},
'star': {
unicode: '★'
},
'diamond-tall': {
unicode: '♦'
},
'bowtie': {
unicode: '⧓'
},
'diamond-x': {
unicode: '❖'
},
'cross-thin': {
unicode: '+',
noBorder: true
},
'asterisk': {
unicode: '✳',
noBorder: true
},
'y-up': {
unicode: '⅄',
noBorder: true
},
'y-down': {
unicode: 'Y',
noBorder: true
},
'line-ew': {
unicode: '─',
noBorder: true
},
'line-ns': {
unicode: '│',
noBorder: true
}
};

var openSymbols = {};
var keys = Object.keys(symbolsWithOpenSupport);

for(var i = 0; i < keys.length; i++) {
var k = keys[i];
openSymbols[k + '-open'] = extendFlat({}, symbolsWithOpenSupport[k]);
}

var otherSymbols = {
'circle-cross-open': {
unicode: '⨁',
noFill: true
},
'circle-x-open': {
unicode: '⨂',
noFill: true
},
'square-cross-open': {
unicode: '⊞',
noFill: true
},
'square-x-open': {
unicode: '⊠',
noFill: true
}
};

module.exports = extendFlat({},
symbolsWithOpenSupport,
openSymbols,
otherSymbols
);
File renamed without changes.
2 changes: 1 addition & 1 deletion src/traces/scatter3d/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var colorAttributes = require('../../components/colorscale/color_attributes');
var errorBarAttrs = require('../../components/errorbars/attributes');
var DASHES = require('../../constants/gl3d_dashes');

var MARKER_SYMBOLS = require('../../constants/gl_markers');
var MARKER_SYMBOLS = require('../../constants/gl3d_markers');
var extendFlat = require('../../lib/extend').extendFlat;

var scatterLineAttrs = scatterAttrs.line,
Expand Down
2 changes: 1 addition & 1 deletion src/traces/scatter3d/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var str2RgbaArray = require('../../lib/str2rgbarray');
var formatColor = require('../../lib/gl_format_color');
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
var DASH_PATTERNS = require('../../constants/gl3d_dashes');
var MARKER_SYMBOLS = require('../../constants/gl_markers');
var MARKER_SYMBOLS = require('../../constants/gl3d_markers');

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

Expand Down
2 changes: 1 addition & 1 deletion src/traces/scatter3d/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var Scatter3D = {};

Scatter3D.plot = require('./convert');
Scatter3D.attributes = require('./attributes');
Scatter3D.markerSymbols = require('../../constants/gl_markers');
Scatter3D.markerSymbols = require('../../constants/gl3d_markers');
Scatter3D.supplyDefaults = require('./defaults');
Scatter3D.colorbar = require('../scatter/colorbar');
Scatter3D.calc = require('./calc');
Expand Down
2 changes: 1 addition & 1 deletion src/traces/scattergl/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var scatterAttrs = require('../scatter/attributes');
var colorAttributes = require('../../components/colorscale/color_attributes');

var DASHES = require('../../constants/gl2d_dashes');
var MARKERS = require('../../constants/gl_markers');
var MARKERS = require('../../constants/gl2d_markers');
var extendFlat = require('../../lib/extend').extendFlat;
var extendDeep = require('../../lib/extend').extendDeep;

Expand Down
73 changes: 53 additions & 20 deletions src/traces/scattergl/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ var formatColor = require('../../lib/gl_format_color');
var subTypes = require('../scatter/subtypes');
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
var getTraceColor = require('../scatter/get_trace_color');
var MARKER_SYMBOLS = require('../../constants/gl_markers');
var MARKER_SYMBOLS = require('../../constants/gl2d_markers');
var DASHES = require('../../constants/gl2d_dashes');

var AXES = ['xaxis', 'yaxis'];

var transparent = [0, 0, 0, 0];

function LineWithMarkers(scene, uid) {
this.scene = scene;
Expand Down Expand Up @@ -214,7 +214,7 @@ function _convertArray(convert, data, count) {
var convertNumber = convertArray.bind(null, function(x) { return +x; });
var convertColorBase = convertArray.bind(null, str2RGBArray);
var convertSymbol = convertArray.bind(null, function(x) {
return MARKER_SYMBOLS[x] || '●';
return MARKER_SYMBOLS[x] ? x : 'circle';
});

function convertColor(color, opacity, count) {
Expand Down Expand Up @@ -251,8 +251,17 @@ function _convertColor(colors, opacities, count) {
return result;
}

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

function fillColor(colorIn, colorOut, offsetIn, offsetOut) {
for(var j = 0; j < 4; j++) {
colorIn[4 * offsetIn + j] = colorOut[4 * offsetOut + j];
}
}

proto.update = function(options) {
if(options.visible !== true) {
this.isVisible = false;
this.hasLines = false;
Expand Down Expand Up @@ -441,7 +450,7 @@ proto.updateFancy = function(options) {
var getX = (xaxis.type === 'log') ? xaxis.d2l : function(x) { return x; };
var getY = (yaxis.type === 'log') ? yaxis.d2l : function(y) { return y; };

var i, j, xx, yy, ex0, ex1, ey0, ey1;
var i, xx, yy, ex0, ex1, ey0, ey1;

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

var markerSizeFunc = makeBubbleSizeFn(options),
markerOpts = options.marker,
markerOpacity = markerOpts.opacity,
traceOpacity = options.opacity,
colors = convertColorScale(markerOpts, markerOpacity, traceOpacity, len),
glyphs = convertSymbol(markerOpts.symbol, len),
borderWidths = convertNumber(markerOpts.line.width, len),
borderColors = convertColorScale(markerOpts.line, markerOpacity, traceOpacity, len),
index;
var markerSizeFunc = makeBubbleSizeFn(options);
var markerOpts = options.marker;
var markerOpacity = markerOpts.opacity;
var traceOpacity = options.opacity;
var symbols = convertSymbol(markerOpts.symbol, len);
var colors = convertColorScale(markerOpts, markerOpacity, traceOpacity, len);
var borderWidths = convertNumber(markerOpts.line.width, len);
var borderColors = convertColorScale(markerOpts.line, markerOpacity, traceOpacity, len);
var index, size, symbol, symbolSpec, isOpen, _colors, _borderColors, bw, minBorderWidth;

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

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

this.scatter.options.sizes[i] = 4.0 * sizes[index];
this.scatter.options.glyphs[i] = glyphs[index];
this.scatter.options.borderWidths[i] = 0.5 * borderWidths[index];
symbol = symbols[index];
symbolSpec = MARKER_SYMBOLS[symbol];
isOpen = isSymbolOpen(symbol);

if(symbolSpec.noBorder && !isOpen) {
_colors = borderColors;
} else {
_colors = colors;
}

if(isOpen) {
_borderColors = colors;
} else {
_borderColors = borderColors;
}

// See https://github.com/plotly/plotly.js/pull/1781#discussion_r121820798
// for more info on this logic
size = sizes[index];
bw = borderWidths[index];
minBorderWidth = (symbolSpec.noBorder || symbolSpec.noFill) ? 0.1 * size : 0;

this.scatter.options.sizes[i] = 4.0 * size;
this.scatter.options.glyphs[i] = symbolSpec.unicode;
this.scatter.options.borderWidths[i] = 0.5 * ((bw > minBorderWidth) ? bw - minBorderWidth : 0);

for(j = 0; j < 4; ++j) {
this.scatter.options.colors[4 * i + j] = colors[4 * index + j];
this.scatter.options.borderColors[4 * i + j] = borderColors[4 * index + j];
if(isOpen && !symbolSpec.noBorder && !symbolSpec.noFill) {
fillColor(this.scatter.options.colors, transparent, i, 0);
} else {
fillColor(this.scatter.options.colors, _colors, i, index);
}
fillColor(this.scatter.options.borderColors, _borderColors, i, index);
}

this.fancyScatter.update();
Expand Down
Binary file modified test/image/baselines/gl2d_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_axes_booleans.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_axes_labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_axes_lines.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_axes_range_manual.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_axes_range_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_axes_range_type.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_date_axes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_error_bars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/gl2d_marker_line_width.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_marker_symbols.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_multiple_subplots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_scatter-colorscale-colorbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_scatter-marker-line-colorscales.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_simple_inset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_size_margins.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_stacked_coupled_subplots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl2d_stacked_subplots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/gl3d_marker_symbols.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/marker_line_width.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/marker_symbols.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading