Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

136
LINES

< > BotCompany Repo | #1013923 // ante! Graph [LIVE]

JavaX source code (desktop) [tags: butter use-pretranspiled] - run with: x30.jar - homepage

Download Jar. Libraryless. Click here for Pure Java version (1513L/11K).

1  
!7
2  
3  
html {
4  
  ret hhtml(hhead(
5  
    loadJQuery()
6  
    + htitle("ante! available computing power")
7  
    + [[<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>]])
8  
    + hbody(
9  
      hSilentComputator()
10  
    + [[<div style="width: 100%;"><canvas id="canvas"></canvas>]]
11  
    + hjavascript([[
12  
13  
window.chartColors = {
14  
	red: 'rgb(255, 99, 132)',
15  
	orange: 'rgb(255, 159, 64)',
16  
	yellow: 'rgb(255, 205, 86)',
17  
	green: 'rgb(75, 192, 192)',
18  
	blue: 'rgb(54, 162, 235)',
19  
	purple: 'rgb(153, 102, 255)',
20  
	grey: 'rgb(201, 203, 207)'
21  
};
22  
23  
	// INITIALIZATION
24  
	
25  
	function randomScalingFactor() { return 5; }
26  
27  
		var config = {
28  
			type: 'line',
29  
			data: {
30  
				labels: [],
31  
				datasets: [{
32  
					label: 'Computing devices',
33  
					backgroundColor: window.chartColors.red,
34  
					borderColor: window.chartColors.red,
35  
					data: [],
36  
					fill: false,
37  
				}, {
38  
					label: 'Connected devices',
39  
					backgroundColor: window.chartColors.yellow,
40  
					borderColor: window.chartColors.yellow,
41  
					data: [],
42  
					fill: false,
43  
				}, {
44  
					data: [],
45  
					showLine: false,
46  
					pointRadius: 0
47  
				}]
48  
			},
49  
			options: {
50  
        legend: {
51  
          labels: {
52  
            filter: function(legendItem, chartData) {
53  
              //return legendItem.dataSetIndex != 2;
54  
              return legendItem.text != null;
55  
            },
56  
            fontSize: 18
57  
          },
58  
        },
59  
60  
				responsive: true,
61  
				title: {
62  
					display: true,
63  
					text: 'ante! available computing power',
64  
					fontSize: 32
65  
				},
66  
				tooltips: {
67  
					mode: 'index',
68  
					intersect: false,
69  
					filter: function(item, data) { return item.datasetIndex < 2; }
70  
				},
71  
				hover: {
72  
					mode: 'nearest',
73  
					intersect: true
74  
				},
75  
				scales: {
76  
					xAxes: [{
77  
						display: true,
78  
						scaleLabel: {
79  
							display: true,
80  
							labelString: 'Time'
81  
						}
82  
					}],
83  
					yAxes: [{
84  
						display: true,
85  
						scaleLabel: {
86  
							display: true,
87  
							labelString: ''
88  
						},
89  
						ticks: { stepSize: 1 }
90  
					}]
91  
				}
92  
			}
93  
		};
94  
95  
		window.onload = function() {
96  
			var ctx = document.getElementById('canvas').getContext('2d');
97  
			window.myLine = new Chart(ctx, config);
98  
			var start = +new Date(), n = -2;
99  
			var lastValue = null;
100  
		
101  
		  var f;
102  
  		function f() {
103  
  		  $.get('http://butter.botcompany.de:8080/1013835/raw/n2', function(jsn) {
104  
  		    jsn = JSON.parse(jsn);
105  
    		  var value = jsn[1];
106  
    		  var value2 = jsn[0];
107  
    		  var value3 = jsn[1]+1; // dummy for max
108  
    		  var diff = Math.round((new Date()-start)/$INTERVAL);
109  
    		  var ds = config.data.datasets[0].data;
110  
    		  var ds2 = config.data.datasets[1].data;
111  
    		  var ds3 = config.data.datasets[2].data;
112  
    		  var change = false;
113  
    			while (n < diff) {
114  
    			  ++n;
115  
    				config.data.labels.push('');
116  
    				if (lastValue == null) lastValue = value;
117  
    				ds.push(value-lastValue);
118  
    				lastValue = value;
119  
    				ds2.push(value2);
120  
    				ds3.push(value2+1);
121  
    				change = true;
122  
    			}
123  
    			while (ds.length > 20) {
124  
    			  config.data.labels.shift();
125  
    			  ds.shift();
126  
    				ds2.shift();
127  
    				ds3.shift();
128  
    			}
129  
    			if (change) window.myLine.update();
130  
    		});
131  
  		}
132  
  		setInterval(f, $INTERVAL);
133  
  		f();
134  
		};
135  
	]].replace("$INTERVAL", str(5000)))));
136  
}

Author comment

Began life as a copy of #1013912

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1013923
Snippet name: ante! Graph [LIVE]
Eternal ID of this version: #1013923/49
Text MD5: 4672fd262ce6232f97985c44e06c6520
Transpilation MD5: 98b89a834c3edf7d964ba1ebe787f89e
Author: stefan
Category: javax / web
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-06 23:41:54
Source code size: 3377 bytes / 136 lines
Pitched / IR pitched: No / No
Views / Downloads: 642 / 4480
Version history: 48 change(s)
Referenced in: [show references]