Commit f32849fe authored by 22stmo1bif's avatar 22stmo1bif
Browse files

Enhance ChartCard and ChartView components with improved axis styling and...

Enhance ChartCard and ChartView components with improved axis styling and default time window functionality
parent 1a5672d3
...@@ -66,7 +66,54 @@ export default defineComponent({ ...@@ -66,7 +66,54 @@ export default defineComponent({
title: { display: false } title: { display: false }
}, },
scales: { scales: {
y: { beginAtZero: true } x: {
ticks: {
color: '#333333', // Darker color for x-axis labels
maxRotation: 0,
minRotation: 0,
padding: 10,
font: {
size: 12,
weight: 'bold'
},
maxTicksLimit: 8, // Allow up to 8 ticks
autoSkip: false, // Don't auto-skip labels
callback: function(value, index) {
// Only show non-empty labels
const label = this.getLabelForValue(value as number);
return label || '';
}
},
grid: {
display: true,
color: 'rgba(0, 0, 0, 0.3)', // Darker vertical grid lines
lineWidth: 1,
drawOnChartArea: true, // Draw grid lines over chart area
drawTicks: true
}
},
y: {
beginAtZero: true,
ticks: {
color: '#333333', // Darker color for y-axis labels
padding: 10,
font: {
size: 12
}
},
grid: {
display: true,
color: 'rgba(0, 0, 0, 0.1)'
}
}
},
layout: {
padding: {
left: 15,
right: 35,
top: 15,
bottom: 25
}
} }
} }
} }
...@@ -76,7 +123,7 @@ export default defineComponent({ ...@@ -76,7 +123,7 @@ export default defineComponent({
<style scoped> <style scoped>
.chart-card { .chart-card {
width: 1000px; width: 1200px;
height: 500px; height: 500px;
background: white; background: white;
padding: 1.5rem; padding: 1.5rem;
......
...@@ -12,24 +12,25 @@ ...@@ -12,24 +12,25 @@
<input class="datetime" type="datetime-local" v-model="stop" /> <input class="datetime" type="datetime-local" v-model="stop" />
</label> </label>
<button @click="loadData">Zeitraum aktualisieren</button> <button @click="loadData">Zeitraum aktualisieren</button>
<button @click="loadDataWithDefaultWindow" class="default-btn">Zeige die letzte Woche</button>
</div> </div>
<div class="chart-grid"> <div class="chart-grid">
<ChartCard <ChartCard
title="CO₂ Verlauf" title="CO₂ Verlauf"
:labels="labels" :labels="displayLabels"
:data="co2Data" :data="co2Data"
borderColor="#ff6384" borderColor="#ff6384"
/> />
<ChartCard <ChartCard
title="Temperatur Verlauf" title="Temperatur Verlauf"
:labels="labels" :labels="displayLabels"
:data="temperatureData" :data="temperatureData"
borderColor="#36a2eb" borderColor="#36a2eb"
/> />
<ChartCard <ChartCard
title="Luftfeuchtigkeit Verlauf" title="Luftfeuchtigkeit Verlauf"
:labels="labels" :labels="displayLabels"
:data="humidityData" :data="humidityData"
borderColor="#4bc0c0" borderColor="#4bc0c0"
/> />
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, ref, onMounted } from 'vue' import { defineComponent, ref, onMounted, computed } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import ChartCard from '../components/ChartCard.vue' import ChartCard from '../components/ChartCard.vue'
...@@ -57,6 +58,21 @@ export default defineComponent({ ...@@ -57,6 +58,21 @@ export default defineComponent({
const start = ref('') const start = ref('')
const stop = ref('') const stop = ref('')
// Computed property for displaying max 6 labels
const displayLabels = computed(() => {
const total = labels.value.length
if (total <= 6) return labels.value
const result: string[] = []
for (let i = 0; i < total; i++) {
result.push('')
}
for (let i = 0; i < 6; i++) {
const idx = Math.round(i * (total - 1) / 5)
result[idx] = labels.value[idx]
}
return result
})
function toISOStringSafe(value: string): string { function toISOStringSafe(value: string): string {
try { try {
return new Date(value).toISOString() return new Date(value).toISOString()
...@@ -65,6 +81,24 @@ export default defineComponent({ ...@@ -65,6 +81,24 @@ export default defineComponent({
} }
} }
function setDefaultTimeWindow() {
const now = new Date()
const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000)
// Format dates properly for datetime-local inputs
const formatForInput = (date: Date) => {
const year = date.getFullYear()
const month = ('0' + (date.getMonth() + 1)).slice(-2)
const day = ('0' + date.getDate()).slice(-2)
const hours = ('0' + date.getHours()).slice(-2)
const minutes = ('0' + date.getMinutes()).slice(-2)
return `${year}-${month}-${day}T${hours}:${minutes}`
}
start.value = formatForInput(weekAgo)
stop.value = formatForInput(now)
}
async function loadData() { async function loadData() {
if (!start.value || !stop.value) return if (!start.value || !stop.value) return
...@@ -109,12 +143,14 @@ export default defineComponent({ ...@@ -109,12 +143,14 @@ export default defineComponent({
} }
} }
onMounted(async () => { // Function to load data with default last week window
const now = new Date() async function loadDataWithDefaultWindow() {
const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000) setDefaultTimeWindow()
start.value = weekAgo.toISOString().slice(0, 16)
stop.value = now.toISOString().slice(0, 16)
await loadData() await loadData()
}
onMounted(async () => {
await loadDataWithDefaultWindow()
}) })
return { return {
...@@ -122,10 +158,12 @@ export default defineComponent({ ...@@ -122,10 +158,12 @@ export default defineComponent({
start, start,
stop, stop,
labels, labels,
displayLabels,
co2Data, co2Data,
temperatureData, temperatureData,
humidityData, humidityData,
loadData, loadData,
loadDataWithDefaultWindow,
} }
}, },
}) })
...@@ -134,6 +172,7 @@ export default defineComponent({ ...@@ -134,6 +172,7 @@ export default defineComponent({
<style scoped> <style scoped>
.chart-view { .chart-view {
padding: 2rem; padding: 2rem;
color: #1a1a1a;
} }
.time-form { .time-form {
...@@ -165,6 +204,14 @@ export default defineComponent({ ...@@ -165,6 +204,14 @@ export default defineComponent({
background-color: #0056b3; background-color: #0056b3;
} }
.time-form .default-btn {
background: #28a745;
}
.time-form .default-btn:hover {
background-color: #218838;
}
.chart-grid { .chart-grid {
display: flex; display: flex;
flex-wrap: nowrap; flex-wrap: nowrap;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment