Discover: SidebarFilter Timeframes slider control to line chart done.
This commit is contained in:
BIN
public/timeFrameSlope.jpg
Normal file
BIN
public/timeFrameSlope.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
@@ -8,10 +8,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<Chart type="line" :data="chartData" :options="chartOptions" class="h-3/5" />
|
<Chart type="line" :data="chartData" :options="chartOptions" class="h-3/5" />
|
||||||
<div class="px-2">
|
<div class="px-2">
|
||||||
<Slider v-model="selectArea" :step="1" :min="1" :max="this.filterTimeframe.data.length" range class="mx-2" />
|
<Slider v-model="selectArea" :step="1" :min="1" :max="timeFrameTotal" range class="mx-2" id="canvas"/>
|
||||||
<br/>
|
<br/>
|
||||||
{{ selectArea }}<br/>
|
{{ selectArea }}<br/>
|
||||||
total: {{ this.filterTimeframe.data.length }}
|
total: {{ timeFrameData.length }}<br/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div @click.stop.prevent="">
|
<div @click.stop.prevent="">
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
<Calendar v-model="date" dateFormat="dd/mm/yy"/>
|
<Calendar v-model="date" dateFormat="dd/mm/yy"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<canvas id="myChart"></canvas>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -26,6 +27,7 @@
|
|||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import AllMapDataStore from '@/stores/allMapData.js';
|
import AllMapDataStore from '@/stores/allMapData.js';
|
||||||
import getMoment from 'moment';
|
import getMoment from 'moment';
|
||||||
|
import Chart from 'chart.js/auto'
|
||||||
|
|
||||||
export default{
|
export default{
|
||||||
setup() {
|
setup() {
|
||||||
@@ -36,24 +38,71 @@ export default{
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
// timeFrameData: [],
|
||||||
chartOptions: null,
|
chartOptions: null,
|
||||||
selectArea: [1, 2],
|
selectArea: [1, 10],
|
||||||
date: null
|
date: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
chartData: function() {
|
// Set Slider Time Range,滑塊範圍: 最小值 + data(10 個) + 最大值
|
||||||
let labels = this.filterTimeframe.data.map(time => getMoment(time.x).format("YYYY-MM-DD"));
|
timeFrameData: function(){
|
||||||
let chartData = this.filterTimeframe.data.map(item => {
|
let data = [...this.filterTimeframe.data];
|
||||||
return {
|
// y 軸斜率計算請參考 ./public/timeFrameSlope 的圖
|
||||||
x: getMoment(item.x).format("YYYY-MM-DD"),
|
// x 值為 0 ~ 11,
|
||||||
y: item.y
|
// 將三的座標(ax, ay), (bx, by), (cx, cy)命名為 (a, b), (c, d), (e, f)
|
||||||
}
|
// 最小值: (f - b)(c - a) = (e - a)(d - b),求 b = (ed - ad - fa - fc) / (e - c - a)
|
||||||
|
// 最大值: (f - b)(e - c) = (f - d)(e - a),求 f = (be - bc -de + da) / (a - c)
|
||||||
|
|
||||||
|
// y 軸最小值
|
||||||
|
let a = 0;
|
||||||
|
let b;
|
||||||
|
let c = 1;
|
||||||
|
let d = this.filterTimeframe.data[0].y;
|
||||||
|
let e = 2;
|
||||||
|
let f = this.filterTimeframe.data[1].y;
|
||||||
|
b = (e*d - a*d - f*a - f*c) / (e - c - a)
|
||||||
|
// y 軸最大值
|
||||||
|
let ma = 9;
|
||||||
|
let mb = this.filterTimeframe.data[8].y;
|
||||||
|
let mc = 10;
|
||||||
|
let md = this.filterTimeframe.data[9].y;
|
||||||
|
let me = 11;
|
||||||
|
let mf;
|
||||||
|
mf = (mb*me - mb*mc -md*me + md*ma) / (ma - mc)
|
||||||
|
|
||||||
|
// 添加最小值
|
||||||
|
data.unshift({
|
||||||
|
x: this.filterTimeframe.x_axis.min,
|
||||||
|
y: b,
|
||||||
})
|
})
|
||||||
|
// 添加最大值
|
||||||
|
data.push({
|
||||||
|
x: this.filterTimeframe.x_axis.max,
|
||||||
|
y: mf,
|
||||||
|
})
|
||||||
|
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
timeFrameTotal: function() {
|
||||||
|
return this.timeFrameData.length;
|
||||||
|
},
|
||||||
|
chartData: function() {
|
||||||
|
// !!畫面顯示的時間,資料轉換,在這邊最後一個步驟做就好!!
|
||||||
|
let labels = this.timeFrameData.map(time => getMoment(time.x).format("YYYY-MM-DD"));
|
||||||
|
let chartData = this.timeFrameData.map(item => {
|
||||||
|
return item.y
|
||||||
|
// x: getMoment(item.x).format("YYYY-MM-DD"),
|
||||||
|
})
|
||||||
|
|
||||||
|
const start = this.selectArea[0]-1;
|
||||||
|
const end = this.selectArea[1]-1;
|
||||||
|
const inside = (ctx, value) => ctx.p0DataIndex >= start && ctx.p1DataIndex <= end ? value : undefined;
|
||||||
|
const outside = (ctx, value) => ctx.p0DataIndex < start || ctx.p1DataIndex > end ? value : undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// 要呈現的資料
|
// 要呈現的資料
|
||||||
// labels,
|
labels,
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
label: 'Case', // 資料的標題標籤
|
label: 'Case', // 資料的標題標籤
|
||||||
@@ -61,50 +110,21 @@ export default{
|
|||||||
fill: true,
|
fill: true,
|
||||||
showLine: false,
|
showLine: false,
|
||||||
tension: 0.4,
|
tension: 0.4,
|
||||||
backgroundColor: 'rgba(0,153,255)',
|
backgroundColor: 'rgba(203, 213, 225)',
|
||||||
// pointRadius: 0,
|
pointRadius: 0,
|
||||||
|
spanGaps: true,
|
||||||
|
segment: {
|
||||||
|
backgroundColor: ctx => inside(ctx, 'rgb(0,153,255)') || outside(ctx, 'rgb(203, 213, 225)'),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// label: 'Selected Trace',
|
|
||||||
// // data: [
|
|
||||||
// // {x: 0, y:37.8},
|
|
||||||
// // {x: 0, y:29.5},
|
|
||||||
// // {x: 0, y:17.9},
|
|
||||||
// // {x: 0, y:8.8},
|
|
||||||
// // {x: 0, y:3.2},
|
|
||||||
// // {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},
|
|
||||||
// // ],
|
|
||||||
// data: [
|
|
||||||
// {x: 0, y:37.8},
|
|
||||||
// {x: 0, y:29.5},
|
|
||||||
// {x: null, y:17.9},
|
|
||||||
// ],
|
|
||||||
// // data: this.traces.map(trace=>trace.ratio),
|
|
||||||
// fill: true,
|
|
||||||
// // borderColor: documentStyle.getPropertyValue('--primary-500'),
|
|
||||||
// showLine: false,
|
|
||||||
// tension: 0.4,
|
|
||||||
// backgroundColor: documentStyle.getPropertyValue('--primary-500'),
|
|
||||||
// pointRadius: 0,
|
|
||||||
// }
|
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
sss(e){
|
/**
|
||||||
console.log(e);
|
* Set bar chart Options
|
||||||
// e.stop();
|
*/
|
||||||
// e.prevent();
|
|
||||||
// e.preventDefault();
|
|
||||||
|
|
||||||
},
|
|
||||||
setChartOptions() {
|
setChartOptions() {
|
||||||
// 找出 y 軸最大值,乘以 1.1 讓圖的上方多一點空間
|
// 找出 y 軸最大值,乘以 1.1 讓圖的上方多一點空間
|
||||||
const max = this.filterTimeframe.y_axis.max * 1.1;
|
const max = this.filterTimeframe.y_axis.max * 1.1;
|
||||||
@@ -120,7 +140,10 @@ export default{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
legend: false // 圖例
|
legend: false, // 圖例
|
||||||
|
filler: {
|
||||||
|
propagate: false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
animations: false, // 取消動畫
|
animations: false, // 取消動畫
|
||||||
scales: {
|
scales: {
|
||||||
@@ -153,11 +176,9 @@ export default{
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.chartOptions = this.setChartOptions();
|
this.chartOptions = this.setChartOptions();
|
||||||
this.selectArea = [1, 2];
|
this.selectArea = [1, this.timeFrameTotal];
|
||||||
// console.log(Date.parse('2014/11/01 00:34:44'));
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
canvas{position:relative; z-index:1;}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ export default {
|
|||||||
'Mode': ['Directly follows', 'Eventually follows'],
|
'Mode': ['Directly follows', 'Eventually follows'],
|
||||||
'ModeAtt': ['Case', 'Activity'],
|
'ModeAtt': ['Case', 'Activity'],
|
||||||
'Refine': ['Include', 'Exclude'],
|
'Refine': ['Include', 'Exclude'],
|
||||||
'Containment': ['Contained in', 'Started in', 'End in', 'Activity in', 'Trim'],
|
'Containment': ['Contained in', 'Started in', 'Ended in', 'Active in', 'Trim'],
|
||||||
},
|
},
|
||||||
tab: 'filter', // filter | funnel
|
tab: 'filter', // filter | funnel
|
||||||
selectValue: {
|
selectValue: {
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ export default defineStore('filesStore', {
|
|||||||
})
|
})
|
||||||
if(this.httpStatus < 300) loading.isLoading = false;
|
if(this.httpStatus < 300) loading.isLoading = false;
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
console.dir(error); // safari 測試
|
||||||
this.httpStatus = error.request.status;
|
this.httpStatus = error.request.status;
|
||||||
delay().then(() =>{
|
delay().then(() =>{
|
||||||
loading.isLoading = true;
|
loading.isLoading = true;
|
||||||
@@ -107,6 +108,7 @@ export default defineStore('filesStore', {
|
|||||||
});
|
});
|
||||||
if(this.httpStatus < 300) loading.isLoading = false;
|
if(this.httpStatus < 300) loading.isLoading = false;
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
console.dir(error); // safari 測試
|
||||||
this.httpStatus = error.request.status;
|
this.httpStatus = error.request.status;
|
||||||
delay().then(() =>{
|
delay().then(() =>{
|
||||||
loading.isLoading = true;
|
loading.isLoading = true;
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export default defineStore('loginStore', {
|
|||||||
this.$router.push('/files');
|
this.$router.push('/files');
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
console.dir(error); // safari 測試
|
||||||
this.isInvalid = true;
|
this.isInvalid = true;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -68,6 +69,7 @@ export default defineStore('loginStore', {
|
|||||||
|
|
||||||
this.userData = response.data;
|
this.userData = response.data;
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
console.dir(error); // safari 測試
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@@ -80,6 +82,7 @@ export default defineStore('loginStore', {
|
|||||||
const response = await axios.get(api);
|
const response = await axios.get(api);
|
||||||
if(response.status !== 200) this.$router.push('/login');
|
if(response.status !== 200) this.$router.push('/login');
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
console.dir(error); // safari 測試
|
||||||
this.$router.push('/login');
|
this.$router.push('/login');
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user