mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
add weight causes updating old chart instead of creating new chart, closes #53
This commit is contained in:
parent
3033f7cc08
commit
1d0220b03d
@ -16,9 +16,10 @@
|
|||||||
<canvas id="canvas"></canvas>
|
<canvas id="canvas"></canvas>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
(async function() {
|
(async function() {
|
||||||
const dateEl = $("#weight-date");
|
const dateEl = $("#weight-date");
|
||||||
const weightEl = $("#weight");
|
const weightEl = $("#weight");
|
||||||
|
let chart;
|
||||||
|
|
||||||
dateEl.datepicker();
|
dateEl.datepicker();
|
||||||
dateEl.datepicker('option', 'dateFormat', 'yy-mm-dd');
|
dateEl.datepicker('option', 'dateFormat', 'yy-mm-dd');
|
||||||
@ -49,10 +50,24 @@
|
|||||||
|
|
||||||
showMessage("Weight has been saved");
|
showMessage("Weight has been saved");
|
||||||
|
|
||||||
drawChart();
|
const data = await getData();
|
||||||
|
|
||||||
|
chart.data = data;
|
||||||
|
chart.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function drawChart() {
|
async function drawChart() {
|
||||||
|
const data = await getData();
|
||||||
|
|
||||||
|
const ctx = $("#canvas")[0].getContext("2d");
|
||||||
|
|
||||||
|
chart = new Chart(ctx, {
|
||||||
|
type: 'line',
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getData() {
|
||||||
const data = await server.exec([], async () => {
|
const data = await server.exec([], async () => {
|
||||||
const notes = await this.getNotesWithAttribute('date_data');
|
const notes = await this.getNotesWithAttribute('date_data');
|
||||||
const data = [];
|
const data = [];
|
||||||
@ -71,21 +86,20 @@
|
|||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
|
|
||||||
const ctx = $("#canvas")[0].getContext("2d");
|
const datasets = [{
|
||||||
|
|
||||||
new Chart(ctx, {
|
|
||||||
type: 'line',
|
|
||||||
data: {
|
|
||||||
labels: data.map(row => row.date),
|
|
||||||
datasets: [{
|
|
||||||
label: "Weight",
|
label: "Weight",
|
||||||
backgroundColor: 'red',
|
backgroundColor: 'red',
|
||||||
borderColor: 'red',
|
borderColor: 'red',
|
||||||
data: data.map(row => row.weight),
|
data: data.map(row => row.weight),
|
||||||
fill: false
|
fill: false
|
||||||
}]
|
}];
|
||||||
}
|
|
||||||
});
|
const labels = data.map(row => row.date);
|
||||||
|
|
||||||
|
return {
|
||||||
|
labels: labels,
|
||||||
|
datasets: datasets
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#weight-form").submit(event => {
|
$("#weight-form").submit(event => {
|
||||||
@ -95,5 +109,5 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
drawChart();
|
drawChart();
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
@ -53,6 +53,10 @@ async function getNoteIdsWithAttribute(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function createAttribute(noteId, name, value = "", sourceId = null) {
|
async function createAttribute(noteId, name, value = "", sourceId = null) {
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
|
|
||||||
const now = utils.nowDate();
|
const now = utils.nowDate();
|
||||||
const attributeId = utils.newAttributeId();
|
const attributeId = utils.newAttributeId();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user