-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
196 lines (184 loc) · 7.82 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
195
196
<!DOCTYPE html>
<html>
<head>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4812VFLT3M"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-4812VFLT3M');
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4922790412146333" crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/jquery-confirm.min.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
#logo{
height: 300px;
}
#subtitle{
font-size: 2em;
padding-left: 25px
}
#link-button{
bottom: 5px;
font-size: 1.5em;
cursor: pointer;
padding-left: 25px;
}
#desc{
padding-left: 25px;
width: 450px;
}
.data-button{
background-color: #05a2a9;
color: white;
width: 200px;
font-size: 1.2em;
}
#dataBox{
height:60vh;
width: 100%;
}
html, body {
height: calc(100vh - 50px);
}
body {
margin: 0;
color: cadetblue;
}
.flex-container {
height: calc(100vh - 50px);
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: center;
justify-content: center;
}
.m-row {
width: auto;
}
.flex-item {
text-align: center;
}
</style>
</head>
<body>
<div class="flex-container">
<div class="m-row">
<div class="flex-item">
<a href="https://github.com/NaturalIntelligence/nimn-spec" target="_blank">
<img src="img/nimn.svg" id="logo">
</a>
</div>
<div class="flex-item" id="subtitle">Just Data</div>
<div class="flex-item" id="desc"><p>Nimn data format can save upto 85% of space / bandwidth in comparison of XML or JSON data.</p></div>
</div>
</div>
<div class="m-row">
<div class="flex-item" id="link-button">Try it online with your Data</div>
</div>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery-confirm.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fast-xml-parser/3.10.0/parser.min.js"></script>
<script src="https://cdn.rawgit.com/nimndata/nimnjs-schema-builder/1f50f478/dist/nimn-schema-builder.js"></script>
<script src="https://cdn.rawgit.com/nimndata/nimnjs/7cf21608/dist/nimn.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>
<script>
$(function(){
$("#link-button").click(function(){
$.dialog({
title: 'Check how much it can save',
columnClass: 'col-md-6 col-md-offset-6 col-xs-4 col-xs-offset-8',
containerFluid: true, // this will add 'container-fluid' instead of 'container'
content: `<div style="text-align:center;">
<div><textarea id="dataBox" placeholder="Paste your XML or JSON data here"></textarea></div>
<br>
<div><button class="btn data-button" onclick="javascript:convert()">Show me comparison</button></div><br>
<div>`
});
});
});
function convert(){
var data = $("#dataBox").val();
if(data.trim().length === 0){
showError();
}else{
try{
var jsonData = JSON.parse( data );
jsonToNimn(jsonData, "JSON", JSON.stringify(jsonData).length);
}catch(e){
//assume it XML
data = data.replace(/>\s*</g, "><");
if(parser.validate(data) === true){
var jsonData = parser.parse(data,xmlOptions);
jsonToNimn(jsonData, "XML", data.length);
}else{
showError();
}
}
}
}
function jsonToNimn(jsonData, type, len){
var schema = nimn.buildSchema( nimnSchemaBuilder.build(jsonData) );
var result = nimn.stringify(schema, jsonData);
displayData(type,result, len);
}
var xmlOptions = {
ignoreAttributes : false,
ignoreNameSpace : false,
allowBooleanAttributes : true,
parseNodeValue : false,
parseAttributeValue : false,
trimValues: true
};
function displayData(type,nimndata, v1){
var v2 = nimndata.length;
var diff = ((v1 - v2) * 100 )/ v1;
diff = Math.round(diff * 100) / 100;
$.dialog({
title: "<span style='color: #008299'>Congrates!!</span>",
columnClass: 'col-md-8 col-md-offset-4 col-xs-4 col-xs-offset-8',
containerFluid: true,
content: `<p>You've saved ${diff}% data.</p>
<p>You can save more when you have fixed values field like enum or enable field level compression.</p>
<canvas id="myChart" ></canvas>
`,
onContentReady : function(){
showGraph(type, v1, v2);
},
escapeKey: true,
backgroundDismiss: true
});
}
function showError(){
$.dialog({
title: "Sorry!",
content: "Invalid or corrupted Data"
});
}
function showGraph(type, v1, v2){
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: [type, "Nimn"],
datasets: [{
label: 'Data Size in bytes',
data: [v1, v2],
backgroundColor: [
'rgba(255, 99, 132)',
'cadetblue'
]
}]
},
options: {
//responsive: false
}
});
}
</script>
</body>
</html>