Add more airlines and fix edit bugs
This commit is contained in:
@@ -1,48 +1,11 @@
|
||||
<template>
|
||||
<div class="chart-wrap">
|
||||
<div class="chart-title">Top airlines</div>
|
||||
|
||||
<div v-if="series.length" class="chart-outer">
|
||||
<div class="chart-scroll" :style="{ height: scrollHeight }" @mousemove="onMouseMove" @mouseleave="onMouseLeave">
|
||||
<UnstyledFlightChart
|
||||
type="bar"
|
||||
:height="chartHeight"
|
||||
:options="chartOptions"
|
||||
:series="chartSeries"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ChartTooltip :visible="!!tooltipItem" :x="tooltipX" :y="tooltipY">
|
||||
<div class="ct-name"><img :src="`${page.logo_api_url}/airlines/logos/tail/id/${tooltipItem?.id}`" width="24" height="24"/>{{ tooltipItem?.name }}</div>
|
||||
<div class="ct-row"><span class="ct-label">Flights</span><span class="ct-val">{{ tooltipItem?.past }}</span></div>
|
||||
<div class="ct-row" v-if="tooltipItem?.upcoming"><span class="ct-label">Upcoming</span><span class="ct-val">{{ tooltipItem?.upcoming }}</span></div>
|
||||
</ChartTooltip>
|
||||
|
||||
<div class="chart-footer">
|
||||
<span class="total-count">{{ totalAirlines }}</span>
|
||||
<span class="total-label">total airlines</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="chart-empty">No airline data available</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type {Flight, SharedProps} from '@/Types/types'
|
||||
import { FlightStats } from "@/Composables/useFlightStats"
|
||||
import { useChartTooltip } from '@/Composables/useChartTooltip'
|
||||
import ChartTooltip from '@/Components/FlightsGoneBy/Charts/ChartTooltip.vue'
|
||||
import {usePage} from "@inertiajs/vue3";
|
||||
import UnstyledFlightChart from "@/Components/FlightsGoneBy/UnstyledFlightChart.vue";
|
||||
|
||||
const page = usePage<SharedProps>().props
|
||||
|
||||
|
||||
const props = defineProps<{
|
||||
flights: Flight[]
|
||||
upcomingFlights: Flight[]
|
||||
}>()
|
||||
import { usePage } from "@inertiajs/vue3"
|
||||
import { SharedProps } from '@/Types/types'
|
||||
import ScrollingHorizontalBarChart from "@/Components/FlightsGoneBy/Charts/ChartTypes/ScrollingHorizontalBarChart.vue"
|
||||
import ChartTooltip from "@/Components/FlightsGoneBy/Charts/ChartTooltip.vue"
|
||||
|
||||
interface AirlineItem {
|
||||
name: string
|
||||
@@ -51,160 +14,50 @@ interface AirlineItem {
|
||||
id: number
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
flightStats: FlightStats
|
||||
}>()
|
||||
|
||||
const page = usePage<SharedProps>().props
|
||||
const { tooltipItem, tooltipX, tooltipY, onMouseMove, onMouseLeave } = useChartTooltip<AirlineItem>()
|
||||
|
||||
const MAX_VISIBLE = 12
|
||||
const BAR_HEIGHT = 32
|
||||
const airlines = computed(() => props.flightStats.topAirlines.value.airlines)
|
||||
|
||||
function countAirlines(flights: Flight[]): Map<string, { count: number; id: number }> {
|
||||
const counts = new Map<string, { count: number; id: number }>()
|
||||
flights.forEach(f => {
|
||||
const airline = f.airline
|
||||
if (!airline?.name) return
|
||||
const existing = counts.get(airline.name) ?? { count: 0, id: airline.id }
|
||||
existing.count++
|
||||
counts.set(airline.name, existing)
|
||||
})
|
||||
return counts
|
||||
}
|
||||
|
||||
const series = computed(() => {
|
||||
const past = countAirlines(props.flights)
|
||||
const upcoming = countAirlines(props.upcomingFlights)
|
||||
const allAirlines = new Set([...past.keys(), ...upcoming.keys()])
|
||||
return [...allAirlines]
|
||||
.map(name => ({
|
||||
name,
|
||||
id: (past.get(name) ?? upcoming.get(name))!.id,
|
||||
past: past.get(name)?.count ?? 0,
|
||||
upcoming: upcoming.get(name)?.count ?? 0,
|
||||
}))
|
||||
.sort((a, b) => (b.past + b.upcoming) - (a.past + a.upcoming))
|
||||
})
|
||||
|
||||
const totalAirlines = computed(() => series.value.length)
|
||||
const chartHeight = computed(() => series.value.length * BAR_HEIGHT + 40)
|
||||
const scrollHeight = computed(() => {
|
||||
const visible = Math.min(series.value.length, MAX_VISIBLE)
|
||||
return `${visible * BAR_HEIGHT + 40}px`
|
||||
})
|
||||
|
||||
const chartSeries = computed(() => [
|
||||
{ name: 'Flights', data: series.value.map(s => s.past) },
|
||||
{ name: 'Upcoming', data: series.value.map(s => s.upcoming) },
|
||||
])
|
||||
|
||||
const chartOptions = computed(() => ({
|
||||
chart: {
|
||||
type: 'bar',
|
||||
background: 'transparent',
|
||||
fontFamily: 'inherit',
|
||||
toolbar: { show: false },
|
||||
animations: { enabled: false },
|
||||
stacked: true,
|
||||
events: {
|
||||
mouseMove: (_e: MouseEvent, _chart: unknown, config: { dataPointIndex: number }) => {
|
||||
if (config.dataPointIndex < 0) { tooltipItem.value = null; return }
|
||||
tooltipItem.value = series.value[config.dataPointIndex] ?? null
|
||||
},
|
||||
mouseLeave: () => { tooltipItem.value = null },
|
||||
},
|
||||
},
|
||||
theme: { mode: 'dark' },
|
||||
plotOptions: {
|
||||
bar: {
|
||||
horizontal: true,
|
||||
barHeight: '60%',
|
||||
borderRadius: 3,
|
||||
borderRadiusWhenStacked: 'last',
|
||||
},
|
||||
},
|
||||
colors: ['#4da6ff', '#ffc107'],
|
||||
dataLabels: { enabled: false },
|
||||
xaxis: {
|
||||
categories: series.value.map(s => s.name),
|
||||
labels: { show: false },
|
||||
axisBorder: { show: false },
|
||||
axisTicks: { show: false },
|
||||
},
|
||||
yaxis: {
|
||||
labels: {
|
||||
style: { colors: '#778899', fontSize: '12px' },
|
||||
},
|
||||
},
|
||||
grid: { show: false },
|
||||
legend: {
|
||||
show: true,
|
||||
position: 'top',
|
||||
horizontalAlign: 'right',
|
||||
labels: { colors: '#778899' },
|
||||
markers: { width: 8, height: 8, radius: 2 },
|
||||
itemMargin: { horizontal: 8 },
|
||||
},
|
||||
tooltip: { enabled: false },
|
||||
states: {
|
||||
hover: { filter: { type: 'lighten', value: 0.1 } },
|
||||
const chartEvents = computed(() => ({
|
||||
mouseMove: (_e: MouseEvent, _chart: unknown, config: { dataPointIndex: number }) => {
|
||||
if (config.dataPointIndex < 0) { tooltipItem.value = null; return }
|
||||
tooltipItem.value = airlines.value[config.dataPointIndex] ?? null
|
||||
},
|
||||
mouseLeave: () => { tooltipItem.value = null },
|
||||
}))
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.chart-wrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.chart-title {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: #556677;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.chart-outer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.chart-scroll {
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #334455 transparent;
|
||||
}
|
||||
|
||||
.chart-scroll::-webkit-scrollbar { width: 4px; }
|
||||
.chart-scroll::-webkit-scrollbar-track { background: transparent; }
|
||||
.chart-scroll::-webkit-scrollbar-thumb { background: #334455; border-radius: 2px; }
|
||||
|
||||
.chart-footer {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 6px;
|
||||
padding-left: 4px;
|
||||
}
|
||||
|
||||
.total-count {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: #e0e6f0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.total-label {
|
||||
font-size: 13px;
|
||||
color: #556677;
|
||||
}
|
||||
|
||||
.chart-empty {
|
||||
height: 280px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 13px;
|
||||
color: #445566;
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<ScrollingHorizontalBarChart
|
||||
title="Top airlines"
|
||||
:series="flightStats.topAirlines.value.series"
|
||||
:categories="airlines.map(a => a.name)"
|
||||
:footer-value="airlines.length"
|
||||
footer-label="total airlines"
|
||||
:events="chartEvents"
|
||||
@mousemove="onMouseMove"
|
||||
@mouseleave="onMouseLeave"
|
||||
>
|
||||
<template #tooltip>
|
||||
<ChartTooltip :visible="!!tooltipItem" :x="tooltipX" :y="tooltipY">
|
||||
<div class="ct-name">
|
||||
<img :src="`${page.logo_api_url}/airlines/logos/tail/id/${tooltipItem?.id}`" width="24" height="24"/>
|
||||
{{ tooltipItem?.name }}
|
||||
</div>
|
||||
<div class="ct-row">
|
||||
<span class="ct-label">Flights</span>
|
||||
<span class="ct-val">{{ tooltipItem?.past }}</span>
|
||||
</div>
|
||||
<div class="ct-row" v-if="tooltipItem?.upcoming">
|
||||
<span class="ct-label">Upcoming</span>
|
||||
<span class="ct-val">{{ tooltipItem?.upcoming }}</span>
|
||||
</div>
|
||||
</ChartTooltip>
|
||||
</template>
|
||||
</ScrollingHorizontalBarChart>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user