-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchart_test.html
138 lines (138 loc) · 6.54 KB
/
chart_test.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
134
135
136
137
138
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<style type="text/css">
#jsonParams{
user-select:all;
}
</style>
<meta name="viewport" content="width=device-width">
<title>GCF Chart Test</title>
<script src="gcf.js" type="text/javascript"></script>
<script src="lib/chart.js" type="text/javascript"></script>
<script src="lib/chartjs-adapter-date-fns.bundle.min.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<script type="text/javascript">
let stock=null
function chartTest_update(){
jsonParams.innerText="["+baseValue.value+","+variability.value+","+volatility.value+","+noisiness.value+","+influenceability.value+","+seed.value+"]"
gameT.innerText=gameTimerAsDate().toGMTString()
let s=new Stock("TEST","Test","Test stock",Number(baseValue.value),Number(variability.value),Number(volatility.value),Number(noisiness.value),Number(influenceability.value),0,0,null,Number(seed.value))
stock=s
stockValue.innerText=s.getValue().toFixed(3)+" Kr"
longTermInvestmentRating.innerText=krolikRating(s.getLongTermInvestmentRating())
speculativeInvestmentRating.innerText=fitzgeraldRating(s.getSpeculativeInvestmentRating())
let ctx=document.querySelector("canvas.chart")
let start=~~gameTimer()-chartDays
let end=gameTimer()
let step=(end-start)/1000
if(step<0.001) step=0.001
let values=[]
for(i=start;i<end;i+=step){
values.push({x:i*(1000*60*60*24),y:s.getValue(i)})
}
values.push({x:end*(1000*60*60*24),y:s.getValue(end)})
if(!ctx.chartjs){
let chart=new Chart(ctx,{
type:"line",
data:{
datasets:[{
label:s._name,
indexAxis:'x',
borderWidth:1,
radius:0,
data:values
}]
},
options: {
animation:false,
parsing:false,
//responsive:false,
interaction: {
mode: 'nearest',
axis: 'x',
intersect: false
},
plugins: {
decimation: {
enabled: true,
samples:10
},
legend:{
display:false,
}
},
scales: {
x: {
type: 'time',
time:{
unit:'day'
},
title:{
display:true,
text:'Data',
},
},
y:{
type:'linear',
title:{
display:true,
text:'Kr',
},
/*min:0*/
}
},
}
})
ctx.chartjs=chart
}else{
ctx.chartjs.data.datasets[0].data=values
ctx.chartjs.update()
}
}
function initChartTest(){
chartDays=365
chartTest_update()
setInterval(chartTest_update,1000)
}
</script>
</head>
<body onload="initChartTest()">
<div>
Current date: <span id="gameT"></span>
</div>
<div>
Price: <span id="stockValue"></span>
</div>
<div style="width:100%; max-width:50rem; height:30rem;">
<canvas class="chart" id="chart"></canvas>
</div>
<div>
<button onclick="chartDays=1;chartTest_update()">1d</button>
<button onclick="chartDays=7;chartTest_update()">1w</button>
<button onclick="chartDays=30;chartTest_update()">1m</button>
<button onclick="chartDays=365;chartTest_update()">1y</button>
<button onclick="chartDays=3650;chartTest_update()">10y</button>
<button onclick="chartDays=7300;chartTest_update()">20y</button>
<button onclick="chartDays=18250;chartTest_update()">50y</button>
<button onclick="chartDays=36500;chartTest_update()">100y</button>
</div>
<div>
Long Term Investment Rating: <span id="longTermInvestmentRating"></span><br>
Speculative Investment Rating: <span id="speculativeInvestmentRating"></span>
</div>
<table>
<tr><td><label for="baseValue">Base Value</label></td><td><input type="number" min="0" step="0.001" value="100" id="baseValue"></td></tr>
<tr><td><label for="variability">Variability</label></td><td><input type="number" min="0" step="0.01" value="0.4" id="variability"></td></tr>
<tr><td><label for="volatility">Volatility</label></td><td><input type="number" min="0" step="0.001" value="0.02" id="volatility"></td></tr>
<tr><td><label for="noisiness">Noisiness</label></td><td><input type="number" min="0" step="0.01" value="1" id="noisiness"></td></tr>
<tr><td><label for="influenceability">Influenceability</label></td><td><input type="number" step="0.001" value="0.5" id="influenceability"></td></tr>
<tr><td><label for="seed">Seed</label></td><td><input type="number" step="1" value="1000" id="seed"></td></tr>
</table>
<div>
JSON Params: <span id="jsonParams"></span>
</div>
</body>
</html>