123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- @model Edge.WebHost.Models.VeederRoot_ATG_Console_Handler_Models.AtgController
- @{
- ViewData["Title"] = "Auto Tank Gauge System";
- Layout = null;
- }
- <script>
- function clearCanvas(canvas) {
- var cxt = canvas.getContext("2d");
- cxt.clearRect(0, 0, canvas.width, canvas.height);
- }
-
- function drawTank(canvas, x, y, r, productDatas, horiLineDatas) {
- var context = canvas.getContext('2d');
-
- context.beginPath();
- context.setLineDash([]);
- context.arc(x, y, r, 0, 2 * Math.PI, false);
- context.closePath();
- context.lineWidth = 1;
- context.fillStyle = 'white';
- context.fill();
- context.strokeStyle = '#550000';
- context.stroke();
- productDatas.forEach(function (data) {
-
- var temp_tri_w = Math.sqrt(Math.pow(r, 2) - Math.pow(r - data.height, 2));
- var temp_tri_h = r - data.height;
-
- var sectorArc = Math.acos(temp_tri_h / r) * 2;
-
-
- context.beginPath();
- context.arc(x, y, r, (Math.PI - sectorArc) / 2, (Math.PI - sectorArc) / 2 + sectorArc, false);
-
- line_start_x = x - temp_tri_w;
- line_end_x = x - temp_tri_w + temp_tri_w * 2;
- line_start_y = y + r - data.height;
- line_end_y = y + r - data.height;
- context.moveTo(line_start_x, line_start_y);
- context.lineTo(line_end_x, line_end_y);
-
-
- context.closePath();
- context.lineWidth = 1;
- context.fillStyle = data.color;
- context.fill();
- context.font = 'Bold 14px Arial';
- context.textAlign = 'center';
- context.textBaseline = 'middle';
- context.fillStyle = 'black';
- context.fillText(data.text, line_start_x - 10, line_start_y);
-
-
- });
- horiLineDatas.forEach(function (data) {
- if (data.height > r * 2) {
- console.error('horiLine length should not exceed r*2, but now is ' + data.height);
- return;
- }
- var coordinate_height_y = r * 2 - data.height + y - r;
-
- var comp = Math.sqrt(Math.pow(r, 2) - Math.pow(coordinate_height_y - y, 2));
- line_start_x = -comp + x;
- line_end_x = comp + x;
-
-
- context.beginPath();
- context.lineWidth = 1;
- context.setLineDash([3, 2]);
- context.moveTo(line_start_x, coordinate_height_y);
- context.lineTo(line_end_x, coordinate_height_y);
- context.strokeStyle = data.strokeColor;
- context.stroke();
- context.font = 'italic 10px Arial';
- context.textAlign = 'center';
- context.textBaseline = 'middle';
- context.fillStyle = 'gray';
- context.fillText(data.text, line_start_x + (line_end_x - line_start_x) / 2, coordinate_height_y - 4);
-
- });
- }
- </script>
- <script src="~/js/Chart.bundle.js"></script>
- <script src="~/js/jquery-3.4.1.min.js"></script>
- @*<div class="text-center">
- <h3 class="display-4">This is the ATG Console Web App</h3>
- </div>*@
- @if (Model == null || Model.Tanks == null)
- {
- <h1>The console is <b>NOT ready</b> for connection, will auto reload once it's done...</h1>
- <script>
- setInterval(function () { location.reload() }, 3000);
- </script>
- }
- @if (Model.Tanks != null && Model.Tanks.Any())
- @foreach (var tank in Model.Tanks)
- {
- var atgConsoleLengthUnitDisplayStr = "mm";
- var atgConsoleVolumeUnitDisplayStr = "L";
- if (Model.SystemUnit == Edge.Core.IndustryStandardInterface.ATG.SystemUnit.US)
- atgConsoleLengthUnitDisplayStr = "inches";
- else if (Model.SystemUnit == Edge.Core.IndustryStandardInterface.ATG.SystemUnit.ImperialGallons)
- atgConsoleLengthUnitDisplayStr = "yard";
- <div style="border-color:gray;border-style:solid;border-width:thin;padding:4px">
- <p style="margin-top:@(10*(tank.TankNumber-1))px">
- Tank No.: <b>@tank.TankNumber</b>, has product: <b>@(tank.Product?.ProductLabel ?? "")(code: @(tank.Product?.ProductCode ?? ""))</b>
- is in tank state: <b>@(tank.State)</b>, Diameter: @(tank.Diameter ?? -1)@atgConsoleLengthUnitDisplayStr
- </p>
- <div style="display:flex;">
-
- <div class="chart-container" style="position: relative;height:@(100/Model.Tanks.Count())vh; width:100vh;">
- <canvas id="tank_@(tank.TankNumber)_Height_Water_Chart" aria-label="ThisIsTheCanvas" style="">Your browser does not support the canvas element.</canvas>
- </div>
- <canvas id="tank_@(tank.TankNumber)_Height_Water_SectionalView" aria-label="ThisIsTheCanvas"
- style="height:@(100/Model.Tanks.Count())vh; width:50vh;">
- Your browser does not support the canvas element.
- </canvas>
- </div>
- </div>
- <script>
- var ctx_tank_@(tank.TankNumber)_Height_Water_Chart = document.getElementById('tank_@(tank.TankNumber)_Height_Water_Chart');
- var tank_@(tank.TankNumber)_Height_Water_Chart = new Chart(ctx_tank_@(tank.TankNumber)_Height_Water_Chart, {
- type: 'line',
- data: {
-
- datasets: [{
- label: '油高',
-
- backgroundColor: 'rgba(204, 204, 0, 0.2)',
- borderColor: [
- 'rgba(255, 99, 132, 1)',
- 'rgba(54, 162, 235, 1)',
- 'rgba(255, 206, 86, 1)',
- 'rgba(75, 192, 192, 1)',
- 'rgba(153, 102, 255, 1)',
- 'rgba(255, 159, 64, 1)'
- ],
- borderWidth: 1
- },
- {
- label: '水高',
-
- backgroundColor: 'rgba(0, 255, 255, 0.2)',
- borderColor: [
- 'rgba(255, 99, 132, 1)',
- 'rgba(54, 162, 235, 1)',
- 'rgba(255, 206, 86, 1)',
- 'rgba(75, 192, 192, 1)',
- 'rgba(153, 102, 255, 1)',
- 'rgba(255, 159, 64, 1)'
- ],
- borderWidth: 1
- }]
- },
- options: {
- maintainAspectRatio: false,
- scales: {
- yAxes: [{
- ticks: {
- beginAtZero: true,
-
- callback: function (value, index, values) {
- return value + '@atgConsoleLengthUnitDisplayStr';
- }
- }
- }]
- }
- }
- });
-
- </script>
- }
- <script>
- var productHeight = 0;
- var waterHeight = 0;
- var maxChartStackDataCount = 30;
- function add_Height_Water_Data(__chart, tankNumber) {
- $.getJSON('Details/?tankNumber=' + tankNumber, function (datas) {
- if (datas == null) {
- console.log('response datas is null'); return;
- }
-
- datas.forEach(function (d) {
- var chartName = 'tank_' + d.tankNumber + '_Height_Water_Chart';
- var chart = window[chartName];
- if (chart == null) return;
-
-
- chart.data.datasets.forEach((purgeDataset) => {
- if (purgeDataset.data.length > maxChartStackDataCount) {
-
- purgeDataset.data = purgeDataset.data.slice(purgeDataset.data.length - maxChartStackDataCount, purgeDataset.data.length);
-
-
-
-
- }
- });
- if (chart.data.labels.length > maxChartStackDataCount) {
- chart.data.labels = chart.data.labels.slice(chart.data.labels.length - maxChartStackDataCount, chart.data.labels.length);
- }
-
- chart.data.labels.push(d.timeStamp);
- chart.data.datasets.forEach((dataset) => {
- if (dataset.label === "油高") {
- dataset.data.push(d.height);
- productHeight = d.height;
- }
- else if (dataset.label === "水高") {
- dataset.data.push(d.water);
- waterHeight = d.water;
- } else return;
- chart.update({
- duration: 600,
- easing: 'easeOutBounce'
- });
- var sectionalViewCanvas = document.getElementById('tank_' + d.tankNumber + '_Height_Water_SectionalView');
- this.clearCanvas(sectionalViewCanvas);
- this.drawTank(sectionalViewCanvas, 150, 80, 60, [
- { height: productHeight / 1800 * 60 * 2, color: 'orange', text: '92#' },
- { height: waterHeight / 1800 * 60 * 2, color: '#00ced1', text: 'water' }],
- [{ height: 90, strokeColor: 'red', text: 'fuel high' },
- { height: 30, strokeColor: 'blue', text: 'water high' }]);
- });
- });
- })
- }
- function removeData(chart) {
- chart.data.labels.pop();
- chart.data.datasets.forEach((dataset) => {
- dataset.data.pop();
- });
- chart.update();
- }
- setInterval(function () { add_Height_Water_Data(null, null) }, 1500);
- </script>
|