-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
195 lines (163 loc) · 6.07 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="js/UnitConverterUNECERec20.js"></script>
<style type="text/css">
body { background-color: #FFFFFF; font-size: 1en; font-family: Arial, Helvetica, Geneva, sans-serif; }
h1 { text-align: center; }
table {width: 95%; margin-left: 5%; }
td {width: 50%;}
textarea {width: 100%; height: 4em; font-size: 1em;}
.supportedPropertyType {width: 15%; text-align: right; padding-right: 1em;}
.supportedPropertyUnits {width: 85%; text-align: left; padding-left: 1em;}
table.supportedProperties tbody tr:nth-child(odd) { background-color: #ffeecc }
table.supportedProperties tbody tr:nth-child(even) { background-color: #ccccff }
select#selectCodeNameOrSymbol { font-size: 1em; font-family: Arial, Helvetica, Geneva, sans-serif; font-weight: 700;}
</style>
</head>
<body>
<div id="app1">
<h1>Simple demo page for UnitConverterUNECERec20</h1>
<p>This page makes use of the UnitConverterUNECERec20 JavaScript library soon to be provided at <a href="https://github.com/gs1" target="_blank">https://github.com/gs1</a> (currently at <a href="https://github.com/mgh128/UnitConverterUNECERec20/" target="_blank">https://github.com/mgh128/UnitConverterUNECERec20/</a>)</p>
<p>The library provides methods for converting between units of measure expressed using UN ECE Recommentation 20 unit codes.</p>
<p>It has been developed to enable easier querying and interpretation of sensor data and other quantitative data expressed using UN ECE Recommendation 20 unit codes.</p>
<p>Currently the tool supports a total of {{unitsData.length}} units and {{Object.keys(properties).length}} physical properties - <a href="#supportedProperties">see below for further details</a>.</p>
<h2>convert() method</h2>
<p>The convert method converts a unit code and numeric value into an equivalent value for a specified target unit code</p>
<table>
<tr><td>convert({"<select id="inputUnit" v-model="inputUnit">
<option v-for="option in unitsData" v-bind:value="option.rec20">
{{ option.rec20 }}
</option>
</select>",<input type="text" v-model="inputValue">},"<select id="inputUnit" v-model="outputUnit">
<option v-for="option in relatedUnits1" >
{{ option }}
</option>
</select>")</td><td>Result: <input type="text" v-model="outputValue"></td></tr>
</table>
<h2>relatedUnits() method</h2>
<p>The relatedUnits method returns a list of all related units for the same physical property (e.g. all related temperature units)<p>
<table>
<tr><td>relatedUnits("<select id="inputUnit2" v-model="inputUnit2">
<option v-for="option in unitsData" v-bind:value="option.rec20">
{{ option.rec20 }}
</option>
</select>")</td><td>Result: {{JSON.stringify(relatedUnits)}}</td></tr>
</table>
<h2>multiconvert() method</h2>
<p>The multiconvert method converts a unit code and numeric value into equivalent values for all related units of the same physical property (e.g. all related temperature units)<p>
<table>
<tr><td colspan="2">multiconvert({"<select id="inputUnit3" v-model="inputUnit3">
<option v-for="option in unitsData" v-bind:value="option.rec20">
{{ option.rec20 }}
</option>
</select>",<input type="text" v-model="inputValue3">})</td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2">Result: {{JSON.stringify(multiconvertresults)}}</td></tr>
</table>
<a name="supportedProperties"></a>
<h2>Supported properties</h2>
<table class="supportedProperties">
<thead>
<tr>
<th class="supportedPropertyType">Property</th><th class="supportedPropertyUnits">Show <select id="selectCodeNameOrSymbol" v-model="selectCodeNameOrSymbol">
<option v-for="option in selectionOptions">{{option}}
</select></th>
</tr>
</thead>
<tbody>
<tr v-for="property in properties"><td class="supportedPropertyType">{{property.type}}</td><td class="supportedPropertyUnits">{{property[selectCodeNameOrSymbol].join(" , ")}}</td></tr>
</tbody>
</table>
<h2>Data table</h2>
<textarea v-model="unitsTable"></textarea>
</div>
<script language="javascript">
var units=new UnitConverterUNECERec20();
var unitsData = units.unitsData;
var inputUnit="FAH";
var outputUnit="CEL";
var inputUnit2="ATM";
var inputValue=212;
var inputUnit3="CEL";
var inputValue3=100;
var selectCodeNameOrSymbol="codes";
var selectionOptions = ["codes","symbols","names"];
function escapeEntities(string) {
return string.replace("°","°");
}
var app1 = new Vue({
el: "#app1",
data : {
units: units,
unitsData : unitsData,
inputUnit: inputUnit,
inputUnit2: inputUnit2,
inputUnit3: inputUnit3,
outputUnit: outputUnit,
inputValue: inputValue,
inputValue3: inputValue3,
selectCodeNameOrSymbol: selectCodeNameOrSymbol,
selectionOptions : selectionOptions
},
computed : {
unitsTable: function() {
return JSON.stringify(this.unitsData,2);
},
properties: function() {
var properties={};
for (i in this.unitsData) {
var el=unitsData[i];
var t=el.type;
var s=el.symbol;
var n=el.name;
var c=el.rec20;
if (properties.hasOwnProperty(t)) {
properties[t].symbols.push(escapeEntities(s));
properties[t].names.push(escapeEntities(n));
properties[t].codes.push(c);
} else {
var e={}
e.symbols=[escapeEntities(s)];
e.names=[escapeEntities(n)];
e.codes=[c];
e.type=t;
properties[t]=e;
}
}
console.log(JSON.stringify(properties));
return properties;
},
outputValue: function() {
var rv="";
if ((this.inputValue!=="") && (this.outputUnit!=="") && (this.inputUnit!=="")) {
var io={};
io[this.inputUnit]=this.inputValue;
rv = units.convert(io,this.outputUnit);
}
return rv;
},
relatedUnits: function() {
return units.relatedUnits(this.inputUnit2);
},
relatedUnits1: function() {
var rv;
rv=units.relatedUnits(this.inputUnit);
if (rv.indexOf(this.outputUnit) == -1) {
this.outputUnit=rv[0];
}
return rv;
},
multiconvertresults: function() {
var rv="";
var io={};
io[this.inputUnit3]=this.inputValue3;
rv=units.multiconvert(io);
return rv;
}
}
});
</script>
</body>
</html>