-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
214 lines (186 loc) · 7.82 KB
/
index.html
File metadata and controls
214 lines (186 loc) · 7.82 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
<script type="text/JavaScript" src="jsDraw2DX.js"></script>
</head>
<body>
<defs>
<marker id="Triangle"
viewBox="0 0 10 10"
refX="0" refY="3"
markerWidth="6"
markerHeight="6"
fill="blue"
orient="auto">
<path d="M 0 0 L 6 3 L 0 6 z" />
</marker>
</defs>
<div id="graphics" style="overflow:hidden;position:relative;width:1120px;height:470px;"></div>
<script src="testData.js" type="text/javascript">
</script>
<script type="text/JavaScript">
//Define graphics
var graphicsDiv=document.getElementById("graphics");
var gr = new jxGraphics(graphicsDiv);
//Define drawing pen/brush/font
var brushInfo = new jxBrush(new jxColor('#008B8B'));
var penBorder = new jxPen(new jxColor('gray'), 1);
var font = new jxFont();
font.size = '8pt';
graphicsDiv.onmousemove = getMouseXY;
var mouseX = 0, mouseY = 0;
//Info box
var infoBox = new jxRect(null, 160, 50, new jxPen(new jxColor('#008B8B'), 1), new jxBrush(new jxColor('white')));
var countryText = new jxText(null, null, font); countryText.brush = brushInfo;
var popText = new jxText(null, null, font); popText.brush = brushInfo;
//Background
var bg = new jxRect(new jxPoint(0, 0), 1120, 470, penBorder, new jxBrush(new jxColor('#ADD8E6')));
bg.draw(gr);
var title = new jxText(new jxPoint(10, 20), 'World Population Density Map', font, null, new jxBrush(new jxColor('black')));
title.draw(gr);
//greenShade = new jxColor(255, 255, 255);
//var polyline = new jxPolyline([new jxPoint(400, 100), new jxPoint(200, 400)], penBorder, new jxBrush(greenShade));
//polyline.draw(gr);
var marker = document.createElementNS("http://www.w3.org/2000/svg", "marker");
marker.setAttribute("id", "markerEnd");
marker.setAttribute("viewBox", "0 0 10 10");
marker.setAttribute("markerWidth", "6");
marker.setAttribute("markerHeight", "6");
marker.setAttribute("refX", "4");
marker.setAttribute("refY", "3");
marker.setAttribute("orient", "auto");
marker.setAttribute("markerUnits", "strokeWidth");
//marker.setAttribute("d", "M 0 0 L 6 3 L 0 6 z");
var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
marker.appendChild(path);
path.setAttribute("d", "M 0 0 L 6 3 L 0 6 z");
path.setAttribute('fill', 'blue');
gr.getDefs().appendChild(marker);
var polyline = document.createElementNS("http://www.w3.org/2000/svg", "polyline");
polyline.setAttribute("points", new jxPoint(50,10).x+ " 50, 70 70");
polyline.setAttribute("fill", "none");
polyline.setAttribute("stroke", "blue");
polyline.setAttribute("stroke-width", "7");
polyline.setAttribute("marker-end", "url(#markerEnd)");
gr.getSVG().appendChild(polyline);
// 0 = boid
// 1 = country selected
var state = 0;
//CountryMap
var countryMap = {}
//Draw country border and fill color as per population density
//countriesData variable is from countriesData.js file
for (var i in countriesData) {
var country = countriesData[i];
countryMap[country.name] = country;
for (var j in country.border) {
var border = country.border[j];
var points = new Array();
for (var k in border) {
var vertex = border[k];
points[points.length]=new jxPoint(vertex[0], vertex[1]);
}
var f =Math.round(480 -100*480/300);
if (f > 255) {
if (f > 511)
greenShade = new jxColor(255, 255, 255);
else
greenShade = new jxColor(f - 255, 255, f - 255);
}
else {
if(f<36)
greenShade = new jxColor(0, 35, 0);
else
greenShade = new jxColor(0, f, 0);
}
var polygon = new jxPolygon(points, penBorder, new jxBrush(greenShade));
//Handle mouse events to show information
polygon.addEventListener('mousemove', showInfo)
polygon.addEventListener('mouseout', hideInfo)
polygon.addEventListener('click', showNeighbors)
polygon.country = country.name;
country.polygon = polygon;
country.center = new jxPoint(country.center[0], country.center[1])
polygon.draw(gr);
}
}
//Display information box
function showInfo(evt, obj) {
if (lastClicked === undefined) {
penBorder.width = 4;
obj.draw(gr);
}
/*infoBox.point = new jxPoint(mouseX+5, mouseY+5);
countryText.point = new jxPoint(mouseX +15, mouseY + 25);
popText.point = new jxPoint(mouseX + 15, mouseY+ 45);
countryText.text = obj.country;
popText.text = 'Population: ' + obj.population + ' /sqKm';
infoBox.draw(gr);
countryText.draw(gr);
popText.draw(gr);*/
}
//Hide information box
function hideInfo(evt, obj) {
if (lastClicked === undefined) {
penBorder.width = 1;
obj.draw(gr);
}
/*infoBox.hide();
countryText.hide();
popText.hide();*/
}
var lastClicked = "";
var arrows = [];
function showNeighbors(evt, obj) {
var country = countryMap[obj.country];
//if (lastClicked != obj.country) {
//alert(["lastClicked = ", lastClicked, "county = ", country.name, "country.neighbor = ", country.neighbor, "country.neighbor.indexOf(lastClicked) = ", country.neighbor.indexOf(lastClicked)])
if (state == 0 || country.neighbor.indexOf(lastClicked) < 0) {
state = 1
for(var i in arrows) {
gr.getSVG().removeChild(arrows[i]);
gr.removeShape(arrows[i]);
delete arrows[i];
}
for (var i in country.neighbor) {
if (country.name == countryMap[country.neighbor[i]].name) continue;
//countryMap[country.neighbor[i]].polygon.draw(gr);
var polyline = document.createElementNS("http://www.w3.org/2000/svg", "polyline");
polyline.setAttribute("points", country.center.x + " " + country.center.y +
", " + countryMap[country.neighbor[i]].center.x + " " + countryMap[country.neighbor[i]].center.y);
polyline.setAttribute("fill", "none");
polyline.setAttribute("stroke", "blue");
polyline.setAttribute("stroke-width", "5");
polyline.setAttribute("marker-end", "url(#markerEnd)");
arrows[arrows.length] = polyline;
gr.getSVG().appendChild(polyline);
}
lastClicked = obj.country;
}
else
{
alert("attack!")
//lastClicked = "";
}
}
//Get the mouse cursor position
function getMouseXY(e) {
if (document.all) //For IE
{
mouseX = event.clientX + document.body.parentElement.scrollLeft;
mouseY = event.clientY + document.body.parentElement.scrollTop;
} else {
mouseX = e.pageX
mouseY = e.pageY
}
if (mouseX < 0) { mouseX = 0 }
if (mouseY < 0) { mouseY = 0 }
mouseX = mouseX - graphicsDiv.offsetLeft;
mouseY = mouseY - graphicsDiv.offsetTop;
return true;
}
</script>
</body>
</html>