Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splitted the chart into three different charts #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 51 additions & 0 deletions static/js/hualos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Created by Severin on 12.11.2015.
* sevi_buehler@hotmail.com
*/


C3Chart = function(divId,fields){
var these = this;
these.divId = divId;
these.fields = fields;
these.chart = null;
var monitored = {};

these.init = function(){
these.chart = c3.generate({
bindto:'#' + these.divId,
data: {
x: 'epoch',
columns: []
}
});
};
these.update = function(newData){
fillToMonitored(newData);
updateChart();
};
var fillToMonitored = function(newData){
for (key in newData) {
if (key in monitored) {
monitored[key].push(newData[key]);
} else {
monitored[key] = [key, newData[key]];
}
}
};
var updateChart = function(){
chartColumns = []
chartColumns.push(monitored["epoch"]);
for(key in monitored){
for(var i in these.fields){
field = these.fields[i];
if(key==field){
chartColumns.push(monitored[key]);
}
}
}
these.chart.load({
columns:chartColumns
});
};
};
109 changes: 66 additions & 43 deletions templates/test.html
Original file line number Diff line number Diff line change
@@ -1,62 +1,85 @@
<head>
<link href="/static/css/c3.min.css" rel="stylesheet">
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/d3.min.js"></script>
<script type="text/javascript" src="/static/js/c3.min.js"></script>
<link href="../static/css/c3.min.css" rel="stylesheet">
<link href="../static/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/d3.min.js"></script>
<script type="text/javascript" src="../static/js/c3.min.js"></script>
<script type="text/javascript" src="../static/js/hualos.js"></script>
</head>

<body>
<div class="container">
<h1>Keras - Total Visualization Project</h1>
<h2>Initial tests</h2>

<hr>
<div id="visualization"></div>
<div class="container-fluid">
<div class="container">
<div class="row">
<h1>Keras - Total Visualization Project</h1>
<hr>
</div>
<div class="row">
<div class="col-md-12 col-lg-6">
<h2>Loss</h2>
<div id="lossChart"></div>
</div>
<div class="col-md-12 col-lg-6">
<h2>Accurancy</h2>
<div id="accChart"></div>
</div>
<div class="col-md-12 col-lg-6">
<h2>Other</h2>
<div id="otherChart"></div>
</div>
</div>
</div>
</div>

</body>

<script type="text/javascript">
accChart = new C3Chart("accChart",["acc", "val_acc"]);
lossChart = new C3Chart("lossChart",["loss", "val_loss"]);
otherChart = new C3Chart("otherChart",["batch", "size"]);

var update = function(newData){
accChart.update(newData);
lossChart.update(newData);
otherChart.update(newData);
};
var addTestData = function() {
mydata1 = {
"acc":0.953,
"loss":0.185,
"batch":92,
"epoch":20,
"val_acc":0.94,
"val_loss":0.11,
"size":127
};
mydata2 = {
"acc":0.97,
"loss":0.17,
"batch":92,
"epoch":21,
"val_acc":0.96,
"val_loss":0.10,
"size":127
};
update(mydata1);
update(mydata2);
};

$(document).ready(function(){
var monitored = {};
accChart.init();
lossChart.init();
otherChart.init();

var source = new EventSource('/subscribe/epoch/end/');
var chart = null;

//addTestData();
source.addEventListener('message', function(e) {
console.log(e.data);
var data = JSON.parse(e.data);
console.log(data);
if (chart === null) {
for (key in data) {
monitored[key] = [key, data[key]];
}
var columns = [];
for (key in monitored) {
columns.push(monitored[key]);
}
chart = c3.generate({
bindto:'#visualization',
data: {
x: 'epoch',
columns: columns
}
});
}
else {
for (key in data) {
if (key in monitored) {
monitored[key].push(data[key]);
}
var columns = [];
for (key in monitored) {
columns.push(monitored[key]);
}
chart.load({
columns: columns
});
}
}
update(data);

}, false);
});

Expand Down