Discover: SidebarFilter Timeframes LineChart Option done.
This commit is contained in:
@@ -1,63 +1,115 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="bg-neutral-10 border border-neutral-300 rounded-xl px-4 w-full h-full">
|
<div class="bg-neutral-10 border border-neutral-300 rounded-xl px-4 w-full h-full">
|
||||||
<p class="h2">Hello World</p>
|
<section class="py-2 space-y-2 text-sm min-w-[48%] h-full">
|
||||||
|
<p class="h2">Range Selection</p>
|
||||||
|
<div class="text-primary h2 flex items-center justify-start">
|
||||||
|
<span class="material-symbols-outlined mr-2 text-base">info</span>
|
||||||
|
<p>Select or fill in a time range.</p>
|
||||||
|
</div>
|
||||||
|
<Chart type="line" :data="chartData" :options="chartOptions" class="h-3/5" />
|
||||||
|
<div class="px-2">
|
||||||
|
<Slider v-model="selectArea" :step="1" :min="1" :max="this.filterTimeframe.data.length" range class="mx-2" />
|
||||||
|
<br/>
|
||||||
|
{{ selectArea }}<br/>
|
||||||
|
total: {{ this.filterTimeframe.data.length }}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div @click.stop.prevent="">
|
||||||
|
<span class="block">Start date</span>
|
||||||
|
<Calendar v-model="date" dateFormat="dd/mm/yy" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
import AllMapDataStore from '@/stores/allMapData.js';
|
||||||
|
import getMoment from 'moment';
|
||||||
|
|
||||||
export default{
|
export default{
|
||||||
methods: {
|
setup() {
|
||||||
setChartData() {
|
const allMapDataStore = AllMapDataStore();
|
||||||
const documentStyle = getComputedStyle(document.documentElement);
|
const { filterTimeframe } = storeToRefs(allMapDataStore);
|
||||||
|
|
||||||
|
return {allMapDataStore, filterTimeframe}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
chartOptions: null,
|
||||||
|
selectArea: [1, 2],
|
||||||
|
date: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
chartData: function() {
|
||||||
|
let labels = this.filterTimeframe.data.map(time => getMoment(time.x).format("YYYY-MM-DD"));
|
||||||
|
let chartData = this.filterTimeframe.data.map(item => {
|
||||||
|
return {
|
||||||
|
x: getMoment(item.x).format("YYYY-MM-DD"),
|
||||||
|
y: item.y
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// 要呈現的資料
|
// 要呈現的資料
|
||||||
labels: this.traces.map(trace => ''),
|
// labels,
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: 'Trace', // 資料的標題標籤
|
label: 'Case', // 資料的標題標籤
|
||||||
data: this.traces.map(trace => this.getPercentLabel(trace.ratio)),
|
data: chartData,
|
||||||
fill: true,
|
fill: true,
|
||||||
// borderColor: documentStyle.getPropertyValue('--primary-500'),
|
|
||||||
showLine: false,
|
showLine: false,
|
||||||
tension: 0.4,
|
tension: 0.4,
|
||||||
// backgroundColor: 'rgba(0,153,255)',
|
backgroundColor: 'rgba(0,153,255)',
|
||||||
pointRadius: 0,
|
// pointRadius: 0,
|
||||||
|
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
label: 'Selected Trace',
|
// label: 'Selected Trace',
|
||||||
// data: [
|
// // data: [
|
||||||
// {x: 0, y:37.8},
|
// // {x: 0, y:37.8},
|
||||||
// {x: 0, y:29.5},
|
// // {x: 0, y:29.5},
|
||||||
// {x: 0, y:17.9},
|
// // {x: 0, y:17.9},
|
||||||
// {x: 0, y:8.8},
|
// // {x: 0, y:8.8},
|
||||||
// {x: 0, y:3.2},
|
// // {x: 0, y:3.2},
|
||||||
// {x: 0, y:0.8},
|
// // {x: 0, y:0.8},
|
||||||
// {x: 0, y:0.4},
|
// // {x: 0, y:0.4},
|
||||||
// {x: 0, y:0.4},
|
// // {x: 0, y:0.4},
|
||||||
// {x: 0, y:0.4},
|
// // {x: 0, y:0.4},
|
||||||
// {x: 0, y:0.4},
|
// // {x: 0, y:0.4},
|
||||||
// {x: 0, y:0.4},
|
// // {x: 0, y:0.4},
|
||||||
// ],
|
// // ],
|
||||||
data: [
|
// data: [
|
||||||
{x: 0, y:37.8},
|
// {x: 0, y:37.8},
|
||||||
{x: 0, y:29.5},
|
// {x: 0, y:29.5},
|
||||||
{x: null, y:17.9},
|
// {x: null, y:17.9},
|
||||||
],
|
// ],
|
||||||
// data: this.traces.map(trace=>trace.ratio),
|
// // data: this.traces.map(trace=>trace.ratio),
|
||||||
fill: true,
|
// fill: true,
|
||||||
// borderColor: documentStyle.getPropertyValue('--primary-500'),
|
// // borderColor: documentStyle.getPropertyValue('--primary-500'),
|
||||||
showLine: false,
|
// showLine: false,
|
||||||
tension: 0.4,
|
// tension: 0.4,
|
||||||
backgroundColor: documentStyle.getPropertyValue('--primary-500'),
|
// backgroundColor: documentStyle.getPropertyValue('--primary-500'),
|
||||||
pointRadius: 0,
|
// pointRadius: 0,
|
||||||
}
|
// }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
sss(e){
|
||||||
|
console.log(e);
|
||||||
|
// e.stop();
|
||||||
|
// e.prevent();
|
||||||
|
// e.preventDefault();
|
||||||
|
|
||||||
},
|
},
|
||||||
setChartOptions() {
|
setChartOptions() {
|
||||||
return {
|
// 找出 y 軸最大值,乘以 1.1 讓圖的上方多一點空間
|
||||||
// 自訂屬性設定
|
const max = this.filterTimeframe.y_axis.max * 1.1;
|
||||||
|
|
||||||
|
return { // 自訂屬性設定
|
||||||
maintainAspectRatio: false,
|
maintainAspectRatio: false,
|
||||||
aspectRatio: 0.6,
|
aspectRatio: 0.6,
|
||||||
layout: {
|
layout: {
|
||||||
@@ -68,28 +120,48 @@ export default{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
legend: { // 圖例
|
legend: false // 圖例
|
||||||
display: false,
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
animations: false, // 取消動畫
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
display: false, // 隱藏 x 軸
|
ticks: {
|
||||||
},
|
color: '#0f172a',
|
||||||
y: {
|
|
||||||
ticks: { // 設定間隔數值
|
|
||||||
display: false, // 隱藏數值,只顯示格線
|
|
||||||
min: 0,
|
|
||||||
max: this.traceList[0].ratio,
|
|
||||||
stepSize: (this.traceList[0].ratio)/4,
|
|
||||||
},
|
},
|
||||||
grid: {
|
grid: {
|
||||||
drawBorder: false
|
// drawOnChartArea: false, // 隱藏 x 軸網格
|
||||||
|
display: false,
|
||||||
|
// drawBorder: false,
|
||||||
|
// drawTicks: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
beginAtZero: true, // scale 包含 0
|
||||||
|
max: max,
|
||||||
|
ticks: { // 設定間隔數值
|
||||||
|
display: false, // 隱藏數值,只顯示格線
|
||||||
|
stepSize: max / 4,
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
color: 'rgba(100,116,139)',
|
||||||
|
drawBorder: false,
|
||||||
|
z: 1,
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
display: false,
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
mounted() {
|
||||||
|
this.chartOptions = this.setChartOptions();
|
||||||
|
this.selectArea = [1, 2];
|
||||||
|
// console.log(Date.parse('2014/11/01 00:34:44'));
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<style>
|
||||||
|
canvas{position:relative; z-index:1;}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import Timeline from 'primevue/timeline';
|
|||||||
import InputSwitch from 'primevue/inputswitch';
|
import InputSwitch from 'primevue/inputswitch';
|
||||||
import Chart from 'primevue/chart';
|
import Chart from 'primevue/chart';
|
||||||
import Slider from 'primevue/slider';
|
import Slider from 'primevue/slider';
|
||||||
|
import Calendar from 'primevue/calendar';
|
||||||
|
|
||||||
const emitter = mitt();
|
const emitter = mitt();
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
@@ -88,6 +89,7 @@ app.component('Timeline', Timeline);
|
|||||||
app.component('InputSwitch', InputSwitch);
|
app.component('InputSwitch', InputSwitch);
|
||||||
app.component('Chart', Chart);
|
app.component('Chart', Chart);
|
||||||
app.component('Slider', Slider);
|
app.component('Slider', Slider);
|
||||||
|
app.component('Calendar', Calendar);
|
||||||
app.component('Draggable', draggable); // 拖曳
|
app.component('Draggable', draggable); // 拖曳
|
||||||
|
|
||||||
app.mount("#app");
|
app.mount("#app");
|
||||||
|
|||||||
Reference in New Issue
Block a user