Skip to content

Commit

Permalink
Weight Page
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Jan 3, 2024
1 parent a90d88a commit 4f349b3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Workout diary with GitHub-style year visualization
- [Config](https://github.com/aceberg/exercisediary#config)
- [Options](https://github.com/aceberg/exercisediary#options)
- [Local network only](https://github.com/aceberg/exercisediary#local-network-only)
- [Roadmap](https://github.com/aceberg/exercisediary#roadmap)
- [Roadmap](https://github.com/aceberg/ExerciseDiary/blob/main/docs/ROADMAP.md)
- [Thanks](https://github.com/aceberg/exercisediary#thanks)


Expand Down
9 changes: 6 additions & 3 deletions docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
- [x] Local Themes and JS
- [x] BodyWeight Chart

## IN PROGRESS

- [ ] Weight page

## TODO
- [ ] Login/Password
- [ ] Statistics page
- [ ] Weight page
- [ ] Mobile layout
- [ ] PostgreSQL DB option
- [ ] Add exercise group with 1 button

## MAYBE

- [ ] Sets (#1)
- [ ] Weight field take decimals (#4)
- [ ] Sets [#1](https://github.com/aceberg/ExerciseDiary/issues/1)
- [ ] Weight field take decimals [#4](https://github.com/aceberg/ExerciseDiary/issues/4)
- [ ] Multiple users

## NOT DOING
Expand Down
34 changes: 21 additions & 13 deletions internal/web/public/js/weight-chart.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
var dates = [];
var ws = [];
var wChart = null;

function splitWeight(weight, show) {
dates = [];
ws = [];
var dates = [];
var ws = [];

weight = weight.slice(show)
let arrayLength = weight.length;
for (let i = 0 ; i < arrayLength; i++) {
dates.push(weight[i].Date);
ws.push(weight[i].Weight)
ws.push(weight[i].Weight);
}
// console.log('LDATA =', dates, ws);
return { dates, ws };
};

function weightChart(weight, wcolor, show) {
function weightChart(dates, ws, wcolor, xticks) {

if (weight) {
splitWeight(weight, show);
// console.log('FDATA =', dates, ws);

const ctx = document.getElementById('weight-chart');

new Chart(ctx, {
if (wChart){
wChart.clear();
wChart.destroy();
};

wChart = new Chart(ctx, {
type: 'line',
data: {
labels: dates,
Expand All @@ -36,7 +37,7 @@ function weightChart(weight, wcolor, show) {
scales: {
x: {
ticks: {
display: false
display: xticks
},
},
y: {
Expand All @@ -50,5 +51,12 @@ function weightChart(weight, wcolor, show) {
}
}
});
}
};

function generateWeightChart(weight, wcolor, show) {
if (weight) {
let { dates, ws } = splitWeight(weight, show);

weightChart(dates, ws, wcolor, false);
};
};
36 changes: 28 additions & 8 deletions internal/web/public/js/weight.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
var offset = 0;

function setToday() {
today = new Date().toJSON().slice(0, 10);
document.getElementById("todayDate").value = today;
};


function addWeight(date, weight, id) {
function addWeight(i, date, weight, id) {

html_code = '<tr><td>'+date+'</td><td>'+weight+'</td><td><a href="/weight/?del='+id+'"><button class="btn del-set-button" title="Delete" ><i class="bi bi-x-square"></i></button></a></td></tr>';
html_code = '<tr><td style="opacity: 45%;">'+i+'.</td><td>'+date+'</td><td>'+weight+'</td><td><a href="/weight/?del='+id+'"><button class="btn del-set-button" title="Delete" ><i class="bi bi-x-square"></i></button></a></td></tr>';

document.getElementById('weightList').insertAdjacentHTML('beforeend', html_code);
};

function setWeights(weights, offset) {
var start = 0;
function setWeights(weights, wcolor, off) {
let start = 0, end = 0, step = 10;
let dates = [], ws = [];

offset = offset + off;
if (offset<0) {
offset = 0;
};

let arrayLength = weights.length;
let move = step + offset*step;

if (arrayLength > offset) {
start = arrayLength - offset;
if (arrayLength > move) {
start = arrayLength - move;
} else {
start = 0;
offset = offset - 1;
};
end = start + step;

// console.log("OFF =", offset, ", START =", start, ", END =", end)

document.getElementById('weightList').innerHTML = "";

for (let i = start ; i < arrayLength; i++) {
addWeight(weights[i].Date, weights[i].Weight, weights[i].ID)
for (let i = start ; i < end; i++) {
dates.push(weights[i].Date);
ws.push(weights[i].Weight);
addWeight(i+1, weights[i].Date, weights[i].Weight, weights[i].ID)
};
weightChart(dates, ws, wcolor, true);
};
2 changes: 1 addition & 1 deletion internal/web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ <h5 class="modal-title">{{ .Name }}</h5>

<script>
setFormDate({{ .ExData.Sets }});
weightChart({{ .ExData.Weight }}, {{ .Config.HeatColor }}, -7);
generateWeightChart({{ .ExData.Weight }}, {{ .Config.HeatColor }}, -7);
makeChart({{ .HeatMap }}, {{ .Config.HeatColor }}, {{ .ExData.Sets }});
</script>
{{ template "footer.html" }}
Expand Down
8 changes: 6 additions & 2 deletions internal/web/templates/weight.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
<div class="card-body">
<table class="table table-borderless">
<thead>
<th></th>
<th>Date</th>
<th>Weight</th>
<th>Del</th>
</thead>
<tbody id="weightList">
</tbody>
</table>
<div class="gap-3 hstack">
<button onclick='setWeights({{ .ExData.Weight }}, {{ .Config.HeatColor }}, 1);' class="m-auto btn del-set-button"><i class="bi bi-arrow-left-square"></i></button>
<button onclick='setWeights({{ .ExData.Weight }}, {{ .Config.HeatColor }}, -1);' class="m-auto btn del-set-button"><i class="bi bi-arrow-right-square"></i></button>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -47,8 +52,7 @@

<script>
setToday();
setWeights({{ .ExData.Weight }}, 10);
weightChart({{ .ExData.Weight }}, {{ .Config.HeatColor }}, -10);
setWeights({{ .ExData.Weight }}, {{ .Config.HeatColor }}, 0);
</script>

{{ template "footer.html" }}
Expand Down

0 comments on commit 4f349b3

Please sign in to comment.