diff --git a/src/constants/constants.js b/src/constants/constants.js new file mode 100644 index 0000000..d413b10 --- /dev/null +++ b/src/constants/constants.js @@ -0,0 +1,156 @@ +export const knownLayoutChartOption = { + padding: { + top: 16, + left: 8, + right: 8, + } + }; +export const knownScaleLineChartOptions = { +x: { + type: 'time', + title: { + display: true, + color: '#334155', + font: { + size: 12, + lineHeight: 2 + } + }, + time: { + displayFormats: { + second: 'h:mm:ss', // ex: 1:11:11 + minute: 'M/d h:mm', // ex: 1/1 1:11 + hour: 'M/d h:mm', // ex: 1/1 1:11 + day: 'M/d h', // ex: 1/1 1 + month: 'y/M/d', // ex: 1911/1/1 + }, + }, + ticks: { + display: true, + maxRotation: 0, // 不旋轉 lable 0~50 + color: '#64748b', + source: 'labels', // 依比例彈性顯示 label 數量 + }, + border: { + color: '#64748b', + }, + grid: { + tickLength: 0, // 網格是否超過邊線 + } +}, +y: { + beginAtZero: true, // scale 包含 0 + title: { + display: true, + color: '#334155', + font: { + size: 12, + lineHeight: 2 + }, + }, + ticks:{ + color: '#64748b', + padding: 8, + }, + grid: { + color: '#64748b', + }, + border: { + display: false, // 隱藏左側多出來的線 + }, +}, +}; +export const knownScaleHorizontalChartOptions = { +x: { + title: { + display: true, + color: '#334155', + font: { + size: 12, + lineHeight: 2 + } + }, + ticks: { + display: true, + maxRotation: 0, // 不旋轉 lable 0~50 + color: '#64748b', + }, + grid: { + color: '#64748b', + tickLength: 0, // 網格是否超過邊線 + }, + border: { + display:false, + }, +}, +y: { + beginAtZero: true, // scale 包含 0 + type: 'category', + title: { + display: true, + color: '#334155', + font: { + size: 12, + lineHeight: 2 + }, + }, + ticks:{ + color: '#64748b', + padding: 8, + }, + grid: { + display:false, + color: '#64748b', + }, + border: { + display: false, // 隱藏左側多出來的線 + }, +}, +}; +export const knownScaleBarChartOptions = { +x: { + title: { + display: true, + color: '#334155', + font: { + size: 12, + lineHeight: 2 + } + }, + ticks: { + display: true, + maxRotation: 0, // 不旋轉 lable 0~50 + color: '#64748b', + }, + grid: { + color: '#64748b', + tickLength: 0, // 網格是否超過邊線 + }, + border: { + display:false, + }, + }, + y: { + beginAtZero: true, // scale 包含 0 + type: 'category', + title: { + display: true, + color: '#334155', + font: { + size: 12, + lineHeight: 2 + }, + }, + ticks:{ + color: '#64748b', + padding: 8, + }, + grid: { + display:false, + color: '#64748b', + }, + border: { + display: false, // 隱藏左側多出來的線 + }, + }, +}; \ No newline at end of file diff --git a/src/module/timeLabel.js b/src/module/timeLabel.js index c9916bb..e2860cb 100644 --- a/src/module/timeLabel.js +++ b/src/module/timeLabel.js @@ -289,5 +289,7 @@ export const setTimeStringFormatBaseOnTimeDifference = (minTimeStamp, maxTimeSta * @param {string} timeFormat For example, 'MM/DD' */ export const mapTimestampToAxisTicksByFormat = (timeStampArr, timeFormat) => { - return timeStampArr.map(ts => moment(ts).format(timeFormat)); + if (timeStampArr) { + return timeStampArr.map(ts => moment(ts).format(timeFormat)); + } }; \ No newline at end of file diff --git a/src/stores/performance.js b/src/stores/performance.js index ce7b05a..2c4a880 100644 --- a/src/stores/performance.js +++ b/src/stores/performance.js @@ -6,6 +6,12 @@ export default defineStore('performanceStore', { allPerformanceData: null, freqChartData: null, freqChartOptions: null, + freqChartXData: { + minX: null, + maxX: null, + xData: null, + content: null, + } }), getters: { performanceData: state => { @@ -50,5 +56,12 @@ export default defineStore('performanceStore', { setFreqChartOptions(freqChartOptions){ this.freqChartOptions = freqChartOptions; }, + /** + * + * @param {object} freqChartXData + */ + setFreqChartXData(freqChartXData) { + this.freqChartXData = freqChartXData; + } }, }) diff --git a/src/views/Compare/Dashboard/index.vue b/src/views/Compare/Dashboard/index.vue index a31f47f..3670cde 100644 --- a/src/views/Compare/Dashboard/index.vue +++ b/src/views/Compare/Dashboard/index.vue @@ -162,163 +162,13 @@ import { simpleTimeLabel, followTimeLabel, dateLabel, getYTicksByIndex, } from '@/module/timeLabel.js'; import i18next from '@/i18n/i18n'; +import { + knownLayoutChartOption, + knownScaleLineChartOptions, + knownScaleHorizontalChartOptions, + knownScaleBarChartOptions, + } from "@/constants/constants.js"; -const knownLayoutChartOption = { - padding: { - top: 16, - left: 8, - right: 8, - } -}; -const knownScaleLineChartOptions = { - x: { - type: 'time', - title: { - display: true, - color: '#334155', - font: { - size: 12, - lineHeight: 2 - } - }, - time: { - displayFormats: { - second: 'h:mm:ss', // ex: 1:11:11 - minute: 'M/d h:mm', // ex: 1/1 1:11 - hour: 'M/d h:mm', // ex: 1/1 1:11 - day: 'M/d h', // ex: 1/1 1 - month: 'y/M/d', // ex: 1911/1/1 - }, - }, - ticks: { - display: true, - maxRotation: 0, // 不旋轉 lable 0~50 - color: '#64748b', - source: 'labels', // 依比例彈性顯示 label 數量 - }, - border: { - color: '#64748b', - }, - grid: { - tickLength: 0, // 網格是否超過邊線 - } - }, - y: { - beginAtZero: true, // scale 包含 0 - title: { - display: true, - color: '#334155', - font: { - size: 12, - lineHeight: 2 - }, - }, - ticks:{ - color: '#64748b', - padding: 8, - }, - grid: { - color: '#64748b', - }, - border: { - display: false, // 隱藏左側多出來的線 - }, - }, -}; -const knownScaleHorizontalChartOptions = { - x: { - title: { - display: true, - color: '#334155', - font: { - size: 12, - lineHeight: 2 - } - }, - ticks: { - display: true, - maxRotation: 0, // 不旋轉 lable 0~50 - color: '#64748b', - }, - grid: { - color: '#64748b', - tickLength: 0, // 網格是否超過邊線 - }, - border: { - display:false, - }, - }, - y: { - beginAtZero: true, // scale 包含 0 - type: 'category', - title: { - display: true, - color: '#334155', - font: { - size: 12, - lineHeight: 2 - }, - }, - ticks:{ - color: '#64748b', - padding: 8, - }, - grid: { - display:false, - color: '#64748b', - }, - border: { - display: false, // 隱藏左側多出來的線 - }, - }, -}; -const knownScaleBarChartOptions = { - x: { - title: { - display: true, - color: '#334155', - font: { - size: 12, - lineHeight: 2 - } - }, - ticks: { - display: true, - maxRotation: 0, // 不旋轉 lable 0~50 - color: '#64748b', - }, - grid: { - color: '#64748b', - tickLength: 0, // 網格是否超過邊線 - }, - border: { - display:false, - }, - }, - y: { - beginAtZero: true, // scale 包含 0 - type: 'category', - title: { - display: true, - color: '#334155', - font: { - size: 12, - lineHeight: 2 - }, - }, - ticks:{ - color: '#64748b', - padding: 8, - }, - grid: { - display:false, - color: '#64748b', - }, - border: { - display: false, // 隱藏左側多出來的線 - }, - }, - }; export default { setup() { diff --git a/src/views/Discover/Performance/FreqChart.vue b/src/views/Discover/Performance/FreqChart.vue index 4456a2c..1a685be 100644 --- a/src/views/Discover/Performance/FreqChart.vue +++ b/src/views/Discover/Performance/FreqChart.vue @@ -3,22 +3,151 @@