-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36a6a9d
commit d57d075
Showing
13 changed files
with
236 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.reading { | ||
.big-number { | ||
line-height: 4rem; | ||
height: 4rem; | ||
.trend { | ||
vertical-align: top; | ||
line-height: 4rem; | ||
font-size: 2rem; | ||
|
||
} | ||
.value { | ||
font-size: 4rem; | ||
line-height: 4rem; | ||
font-weight: bold; | ||
} | ||
.unit { | ||
font-size: 2rem; | ||
line-height: 4rem; | ||
} | ||
} | ||
.sparkline { | ||
height: 4rem; | ||
width: 100%; | ||
margin-bottom: 0.5rem; | ||
.u-under { | ||
display: none; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as $ from "jquery"; | ||
import uPlot from "uplot"; | ||
|
||
class Sparkline { | ||
constructor(element) { | ||
this.element = element; | ||
this.deviceId = element.dataset["deviceId"]; | ||
this.sensorId = element.dataset["sensorId"]; | ||
this.fromDate = element.dataset["fromDate"] ?? this.getDateString(-24 * 60 * 60 * 1000); | ||
this.toDate = element.dataset["toDate"] = this.getDateString(); | ||
} | ||
|
||
getDateString(offset = 0) { | ||
return new Date(new Date() - offset).toISOString() | ||
} | ||
|
||
async init() { | ||
const data = await $.ajax({ | ||
url:`/devices/${this.deviceId}/readings?rollup=5m&sensor_id=${this.sensorId}&from=${this.fromDate}&to=${this.toDate}`, | ||
method: "GET", | ||
}); | ||
const timestamps = data.readings.map(x => Date.parse(x[0]) / 1000); | ||
const values = data.readings.map(x => x[1]); | ||
self.uplot = new uPlot( | ||
{ | ||
width: this.element.offsetWidth / window.devicePixelRatio, | ||
height: this.element.offsetHeight / window.devicePixelRatio, | ||
pxAlign: false, | ||
cursor: { | ||
show: false | ||
}, | ||
select: { | ||
show: false, | ||
}, | ||
legend: { | ||
show: false, | ||
}, | ||
series: [ | ||
{}, | ||
{ | ||
show: true, | ||
spanGaps: false, | ||
stroke: "#1C1C1C", | ||
fill: "#FFC100", | ||
width: 1 | ||
} | ||
], | ||
axes: [ | ||
{ show: false }, | ||
{ show: false } | ||
], | ||
cursor: { | ||
hover: { | ||
prox: 30, | ||
bias: 0, | ||
skip: [null] | ||
} | ||
}, | ||
}, | ||
[timestamps, values], | ||
this.element | ||
); | ||
} | ||
} | ||
|
||
export function setupSparklines() { | ||
$(".sparkline").each(function(ix, element) { | ||
const line = new Sparkline(element); | ||
line.init(); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div class="reading"> | ||
<%= render layout: "ui/shared/box", locals: { class: "mb-3 p-3", no_padding: true } do %> | ||
<div class="row align-items-top mb-3"> | ||
<div class="col-12 col-md-4"> | ||
<h3><%= component.measurement_name %></h3> | ||
<p>Last reading at: <%= component.last_reading_at.to_s(:long_ordinal) %></p> | ||
</div> | ||
<div class="col-12 col-md-3"> | ||
<div class="big-number"> | ||
<span class="trend"><% case component.trend %><% when -1 %>🔺<% when 1 %>🔻<% else %><strong>=</strong><% end %></span><span class="value"><%= component.latest_value.round(2) %></span><span class="unit"><%= component.value_unit %></span> | ||
</div> | ||
</div> | ||
<div class="col-12 col-md-5"> | ||
<%= render partial: "ui/shared/sparkline", locals: { component: component } %> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<p><i><%= component.measurement_description %></i></p> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<div class="bg-white w-100 border border-thick <%= "p-3 pb-4 pb-md-5" unless local_assigns[:no_padding] %>"> | ||
<div class="bg-white w-100 border border-thick <%= "p-3 pb-4 pb-md-5" unless local_assigns[:no_padding] %> <%= local_assigns[:class] || "" %>"> | ||
<%= yield %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div | ||
class="sparkline" | ||
data-device-id="<%= component.device_id %>" | ||
data-sensor-id="<%= component.sensor_id %>" | ||
data-from-date="<%= local_assigns[:from] || component.last_reading_at - 1.day %>" | ||
data-to-date="<%= local_assigns[:to] || component.last_reading_at %>" | ||
></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters