Browse Source

fix popup window DOM persistence, add statistics tab, improve poseidon charts

master
o.moresis 2 years ago
parent
commit
3f6345c1bb
  1. 179
      public/js/more-info.js
  2. 2
      public/js/tools/leaflet/L.Control.Window.js
  3. 5
      public/js/tools/leaflet/L.TileLayer.BetterWMS.js
  4. 2
      src/Services/API.php
  5. 2
      src/Services/PoseidonAPI.php
  6. 2
      src/Services/WfdAPI.php
  7. 11
      src/Views/more-info.php
  8. 8
      src/Views/tabpanel.php

179
public/js/more-info.js

@ -3,6 +3,7 @@ function moreInfo() {
lineChart: {}, lineChart: {},
entityGroup: Alpine.store('entity').entityGroup, entityGroup: Alpine.store('entity').entityGroup,
entityId: selectedEntityId || Alpine.store('entity').id, entityId: selectedEntityId || Alpine.store('entity').id,
params: (this.entityGroup === 'POSEIDON' ? Alpine.store('entity').params.split(' ') : []),
dopen: false, dopen: false,
copen: false, copen: false,
loading: false, loading: false,
@ -97,11 +98,11 @@ function moreInfo() {
}).render(grid); }).render(grid);
}, },
drawDataChart() { drawDataChart() {
delete this.lineChart;
delete ctx;
if (this.entityGroup !== 'POSEIDON') if (this.entityGroup !== 'POSEIDON')
return; return;
Alpine.store('entity').params.split(' ').forEach((param, idx) => {
this.addCheckbox(param, idx);
});
console.debug('drawing poseidon chart...'); console.debug('drawing poseidon chart...');
this.lineChart = {}; this.lineChart = {};
var ctx = document.getElementById('data-chart').getContext('2d'); var ctx = document.getElementById('data-chart').getContext('2d');
@ -114,108 +115,94 @@ function moreInfo() {
.then(data => { .then(data => {
Alpine.store('loading', false); Alpine.store('loading', false);
console.debug("data poseidon: ", data); console.debug("data poseidon: ", data);
let chartData = []; let chartData = {};
for (var i = 0; i < data.length; i++) { const labels = data.map(item => new Date(item.dt).toLocaleDateString('el-GR'));
var item = data[i]; const values = data.map(item => item.val);
chartData.push({ console.debug(labels);
x: new Date(item.dt), console.debug(values);
y: item.val chartData = {
}); labels: labels,
} datasets: [{
this.lineChart = new Chart( label: 'param',
ctx, data: values
{ }]
type: 'line', };
data: { console.debug(chartData);
labels: chartData.map(row => row.x), this.lineChart = new Chart(ctx, {
datasets: [ type: 'line',
{ data: chartData,
label: 'PARAM', options: {
data: chartData.map(row => row.y) scales: {
}
]
},
options: {
scales: {
xAxes: [{ xAxes: [{
type: 'time', type: 'time',
time: { time: {
unit: 'day' displayFormats: {
} day: 'DD MMM YYYY'
},
unit: 'day',
stepSize: 20
}
}] }]
} }
}} }
});
);
});
},
addCheckbox(type, index) {
var label = document.createElement('label');
var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = (index === 0);
checkbox.addEventListener('change', function() {
this.lineChart.data.datasets[index].hidden = !checkbox.checked;
this.lineChart.update();
}); });
label.appendChild(checkbox);
label.appendChild(document.createTextNode(type));
document.getElementById('checkbox-container').appendChild(label);
} }
}; };
} }
function poseidonChart(data) { // function poseidonChart(data) {
// var typeGroups = {};
var typeGroups = {}; // for (var i = 0; i < data.length; i++) {
for (var i = 0; i < data.length; i++) { // var item = data[i];
var item = data[i]; // if (!typeGroups[item.type]) {
if (!typeGroups[item.type]) { // typeGroups[item.type] = [];
typeGroups[item.type] = []; // }
} // typeGroups[item.type].push({
typeGroups[item.type].push({ // x: item.date,
x: item.date, // y: item.value
y: item.value // });
}); // }
} //
// console.debug(typeGroups);
var datasets = []; // this.params = typeGroups.type;
var index = 0; // var datasets = [];
for (var type in typeGroups) { // var index = 0;
datasets.push({ // for (var type in typeGroups) {
label: type, // datasets.push({
data: typeGroups[type], // label: type,
borderColor: getRandomColor(), // data: typeGroups[type],
fill: false, // borderColor: getRandomColor(),
hidden: false // fill: false,
}); // hidden: false
addCheckbox(type, index++); // });
} // addCheckbox(type, index++);
// }
var ctx = document.getElementById('myChart').getContext('2d'); //
var myChart = new Chart(ctx, { // var ctx = document.getElementById('myChart').getContext('2d');
type: 'line', // var myChart = new Chart(ctx, {
data: { // type: 'line',
datasets: datasets // data: {
}, // datasets: datasets
options: { // },
scales: { // options: {
xAxes: [{ // scales: {
type: 'time', // xAxes: [{
time: { // type: 'time',
unit: 'week' // time: {
} // unit: 'week'
}] // }
} // }]
} // }
});} // }
// });
// }
//
//
//
//
function getRandomColor() { function getRandomColor() {
var letters = '0123456789ABCDEF'; var letters = '0123456789ABCDEF';

2
public/js/tools/leaflet/L.Control.Window.js

@ -114,6 +114,7 @@ L.Control.Window = L.Control.extend({
var close = this._closeButton; var close = this._closeButton;
L.DomEvent.off(close, 'click', this.close, this); L.DomEvent.off(close, 'click', this.close, this);
} }
this._source.remove();
return this; return this;
}, },
mapResized : function(){ mapResized : function(){
@ -181,6 +182,7 @@ L.Control.Window = L.Control.extend({
L.DomUtil.removeClass(this._wrapper, 'visible'); L.DomUtil.removeClass(this._wrapper, 'visible');
this.fire('hide'); this.fire('hide');
this._container.remove(); // fixes DOM element persistence
return this; return this;
}, },

5
public/js/tools/leaflet/L.TileLayer.BetterWMS.js

@ -73,11 +73,6 @@ L.TileLayer.BetterWMS = L.TileLayer.WMS.extend({
} else { } else {
mruPopup(properties); mruPopup(properties);
} }
// Otherwise show the content in a popup, or something.
// L.popup({ maxWidth: 800})
// .setLatLng(latlng)
// .setContent('placeholder')
// .openOn(this._map);
} }
}); });

2
src/Services/API.php

@ -25,7 +25,6 @@ class API
// Initialize cURL // Initialize cURL
if ($this->isBasicAuth) { if ($this->isBasicAuth) {
curl_setopt($this->curl, CURLOPT_USERPWD, "$this->username:$this->password"); curl_setopt($this->curl, CURLOPT_USERPWD, "$this->username:$this->password");
curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
} }
@ -40,6 +39,7 @@ class API
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this::convert_headers($this->headers)); curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this::convert_headers($this->headers));
} }
if (!empty($data)) { if (!empty($data)) {
// Set the HTTP method to GET // Set the HTTP method to GET
curl_setopt($this->curl, CURLOPT_URL, $url . "?" . http_build_query($data)); curl_setopt($this->curl, CURLOPT_URL, $url . "?" . http_build_query($data));

2
src/Services/PoseidonAPI.php

@ -52,7 +52,7 @@ class PoseidonAPI extends API {
public function getPlatformData($platform) { public function getPlatformData($platform) {
$endpoint = "api/data/{$platform}/"; $endpoint = "api/data/{$platform}/";
$params = "ATMS"; // debugging $params = ["ATMS"]; // debugging
$data = array( $data = array(
"param__pname__in" => implode(',', $params), "param__pname__in" => implode(',', $params),
); );

2
src/Services/WfdAPI.php

@ -14,7 +14,7 @@ class WfdAPI extends API {
public function __construct() public function __construct()
{ {
$url = Constants::getAPIbaseURL($this->apiName); $url = Config::getAPIbaseURL($this->apiName);
parent::__construct($url); parent::__construct($url);
$this->username = "ct_api_user"; $this->username = "ct_api_user";

11
src/Views/more-info.php

@ -1,6 +1,13 @@
<div x-data="moreInfo()"> <div x-data="moreInfo()">
<fieldset id="checkbox-container" class="field"></fieldset> <fieldset id="checkbox-container" class="field">
<div id="chart-wrapper" x-init="drawDataChart()"> <template x-for="param in params" :key="param">
<label class="checkbox" :for="$id('param-input')">
<input type="checkbox" id="$id('param-input')" :value="param">
<span x-text="param"></span>
</label>
</template>
</fieldset>
<div x-if="entityGroup === 'POSEIDON'" id="chart-wrapper" x-init="drawDataChart()">
<canvas id="data-chart" ></canvas> <canvas id="data-chart" ></canvas>
</div> </div>
<p class="px-4">You may request the whole entity (cruise/station etc.) without selecting search criteria or be more specific by doing so.</p> <p class="px-4">You may request the whole entity (cruise/station etc.) without selecting search criteria or be more specific by doing so.</p>

8
src/Views/tabpanel.php

@ -33,6 +33,12 @@
</li> </li>
<li :class="isActiveTab(4) ? 'is-active' : ''"> <li :class="isActiveTab(4) ? 'is-active' : ''">
<a @click="setActiveTab(4)"> <a @click="setActiveTab(4)">
<span class="icon is-small"><i class="fas fa-chart-column" aria-hidden="true"></i></span>
<span>Statistics</span>
</a>
</li>
<li :class="isActiveTab(5) ? 'is-active' : ''">
<a @click="setActiveTab(5)">
<span class="icon is-small"><i class="fas fa-screwdriver-wrench" aria-hidden="true"></i></span> <span class="icon is-small"><i class="fas fa-screwdriver-wrench" aria-hidden="true"></i></span>
<span>Admin Panel</span> <span>Admin Panel</span>
</a> </a>
@ -49,6 +55,8 @@
<?php include('main-map.php'); ?> <?php include('main-map.php'); ?>
<?php include('main-metadata.php'); ?> <?php include('main-metadata.php'); ?>
<?php include('main-about.php'); ?> <?php include('main-about.php'); ?>
<?php include('main-statistics.php'); ?>
<?php include('main-admin.php'); ?>
</main> </main>
</div> </div>
<?php include('spinner.php'); ?> <?php include('spinner.php'); ?>

Loading…
Cancel
Save