-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChannelPanel.js
148 lines (97 loc) · 4.6 KB
/
ChannelPanel.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
function newAAMastersPlottersBollingerChannelsBollingerChannelsChannelPanel () {
let thisObject = {
fitFunction: undefined,
onEventRaised: onEventRaised,
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
};
let container = newContainer();
container.initialize();
thisObject.container = container;
container.displacement.containerName = "Channel";
container.frame.containerName = "Channel";
let currentChannel;
let panelTabButton
return thisObject;
function initialize() {
thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL;
thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL;
thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 5;
thisObject.container.frame.position.y = viewPort.visibleArea.bottomLeft.y - thisObject.container.frame.height;
panelTabButton = newPanelTabButton()
panelTabButton.parentContainer = thisObject.container
panelTabButton.container.frame.parentFrame = thisObject.container.frame
panelTabButton.fitFunction = thisObject.fitFunction
panelTabButton.initialize()
}
function getContainer(point) {
let container;
container = panelTabButton.getContainer(point)
if (container !== undefined) { return container }
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
let checkPoint = {
x: point.x,
y: point.y
}
checkPoint = thisObject.fitFunction(checkPoint)
if (point.x === checkPoint.x && point.y === checkPoint.y) {
return thisObject.container;
}
}
}
function onEventRaised(lasCurrentChannel) {
currentChannel = lasCurrentChannel;
}
function draw() {
thisObject.container.frame.draw(false, false, true, thisObject.fitFunction);
plotCurrentChannelInfo();
panelTabButton.draw()
}
function plotCurrentChannelInfo() {
const frameBodyHeight = thisObject.container.frame.getBodyHeight();
const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight;
const X_AXIS = thisObject.container.frame.width / 2;
const Y_AXIS = frameTitleHeight + frameBodyHeight / 2;
if (currentChannel === undefined) { return; }
if (currentChannel.innerChannel === undefined) {
currentChannel.innerChannel = {
direction: '',
period: ''
}
}
let y;
printLabel('Direction', X_AXIS, frameTitleHeight + frameBodyHeight * 0.05, '1');
printLabel(currentChannel.innerChannel.direction, X_AXIS, frameTitleHeight + frameBodyHeight * 0.10, '0.50');
printLabel('Periods', X_AXIS, frameTitleHeight + frameBodyHeight * 0.15, '1');
printLabel(currentChannel.innerChannel.period, X_AXIS, frameTitleHeight + frameBodyHeight * 0.20, '0.50');
let fixedValue = '';
fixedValue = currentChannel.innerChannel.firstMovingAverage;
if (fixedValue !== undefined) { fixedValue = fixedValue.toFixed(2); } else { fixedValue = ''; }
printLabel('Initial Moving Average', X_AXIS, frameTitleHeight + frameBodyHeight * 0.25, '1');
printLabel(fixedValue, X_AXIS, frameTitleHeight + frameBodyHeight * 0.30, '0.50');
fixedValue = currentChannel.innerChannel.lastMovingAverage;
if (fixedValue !== undefined) { fixedValue = fixedValue.toFixed(2); } else { fixedValue = '';}
printLabel('Final Moving Average', X_AXIS, frameTitleHeight + frameBodyHeight * 0.35, '1');
printLabel(fixedValue, X_AXIS, frameTitleHeight + frameBodyHeight * 0.40, '0.50');
function printLabel(labelToPrint, x, y, opacity) {
let labelPoint;
let fontSize = 10;
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY;
let label = '' + labelToPrint;
let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO;
labelPoint = {
x: x - xOffset,
y: y
};
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint);
labelPoint = thisObject.fitFunction(labelPoint)
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')';
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y);
}
browserCanvasContext.closePath();
browserCanvasContext.fill();
}
}