-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathplot.js
102 lines (83 loc) · 3.31 KB
/
plot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* Copyright 2012-2018, 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 d3 = require('d3');
var isNumeric = require('fast-isnumeric');
var Lib = require('../../lib');
var Drawing = require('../../components/drawing');
var helpers = require('../../plots/polar/helpers');
module.exports = function plot(gd, subplot, cdbar) {
var xa = subplot.xaxis;
var ya = subplot.yaxis;
var radialAxis = subplot.radialAxis;
var angularAxis = subplot.angularAxis;
var pathFn = makePathFn(subplot);
var barLayer = subplot.layers.frontplot.select('g.barlayer');
Lib.makeTraceGroups(barLayer, cdbar, 'trace bars').each(function(cd) {
var plotGroup = cd[0].node3 = d3.select(this);
var pointGroup = Lib.ensureSingle(plotGroup, 'g', 'points');
var bars = pointGroup.selectAll('g.point').data(Lib.identity);
bars.enter().append('g')
.style('vector-effect', 'non-scaling-stroke')
.style('stroke-miterlimit', 2)
.classed('point', true);
bars.exit().remove();
bars.each(function(di) {
var bar = d3.select(this);
var rp0 = di.rp0 = radialAxis.c2p(di.s0);
var rp1 = di.rp1 = radialAxis.c2p(di.s1);
var thetag0 = di.thetag0 = angularAxis.c2g(di.p0);
var thetag1 = di.thetag1 = angularAxis.c2g(di.p1);
var dPath;
if(!isNumeric(rp0) || !isNumeric(rp1) ||
!isNumeric(thetag0) || !isNumeric(thetag1) ||
rp0 === rp1 || thetag0 === thetag1
) {
// do not remove blank bars, to keep data-to-node
// mapping intact during radial drag, that we
// can skip calling _module.style during interactions
dPath = 'M0,0Z';
} else {
// this 'center' pt is used for selections and hover labels
var rg1 = radialAxis.c2g(di.s1);
var thetagMid = (thetag0 + thetag1) / 2;
di.ct = [
xa.c2p(rg1 * Math.cos(thetagMid)),
ya.c2p(rg1 * Math.sin(thetagMid))
];
dPath = pathFn(rp0, rp1, thetag0, thetag1);
}
Lib.ensureSingle(bar, 'path').attr('d', dPath);
});
// clip plotGroup, when trace layer isn't clipped
Drawing.setClipUrl(plotGroup, subplot._hasClipOnAxisFalse ? subplot.clipIds.forTraces : null);
});
};
function makePathFn(subplot) {
var cxx = subplot.cxx;
var cyy = subplot.cyy;
if(subplot.vangles) {
return function(r0, r1, _a0, _a1) {
var a0, a1;
if(Lib.angleDelta(_a0, _a1) > 0) {
a0 = _a0;
a1 = _a1;
} else {
a0 = _a1;
a1 = _a0;
}
var va0 = helpers.findEnclosingVertexAngles(a0, subplot.vangles)[0];
var va1 = helpers.findEnclosingVertexAngles(a1, subplot.vangles)[1];
var vaBar = [va0, (a0 + a1) / 2, va1];
return helpers.pathPolygonAnnulus(r0, r1, a0, a1, vaBar, cxx, cyy);
};
}
return function(r0, r1, a0, a1) {
return Lib.pathAnnulus(r0, r1, a0, a1, cxx, cyy);
};
}