Skip to content

Commit f0863d8

Browse files
committed
v8.8 release (part2)
add flot curverLines support and example use, allow loading vars/functions in userMetrics, beautify `userMetrics/_example.js`
1 parent 384c089 commit f0863d8

File tree

3 files changed

+75
-5
lines changed

3 files changed

+75
-5
lines changed

gateway.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,21 @@ try {
7575
{
7676
fs.readdirSync(__dirname + '/' + userMetricsDir).forEach(function(file) {
7777
if (file.match(/\.js$/) !== null) {
78-
var name = file.replace('.js', '');
79-
console.info('LOADING USER METRICS MODULE [' + name + ']');
78+
console.info('LOADING USER METRICS MODULE [' + file + ']');
8079
try {
8180
var tmp = require(__dirname + '/' + userMetricsDir + '/' + file);
82-
metricsDef = merge(true, metricsDef, tmp);
81+
metricsDef.metrics = merge(true, metricsDef.metrics, tmp.metrics);
82+
metricsDef.motes = merge(true, metricsDef.motes, tmp.motes);
83+
metricsDef.events = merge(true, metricsDef.events, tmp.events);
84+
delete tmp.metrics;
85+
delete tmp.motes;
86+
delete tmp.events;
87+
metricsDef = merge(true, metricsDef, tmp); //merge anything else (properties, variables, objects, functions)
88+
//console.info('USER METRICS MERGE RESULT V: ' + JSON.stringify(metricsDef.metrics.V)); //verify that a custom metric was loaded
89+
//console.info('USER METRICS MERGE RESULT VAR: ' + JSON.stringify(metricsDef.ONEDAYHOURS)); //verify that a custom variable was loaded
90+
//console.info('USER METRICS MERGE RESULT FUNC: ' + metricsDef.secondsInOneDay.toString()); //verify that a custom function was loaded
8391
} catch (ex) {
84-
console.error('FAIL LOADING USER METRICS MODULE ['+ name + ']: ' + ex.message);
92+
console.error('FAIL LOADING USER METRICS MODULE ['+ file + ']: ' + ex.message);
8593
}
8694
}
8795
});

userMetrics/_example.js

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
/*this sample metric will override that which is already defined in main metrics.js*/
22
/*you can redefine defaults or write your own new custom metrics in 1 or more files in this folder, separate them as you'd like - they all get merged together when the app loads*/
33
exports.metrics = {
4-
V : { name:'V', regexp:/(?:V?BAT|VOLTS|V)\:([\d\.]+)v?/i, value:'', unit:'v', graph:1, graphOptions:{ legendLbl:'VOLTZ!', lines: { fill:true, lineWidth:1 }, yaxis: { min: 0, autoscaleMargin: 0.5 }}}
4+
V:
5+
{
6+
name: 'V',
7+
regexp: /(?:V?BAT|VOLTS|V)\:([\d\.]+)v?/i,
8+
value: '',
9+
unit: 'v',
10+
graph: 1,
11+
graphOptions:
12+
{
13+
legendLbl: 'VOLTZ!',
14+
lines:
15+
{
16+
fill: true,
17+
lineWidth: 1
18+
},
19+
yaxis:
20+
{
21+
min: 0,
22+
autoscaleMargin: 0.25
23+
}
24+
}
25+
},
26+
H:
27+
{
28+
name: 'H',
29+
regexp: /H\:([\d\.]+)/i,
30+
value: '',
31+
unit: '%',
32+
pin: 1,
33+
graph: 1,
34+
graphOptions:
35+
{
36+
legendLbl: 'Humidity',
37+
lines:
38+
{
39+
lineWidth: 1
40+
},
41+
yaxis:
42+
{
43+
autoscaleMargin: 0.25
44+
},
45+
series:
46+
{
47+
curvedLines:
48+
{
49+
active: true,
50+
apply: true,
51+
//monotonicFit: true, //makes the curve tight to datapoints
52+
//nrSplinePoints: 5 //number of sample points (of the spline) in between two consecutive points (more = smoother)
53+
}
54+
}
55+
}
56+
}
57+
};
58+
59+
/*example of defining a property to use anywhere in the app/events or in other custom functions*/
60+
exports.ONEDAYHOURS = 24;
61+
62+
/*example of defining a general purpose function to use in the app/events or in other custom functions*/
63+
exports.secondsInOneDay = function() {
64+
var result = exports.ONEDAYHOURS * 3600;
65+
return result;
566
};

www/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.min.js"></script>
6161
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.time.min.js"></script>
6262
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.selection.min.js"></script>
63+
<script language="javascript" type="text/javascript" src="https://rawgit.com/MichaelZinsmaier/CurvedLines/master/curvedLines.js"></script>
6364
<script language="javascript" type="text/javascript" src="js/graphHelper.js"></script>
6465
<script language="javascript" type="text/javascript" src="js/dateFormat.js"></script> <!-- for demo see http://jsfiddle.net/phZr7/1/ -->
6566
<script language="javascript" type="text/javascript" src="js/bind.1.0.1.min.js"></script>

0 commit comments

Comments
 (0)