ewdlop commited on
Commit
02e8a96
·
verified ·
1 Parent(s): 6be0dae

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +562 -19
index.html CHANGED
@@ -1,19 +1,562 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Decimal Rounding Graph</title>
7
+ <style>
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ body {
15
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
16
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
17
+ min-height: 100vh;
18
+ padding: 20px;
19
+ }
20
+
21
+ .container {
22
+ max-width: 1200px;
23
+ margin: 0 auto;
24
+ background: white;
25
+ border-radius: 15px;
26
+ box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
27
+ overflow: hidden;
28
+ }
29
+
30
+ .header {
31
+ background: linear-gradient(45deg, #4CAF50, #45a049);
32
+ color: white;
33
+ padding: 30px;
34
+ text-align: center;
35
+ }
36
+
37
+ .header h1 {
38
+ font-size: 2.5em;
39
+ margin-bottom: 10px;
40
+ }
41
+
42
+ .header p {
43
+ font-size: 1.1em;
44
+ opacity: 0.9;
45
+ }
46
+
47
+ .controls {
48
+ padding: 30px;
49
+ background: #f8f9fa;
50
+ border-bottom: 1px solid #e9ecef;
51
+ }
52
+
53
+ .input-group {
54
+ display: flex;
55
+ gap: 20px;
56
+ align-items: center;
57
+ justify-content: center;
58
+ flex-wrap: wrap;
59
+ }
60
+
61
+ .input-container {
62
+ display: flex;
63
+ flex-direction: column;
64
+ gap: 5px;
65
+ }
66
+
67
+ label {
68
+ font-weight: 600;
69
+ color: #333;
70
+ font-size: 14px;
71
+ }
72
+
73
+ input[type="number"] {
74
+ padding: 12px 15px;
75
+ border: 2px solid #ddd;
76
+ border-radius: 8px;
77
+ font-size: 16px;
78
+ width: 200px;
79
+ transition: border-color 0.3s ease;
80
+ }
81
+
82
+ input[type="number"]:focus {
83
+ outline: none;
84
+ border-color: #4CAF50;
85
+ box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
86
+ }
87
+
88
+ .btn {
89
+ background: linear-gradient(45deg, #4CAF50, #45a049);
90
+ color: white;
91
+ border: none;
92
+ padding: 12px 30px;
93
+ border-radius: 8px;
94
+ font-size: 16px;
95
+ font-weight: 600;
96
+ cursor: pointer;
97
+ transition: all 0.3s ease;
98
+ margin-top: 20px;
99
+ }
100
+
101
+ .btn:hover {
102
+ transform: translateY(-2px);
103
+ box-shadow: 0 5px 15px rgba(76, 175, 80, 0.3);
104
+ }
105
+
106
+ .content {
107
+ display: flex;
108
+ gap: 30px;
109
+ padding: 30px;
110
+ }
111
+
112
+ .graph-container {
113
+ flex: 2;
114
+ background: white;
115
+ border-radius: 10px;
116
+ box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
117
+ padding: 20px;
118
+ min-height: 400px;
119
+ }
120
+
121
+ .data-table {
122
+ flex: 1;
123
+ background: white;
124
+ border-radius: 10px;
125
+ box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
126
+ padding: 20px;
127
+ max-height: 500px;
128
+ overflow-y: auto;
129
+ }
130
+
131
+ .graph-title {
132
+ text-align: center;
133
+ color: #333;
134
+ margin-bottom: 20px;
135
+ font-size: 1.3em;
136
+ font-weight: 600;
137
+ }
138
+
139
+ .graph-svg {
140
+ width: 100%;
141
+ height: 350px;
142
+ border: 1px solid #e9ecef;
143
+ border-radius: 8px;
144
+ }
145
+
146
+ .table-title {
147
+ text-align: center;
148
+ color: #333;
149
+ margin-bottom: 15px;
150
+ font-size: 1.2em;
151
+ font-weight: 600;
152
+ }
153
+
154
+ table {
155
+ width: 100%;
156
+ border-collapse: collapse;
157
+ font-size: 14px;
158
+ }
159
+
160
+ th, td {
161
+ padding: 10px;
162
+ text-align: left;
163
+ border-bottom: 1px solid #e9ecef;
164
+ }
165
+
166
+ th {
167
+ background: #f8f9fa;
168
+ font-weight: 600;
169
+ color: #333;
170
+ }
171
+
172
+ tr:hover {
173
+ background: #f8f9fa;
174
+ }
175
+
176
+ .original-value {
177
+ background: #e8f5e8;
178
+ padding: 15px;
179
+ border-radius: 8px;
180
+ margin-bottom: 20px;
181
+ text-align: center;
182
+ font-size: 1.1em;
183
+ font-weight: 600;
184
+ color: #2e7d32;
185
+ }
186
+
187
+ .error {
188
+ color: #d32f2f;
189
+ text-align: center;
190
+ padding: 20px;
191
+ font-size: 1.1em;
192
+ }
193
+
194
+ @media (max-width: 768px) {
195
+ .content {
196
+ flex-direction: column;
197
+ }
198
+
199
+ .input-group {
200
+ flex-direction: column;
201
+ align-items: stretch;
202
+ }
203
+
204
+ input[type="number"] {
205
+ width: 100%;
206
+ }
207
+ }
208
+
209
+ .axis-line {
210
+ stroke: #333;
211
+ stroke-width: 2;
212
+ }
213
+
214
+ .grid-line {
215
+ stroke: #e0e0e0;
216
+ stroke-width: 1;
217
+ }
218
+
219
+ .data-point {
220
+ fill: #4CAF50;
221
+ stroke: #2e7d32;
222
+ stroke-width: 2;
223
+ }
224
+
225
+ .data-line {
226
+ fill: none;
227
+ stroke: #4CAF50;
228
+ stroke-width: 3;
229
+ }
230
+
231
+ .axis-label {
232
+ font-family: Arial, sans-serif;
233
+ font-size: 12px;
234
+ fill: #333;
235
+ }
236
+
237
+ .axis-title {
238
+ font-family: Arial, sans-serif;
239
+ font-size: 14px;
240
+ font-weight: bold;
241
+ fill: #333;
242
+ }
243
+ </style>
244
+ </head>
245
+ <body>
246
+ <div class="container">
247
+ <div class="header">
248
+ <h1>Decimal Rounding Visualizer</h1>
249
+ <p>Enter a number and see how rounding to different decimal places affects its value</p>
250
+ </div>
251
+
252
+ <div class="controls">
253
+ <div class="input-group">
254
+ <div class="input-container">
255
+ <label for="numberInput">Enter Number:</label>
256
+ <input type="number" id="numberInput" step="any" placeholder="e.g., 3.14159265" value="3.14159265">
257
+ </div>
258
+ <div class="input-container">
259
+ <label for="maxDigits">Maximum Decimal Places:</label>
260
+ <input type="number" id="maxDigits" min="1" max="15" value="8" placeholder="e.g., 8">
261
+ </div>
262
+ <button class="btn" onclick="generateGraph()">Generate Graph</button>
263
+ </div>
264
+ </div>
265
+
266
+ <div class="content">
267
+ <div class="graph-container">
268
+ <div class="graph-title">Rounding Visualization</div>
269
+ <div id="originalValue" class="original-value"></div>
270
+ <svg class="graph-svg" id="graphSvg"></svg>
271
+ </div>
272
+
273
+ <div class="data-table">
274
+ <div class="table-title">Rounded Values</div>
275
+ <div id="tableContainer"></div>
276
+ </div>
277
+ </div>
278
+ </div>
279
+
280
+ <script>
281
+ function generateGraph() {
282
+ const numberInput = document.getElementById('numberInput').value;
283
+ const maxDigits = parseInt(document.getElementById('maxDigits').value);
284
+
285
+ if (!numberInput || isNaN(parseFloat(numberInput))) {
286
+ showError('Please enter a valid number');
287
+ return;
288
+ }
289
+
290
+ if (!maxDigits || maxDigits < 1 || maxDigits > 15) {
291
+ showError('Please enter a valid number of decimal places (1-15)');
292
+ return;
293
+ }
294
+
295
+ const originalNumber = parseFloat(numberInput);
296
+
297
+ // Show original value
298
+ document.getElementById('originalValue').innerHTML =
299
+ `Original Value: <strong>${originalNumber}</strong>`;
300
+
301
+ // Generate rounded values
302
+ const data = [];
303
+ for (let i = 0; i <= maxDigits; i++) {
304
+ const rounded = parseFloat(originalNumber.toFixed(i));
305
+ data.push({
306
+ digits: i,
307
+ value: rounded,
308
+ difference: Math.abs(originalNumber - rounded)
309
+ });
310
+ }
311
+
312
+ // Create graph
313
+ createGraph(data, originalNumber);
314
+
315
+ // Create table
316
+ createTable(data);
317
+ }
318
+
319
+ function createGraph(data, originalValue) {
320
+ const svg = document.getElementById('graphSvg');
321
+ const width = svg.clientWidth;
322
+ const height = 350;
323
+
324
+ // Clear previous graph
325
+ svg.innerHTML = '';
326
+
327
+ // Set SVG dimensions
328
+ svg.setAttribute('viewBox', `0 0 ${width} ${height}`);
329
+
330
+ // Margins
331
+ const margin = { top: 20, right: 40, bottom: 60, left: 60 };
332
+ const graphWidth = width - margin.left - margin.right;
333
+ const graphHeight = height - margin.top - margin.bottom;
334
+
335
+ // Find min and max values for Y-axis
336
+ const values = data.map(d => d.value);
337
+ const minValue = Math.min(...values);
338
+ const maxValue = Math.max(...values);
339
+ const valueRange = maxValue - minValue;
340
+ const yPadding = valueRange * 0.1 || 0.1; // Add 10% padding or minimum 0.1
341
+
342
+ const yMin = minValue - yPadding;
343
+ const yMax = maxValue + yPadding;
344
+
345
+ // Scale functions
346
+ const xScale = (digits) => margin.left + (digits / data.length) * graphWidth;
347
+ const yScale = (value) => margin.top + ((yMax - value) / (yMax - yMin)) * graphHeight;
348
+
349
+ // Create grid lines
350
+ const gridLines = 8;
351
+ for (let i = 0; i <= gridLines; i++) {
352
+ const y = margin.top + (i / gridLines) * graphHeight;
353
+ const gridValue = yMax - (i / gridLines) * (yMax - yMin);
354
+
355
+ // Horizontal grid line
356
+ const gridLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
357
+ gridLine.setAttribute('x1', margin.left);
358
+ gridLine.setAttribute('y1', y);
359
+ gridLine.setAttribute('x2', margin.left + graphWidth);
360
+ gridLine.setAttribute('y2', y);
361
+ gridLine.setAttribute('class', 'grid-line');
362
+ svg.appendChild(gridLine);
363
+
364
+ // Y-axis label
365
+ const label = document.createElementNS('http://www.w3.org/2000/svg', 'text');
366
+ label.setAttribute('x', margin.left - 10);
367
+ label.setAttribute('y', y + 4);
368
+ label.setAttribute('text-anchor', 'end');
369
+ label.setAttribute('class', 'axis-label');
370
+ label.textContent = gridValue.toFixed(6);
371
+ svg.appendChild(label);
372
+ }
373
+
374
+ // X-axis
375
+ const xAxis = document.createElementNS('http://www.w3.org/2000/svg', 'line');
376
+ xAxis.setAttribute('x1', margin.left);
377
+ xAxis.setAttribute('y1', margin.top + graphHeight);
378
+ xAxis.setAttribute('x2', margin.left + graphWidth);
379
+ xAxis.setAttribute('y2', margin.top + graphHeight);
380
+ xAxis.setAttribute('class', 'axis-line');
381
+ svg.appendChild(xAxis);
382
+
383
+ // Y-axis
384
+ const yAxis = document.createElementNS('http://www.w3.org/2000/svg', 'line');
385
+ yAxis.setAttribute('x1', margin.left);
386
+ yAxis.setAttribute('y1', margin.top);
387
+ yAxis.setAttribute('x2', margin.left);
388
+ yAxis.setAttribute('y2', margin.top + graphHeight);
389
+ yAxis.setAttribute('class', 'axis-line');
390
+ svg.appendChild(yAxis);
391
+
392
+ // X-axis labels
393
+ data.forEach((d, i) => {
394
+ const x = margin.left + (i / (data.length - 1)) * graphWidth;
395
+
396
+ // X-axis tick
397
+ const tick = document.createElementNS('http://www.w3.org/2000/svg', 'line');
398
+ tick.setAttribute('x1', x);
399
+ tick.setAttribute('y1', margin.top + graphHeight);
400
+ tick.setAttribute('x2', x);
401
+ tick.setAttribute('y2', margin.top + graphHeight + 5);
402
+ tick.setAttribute('class', 'axis-line');
403
+ svg.appendChild(tick);
404
+
405
+ // X-axis label
406
+ const label = document.createElementNS('http://www.w3.org/2000/svg', 'text');
407
+ label.setAttribute('x', x);
408
+ label.setAttribute('y', margin.top + graphHeight + 20);
409
+ label.setAttribute('text-anchor', 'middle');
410
+ label.setAttribute('class', 'axis-label');
411
+ label.textContent = d.digits;
412
+ svg.appendChild(label);
413
+ });
414
+
415
+ // Create line path
416
+ let pathData = '';
417
+ data.forEach((d, i) => {
418
+ const x = margin.left + (i / (data.length - 1)) * graphWidth;
419
+ const y = yScale(d.value);
420
+
421
+ if (i === 0) {
422
+ pathData += `M ${x} ${y}`;
423
+ } else {
424
+ pathData += ` L ${x} ${y}`;
425
+ }
426
+ });
427
+
428
+ const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
429
+ path.setAttribute('d', pathData);
430
+ path.setAttribute('class', 'data-line');
431
+ svg.appendChild(path);
432
+
433
+ // Create data points
434
+ data.forEach((d, i) => {
435
+ const x = margin.left + (i / (data.length - 1)) * graphWidth;
436
+ const y = yScale(d.value);
437
+
438
+ const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
439
+ circle.setAttribute('cx', x);
440
+ circle.setAttribute('cy', y);
441
+ circle.setAttribute('r', 4);
442
+ circle.setAttribute('class', 'data-point');
443
+
444
+ // Add hover effect
445
+ circle.addEventListener('mouseenter', (e) => {
446
+ e.target.setAttribute('r', 6);
447
+
448
+ // Create tooltip
449
+ const tooltip = document.createElementNS('http://www.w3.org/2000/svg', 'g');
450
+ tooltip.setAttribute('id', 'tooltip');
451
+
452
+ const rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
453
+ rect.setAttribute('x', x - 40);
454
+ rect.setAttribute('y', y - 35);
455
+ rect.setAttribute('width', 80);
456
+ rect.setAttribute('height', 25);
457
+ rect.setAttribute('fill', '#333');
458
+ rect.setAttribute('rx', 4);
459
+
460
+ const text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
461
+ text.setAttribute('x', x);
462
+ text.setAttribute('y', y - 18);
463
+ text.setAttribute('text-anchor', 'middle');
464
+ text.setAttribute('fill', 'white');
465
+ text.setAttribute('font-size', '12');
466
+ text.textContent = d.value.toString();
467
+
468
+ tooltip.appendChild(rect);
469
+ tooltip.appendChild(text);
470
+ svg.appendChild(tooltip);
471
+ });
472
+
473
+ circle.addEventListener('mouseleave', (e) => {
474
+ e.target.setAttribute('r', 4);
475
+ const tooltip = document.getElementById('tooltip');
476
+ if (tooltip) {
477
+ tooltip.remove();
478
+ }
479
+ });
480
+
481
+ svg.appendChild(circle);
482
+ });
483
+
484
+ // Add axis titles
485
+ const xTitle = document.createElementNS('http://www.w3.org/2000/svg', 'text');
486
+ xTitle.setAttribute('x', margin.left + graphWidth / 2);
487
+ xTitle.setAttribute('y', height - 10);
488
+ xTitle.setAttribute('text-anchor', 'middle');
489
+ xTitle.setAttribute('class', 'axis-title');
490
+ xTitle.textContent = 'Decimal Places';
491
+ svg.appendChild(xTitle);
492
+
493
+ const yTitle = document.createElementNS('http://www.w3.org/2000/svg', 'text');
494
+ yTitle.setAttribute('x', 15);
495
+ yTitle.setAttribute('y', margin.top + graphHeight / 2);
496
+ yTitle.setAttribute('text-anchor', 'middle');
497
+ yTitle.setAttribute('class', 'axis-title');
498
+ yTitle.setAttribute('transform', `rotate(-90, 15, ${margin.top + graphHeight / 2})`);
499
+ yTitle.textContent = 'Rounded Value';
500
+ svg.appendChild(yTitle);
501
+
502
+ // Add original value line
503
+ const originalY = yScale(originalValue);
504
+ const originalLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
505
+ originalLine.setAttribute('x1', margin.left);
506
+ originalLine.setAttribute('y1', originalY);
507
+ originalLine.setAttribute('x2', margin.left + graphWidth);
508
+ originalLine.setAttribute('y2', originalY);
509
+ originalLine.setAttribute('stroke', '#ff5722');
510
+ originalLine.setAttribute('stroke-width', 2);
511
+ originalLine.setAttribute('stroke-dasharray', '5,5');
512
+ svg.appendChild(originalLine);
513
+ }
514
+
515
+ function createTable(data) {
516
+ const container = document.getElementById('tableContainer');
517
+
518
+ let html = `
519
+ <table>
520
+ <thead>
521
+ <tr>
522
+ <th>Decimal Places</th>
523
+ <th>Rounded Value</th>
524
+ <th>Difference</th>
525
+ </tr>
526
+ </thead>
527
+ <tbody>
528
+ `;
529
+
530
+ data.forEach(d => {
531
+ html += `
532
+ <tr>
533
+ <td>${d.digits}</td>
534
+ <td>${d.value}</td>
535
+ <td>${d.difference.toExponential(3)}</td>
536
+ </tr>
537
+ `;
538
+ });
539
+
540
+ html += `
541
+ </tbody>
542
+ </table>
543
+ `;
544
+
545
+ container.innerHTML = html;
546
+ }
547
+
548
+ function showError(message) {
549
+ document.getElementById('originalValue').innerHTML = '';
550
+ document.getElementById('graphSvg').innerHTML = `
551
+ <text x="50%" y="50%" text-anchor="middle" class="error">${message}</text>
552
+ `;
553
+ document.getElementById('tableContainer').innerHTML = `
554
+ <div class="error">${message}</div>
555
+ `;
556
+ }
557
+
558
+ // Generate initial graph
559
+ generateGraph();
560
+ </script>
561
+ </body>
562
+ </html>