-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Showing
5 changed files
with
135 additions
and
7 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
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,103 @@ | ||
|
||
function lowerData(heat) { | ||
var ldata = []; | ||
let arrayLength = heat.length; | ||
for (let i = 0 ; i < arrayLength; i++) { | ||
let val = heat[i]; | ||
ldata.push({ | ||
x: val.X, | ||
y: val.Y, | ||
d: val.D, | ||
v: val.V | ||
}); | ||
} | ||
console.log('LDATA =', ldata); | ||
return ldata; | ||
}; | ||
|
||
function makeChart(heat, hcolor) { | ||
let ldata = lowerData(heat); | ||
var ctx = document.getElementById('matrix-chart').getContext('2d'); | ||
window.myMatrix = new Chart(ctx, { | ||
type: 'matrix', | ||
data: { | ||
datasets: [{ | ||
label: 'Heatmap', | ||
data: ldata, | ||
backgroundColor(context) { | ||
const value = context.dataset.data[context.dataIndex].v; | ||
const alpha = value / 7; | ||
return Chart.helpers.color(hcolor).alpha(alpha).rgbString(); | ||
}, | ||
borderColor(context) { | ||
const value = context.dataset.data[context.dataIndex].v; | ||
const alpha = 0.5; | ||
return Chart.helpers.color('grey').alpha(alpha).rgbString(); | ||
}, | ||
borderWidth: 1, | ||
hoverBackgroundColor: 'lightgrey', | ||
hoverBorderColor: 'grey', | ||
width() { | ||
return 12; | ||
}, | ||
height() { | ||
return 12; | ||
} | ||
}] | ||
}, | ||
options: { | ||
onClick: (e) => { | ||
const res = window.myMatrix.getElementsAtEventForMode(e, 'nearest', { intersect: true }, true); | ||
|
||
console.log('res =', res[0].element.$context.raw.d); | ||
|
||
// window.location.href = "/diary_show?from="+dayD+"&to="+dayD+""; | ||
}, | ||
plugins: { | ||
legend: false, | ||
tooltip: { | ||
callbacks: { | ||
title() { | ||
return ''; | ||
}, | ||
label(context) { | ||
const v = context.dataset.data[context.dataIndex]; | ||
return [v.v, v.d]; | ||
} | ||
} | ||
} | ||
}, | ||
scales: { | ||
x: { | ||
type: 'category', | ||
offset: true, | ||
reverse: false, | ||
ticks: { | ||
display: false | ||
}, | ||
border: { | ||
display: false | ||
}, | ||
grid: { | ||
display: false | ||
} | ||
}, | ||
y: { | ||
type: 'category', | ||
labels: ['Mo', 'Tu', 'We','Th','Fr','Sa','Su'], | ||
reverse: false, | ||
ticks: { | ||
stepSize: 1, | ||
display: true | ||
}, | ||
border: { | ||
display: false | ||
}, | ||
grid: { | ||
display: false | ||
} | ||
}, | ||
} | ||
} | ||
}); | ||
}; |
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 |
---|---|---|
|
@@ -16,6 +16,9 @@ | |
<link href="https://cdn.jsdelivr.net/gh/aceberg/aceberg-bootswatch-fork@v5/dist/{{ .Config.Theme }}/bootstrap.min.css" rel="stylesheet"> | ||
<!-- JavaScript Bundle with Popper --> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> | ||
<!-- Chart.js --> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | ||
</head> | ||
<body> | ||
<nav class="navbar navbar-expand-sm navbar-dark bg-primary"> | ||
|
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