-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathplot.js
56 lines (42 loc) · 1.48 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
/**
* 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';
var d3 = require('d3');
var Lib = require('../../lib');
module.exports = function plot(gd, plotinfo, cdOHLC, ohlcLayer) {
var ya = plotinfo.yaxis;
var xa = plotinfo.xaxis;
var posHasRangeBreaks = !!xa.rangebreaks;
Lib.makeTraceGroups(ohlcLayer, cdOHLC, 'trace ohlc').each(function(cd) {
var plotGroup = d3.select(this);
var cd0 = cd[0];
var t = cd0.t;
var trace = cd0.trace;
if(trace.visible !== true || t.empty) {
plotGroup.remove();
return;
}
var tickLen = t.tickLen;
var paths = plotGroup.selectAll('path').data(Lib.identity);
paths.enter().append('path');
paths.exit().remove();
paths.attr('d', function(d) {
if(d.empty) return 'M0,0Z';
var xo = xa.c2p(d.pos - tickLen, true);
var xc = xa.c2p(d.pos + tickLen, true);
var x = posHasRangeBreaks ? (xo + xc) / 2 : xa.c2p(d.pos, true);
var yo = ya.c2p(d.o, true);
var yh = ya.c2p(d.h, true);
var yl = ya.c2p(d.l, true);
var yc = ya.c2p(d.c, true);
return 'M' + xo + ',' + yo + 'H' + x +
'M' + x + ',' + yh + 'V' + yl +
'M' + xc + ',' + yc + 'H' + x;
});
});
};