-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOscProbPlot.js
99 lines (84 loc) · 2.98 KB
/
OscProbPlot.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
class OscProbPlot {
constructor() { this.Curves = []; }
DrawAxes(el, xmin_GeV = 0, xmax_GeV = 10, ymin = 0, ymax = 1,
ylabel = "\\(P_{\\textrm{osc.}}\\)") {
this.width = 500;
this.height = 400;
this.margin = {top : 20, right : 20, bottom : 75, left : 95};
this.tot_width = this.width + this.margin.left + this.margin.right;
this.tot_height = this.height + this.margin.top + this.margin.bottom;
let xScale = d3.scaleLinear()
.domain([ xmin_GeV, xmax_GeV ]) // input
.range([ 0, this.width ]); // output
this.xScale = xScale;
let yScale = d3.scaleLinear()
.domain([ ymin, ymax ]) // input
.range([ this.height, 0 ]); // output
this.yScale = yScale;
this.lineGen = d3.line()
.x(function(d) { return xScale(d[0]); })
.y(function(d) { return yScale(d[1]); });
this.svg = d3.select(el)
.append("svg")
.attr("width", this.tot_width)
.attr("height", this.tot_height)
.append("g")
.attr("transform", "translate(" + this.margin.left + "," +
this.margin.top + ")");
this.svg.append("g")
.attr("class", "x_axis biglabel")
.attr("transform", "translate(0," + this.height + ")")
.call(d3.axisBottom(xScale).tickArguments([ 5 ]));
RenderLatexLabel(
this.svg.append("text").text("\\(E_{\\nu} \\textrm{(GeV)}\\)"),
this.svg, "25ex", "10ex", this.width * 0.4, this.height * 0.72, 1.5,
1.5);
this.svg.append("g")
.attr("class", "y_axis biglabel")
.call(d3.axisLeft(yScale).tickArguments([ 3 ]));
RenderLatexLabel(this.svg.append("text").text(ylabel), this.svg, "25ex",
"10ex", -100, -65, 1.5, 1.5, -90);
}
ScrubCurvePoints(curve) {
let xScale = this.xScale;
let width = this.width;
curve.data = curve.data.filter((value, index, arr) => {
let svg_coords = xScale(value[0]);
return ((svg_coords > 0) && (svg_coords < width));
});
}
GetLastCurveIndex() {
if (this.Curves.length == 0) {
return 0;
} else {
return this.Curves.length - 1;
}
}
SetCurve(idx, curve) {
this.ScrubCurvePoints(curve);
if (this.Curves.length > idx) {
this.RemoveCurve(idx);
} else {
this.Curves.length = idx + 1;
}
this.Curves[idx] =
this.svg.append("path")
.attr("d",
this.lineGen(curve.data)) // 11. Calls the line generator
.attr("class", `osc_line ColorWheel-${idx + 1}`);
};
RemoveCurve(idx) {
if (this.Curves.length > idx) {
if (this.Curves[idx] != undefined) {
this.Curves[idx].remove();
}
}
}
ClearAll() {
for (let idx = 0; idx < this.Curves.length; ++idx) {
if (this.Curves[idx] != undefined) {
this.Curves[idx].remove();
}
}
}
};