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

Draw & adjust new shapes over image trace and cartesian subplots #4775

Merged
merged 71 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
ac75850
should not coerce shape.line.color and line.dash when line.width is zero
archmoj Jan 16, 2020
d5ee950
use Math.max instead of complex logic
archmoj Jan 16, 2020
3ecddcb
refactor conditions - avoid using Bitwise NOT to invert -1
archmoj Jan 16, 2020
eee814e
refactor list of dragmodes
archmoj Feb 13, 2020
0a0326c
reuse cartesian clearSelect function in mapbox and geo
archmoj Feb 14, 2020
11879d1
add new icons and modebars to draw new shapes
archmoj Mar 3, 2020
ddfc1bd
add new dragmodes and helpers
archmoj Mar 3, 2020
3ea4a25
add new attributes for drawing new shapes
archmoj Mar 3, 2020
d0ade83
handle scattergl and splom
archmoj Mar 3, 2020
8fd8b0c
prep to handle mapbox and ternary
archmoj Mar 3, 2020
07b07dc
add new shapes over cartesian traces
archmoj Apr 19, 2020
0c495e1
enable new modebars by default for now i.e. to test
archmoj Apr 19, 2020
1040786
improve edit open paths
archmoj Apr 20, 2020
47870fa
prep to edit curves
archmoj Apr 20, 2020
1106180
towards better handling of closing point
archmoj Apr 20, 2020
a585394
rename new dragmodes as well as modebar button names
archmoj Apr 20, 2020
092a80e
improve shape type defaults considering path in template
archmoj Apr 20, 2020
31209e7
init handle svg curves edits
archmoj Apr 20, 2020
feb7ab1
fix moving curve and handle multi-path e.g. smiley face on shapes mock
archmoj Apr 21, 2020
396d7d3
fix drag start points on closed paths
archmoj Apr 21, 2020
838bda9
revise description and use pre computed indices for circles
archmoj Apr 21, 2020
90a7ec7
simplify shape activation
archmoj Apr 21, 2020
618d138
fix date extra curve positions
archmoj Apr 21, 2020
c22bc77
simplify handle plotinfo axes and dates
archmoj Apr 21, 2020
5e1c9d9
fix edits with paper anchor
archmoj Apr 21, 2020
adb65f6
fixup for traces that has select but not x and y axes
archmoj Apr 21, 2020
38aef9e
do not change template shapes for now
archmoj Apr 21, 2020
98c7e9a
better handle for multiple polygons - only one newShape at a time
archmoj Apr 21, 2020
fc1d347
improve type detection on edit
archmoj Apr 22, 2020
569ce1c
fix circle on log
archmoj Apr 22, 2020
a20b290
fix closing point on path
archmoj Apr 22, 2020
77bf203
fix edit shapes with refs to one cartesian axis as well as paper
archmoj Apr 22, 2020
5f57d5c
create a reusable function to prepare options and plotinfo for arrayE…
archmoj Apr 22, 2020
9a4f4bf
move makeOptionsAndPlotinfo to shape helpers
archmoj Apr 22, 2020
18dd4f8
deactivate shape from pan and zoom dragmodes
archmoj Apr 22, 2020
1fcd55a
handle other deactivation scenarios
archmoj Apr 22, 2020
281666e
accept pre-defined draw buttons as string
archmoj Apr 22, 2020
83b6cd2
apply _guiRelayout instead of relayout when adding a new shape
archmoj Apr 22, 2020
cedad52
improve description
archmoj Apr 22, 2020
b90d179
Ensure config.editable:true works as it was before
archmoj Apr 23, 2020
7c26cd1
corce fillrule for all shape types
archmoj Apr 23, 2020
4bcc06a
correct early return from shape drawOne
archmoj Apr 23, 2020
f0ae835
fixup ternary clearSelect call
archmoj Apr 23, 2020
f7643cc
fixup ternary select
archmoj Apr 23, 2020
268aaaa
improve read shape positions
archmoj Apr 23, 2020
bea9230
add modebar test
archmoj Apr 23, 2020
dffe30a
draw shape test
archmoj Apr 23, 2020
ae24e27
active shape test
archmoj Apr 24, 2020
8c8f724
fix double click path vertices
archmoj Apr 25, 2020
852a7fb
add test for eraseshape button
archmoj Apr 26, 2020
3eee6f1
Update test/jasmine/tests/draw_shape_test.js
archmoj Apr 27, 2020
44dec73
update draw modebar button descriptions
archmoj Apr 27, 2020
d99b44b
update shape.editable description
archmoj Apr 27, 2020
1f19699
clear ternary and add comment about mapbox
archmoj Apr 27, 2020
a666206
erase getAxId helper function
archmoj Apr 27, 2020
63ef7aa
move newshape & activeshape attributes & defaults to components/shape…
archmoj Apr 27, 2020
d7e24b8
remove extra layer to activate shape on click
archmoj Apr 27, 2020
1089cd4
move newshape draw functions from cartesian to components/shapes/draw…
archmoj Apr 27, 2020
26def59
rename new tests to draw_newshape
archmoj Apr 27, 2020
6dbbd5c
fixup remove vertex
archmoj Apr 27, 2020
a824d85
split new draw code into multiple files
archmoj Apr 27, 2020
c5ff5df
revise outline updates in shape eidts
archmoj Apr 27, 2020
4039257
correct call to update vertices on click
archmoj Apr 27, 2020
0662ae7
apply arrayEditor to produce the updates for shapes in layout
archmoj Apr 27, 2020
d017bb7
simplify ellipse edit updates
archmoj Apr 28, 2020
9cd1ba1
simplify vertex buttons
archmoj Apr 28, 2020
00b6ae2
no need to display vertex controllers while dragging
archmoj Apr 28, 2020
efc85d6
simplify - no need for special cursor handling for rects
archmoj Apr 28, 2020
c69244f
simplify controllers - no need for invisible draggers
archmoj Apr 28, 2020
0ad14d1
split one big test into smaller tests to avoid side effects and futur…
archmoj Apr 28, 2020
2911e4f
speed up interactive circle edits
archmoj Apr 28, 2020
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"ndarray": "^1.0.18",
"ndarray-fill": "^1.0.2",
"ndarray-homography": "^1.0.0",
"parse-svg-path": "^0.1.2",
"point-cluster": "^3.1.8",
"polybooljs": "^1.2.0",
"regl": "^1.3.11",
Expand Down
57 changes: 57 additions & 0 deletions src/components/dragelement/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright 2012-2020, 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';

exports.selectMode = function(dragmode) {
return (
dragmode === 'lasso' ||
dragmode === 'select'
);
};

exports.drawMode = function(dragmode) {
return (
dragmode === 'drawclosedpath' ||
dragmode === 'drawopenpath' ||
dragmode === 'drawline' ||
dragmode === 'drawrect' ||
dragmode === 'drawcircle'
);
};

exports.openMode = function(dragmode) {
return (
dragmode === 'drawline' ||
dragmode === 'drawopenpath'
);
};

exports.rectMode = function(dragmode) {
return (
dragmode === 'select' ||
dragmode === 'drawline' ||
dragmode === 'drawrect' ||
dragmode === 'drawcircle'
);
};

exports.freeMode = function(dragmode) {
return (
dragmode === 'lasso' ||
dragmode === 'drawclosedpath' ||
dragmode === 'drawopenpath'
);
};

exports.selectingOrDrawing = function(dragmode) {
return (
exports.freeMode(dragmode) ||
exports.rectMode(dragmode)
);
};
21 changes: 17 additions & 4 deletions src/components/fx/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,20 @@ module.exports = {
dragmode: {
valType: 'enumerated',
role: 'info',
values: ['zoom', 'pan', 'select', 'lasso', 'orbit', 'turntable', false],
values: [
'zoom',
'pan',
'select',
'lasso',
'drawclosedpath',
'drawopenpath',
'drawline',
'drawrect',
'drawcircle',
'orbit',
'turntable',
false
],
dflt: 'zoom',
editType: 'modebar',
description: [
Expand Down Expand Up @@ -161,9 +174,9 @@ module.exports = {
values: ['h', 'v', 'd', 'any'],
dflt: 'any',
description: [
'When "dragmode" is set to "select", this limits the selection of the drag to',
'horizontal, vertical or diagonal. "h" only allows horizontal selection,',
'"v" only vertical, "d" only diagonal and "any" sets no limit.'
'When `dragmode` is set to *select*, this limits the selection of the drag to',
'horizontal, vertical or diagonal. *h* only allows horizontal selection,',
'*v* only vertical, *d* only diagonal and *any* sets no limit.'
].join(' '),
editType: 'none'
}
Expand Down
56 changes: 54 additions & 2 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
var Registry = require('../../registry');
var Plots = require('../../plots/plots');
var axisIds = require('../../plots/cartesian/axis_ids');
var Lib = require('../../lib');
var Icons = require('../../fonts/ploticon');

var eraseActiveShape = require('../shapes/draw').eraseActiveShape;
var Lib = require('../../lib');
var _ = Lib._;

var modeBarButtons = module.exports = {};
Expand Down Expand Up @@ -134,6 +134,58 @@ modeBarButtons.lasso2d = {
click: handleCartesian
};

modeBarButtons.drawclosedpath = {
name: 'drawclosedpath',
title: function(gd) { return _(gd, 'Draw closed freeform'); },
attr: 'dragmode',
val: 'drawclosedpath',
icon: Icons.drawclosedpath,
click: handleCartesian
};

modeBarButtons.drawopenpath = {
name: 'drawopenpath',
title: function(gd) { return _(gd, 'Draw open freeform'); },
attr: 'dragmode',
val: 'drawopenpath',
icon: Icons.drawopenpath,
click: handleCartesian
};

modeBarButtons.drawline = {
name: 'drawline',
title: function(gd) { return _(gd, 'Draw line'); },
attr: 'dragmode',
val: 'drawline',
icon: Icons.drawline,
click: handleCartesian
};

modeBarButtons.drawrect = {
name: 'drawrect',
title: function(gd) { return _(gd, 'Draw rectangle'); },
attr: 'dragmode',
val: 'drawrect',
icon: Icons.drawrect,
click: handleCartesian
};

modeBarButtons.drawcircle = {
name: 'drawcircle',
title: function(gd) { return _(gd, 'Draw circle'); },
attr: 'dragmode',
val: 'drawcircle',
icon: Icons.drawcircle,
click: handleCartesian
};

modeBarButtons.eraseshape = {
name: 'eraseshape',
title: function(gd) { return _(gd, 'Erase active shape'); },
icon: Icons.eraseshape,
click: eraseActiveShape
};

modeBarButtons.zoomIn2d = {
name: 'zoomIn2d',
title: function(gd) { return _(gd, 'Zoom in'); },
Expand Down
28 changes: 28 additions & 0 deletions src/components/modebar/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ module.exports = function manageModeBar(gd) {
else fullLayout._modeBar = createModeBar(gd, buttonGroups);
};

var DRAW_MODES = [
'drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape'
];

// logic behind which buttons are displayed by default
function getButtonGroups(gd) {
var fullLayout = gd._fullLayout;
Expand Down Expand Up @@ -170,6 +179,25 @@ function getButtonGroups(gd) {
dragModeGroup.push('select2d', 'lasso2d');
}

// accept pre-defined buttons as string
if(Array.isArray(buttonsToAdd)) {
var newList = [];
for(var i = 0; i < buttonsToAdd.length; i++) {
var b = buttonsToAdd[i];
if(typeof b === 'string') {
if(DRAW_MODES.indexOf(b) !== -1) {
if(
fullLayout._has('mapbox') || // draw shapes in paper coordinate (could be improved in future to support data coordinate, when there is no pitch)
fullLayout._has('cartesian') // draw shapes in data coordinate
) {
dragModeGroup.push(b);
}
}
} else newList.push(b);
}
buttonsToAdd = newList;
}

addGroup(dragModeGroup);
addGroup(zoomGroup.concat(resetGroup));
addGroup(hoverGroup);
Expand Down
25 changes: 24 additions & 1 deletion src/components/shapes/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,31 @@ module.exports = templatedArray('shape', {
role: 'info',
editType: 'arraydraw',
description: [
'Sets the color filling the shape\'s interior.'
'Sets the color filling the shape\'s interior. Only applies to closed shapes.'
].join(' ')
},
fillrule: {
valType: 'enumerated',
values: ['evenodd', 'nonzero'],
dflt: 'evenodd',
role: 'info',
editType: 'arraydraw',
description: [
'Determines which regions of complex paths constitute the interior.',
'For more info please visit https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule'
].join(' ')
},
editable: {
valType: 'boolean',
role: 'info',
dflt: false,
editType: 'calc+arraydraw',
description: [
'Determines whether the shape could be activated for edit or not.',
'Has no effect when the older editable shapes mode is enabled via',
'`config.editable` or `config.edits.shapePosition`.'
].join(' ')
},

editType: 'arraydraw'
});
18 changes: 12 additions & 6 deletions src/components/shapes/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
}

var visible = coerce('visible');

if(!visible) return;

var path = coerce('path');
var dfltType = path ? 'path' : 'rect';
var shapeType = coerce('type', dfltType);
if(shapeOut.type !== 'path') delete shapeOut.path;

coerce('editable');
coerce('layer');
coerce('opacity');
coerce('fillcolor');
coerce('line.color');
coerce('line.width');
coerce('line.dash');
coerce('fillrule');
var lineWidth = coerce('line.width');
if(lineWidth) {
coerce('line.color');
coerce('line.dash');
}

var dfltType = shapeIn.path ? 'path' : 'rect';
var shapeType = coerce('type', dfltType);
var xSizeMode = coerce('xsizemode');
var ySizeMode = coerce('ysizemode');

Expand Down
Loading