Skip to content

Commit

Permalink
fix: 每日活跃图表垂直时时间排列 (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanaTsuk1 committed Jul 6, 2024
1 parent d2fbc00 commit e76862e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/components/widget/DailyActivity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ const labelList = ref<Array<SelectLabel>>([])
const activityList = ref<Array<SelectActivity>>([])
const programList = ref<Array<SelectProgram>>([])
const x = new Array(24).fill(0).map((_, i) => i)
const vertical = computed(() => props.data.fields?.vertical || false)
const option = computed(() => {
const x = new Array(24).fill(0).map((_, i) => i)
const xAxisData = vertical.value ? x.reverse() : x
const transformNoteList = splitByHour(noteList.value).filter(i => isSameDay(selectedDateVModel.value, i.start))
const transformactivityList = splitByHour(activityList.value).filter(i => isSameDay(selectedDateVModel.value, i.start))
Expand All @@ -31,7 +32,7 @@ const option = computed(() => {
name,
type: 'bar',
stack: 'label',
data: x.map(time => calcTotalTime(transformNoteList.filter(i => i.label.id == id && (isSameHour(new Date(selectedDateVModel.value).setHours(time), i.start))))),
data: xAxisData.map(time => calcTotalTime(transformNoteList.filter(i => i.label.id == id && (isSameHour(new Date(selectedDateVModel.value).setHours(time), i.start))))),
itemStyle: {
color: transformNoteList.find(i => i.label.id == id)?.label.color,
},
Expand All @@ -46,7 +47,7 @@ const option = computed(() => {
name,
type: 'bar',
stack: 'label',
data: x.map(time => calcTotalTime(transformactivityList.filter(i => i.program.id == id && (isSameHour(new Date(selectedDateVModel.value).setHours(time), i.start))))),
data: xAxisData.map(time => calcTotalTime(transformactivityList.filter(i => i.program.id == id && (isSameHour(new Date(selectedDateVModel.value).setHours(time), i.start))))),
itemStyle: {
color: transformactivityList.find(i => i.program.id == id)?.program.color,
},
Expand All @@ -56,12 +57,13 @@ const option = computed(() => {
}
})
const xAxisData = x.map(complement)
const xAxis = [
{
type: 'category',
data: vertical.value ? xAxisData.reverse() : xAxisData,
data: xAxisData,
axisLabel: {
formatter: complement,
},
},
]
Expand Down
6 changes: 4 additions & 2 deletions src/components/widget/SingleCategoryBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ async function init() {
const option = computed<EChartsOption>(() => {
const x = new Array(day).fill(0).map((_, i) => subDays(new Date(), i).getTime())
const xAxisData = vertical.value ? x : x.reverse()
const xAxis = {
type: 'category',
data: vertical.value ? x : x.reverse(),
data: xAxisData,
axisLabel: {
formatter: time => format(new Date(Number(time)), 'MM-dd'),
},
Expand Down Expand Up @@ -107,7 +109,7 @@ const option = computed<EChartsOption>(() => {
},
series: {
type: 'bar',
data: x.map(date => calcTotalTime(list.value.filter(({ start }) => isSameDay(date, start)))),
data: xAxisData.map(date => calcTotalTime(list.value.filter(({ start }) => isSameDay(date, start)))),
itemStyle: {
color: color.value,
},
Expand Down

0 comments on commit e76862e

Please sign in to comment.