-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- ADD: Added a data statistics page with overview stats per trial.
- Loading branch information
1 parent
9e84ba3
commit 35525d3
Showing
8 changed files
with
786 additions
and
6 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,179 @@ | ||
<template> | ||
<div ref="wrapper"> | ||
<div ref="chart" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { mapGetters } from 'vuex' | ||
const Plotly = require('plotly.js/lib/core') | ||
// Only register the chart types we're actually using to reduce the final bundle size | ||
Plotly.register([ | ||
require('plotly.js/lib/heatmap') | ||
]) | ||
export default { | ||
props: { | ||
chartData: { | ||
type: Map, | ||
default: () => new Map() | ||
} | ||
}, | ||
data: function () { | ||
return { | ||
width: 1000 | ||
} | ||
}, | ||
computed: { | ||
...mapGetters([ | ||
'storeLocale', | ||
'storeDarkMode' | ||
]), | ||
dateFormat: function () { | ||
return new Intl.DateTimeFormat(this.storeLocale || 'en', { month: 'short' }) | ||
}, | ||
months: function () { | ||
if (this.dateFormat) { | ||
return [...Array(12).keys()].map(m => this.dateFormat.format(new Date(Date.UTC(2000, m, 1, 0, 0, 0)))).reverse() | ||
} else { | ||
return [] | ||
} | ||
}, | ||
isHorizontal: function () { | ||
return this.width < 720 | ||
} | ||
}, | ||
watch: { | ||
isHorizontal: function () { | ||
this.update() | ||
}, | ||
storeDarkMode: function () { | ||
this.update() | ||
}, | ||
chartData: function () { | ||
this.update() | ||
} | ||
}, | ||
methods: { | ||
update: function () { | ||
try { | ||
Plotly.purge(this.$refs.chart) | ||
} catch { | ||
} | ||
let z = [ | ||
new Array(31).fill(0), | ||
new Array(30).fill(0), | ||
new Array(31).fill(0), | ||
new Array(30).fill(0), | ||
new Array(31).fill(0), | ||
new Array(31).fill(0), | ||
new Array(30).fill(0), | ||
new Array(31).fill(0), | ||
new Array(30).fill(0), | ||
new Array(31).fill(0), | ||
new Array(29).fill(0), | ||
new Array(31).fill(0) | ||
] | ||
let max = 0 | ||
this.chartData.forEach((value, key) => { | ||
const d = new Date(key) | ||
z[11 - d.getMonth()][d.getDate() - 1] = value | ||
max = Math.max(max, value) | ||
}) | ||
const x = Array.from(Array(31).keys()).map(i => i + 1) | ||
const y = this.months | ||
if (this.isHorizontal) { | ||
z = z[0].map((col, i) => z.reverse().map(row => row[i])) | ||
} | ||
const data = [{ | ||
z: z, | ||
x: this.isHorizontal ? y.reverse() : x, | ||
y: this.isHorizontal ? x : y, | ||
name: '', | ||
type: 'heatmap', | ||
hoverongaps: false, | ||
xgap: 1, | ||
ygap: 1, | ||
colorscale: [ | ||
[0, this.storeDarkMode ? '#2f2f2f' : '#e4e4e4'], | ||
[1, '#00a0f1'] | ||
], | ||
colorbar: { | ||
title: { | ||
side: 'right', | ||
font: { color: this.storeDarkMode ? 'white' : 'black' } | ||
}, | ||
tickfont: { color: this.storeDarkMode ? 'white' : 'black' }, | ||
orientation: this.isHorizontal ? 'h' : 'v' | ||
}, | ||
hovertemplate: '%{x}. %{y}: %{z}' | ||
}] | ||
let xAxis = { | ||
showgrid: false, | ||
tickmode: 'array', | ||
// nticks: 31, | ||
tickvals: Array.from(Array(31).keys()).map(i => i + 1), | ||
title: { text: this.$t('widgetChartHeatmapAxisTitleDay'), font: { color: this.storeDarkMode ? 'white' : 'black' } }, | ||
tickfont: { color: this.storeDarkMode ? 'white' : 'black' } | ||
} | ||
let yAxis = { | ||
showgrid: false, | ||
title: { text: this.$t('widgetChartHeatmapAxisTitleMonth'), font: { color: this.storeDarkMode ? 'white' : 'black' } }, | ||
tickfont: { color: this.storeDarkMode ? 'white' : 'black' } | ||
} | ||
if (this.isHorizontal) { | ||
[xAxis, yAxis] = [yAxis, xAxis] | ||
} | ||
const layout = { | ||
height: this.isHorizontal ? 800 : 500, | ||
margin: { | ||
t: 0 | ||
}, | ||
paper_bgcolor: 'transparent', | ||
plot_bgcolor: 'transparent', | ||
xaxis: xAxis, | ||
yaxis: yAxis | ||
} | ||
const config = { | ||
responsive: true, | ||
displaylogo: false | ||
} | ||
Plotly.newPlot(this.$refs.chart, data, layout, config) | ||
}, | ||
onResize: function () { | ||
this.width = this.$refs.wrapper.clientWidth | ||
} | ||
}, | ||
beforeDestroy: function () { | ||
try { | ||
Plotly.purge(this.$refs.chart) | ||
} catch { | ||
} | ||
window.removeEventListener('resize', this.onResize) | ||
}, | ||
mounted: function () { | ||
this.onResize() | ||
window.addEventListener('resize', this.onResize) | ||
this.update() | ||
} | ||
} | ||
</script> | ||
|
||
<style> | ||
</style> |
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,52 @@ | ||
/** | ||
* Converts a HEX value into an RGB object | ||
* @param {String} hex The hex color | ||
*/ | ||
const hexToRgb = (hex) => { | ||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) | ||
return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null | ||
} | ||
|
||
const rgbToHex = (c) => `#${((1 << 24) + (c.r << 16) + (c.g << 8) + c.b).toString(16).slice(1)}` | ||
|
||
/** | ||
* Determines the best text color (either white or black) given the background color | ||
* @param {String} backgroundColor The background color in HEX | ||
*/ | ||
const getHighContrastTextColor = (backgroundColor) => { | ||
if (backgroundColor) { | ||
const rgb = hexToRgb(backgroundColor) | ||
if (!rgb) { | ||
return 'black' | ||
} | ||
const o = Math.round(((rgb.r * 299) + (rgb.g * 587) + (rgb.b * 114)) / 1000) | ||
return (o > 125) ? 'black' : 'white' | ||
} else { | ||
return 'black' | ||
} | ||
} | ||
|
||
const shadeColor = (hex, percent) => { | ||
const rgb = hexToRgb(hex) | ||
|
||
let r = parseInt(rgb.r * (100 + percent) / 100) | ||
let g = parseInt(rgb.g * (100 + percent) / 100) | ||
let b = parseInt(rgb.b * (100 + percent) / 100) | ||
|
||
r = (r < 255) ? r : 255 | ||
g = (g < 255) ? g : 255 | ||
b = (b < 255) ? b : 255 | ||
|
||
r = Math.round(r) | ||
g = Math.round(g) | ||
b = Math.round(b) | ||
|
||
return rgbToHex({ r, g, b }) | ||
} | ||
|
||
export { | ||
getHighContrastTextColor, | ||
shadeColor, | ||
hexToRgb, | ||
rgbToHex | ||
} |
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
Oops, something went wrong.