Skip to content

Commit

Permalink
implement hover time display for averages
Browse files Browse the repository at this point in the history
  • Loading branch information
chienleng committed Oct 5, 2023
1 parent 6b9e785 commit 510eb01
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 2 deletions.
79 changes: 79 additions & 0 deletions components/SummaryTable/DatesDisplayToD.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<template>
<header>
<time v-if="isHovering">
{{
hoveredTime
}}
</time>

<span v-if="!isHovering">
<time>
{{ startDate | customFormatDate({ range, interval, isStart: true }) }}
</time>
<time>
{{
endDate
| customFormatDate({ range, interval, showYear: true, isEnd: true })
}}
</time>
</span>

<small>
{{ timezoneString }}
</small>
</header>
</template>

<script>
export default {
props: {
isHovering: {
type: Boolean,
default: () => false
},
startDate: {
type: Number,
default: () => 0
},
endDate: {
type: Number,
default: () => 0
},
hoveredTime: {
type: String,
default: ''
},
range: {
type: String,
default: () => ''
},
interval: {
type: String,
default: () => ''
},
timezoneString: {
type: String,
default: () => ''
}
}
}
</script>

<style lang="scss" scoped>
header {
text-align: right;
font-size: 16px;
font-weight: 300;
color: #000;
padding-bottom: 1rem / 5;
border-bottom: 1px solid #000;
user-select: none;
small {
font-size: 0.8em;
}
}
</style>
19 changes: 19 additions & 0 deletions components/SummaryTable/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@
/>

<div v-else>
<div v-if="isTimeOfDayView">
<DatesDisplayToD
:is-hovering="hoverOn"
:hovered-time="timeOfDayHoverTime"
:start-date="startDate"
:end-date="endDate"
:range="range"
:interval="interval"
:timezone-string="isEnergyType ? '' : regionTimezoneString"
/>
</div>
<dates-display
v-else
:is-hovering="hoverOn"
:hovered-date="hoveredDate"
:focus-on="focusOn"
Expand Down Expand Up @@ -401,19 +413,22 @@ import { energy_sum } from '@opennem/energy-tools'
import * as OPTIONS from '@/constants/chart-options.js'
import { GROUP_DETAILED } from '@/constants/energy-fuel-techs'
import EventBus from '@/plugins/eventBus'
import { getTimeLabel } from '@/data/transform/time-of-day'
import Domain from '~/services/Domain.js'
import GroupSelector from '~/components/ui/FuelTechGroupSelector'
import ColumnSelector from '~/components/ui/SummaryColumnSelector'
import ExportLegend from '@/components/Energy/Export/Legend'
import Items from './Items'
import DatesDisplay from './DatesDisplay'
import DatesDisplayToD from './DatesDisplayToD'
export default {
components: {
GroupSelector,
ColumnSelector,
Items,
DatesDisplay,
DatesDisplayToD,
ExportLegend
},
Expand Down Expand Up @@ -577,6 +592,10 @@ export default {
return this.dashboardView === 'time-of-day'
},
timeOfDayHoverTime() {
return getTimeLabel(this.hoverDate)
},
chartUnit() {
return this.isEnergy ? this.chartEnergyUnit : this.chartPowerUnit
},
Expand Down
4 changes: 2 additions & 2 deletions data/transform/time-of-day.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export function getTimeLabel(d) {
const date = new Date(d)
const hours = date.getUTCHours()
const minutes = date.getUTCMinutes()
const ampm = hours >= 12 ? 'pm' : 'am'
const ampm = hours >= 12 ? 'PM' : 'AM'
const hour = function() {
return hours === 0 || hours === 12 ? 12 : hours % 12
}()
const min = minutes === 0 ? '' : `:${(minutes + '').padStart(2, '0')}`
return `${hour}${min}${ampm}`
return `${hour}${min} ${ampm}`
}

function getTimebucket(interval, jsDate) {
Expand Down

0 comments on commit 510eb01

Please sign in to comment.