Skip to content

Commit

Permalink
Update info.json, sensorBoolChart and sensorNumberChart widgets for P…
Browse files Browse the repository at this point in the history
…olimer 2
  • Loading branch information
vdomos committed Dec 12, 2017
1 parent 688f047 commit 04175a5
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 51 deletions.
6 changes: 6 additions & 0 deletions packs/widgets/highcharts/info.json
Expand Up @@ -67,6 +67,12 @@
"type": "boolean",
"default": "False"
},
"precision" : {
"name": "Number precision",
"description": "Set the numeric precision",
"type": "number",
"default": "1"
},
"color" : {
"name": "HighStock line graph color",
"description": "HighStock line graph color",
Expand Down
53 changes: 31 additions & 22 deletions packs/widgets/highcharts/sensorBoolChart.html
Expand Up @@ -50,7 +50,7 @@
position: absolute;
bottom: 2px;
right: 5px;
font-size: calc(1.3em*var(--wscale-h));
font-size: calc(1em*var(--wscale-h)*var(--wscale-r));
}
#icongraphlink {
text-decoration: none;
Expand All @@ -59,20 +59,20 @@
#graph {
display: none;
position: fixed;
top: 50%;
left: 50%;
top: 10px;
left: 10px;
width: 750px;
min-height: 440px;
background-color: rgba(50, 50, 50, 0.5);
border: 6px solid rgba(50, 50, 50, 0.5) ;
margin-top: -220px;
margin-left: -375px;
/* margin-top: -220px; */
/* margin-left: -375px; */
z-index: 10;
}
#loadicon {
position:relative;
left:420px;
top:210px;
left:370px;
top:190px;
font-size: 3em;
color: white;
}
Expand Down Expand Up @@ -178,20 +178,24 @@
}

// ------------------------------------------------------------------------------------
historyChanged(newValue, oldValue) {
historyChanged(newValue, oldValue) {
//console.error("### historyChanged: " + newValue);
this.data = [] ;
for (let i = 0; i < newValue.length; i++) {
for (var i = 0; i < newValue.length; i++) {
var value = [] ;
value[0] = newValue[i].timestamp * 1000 ;
if (this.$.primary.datatype_id != "DT_OpenClose") value[1] = newValue[i].value_num ;
else value[1] = newValue[i].value_num == 1 ? 0 : 1 ;
this.data.push(value)
}

//console.error("### Data: " + this.data) ;

var self = this; // Important for rangeSelector buttons event !
var dataObject = {
rangeSelector: {
buttonTheme: {
width: 70
},
buttons: [{
type: '',
count: 1,
Expand All @@ -211,30 +215,33 @@
text: this.$.primary.device['name']
},
subtitle: {
/* text: '<i>(Current ' + this.periode + ')</i>' */
text: '<i>(' + this.periode + ')</i>'
},
},
xAxis: {
gridLineWidth: 1,
ordinal: false,
events: {
setExtremes: function(e) {
if(typeof(e.rangeSelectorButton) !== 'undefined') {
if(typeof(e.rangeSelectorButton) !== 'undefined')
{
console.error("Button " + e.rangeSelectorButton.text + " pressed");
mychart.setTitle({text: self.localize("Loading data") + "..."});
mychart.series[0].remove(true);
self.periode = e.rangeSelectorButton.text;
switch(self.periode) {
case self.localize('Day'):
case self.localize("Day"):
var from = moment().subtract(1, "days").unix();
break;
case self.localize('Week'):
var from = moment().subtract(1, "weeks").unix();
case self.localize("Week"):
var from = moment().subtract(1, "weeks").unix();
break;
case self.localize('Month'):
case self.localize("Month"):
var from = moment().subtract(1, "months").unix();
break;
}
console.log("### timestamp - 1 " + self.periode + ": " + from);
self.$.primary.getLastFrom(from);
}
console.error("### timestamp - 1 " + self.periode + ": " + from);
self.$.primary.getLastFrom(from) ;
}
}
}
Expand All @@ -250,7 +257,8 @@
},
series: [{
name: this.$.primary.name,
type: 'spline',
type: 'line',
step: "left",
data: this.data,
color: this.color,
lineWidth: 1,
Expand All @@ -264,8 +272,9 @@
chart: {
renderTo: this.$.graph
}
};
var mychart = new Highcharts.StockChart(dataObject);
};

var mychart = new Highcharts.StockChart(dataObject);
}

// ------------------------------------------------------------------------------------
Expand Down
67 changes: 38 additions & 29 deletions packs/widgets/highcharts/sensorNumberChart.html
Expand Up @@ -40,13 +40,15 @@
position: absolute;
top:5px;
right: 5px;
font-size: calc(2em*var(--wscale-h));
/* font-size: calc(2em*var(--wscale-h)); */
font-size: calc(1em*var(--wscale-h)*var(--wscale-r));
}
#icongraph {
position: absolute;
bottom: 2px;
right: 5px;
font-size: calc(1.3em*var(--wscale-h));
/* font-size: calc(1.3em*var(--wscale-h)); */
font-size: calc(1em*var(--wscale-h)*var(--wscale-r));

}
#icongraphlink {
Expand All @@ -56,20 +58,20 @@
#graph {
display: none;
position: fixed;
top: 50%;
left: 50%;
top: 10px;
left: 10px;
width: 750px;
min-height: 440px;
background-color: rgba(50, 50, 50, 0.5);
border: 6px solid rgba(50, 50, 50, 0.5) ;
margin-top: -220px;
margin-left: -375px;
/* margin-top: -220px; */
/* margin-left: -375px; */
z-index: 10;
}
#loadicon {
position:relative;
left:420px;
top:210px;
left:370px;
top:190px;
font-size: 3em;
color: white;
}
Expand All @@ -86,7 +88,7 @@
<div id="icongraph" on-click="displayGraph">
<a id="icongraphlink" href="#"><i class="fa fa-area-chart"></i></a>
</div>
<div id="graph" on-dblclick="hideGraph"><i id="loadicon" class="fa fa-spinner fa-pulse"><i id="loadicon" class="fa fa-spinner fa-pulse"></i></div>
<div id="graph" on-dblclick="hideGraph"><i id="loadicon" class="fa fa-spinner fa-pulse"></i></div>

</template>

Expand Down Expand Up @@ -163,6 +165,9 @@
// ------------------------------------------------------------------------------------
sensorvalueChanged(newValue, oldValue) {
newValue = newValue.stored_value;
if (!Number.isInteger(newValue)) {
newValue = parseFloat(newValue).toFixed(this.options['precision']);
}
var unit = this.datatypes[this.$.primary.datatype_id]['unit'];
if (this.options['autoconvert']==1 && newValue > 0) {
var k = 1000;
Expand All @@ -185,17 +190,17 @@
historyChanged(newValue, oldValue) {
//console.error("historyChanged: " + newValue);
this.data = [] ;

for (var i = 0; i < newValue.length; i++) {
let value = [] ;

var value = [] ;
switch(this.periode) {
case this.localize('Day'): // year month day hour minute s ms
case this.localize("Day"): // year month day hour minute s ms
var dt = new Date(newValue[i][0], newValue[i][1] - 1, newValue[i][3], newValue[i][4], newValue[i][5], 0, 0) ;
value[1] = newValue[i][6] ;
break;
case this.localize('Week'):
case this.localize('Month'): // Month Per hours
var dt = new Date(newValue[i][0], newValue[i][1] - 1, newValue[i][3], newValue[i][4], 0, 0, 0) ;
case this.localize("Week"):
case this.localize("Month"): // Month Per hours
var dt = new Date(newValue[i][0], newValue[i][1] - 1, newValue[i][3], newValue[i][4], 0, 0, 0) ;
value[1] = newValue[i][5] ;
break;
}
Expand All @@ -204,10 +209,13 @@
this.data.push(value)
}
//console.error("==> " + this.data) ;

var self = this; // Important for rangeSelector buttons event !
var dataObject = {
rangeSelector: {
buttonTheme: {
width: 70
},
buttons: [{
type: '',
count: 1,
Expand All @@ -228,28 +236,29 @@
},
subtitle: {
text: '<i>(' + this.periode + ')</i>'
},
},
xAxis: {
gridLineWidth: 1,
ordinal: false,
events: {
setExtremes: function(e) {
if(typeof(e.rangeSelectorButton) !== 'undefined') {
mychart.setTitle({text: self.localize("Loading data") + "..."});
if(typeof(e.rangeSelectorButton) !== 'undefined')
{
console.error("Button " + e.rangeSelectorButton.text + " pressed");
mychart.setTitle({text: self.localize("Loading data") + " ..."});
mychart.series[0].remove(true);
self.periode = e.rangeSelectorButton.text;
self.periode = e.rangeSelectorButton.text ;
switch(self.periode) {
case self.localize('Day'):
case self.localize("Day"):
self.$.primary.getCurrentDay() ; // 'interval': 'minute'
break;
case self.localize('Week'):
self.$.primary.getCurrentWeek() ; // 'interval': 'hour'
case self.localize("Week"):
self.$.primary.getCurrentWeek() ; // 'interval': 'hour'
break;
case self.localize('Month'):
//self.$.primary.getCurrentMonth() ; // 'interval': 'day'
case self.localize("Month"):
self.$.primary.getCurrentMonthPerHour() ; // 'interval': 'hour'
break;
}
}
}
}
}
Expand Down Expand Up @@ -277,10 +286,10 @@
chart: {
renderTo: this.$.graph
}
};
};

var mychart = new Highcharts.StockChart(dataObject);

}
}

// ------------------------------------------------------------------------------------
displayGraph() {
Expand Down

0 comments on commit 04175a5

Please sign in to comment.