-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
133 lines (120 loc) · 5.01 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Three-Phase Electrical System Visualization</title>
<link rel="stylesheet" type="text/css" href="style - Cópia.css">
<link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
<script src="d3.v7.min.js"></script>
</head>
<body class="dark-mode">
<button id="toggle-button"><i type="solid" class='bx bxs-sun'></i></button>
<div id="main-container">
<p class="pageTitle">Impedance relationship to Voltage and Current (p.u.)</p>
<div id="first-row">
<div id="input-fields1"></div>
<div id="visualization"></div>
<div id="input-fields"></div>
</div>
</div>
<script>
document.getElementById('toggle-button').addEventListener('click', function () {
var body = document.body;
if (body.classList.contains('dark-mode')) {
body.classList.remove('dark-mode');
body.classList.add('light-mode');
d3.select("#rectFrame").style("stroke", "black")
document.getElementsByClassName("bxs-sun")[0].classList.remove("bxs-sun");
document.getElementsByClassName("bx")[0].classList.add("bxs-moon");
} else {
body.classList.remove('light-mode');
body.classList.add('dark-mode');
d3.select("#rectFrame").style("stroke", "white")
document.getElementsByClassName("bxs-moon")[0].classList.remove("bxs-moon");
document.getElementsByClassName("bx")[0].classList.add("bxs-sun");
}
});
var maxStatus = 2;
var visualizationElement = d3.select("#visualization");
const margin = { top: 20, right: 20, bottom: 20, left: 20 };
const boundingRect = document.getElementById("visualization");
const svgWidth = Math.min(visualizationElement._groups[0][0].clientWidth - margin.left - margin.right, window.innerHeight + visualizationElement._groups[0][0].clientHeight - margin.top - margin.bottom - document.getElementsByClassName("pageTitle")[0].clientHeight);
const arrowSize = 8;
const colors = { A: 'red', B: 'gold', C: 'blue', Z0: "darkgrey", Z1: "limegreen", Z2: "magenta" };
var svg = visualizationElement.append("svg")
.attr("width", svgWidth + margin.left + margin.right)
.attr("height", svgWidth + margin.top + margin.bottom)
.attr("id", "gMainVisual")
.style("overflow", "visible");
const mainGroup = svg.append('g')
.attr('transform', `translate(${margin.left / 2}, ${margin.top / 2})`)
.attr("id", "gMainVisual")
.style("border", "1px solid black");
const border = svg.append('rect')
.attr('x', 0)
.attr('y', 0)
.attr('height', svgWidth + margin.top + margin.bottom)
.attr('width', svgWidth + margin.left + margin.right)
.attr('transform', `translate(${margin.left / 2}, ${margin.top / 2})`)
.style('stroke', 'white')
.style('fill', 'none')
.style('stroke-width', '1px')
.attr("id", "rectFrame");
svg.append("defs").selectAll("marker")
.data("markc-arc")
.enter().append("marker")
.attr("id", `markc-arc`)
.attr("viewBox", "0 -5 10 10")
.attr("refX", 5)
.attr("refY", 0)
.attr("markerWidth", arrowSize / 1.5)
.attr("markerHeight", arrowSize)
.attr("orient", "auto")
.append("path")
.attr("d", "M0,-5L10,0L0,5")
.style("fill", "darkgrey");
const y = 30
const x = 15
svg.append("path").attr("d", `M ${svgWidth + x},${margin.top + y} A 15,15 0 1 1 ${svgWidth + x - 15},${margin.top + (y - 15)}`).attr("stroke", "darkgrey").attr("stroke-width", 2).attr("fill", "none").style("marker-end", "url(#markc-arc)");
svg.append("path").attr("d", `m ${svgWidth},${margin.top + 25} 0,10`).attr("stroke", "darkgrey").attr("stroke-width", 2).attr("fill", "none");
svg.append("path").attr("d", `m ${svgWidth - 5},${margin.top + 30} 10,0`).attr("stroke", "darkgrey").attr("stroke-width", 2).attr("fill", "none");
// Create scales
var xScale = d3.scaleLinear().domain([-3, 3]).range([0, svgWidth]);
var yScale = d3.scaleLinear().domain([-3, 3]).range([svgWidth, 0]);
// Add axes and gridlines
var xAxis = d3.axisBottom(xScale);
var yAxis = d3.axisLeft(yScale);
mainGroup.append("g")
.attr("class", "x-axis")
.attr("transform", "translate(" + margin.left + "," + svgWidth / 2 + ")")
.call(xAxis);
mainGroup.append("g")
.attr("class", "y-axis")
.attr("transform", "translate(" + svgWidth / 2 + "," + margin.top + ")")
.call(yAxis);
// Create vector data
var vectorsData = {
VA: { x: 2, y: 0 },
VB: { x: -1, y: -Math.sqrt(3) },
VC: { x: -1, y: +Math.sqrt(3) },
IA: { x: 1, y: 0 },
IB: { x: -0.5, y: -0.8660254037844386 },
IC: { x: -0.5, y: +0.8660254037844386 },
ZA: { x: 2, y: 0 },
ZB: { x: 2, y: 0 },
ZC: { x: 2, y: 0 },
I0: { x: 0, y: 0 },
I1: { x: 1, y: 0 },
I2: { x: 0, y: 0 },
V0: { x: 0, y: 0 },
V1: { x: 3, y: 0 },
V2: { x: 3, y: 0 },
Z0: { x: 0, y: 0 },
Z1: { x: 3, y: 0 },
Z2: { x: 0, y: 0 },
};
</script>
<script type="module" src="index.js"></script>
</body>
</html>