Merge branch 'main' into acct_mgmt
This commit is contained in:
@@ -127,8 +127,8 @@ export function simpleTimeLabel(second, fixedNumber = 0) {
|
|||||||
const hour = 60 * 60;
|
const hour = 60 * 60;
|
||||||
const minutes = 60;
|
const minutes = 60;
|
||||||
const dd = Math.floor(second / day);
|
const dd = Math.floor(second / day);
|
||||||
const hh = Math.floor((second % day) / hour);
|
const hh = Math.floor((second / hour) / day);
|
||||||
const mm = Math.floor((second % hour) / minutes);
|
const mm = Math.floor((second / hour) / minutes);
|
||||||
|
|
||||||
if(dd > 0){
|
if(dd > 0){
|
||||||
return (second / day).toFixed(fixedNumber) + "d";
|
return (second / day).toFixed(fixedNumber) + "d";
|
||||||
|
|||||||
@@ -313,123 +313,7 @@ export default {
|
|||||||
if(totalBars > 10) horizontalBar = (totalBars - 10) * 16 + this.horizontalBarHeight;
|
if(totalBars > 10) horizontalBar = (totalBars - 10) * 16 + this.horizontalBarHeight;
|
||||||
|
|
||||||
return horizontalBar + 'px'
|
return horizontalBar + 'px'
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* 建立折線圖
|
|
||||||
* @param { object } chartData chart data
|
|
||||||
* @param { object } content titels 標題文字
|
|
||||||
* @param { string } yUnit y 軸單位 'date' | 'count'
|
|
||||||
*/
|
|
||||||
getLineChart(chartData, content, yUnit, whichCaller) {
|
|
||||||
let datasets;
|
|
||||||
let minX = chartData.x_axis.min;
|
|
||||||
let maxX = chartData.x_axis.max;
|
|
||||||
let maxY = chartData.y_axis.max;
|
|
||||||
let xData;
|
|
||||||
let primeVueSetData = {};
|
|
||||||
let primeVueSetOption = {};
|
|
||||||
const getMoment = (time)=> {
|
|
||||||
return this.$moment(time).format('YYYY/M/D hh:mm:ss')
|
|
||||||
};
|
|
||||||
const getSimpleTimeLabel = simpleTimeLabel;
|
|
||||||
const getFollowTimeLabel = followTimeLabel;
|
|
||||||
|
|
||||||
switch (yUnit) {
|
|
||||||
case 'date':
|
|
||||||
datasets = setLineChartData(chartData.data, chartData.x_axis.max, chartData.x_axis.min, false, chartData.y_axis.max,
|
|
||||||
chartData.y_axis.min);
|
|
||||||
xData = this.setXLabelsData(chartData.x_axis);
|
|
||||||
break;
|
|
||||||
case 'count': // 次數 10 個點
|
|
||||||
datasets = chartData.data;
|
|
||||||
xData = chartData.data.map(item => new Date(item.x).getTime());
|
|
||||||
|
|
||||||
// special case, freq chart case
|
|
||||||
if(whichCaller === "freqChartCaller") {
|
|
||||||
this.setFreqChartXData({ minX, maxX, xData, content});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Customize X axis ticks due to different differences between min and max of data group
|
|
||||||
// Compare page and Performance page share the same logic
|
|
||||||
const formatToSet = setTimeStringFormatBaseOnTimeDifference(minX, maxX);
|
|
||||||
const ticksOfXAxis = mapTimestampToAxisTicksByFormat(xData, formatToSet);
|
|
||||||
const customizedScaleOption = this.getCustomizedScaleOption(
|
|
||||||
knownScaleLineChartOptions, {
|
|
||||||
customizeOptions: {
|
|
||||||
content, ticksOfXAxis,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
primeVueSetData = {
|
|
||||||
labels: xData,
|
|
||||||
datasets: [
|
|
||||||
{
|
|
||||||
label: content.title,
|
|
||||||
data: datasets,
|
|
||||||
fill: false,
|
|
||||||
tension: 0, // 貝茲曲線張力
|
|
||||||
borderColor: '#0099FF',
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
primeVueSetOption = {
|
|
||||||
responsive: true,
|
|
||||||
maintainAspectRatio: false,
|
|
||||||
layout: {
|
|
||||||
padding: {
|
|
||||||
top: 16,
|
|
||||||
left: 8,
|
|
||||||
right: 8,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
plugins: {
|
|
||||||
legend: false, // 圖例
|
|
||||||
tooltip: {
|
|
||||||
displayColors: false,
|
|
||||||
titleFont: {weight: 'normal'},
|
|
||||||
callbacks: {
|
|
||||||
title: function(context) {
|
|
||||||
return `${content.x}: ${getMoment(context[0].parsed.x)}`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
display: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
scales: customizedScaleOption,
|
|
||||||
};
|
|
||||||
|
|
||||||
switch (yUnit) {
|
|
||||||
case 'date':
|
|
||||||
primeVueSetOption.plugins.tooltip.callbacks.label = function(context) {
|
|
||||||
return `${content.y}: ${getSimpleTimeLabel(context.parsed.y, 2)}`;
|
|
||||||
};
|
|
||||||
primeVueSetOption.scales.x.min = minX;
|
|
||||||
primeVueSetOption.scales.x.max = maxX;
|
|
||||||
primeVueSetOption.scales.y.ticks.callback = function (value, index, ticks) {
|
|
||||||
// resultStepSize: Y 軸一個刻度的高度的純數值部分,unitToUse則可能是 d,h,m,s 四者之一
|
|
||||||
// ticks.length是動態由 PrimeVue 決定的,例如可能是 6 或是 8
|
|
||||||
const {resultStepSize, unitToUse} = getStepSizeOfYTicks(ticks[ticks.length - 1].value, ticks.length);
|
|
||||||
return getYTicksByIndex(resultStepSize, index, unitToUse);
|
|
||||||
};
|
|
||||||
primeVueSetOption.scales.y.ticks.stepSize = resultStepSize;
|
|
||||||
break;
|
|
||||||
case 'count':
|
|
||||||
default:
|
|
||||||
primeVueSetOption.scales.y.ticks.precision = 0; // y 軸顯示小數點後 0 位
|
|
||||||
primeVueSetOption.plugins.tooltip.callbacks.label = function(context) {
|
|
||||||
return `${content.y}: ${context.parsed.y}`;
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return [primeVueSetData, primeVueSetOption]
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 建立長條圖
|
* 建立長條圖
|
||||||
* @param { object } chartData chart data
|
* @param { object } chartData chart data
|
||||||
@@ -813,14 +697,9 @@ export default {
|
|||||||
displayColors: false,
|
displayColors: false,
|
||||||
titleFont: {weight: 'normal'},
|
titleFont: {weight: 'normal'},
|
||||||
callbacks: {
|
callbacks: {
|
||||||
title: function(context) {
|
label: function(context) {
|
||||||
return `${content.x}: ${getMoment(context[0].parsed.x)}`;
|
return `${content.y}: ${getSimpleTimeLabel(context.parsed.y, 2)}`;
|
||||||
}
|
}
|
||||||
//TODO: Not sure which one to apply. callbacks:{
|
|
||||||
// label:function(context) {
|
|
||||||
// return `${content.y}: ${getSimpleTimeLabel(context.parsed.y, 2)}`;
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
|
|||||||
Reference in New Issue
Block a user