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

Add angle, angleref and standoff to marker and add backoff to line as well as adding two new arrow symbols #6297

Merged
merged 30 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dca228a
add angle and angleref to marker
archmoj Aug 9, 2022
9772168
revise new arrow markers based on golden ratio
archmoj Aug 16, 2022
3dcdfe9
fix hash symbol rotation
archmoj Aug 16, 2022
22d1260
declare marker.angle as a number not an angle
archmoj Aug 16, 2022
25fd485
no rotation for 360 and -360 angles
archmoj Aug 19, 2022
1a27d5f
include new arrow markers in gl2d_marker_symbols
archmoj Aug 19, 2022
94177e0
add marker.angle to gl2d traces
archmoj Aug 19, 2022
82cd0e7
test symbols with angle in gl2d
archmoj Aug 19, 2022
ed873a4
test marker.angle in splom
archmoj Aug 19, 2022
c8cc834
test marker.angle in polargl
archmoj Aug 19, 2022
855739d
handle line shapes vhv, hvh, vh and hv
archmoj Aug 25, 2022
f5e269d
add standoff to svg markers with angle
archmoj Aug 25, 2022
09eecfc
Update src/traces/scattergeo/attributes.js
archmoj Aug 26, 2022
52ba9de
update angleref & schema
archmoj Aug 26, 2022
b56c6b1
revise arrow-wide shape
archmoj Aug 26, 2022
da0234e
avoid parsing identical markers for better performance
archmoj Aug 30, 2022
9e14777
make angle arrayOk and use it for marker.angle
archmoj Aug 30, 2022
2ebc1a9
add backoff to line
archmoj Sep 1, 2022
8fb6d9f
improve legends
archmoj Sep 1, 2022
5f8a8f1
improve legends of items with standoff
archmoj Sep 1, 2022
574aa52
add auto backoff
archmoj Sep 6, 2022
48a809a
Update src/traces/scatter/attributes.js
archmoj Sep 19, 2022
66915b4
fix scattercarpet backoff in the first plot
archmoj Sep 19, 2022
5942253
use backward azimuth as base for previous geo angles
archmoj Sep 21, 2022
efc1199
redraw scattergeo with angles on interactions
archmoj Sep 22, 2022
21c6c78
add jasmine test for scattergeo
archmoj Sep 23, 2022
83b1455
update comment
archmoj Sep 29, 2022
dfd34d6
reduce backoff for the arrow marker
archmoj Sep 29, 2022
7052984
add backoff to arrow-up and arrow-bar-up
archmoj Oct 3, 2022
b4ef2ab
fix drawing splines
archmoj Sep 29, 2022
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
137 changes: 133 additions & 4 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ drawing.symbolNumber = function(v) {
0 : Math.floor(Math.max(v, 0));
};

function makePointPath(symbolNumber, r) {
function makePointPath(symbolNumber, r, t, s) {
var base = symbolNumber % 100;
return drawing.symbolFuncs[base](r) + (symbolNumber >= 200 ? DOTPATH : '');
return drawing.symbolFuncs[base](r, t, s) + (symbolNumber >= 200 ? DOTPATH : '');
}

var HORZGRADIENT = {x1: 1, x2: 0, y1: 0, y2: 0};
Expand Down Expand Up @@ -649,7 +649,10 @@ drawing.singlePointStyle = function(d, sel, trace, fns, gd) {
// because that impacts how to handle colors
d.om = x % 200 >= 100;

sel.attr('d', makePointPath(x, r));
var angle = getMarkerAngle(d, trace);
var standoff = getMarkerStandoff(d, trace);

sel.attr('d', makePointPath(x, r, angle, standoff));
}

var perPointGradient = false;
Expand Down Expand Up @@ -898,7 +901,7 @@ drawing.selectedPointStyle = function(s, trace) {
var mx = d.mx || marker.symbol || 0;
var mrc2 = fns.selectedSizeFn(d);

pt.attr('d', makePointPath(drawing.symbolNumber(mx), mrc2));
pt.attr('d', makePointPath(drawing.symbolNumber(mx), mrc2, getMarkerAngle(d, trace), getMarkerStandoff(d, trace)));

// save for Drawing.selectedTextStyle
d.mrc2 = mrc2;
Expand Down Expand Up @@ -1447,3 +1450,129 @@ drawing.setTextPointsScale = function(selection, xScale, yScale) {
el.attr('transform', transforms.join(''));
});
};

function getMarkerStandoff(d, trace) {
var standoff = d.mf;

if(standoff === undefined) {
standoff = trace.marker.standoff || 0;
}

return standoff;
}

var atan2 = Math.atan2;
var cos = Math.cos;
var sin = Math.sin;

function rotate(t, xy) {
var x = xy[0];
var y = xy[1];
return [
x * cos(t) - y * sin(t),
x * sin(t) + y * cos(t)
];
}

var previousX;
var previousY;
var previousI;
var previousTraceUid;

function getMarkerAngle(d, trace) {
var angle = d.ma;

if(angle === undefined) {
angle = trace.marker.angle || 0;
}

var x, y;
var ref = trace.marker.angleref;
if(ref === 'previous' || ref === 'north') {
if(trace._geo) {
var p = trace._geo.project(d.lonlat);
x = p[0];
y = p[1];
} else {
var xa = trace._xA;
var ya = trace._yA;
if(xa && ya) {
x = xa.c2p(d.x);
y = ya.c2p(d.y);
} else {
// case of legends
return 90;
}
}

if(ref === 'north') {
var lon = d.lonlat[0];
var lat = d.lonlat[1];

var north = trace._geo.project([
lon,
lat + 1e-5 // epsilon
]);

var east = trace._geo.project([
lon + 1e-5, // epsilon
lat
]);

var u = atan2(
east[1] - y,
east[0] - x
);

var v = atan2(
north[1] - y,
north[0] - x
);

var t = angle / 180 * Math.PI;
// To use counter-clockwise angles i.e.
// East: 90, West: -90
// to facilitate wind visualisations
// in future we should use t = -t here.

var A = rotate(u, [cos(t), 0]);
var B = rotate(v, [sin(t), 0]);

angle = atan2(
A[1] + B[1],
A[0] + B[0]
) / Math.PI * 180;
}

if(ref === 'previous') {
if(
previousTraceUid === trace.uid &&
d.i === previousI + 1 &&
isNumeric(x) &&
isNumeric(y)
) {
var dX = x - previousX;
var dY = y - previousY;

var shape = trace.line ? trace.line.shape || '' : '';

var lastShapeChar = shape.slice(shape.length - 1);
if(lastShapeChar === 'h') dY = 0;
if(lastShapeChar === 'v') dX = 0;

angle += atan2(dY, dX) / Math.PI * 180 + 90;
} else {
angle = null;
}
}
}

previousX = x;
previousY = y;
previousI = d.i;
previousTraceUid = trace.uid;

return angle;
}

drawing.getMarkerAngle = getMarkerAngle;
Loading