@nuxtseo/pro-search 0.0.0-stage → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/app/components/BingSearchPerformance.vue +201 -0
- package/app/components/RankedSearchRow.vue +46 -0
- package/app/components/RankedSearchTable.vue +94 -0
- package/app/components/SearchConsoleTrend.vue +669 -0
- package/app/components/search-trend.ts +52 -0
- package/nuxt.config.ts +6 -0
- package/package.json +45 -3
- package/shared/bing-performance.ts +31 -0
- package/shared/compare-align.ts +123 -0
- package/shared/navigation.ts +14 -0
- package/shared/ranked-search.ts +7 -0
- package/shared/search-console-trend.ts +44 -0
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { SearchConsoleTrendDay as DataRow, SearchConsoleTrendProps } from '../../shared/search-console-trend'
|
|
3
|
+
import { getGscUnstableCutoffDate } from '@gscdump/sdk/period'
|
|
4
|
+
import { gscMetricColors } from '@nuxtseo/design-system/app/composables/dataVizColors'
|
|
5
|
+
import { formatGroupedNumber } from '@nuxtseo/design-system/app/composables/formatting'
|
|
6
|
+
import { useChartTickPlan } from '@nuxtseo/design-system/app/composables/useChartTickPlan'
|
|
7
|
+
import { Scale, TextAlign } from '@unovis/ts'
|
|
8
|
+
import { VisArea, VisAxis, VisCrosshair, VisLine, VisScatter, VisXYContainer } from '@unovis/vue'
|
|
9
|
+
import { useElementSize } from '@vueuse/core'
|
|
10
|
+
import { computed, useTemplateRef } from 'vue'
|
|
11
|
+
import { ClientOnly, UiButton, UiIcon, UiSkeleton } from '#components'
|
|
12
|
+
import { alignPrev, anchorOffsetDays, calendarChartRows, isolatedChartValue, resolveCompareAligner, toUtcDay } from '../../shared/compare-align'
|
|
13
|
+
|
|
14
|
+
const { value, dateRange, prevValue, fullValue, fullPrevValue, compareMode, compareOffsetDays, columns, height, loading, failure, connectionTo } = defineProps<SearchConsoleTrendProps>()
|
|
15
|
+
const chartFailure = computed(() => value.length ? null : failure)
|
|
16
|
+
|
|
17
|
+
// The metric colour is a CSS custom property a site may override, so mix it
|
|
18
|
+
// rather than parse hex. Mixing with `transparent` in srgb sets only the alpha.
|
|
19
|
+
function metricRgba(metric: keyof typeof gscMetricColors, opacity: number) {
|
|
20
|
+
return `color-mix(in srgb, ${gscMetricColors[metric].color} ${Math.round(opacity * 10000) / 100}%, transparent)`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const gscColors = {
|
|
24
|
+
clicks: { line: metricRgba('clicks', 0.9), area: 'url(#gradient-clicks)', prev: metricRgba('clicks', 0.3) },
|
|
25
|
+
impressions: { line: metricRgba('impressions', 0.7), area: 'url(#gradient-impressions)', prev: metricRgba('impressions', 0.3) },
|
|
26
|
+
ctr: { line: metricRgba('ctr', 0.9), prev: metricRgba('ctr', 0.3) },
|
|
27
|
+
position: { line: metricRgba('position', 0.9), prev: metricRgba('position', 0.3) },
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Shared config for overlaid containers. No horizontal inset — the line bleeds
|
|
31
|
+
// edge-to-edge (and brush/hover pixel→index math maps over the full wrap width,
|
|
32
|
+
// so a side margin would drift the hit-testing). Edge tick labels are kept
|
|
33
|
+
// inside via the text-anchor overrides in <style> below.
|
|
34
|
+
const margin = { left: 0, right: 0, top: 0, bottom: 36 }
|
|
35
|
+
const plotBleed = { left: 0, right: 0 }
|
|
36
|
+
const chartHeight = computed(() => Number(height) || 220)
|
|
37
|
+
const chartInnerHeight = computed(() => chartHeight.value - margin.top - margin.bottom)
|
|
38
|
+
|
|
39
|
+
const svgDefs = `
|
|
40
|
+
<linearGradient id="gradient-clicks" gradientTransform="rotate(90)">
|
|
41
|
+
<stop offset="0%" stop-color="${metricRgba('clicks', 0.25)}" />
|
|
42
|
+
<stop offset="100%" stop-color="${metricRgba('clicks', 0.01)}" />
|
|
43
|
+
</linearGradient>
|
|
44
|
+
<linearGradient id="gradient-impressions" gradientTransform="rotate(90)">
|
|
45
|
+
<stop offset="0%" stop-color="${metricRgba('impressions', 0.2)}" />
|
|
46
|
+
<stop offset="100%" stop-color="${metricRgba('impressions', 0.01)}" />
|
|
47
|
+
</linearGradient>`
|
|
48
|
+
|
|
49
|
+
// --- Comparison data handling ---
|
|
50
|
+
// Unovis applies accessors against the container's data, so we merge prev rows into
|
|
51
|
+
// `value` by calendar-date match (prev.date + 1 year = value.date) and expose them
|
|
52
|
+
// via accessor functions. Using a separate `:data` prop or a shifted x-accessor
|
|
53
|
+
// doesn't work: the former is ignored, the latter expands the x-domain and squishes
|
|
54
|
+
// the current line.
|
|
55
|
+
type MergedRow = DataRow & { prev?: DataRow }
|
|
56
|
+
// The compare series is the immediately-preceding period ('previous', the
|
|
57
|
+
// default) as often as it is year-over-year, so the overlay can't assume a fixed
|
|
58
|
+
// `year - 1` key. Prefer the authoritative window-derived offset (passed by the
|
|
59
|
+
// dashboard; correct even when the compare window's most recent day has no rows),
|
|
60
|
+
// and fall back to anchoring on the most recent day of each series for callers
|
|
61
|
+
// without window context (chat / demo embeds). See `compare-align.ts`.
|
|
62
|
+
const compareAligner = computed(() => {
|
|
63
|
+
const offset = compareOffsetDays ?? (prevValue?.length ? anchorOffsetDays(value, prevValue) : null)
|
|
64
|
+
return resolveCompareAligner(compareMode, offset)
|
|
65
|
+
})
|
|
66
|
+
const calendarValue = computed(() => calendarChartRows(value, dateRange))
|
|
67
|
+
// Unovis Area converts missing values to zero. Fill only observed calendars.
|
|
68
|
+
const clicksComplete = computed(() => calendarValue.value.every(row => Number.isFinite(row.clicks)))
|
|
69
|
+
const impressionsComplete = computed(() => calendarValue.value.every(row => Number.isFinite(row.impressions)))
|
|
70
|
+
const mergedValue = computed<MergedRow[]>(() => alignPrev(calendarValue.value, prevValue, compareAligner.value))
|
|
71
|
+
|
|
72
|
+
const hasComparison = computed(() => mergedValue.value.some(r => r.prev))
|
|
73
|
+
|
|
74
|
+
// NaN y-values break the cubic curve cleanly (d3-shape's default `defined` skips them),
|
|
75
|
+
// so the dashed line only renders across indices where prev data is present.
|
|
76
|
+
const prevClicks = (d: MergedRow) => d.prev?.clicks ?? Number.NaN
|
|
77
|
+
const prevImpressions = (d: MergedRow) => d.prev?.impressions ?? Number.NaN
|
|
78
|
+
// Rate and rank values require impressions. Missing observations leave gaps.
|
|
79
|
+
function observedMetric(row: DataRow, metric: 'ctr' | 'position'): number | undefined {
|
|
80
|
+
const value = row[metric]
|
|
81
|
+
if (!(row.impressions > 0) || !Number.isFinite(value) || (metric === 'position' && value < 1))
|
|
82
|
+
return undefined
|
|
83
|
+
return value
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const prevCtr = (d: MergedRow) => d.prev ? (observedMetric(d.prev, 'ctr') ?? Number.NaN) * 100 : Number.NaN
|
|
87
|
+
const prevPosition = (d: MergedRow) => d.prev ? observedMetric(d.prev, 'position') ?? Number.NaN : Number.NaN
|
|
88
|
+
|
|
89
|
+
// --- Calendar-aware tick planning ---
|
|
90
|
+
// The observed wrap width feeds the plan: at phone widths the span heuristics
|
|
91
|
+
// would crowd labels, so ticks that would collide are dropped reactively.
|
|
92
|
+
const chartEl = useTemplateRef<HTMLElement>('chartEl')
|
|
93
|
+
const { width: chartWidth } = useElementSize(chartEl)
|
|
94
|
+
const { tickPlan, tickFormat } = useChartTickPlan({ dates: () => calendarValue.value.map(v => v.date), width: chartWidth })
|
|
95
|
+
|
|
96
|
+
// With zero horizontal margin a centred label on an edge tick would half-clip
|
|
97
|
+
// outside the svg; anchor it inward instead — but only when the plan actually
|
|
98
|
+
// places a tick on the first/last data point (long spans often don't).
|
|
99
|
+
const firstTickAtEdge = computed(() => tickPlan.value.indices[0] === 0)
|
|
100
|
+
const lastTickAtEdge = computed(() => tickPlan.value.indices.at(-1) === calendarValue.value.length - 1)
|
|
101
|
+
|
|
102
|
+
// --- Unstable/estimated data detection ---
|
|
103
|
+
const unstableCutoffDate = computed(() => getGscUnstableCutoffDate())
|
|
104
|
+
|
|
105
|
+
const unstableCount = computed(() => {
|
|
106
|
+
if (!calendarValue.value.length)
|
|
107
|
+
return 0
|
|
108
|
+
const cutoff = unstableCutoffDate.value
|
|
109
|
+
let count = 0
|
|
110
|
+
for (let i = calendarValue.value.length - 1; i >= 0; i--) {
|
|
111
|
+
if ((calendarValue.value[i]?.date ?? '') > cutoff)
|
|
112
|
+
count++
|
|
113
|
+
else break
|
|
114
|
+
}
|
|
115
|
+
return count
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
// Width percentage for the unstable overlay (from right edge)
|
|
119
|
+
const unstableWidthPct = computed(() => {
|
|
120
|
+
if (!unstableCount.value || calendarValue.value.length < 2)
|
|
121
|
+
return 0
|
|
122
|
+
return Math.min(100, (unstableCount.value - 0.5) / (calendarValue.value.length - 1) * 100)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
// Use the full (unzoomed) series for y-domain calcs when provided, so zooming keeps
|
|
126
|
+
// the value-axis scale stable. Falls back to current value/prev when not zooming.
|
|
127
|
+
const allData = computed(() => {
|
|
128
|
+
const cur = fullValue ?? value
|
|
129
|
+
const prev = fullPrevValue !== undefined ? fullPrevValue : prevValue
|
|
130
|
+
return [...cur, ...(prev || [])]
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
// Separate domain for each metric so each uses full chart height
|
|
134
|
+
const clicksDomain = computed<[number, number]>(() => {
|
|
135
|
+
if (!allData.value.length)
|
|
136
|
+
return [0, 1]
|
|
137
|
+
const max = Math.max(...allData.value.map(d => d.clicks), 1)
|
|
138
|
+
return [0, max * 1.1]
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
const impressionsDomain = computed<[number, number]>(() => {
|
|
142
|
+
if (!allData.value.length)
|
|
143
|
+
return [0, 1]
|
|
144
|
+
const max = Math.max(...allData.value.map(d => d.impressions), 1)
|
|
145
|
+
return [0, max * 1.1]
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
// Use Scale for CTR and Position (they need custom ranges)
|
|
149
|
+
const ctrScale = computed(() => {
|
|
150
|
+
const ctrs = allData.value.flatMap(d => observedMetric(d, 'ctr') == null ? [] : [d.ctr * 100])
|
|
151
|
+
const min = ctrs.length ? Math.min(...ctrs) : 0
|
|
152
|
+
const max = ctrs.length ? Math.max(...ctrs) : 10
|
|
153
|
+
const padding = (max - min) * 0.1 || 1
|
|
154
|
+
return Scale.scaleLinear()
|
|
155
|
+
.domain([Math.max(0, min - padding), max + padding])
|
|
156
|
+
.range([chartInnerHeight.value, 0])
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
// Position scale inverted: lower position = higher on chart
|
|
160
|
+
const positionScale = computed(() => {
|
|
161
|
+
const positions = allData.value.flatMap(d => observedMetric(d, 'position') == null ? [] : [d.position])
|
|
162
|
+
const min = positions.length ? Math.min(...positions) : 1
|
|
163
|
+
const max = positions.length ? Math.max(...positions) : 100
|
|
164
|
+
const padding = (max - min) * 0.1 || 1
|
|
165
|
+
return Scale.scaleLinear()
|
|
166
|
+
.domain([max + padding, Math.max(1, min - padding)])
|
|
167
|
+
.range([chartInnerHeight.value, 0]) // inverted: high position = low on chart
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
// Force re-mount all containers when data changes (date range switch)
|
|
171
|
+
// Use length + first/last date to catch same-length but different-range transitions
|
|
172
|
+
const chartKey = computed(() => {
|
|
173
|
+
const len = calendarValue.value.length
|
|
174
|
+
const first = calendarValue.value[0]?.date ?? ''
|
|
175
|
+
const last = calendarValue.value[len - 1]?.date ?? ''
|
|
176
|
+
return `${len}-${first}-${last}`
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
// Accessors
|
|
180
|
+
const calendarStart = computed(() => toUtcDay(calendarValue.value[0]?.date ?? '1970-01-01'))
|
|
181
|
+
const x = (d: DataRow) => (toUtcDay(d.date) - calendarStart.value) / 86_400_000
|
|
182
|
+
const clicks = (d: DataRow) => d.clicks
|
|
183
|
+
const impressions = (d: DataRow) => d.impressions
|
|
184
|
+
const ctr = (d: DataRow) => (observedMetric(d, 'ctr') ?? Number.NaN) * 100
|
|
185
|
+
const position = (d: DataRow) => observedMetric(d, 'position') ?? Number.NaN
|
|
186
|
+
|
|
187
|
+
// Keep observed provisional values distinct from the solid stable segment.
|
|
188
|
+
// Both segments share the cutoff point so adjacent observations connect;
|
|
189
|
+
// calendar NaNs still break either line instead of inventing a zero or bridge.
|
|
190
|
+
const stableMetric = (metric: (row: DataRow) => number) => (row: DataRow) => row.date <= unstableCutoffDate.value ? metric(row) : Number.NaN
|
|
191
|
+
const provisionalMetric = (metric: (row: DataRow) => number) => (row: DataRow) => row.date >= unstableCutoffDate.value ? metric(row) : Number.NaN
|
|
192
|
+
const stableClicks = stableMetric(clicks)
|
|
193
|
+
const stableImpressions = stableMetric(impressions)
|
|
194
|
+
const stableCtr = stableMetric(ctr)
|
|
195
|
+
const stablePosition = stableMetric(position)
|
|
196
|
+
const provisionalClicks = provisionalMetric(clicks)
|
|
197
|
+
const provisionalImpressions = provisionalMetric(impressions)
|
|
198
|
+
const provisionalCtr = provisionalMetric(ctr)
|
|
199
|
+
const provisionalPosition = provisionalMetric(position)
|
|
200
|
+
|
|
201
|
+
const isolatedClicks = computed(() => isolatedChartValue(mergedValue.value, clicks))
|
|
202
|
+
const isolatedPrevClicks = computed(() => isolatedChartValue(mergedValue.value, prevClicks))
|
|
203
|
+
const isolatedImpressions = computed(() => isolatedChartValue(mergedValue.value, impressions))
|
|
204
|
+
const isolatedPrevImpressions = computed(() => isolatedChartValue(mergedValue.value, prevImpressions))
|
|
205
|
+
const isolatedCtr = computed(() => isolatedChartValue(mergedValue.value, ctr))
|
|
206
|
+
const isolatedPrevCtr = computed(() => isolatedChartValue(mergedValue.value, prevCtr))
|
|
207
|
+
const isolatedPosition = computed(() => isolatedChartValue(mergedValue.value, position))
|
|
208
|
+
const isolatedPrevPosition = computed(() => isolatedChartValue(mergedValue.value, prevPosition))
|
|
209
|
+
|
|
210
|
+
const metricLabels = { clicks: 'Clicks', impressions: 'Impressions', ctr: 'CTR', position: 'Avg. position' }
|
|
211
|
+
type Metric = keyof typeof metricLabels
|
|
212
|
+
const visibleMetrics = computed(() => (columns ?? []).filter((metric): metric is Metric => Object.hasOwn(metricLabels, metric)))
|
|
213
|
+
const accessibleRows = computed(() => mergedValue.value.flatMap((row) => {
|
|
214
|
+
const current = { period: 'Current period', value: row }
|
|
215
|
+
return row.prev ? [current, { period: 'Previous period', value: row.prev }] : [current]
|
|
216
|
+
}))
|
|
217
|
+
function accessibleValue(row: DataRow, metric: Metric): string {
|
|
218
|
+
const value = metric === 'ctr' || metric === 'position' ? observedMetric(row, metric) : row[metric]
|
|
219
|
+
if (value == null || !Number.isFinite(value))
|
|
220
|
+
return '—'
|
|
221
|
+
if (metric === 'ctr')
|
|
222
|
+
return `${(value * 100).toFixed(2)}%`
|
|
223
|
+
if (metric === 'position')
|
|
224
|
+
return value.toFixed(1)
|
|
225
|
+
return formatGroupedNumber(value)
|
|
226
|
+
}
|
|
227
|
+
</script>
|
|
228
|
+
|
|
229
|
+
<template>
|
|
230
|
+
<div
|
|
231
|
+
ref="chartEl"
|
|
232
|
+
data-ui="ProGraphGsc"
|
|
233
|
+
class="gsc-chart"
|
|
234
|
+
:class="{ 'tick-edge-first': firstTickAtEdge, 'tick-edge-last': lastTickAtEdge }"
|
|
235
|
+
:aria-busy="loading || undefined"
|
|
236
|
+
:style="{ height: `${chartHeight}px` }"
|
|
237
|
+
>
|
|
238
|
+
<!-- Read failed. Shown ahead of the skeleton and the empty copy: a site that
|
|
239
|
+
errored is neither loading nor freshly connected, and saying otherwise
|
|
240
|
+
sends the user off waiting for a sync that already finished. -->
|
|
241
|
+
<div
|
|
242
|
+
v-if="chartFailure"
|
|
243
|
+
class="flex flex-col items-center justify-center h-full text-center gap-1"
|
|
244
|
+
role="status"
|
|
245
|
+
>
|
|
246
|
+
<UiIcon name="alert-triangle" class="size-4 text-dimmed" aria-hidden="true" />
|
|
247
|
+
<p class="text-sm text-muted">
|
|
248
|
+
{{ chartFailure._tag === 'property-unavailable' ? 'Search Console property not found.' : chartFailure.message }}
|
|
249
|
+
</p>
|
|
250
|
+
<p class="text-xs text-dimmed">
|
|
251
|
+
{{ chartFailure._tag === 'property-unavailable' ? 'Review the connected property for this site.' : 'Your existing data is safe. This is a read failure, not data loss.' }}
|
|
252
|
+
</p>
|
|
253
|
+
<UiButton
|
|
254
|
+
v-if="chartFailure._tag === 'property-unavailable' && connectionTo"
|
|
255
|
+
size="xs"
|
|
256
|
+
purpose="quiet"
|
|
257
|
+
:to="connectionTo"
|
|
258
|
+
>
|
|
259
|
+
Review connection
|
|
260
|
+
</UiButton>
|
|
261
|
+
</div>
|
|
262
|
+
|
|
263
|
+
<!-- Loading skeleton -->
|
|
264
|
+
<div v-else-if="loading" class="loading-skeleton">
|
|
265
|
+
<div class="flex-1 flex items-end gap-1">
|
|
266
|
+
<div v-for="i in 30" :key="i" class="flex-1 h-full flex">
|
|
267
|
+
<UiSkeleton type="bar" :index="i" />
|
|
268
|
+
</div>
|
|
269
|
+
</div>
|
|
270
|
+
<div class="flex justify-between mt-3">
|
|
271
|
+
<UiSkeleton v-for="i in 5" :key="i" class="h-3" :base="44" :range="8" />
|
|
272
|
+
</div>
|
|
273
|
+
</div>
|
|
274
|
+
|
|
275
|
+
<!-- Not enough data for chart (need >=2 points for lines) -->
|
|
276
|
+
<div v-else-if="value.length < 2" class="flex flex-col items-center justify-center h-full text-center gap-1">
|
|
277
|
+
<!-- Deliberately does NOT claim a sync is pending. The genuine
|
|
278
|
+
not-connected / still-syncing case is caught upstream by the page's
|
|
279
|
+
sample-data overlay, which actually knows the lifecycle state; this
|
|
280
|
+
branch only knows the window came back empty. Asserting "~5 min after
|
|
281
|
+
connect" here told a user with ten days of synced data to go wait. -->
|
|
282
|
+
<p class="text-sm text-muted">
|
|
283
|
+
{{ value.length === 0 ? 'No search impressions in this period.' : 'First day of GSC data is in; trend renders once we have 2+' }}
|
|
284
|
+
</p>
|
|
285
|
+
<p class="text-xs text-dimmed">
|
|
286
|
+
{{ value.length === 0 ? 'Try a wider date range.' : 'Check back tomorrow for the trend line.' }}
|
|
287
|
+
</p>
|
|
288
|
+
</div>
|
|
289
|
+
|
|
290
|
+
<ClientOnly v-else>
|
|
291
|
+
<!-- Estimated data region indicator (discovered via hover tooltip) -->
|
|
292
|
+
<div
|
|
293
|
+
v-if="unstableWidthPct > 0"
|
|
294
|
+
class="estimated-region"
|
|
295
|
+
:style="{ width: `${unstableWidthPct}%`, bottom: `${margin.bottom}px` }"
|
|
296
|
+
>
|
|
297
|
+
<div class="estimated-tint" />
|
|
298
|
+
<div class="estimated-separator" />
|
|
299
|
+
</div>
|
|
300
|
+
|
|
301
|
+
<!-- Layer 1: Impressions -->
|
|
302
|
+
<VisXYContainer
|
|
303
|
+
v-if="columns?.includes('impressions')"
|
|
304
|
+
:key="`impressions-${chartKey}`"
|
|
305
|
+
:height="chartHeight"
|
|
306
|
+
:data="mergedValue"
|
|
307
|
+
:svg-defs="svgDefs"
|
|
308
|
+
:margin="margin"
|
|
309
|
+
:auto-margin="false"
|
|
310
|
+
:bleed="plotBleed"
|
|
311
|
+
:clip-path-extend="4"
|
|
312
|
+
class="chart-layer"
|
|
313
|
+
aria-hidden="true"
|
|
314
|
+
:y-domain="impressionsDomain"
|
|
315
|
+
>
|
|
316
|
+
<VisLine
|
|
317
|
+
v-if="hasComparison"
|
|
318
|
+
curve-type="monotoneX"
|
|
319
|
+
:x="x"
|
|
320
|
+
:y="prevImpressions"
|
|
321
|
+
:color="gscColors.impressions.prev"
|
|
322
|
+
:line-width="1.5"
|
|
323
|
+
:line-dash-array="[6, 4]"
|
|
324
|
+
/>
|
|
325
|
+
<VisArea
|
|
326
|
+
v-if="impressionsComplete"
|
|
327
|
+
:color="gscColors.impressions.area"
|
|
328
|
+
curve-type="monotoneX"
|
|
329
|
+
:x="x"
|
|
330
|
+
:y="impressions"
|
|
331
|
+
/>
|
|
332
|
+
<VisLine
|
|
333
|
+
curve-type="monotoneX"
|
|
334
|
+
:x="x"
|
|
335
|
+
:y="stableImpressions"
|
|
336
|
+
:color="gscColors.impressions.line"
|
|
337
|
+
:line-width="2"
|
|
338
|
+
/>
|
|
339
|
+
<VisLine
|
|
340
|
+
v-if="unstableCount > 0"
|
|
341
|
+
curve-type="monotoneX"
|
|
342
|
+
:x="x"
|
|
343
|
+
:y="provisionalImpressions"
|
|
344
|
+
:color="gscColors.impressions.line"
|
|
345
|
+
:line-width="2"
|
|
346
|
+
:line-dash-array="[2, 3]"
|
|
347
|
+
/>
|
|
348
|
+
<VisScatter v-if="hasComparison" :x="x" :y="isolatedPrevImpressions" :color="gscColors.impressions.prev" :size="6" />
|
|
349
|
+
<VisScatter :x="x" :y="isolatedImpressions" :color="gscColors.impressions.line" :size="6" />
|
|
350
|
+
</VisXYContainer>
|
|
351
|
+
|
|
352
|
+
<!-- Layer 2: Clicks -->
|
|
353
|
+
<VisXYContainer
|
|
354
|
+
v-if="columns?.includes('clicks')"
|
|
355
|
+
:key="`clicks-${chartKey}`"
|
|
356
|
+
:height="chartHeight"
|
|
357
|
+
:data="mergedValue"
|
|
358
|
+
:svg-defs="svgDefs"
|
|
359
|
+
:margin="margin"
|
|
360
|
+
:auto-margin="false"
|
|
361
|
+
:bleed="plotBleed"
|
|
362
|
+
:clip-path-extend="4"
|
|
363
|
+
class="chart-layer"
|
|
364
|
+
aria-hidden="true"
|
|
365
|
+
:y-domain="clicksDomain"
|
|
366
|
+
>
|
|
367
|
+
<VisLine
|
|
368
|
+
v-if="hasComparison"
|
|
369
|
+
curve-type="monotoneX"
|
|
370
|
+
:x="x"
|
|
371
|
+
:y="prevClicks"
|
|
372
|
+
:color="gscColors.clicks.prev"
|
|
373
|
+
:line-width="1.5"
|
|
374
|
+
:line-dash-array="[6, 4]"
|
|
375
|
+
/>
|
|
376
|
+
<VisArea
|
|
377
|
+
v-if="clicksComplete"
|
|
378
|
+
:color="gscColors.clicks.area"
|
|
379
|
+
curve-type="monotoneX"
|
|
380
|
+
:x="x"
|
|
381
|
+
:y="clicks"
|
|
382
|
+
/>
|
|
383
|
+
<VisLine
|
|
384
|
+
curve-type="monotoneX"
|
|
385
|
+
:x="x"
|
|
386
|
+
:y="stableClicks"
|
|
387
|
+
:color="gscColors.clicks.line"
|
|
388
|
+
:line-width="2"
|
|
389
|
+
/>
|
|
390
|
+
<VisLine
|
|
391
|
+
v-if="unstableCount > 0"
|
|
392
|
+
curve-type="monotoneX"
|
|
393
|
+
:x="x"
|
|
394
|
+
:y="provisionalClicks"
|
|
395
|
+
:color="gscColors.clicks.line"
|
|
396
|
+
:line-width="2"
|
|
397
|
+
:line-dash-array="[2, 3]"
|
|
398
|
+
/>
|
|
399
|
+
<VisScatter v-if="hasComparison" :x="x" :y="isolatedPrevClicks" :color="gscColors.clicks.prev" :size="6" />
|
|
400
|
+
<VisScatter :x="x" :y="isolatedClicks" :color="gscColors.clicks.line" :size="6" />
|
|
401
|
+
</VisXYContainer>
|
|
402
|
+
|
|
403
|
+
<!-- Layer 3: CTR metric -->
|
|
404
|
+
<VisXYContainer
|
|
405
|
+
v-if="columns?.includes('ctr')"
|
|
406
|
+
:key="`ctr-${chartKey}`"
|
|
407
|
+
:height="chartHeight"
|
|
408
|
+
:data="mergedValue"
|
|
409
|
+
:margin="margin"
|
|
410
|
+
:auto-margin="false"
|
|
411
|
+
:bleed="plotBleed"
|
|
412
|
+
:clip-path-extend="4"
|
|
413
|
+
class="chart-layer"
|
|
414
|
+
aria-hidden="true"
|
|
415
|
+
>
|
|
416
|
+
<VisLine
|
|
417
|
+
v-if="hasComparison"
|
|
418
|
+
curve-type="monotoneX"
|
|
419
|
+
:x="x"
|
|
420
|
+
:y="prevCtr"
|
|
421
|
+
:y-scale="ctrScale"
|
|
422
|
+
:color="gscColors.ctr.prev"
|
|
423
|
+
:line-width="1.5"
|
|
424
|
+
:line-dash-array="[6, 4]"
|
|
425
|
+
/>
|
|
426
|
+
<VisLine
|
|
427
|
+
curve-type="monotoneX"
|
|
428
|
+
:x="x"
|
|
429
|
+
:y="stableCtr"
|
|
430
|
+
:y-scale="ctrScale"
|
|
431
|
+
:color="gscColors.ctr.line"
|
|
432
|
+
:line-width="2"
|
|
433
|
+
/>
|
|
434
|
+
<VisLine
|
|
435
|
+
v-if="unstableCount > 0"
|
|
436
|
+
curve-type="monotoneX"
|
|
437
|
+
:x="x"
|
|
438
|
+
:y="provisionalCtr"
|
|
439
|
+
:y-scale="ctrScale"
|
|
440
|
+
:color="gscColors.ctr.line"
|
|
441
|
+
:line-width="2"
|
|
442
|
+
:line-dash-array="[2, 3]"
|
|
443
|
+
/>
|
|
444
|
+
<VisScatter v-if="hasComparison" :x="x" :y="isolatedPrevCtr" :y-scale="ctrScale" :color="gscColors.ctr.prev" :size="6" />
|
|
445
|
+
<VisScatter :x="x" :y="isolatedCtr" :y-scale="ctrScale" :color="gscColors.ctr.line" :size="6" />
|
|
446
|
+
</VisXYContainer>
|
|
447
|
+
|
|
448
|
+
<!-- Layer 4: Position metric (inverted scale) -->
|
|
449
|
+
<VisXYContainer
|
|
450
|
+
v-if="columns?.includes('position')"
|
|
451
|
+
:key="`position-${chartKey}`"
|
|
452
|
+
:height="chartHeight"
|
|
453
|
+
:data="mergedValue"
|
|
454
|
+
:margin="margin"
|
|
455
|
+
:auto-margin="false"
|
|
456
|
+
:bleed="plotBleed"
|
|
457
|
+
:clip-path-extend="4"
|
|
458
|
+
class="chart-layer"
|
|
459
|
+
aria-hidden="true"
|
|
460
|
+
>
|
|
461
|
+
<VisLine
|
|
462
|
+
v-if="hasComparison"
|
|
463
|
+
curve-type="monotoneX"
|
|
464
|
+
:x="x"
|
|
465
|
+
:y="prevPosition"
|
|
466
|
+
:y-scale="positionScale"
|
|
467
|
+
:color="gscColors.position.prev"
|
|
468
|
+
:line-width="1.5"
|
|
469
|
+
:line-dash-array="[6, 4]"
|
|
470
|
+
/>
|
|
471
|
+
<VisLine
|
|
472
|
+
curve-type="monotoneX"
|
|
473
|
+
:x="x"
|
|
474
|
+
:y="stablePosition"
|
|
475
|
+
:y-scale="positionScale"
|
|
476
|
+
:color="gscColors.position.line"
|
|
477
|
+
:line-width="2"
|
|
478
|
+
/>
|
|
479
|
+
<VisLine
|
|
480
|
+
v-if="unstableCount > 0"
|
|
481
|
+
curve-type="monotoneX"
|
|
482
|
+
:x="x"
|
|
483
|
+
:y="provisionalPosition"
|
|
484
|
+
:y-scale="positionScale"
|
|
485
|
+
:color="gscColors.position.line"
|
|
486
|
+
:line-width="2"
|
|
487
|
+
:line-dash-array="[2, 3]"
|
|
488
|
+
/>
|
|
489
|
+
<VisScatter v-if="hasComparison" :x="x" :y="isolatedPrevPosition" :y-scale="positionScale" :color="gscColors.position.prev" :size="6" />
|
|
490
|
+
<VisScatter :x="x" :y="isolatedPosition" :y-scale="positionScale" :color="gscColors.position.line" :size="6" />
|
|
491
|
+
</VisXYContainer>
|
|
492
|
+
|
|
493
|
+
<!-- Layer 5: X-Axis + Crosshair (topmost, captures all pointer events) -->
|
|
494
|
+
<VisXYContainer
|
|
495
|
+
:key="`interactive-${chartKey}`"
|
|
496
|
+
:height="chartHeight"
|
|
497
|
+
:data="mergedValue"
|
|
498
|
+
:margin="margin"
|
|
499
|
+
:auto-margin="false"
|
|
500
|
+
:bleed="plotBleed"
|
|
501
|
+
:clip-path-extend="4"
|
|
502
|
+
class="chart-layer chart-layer--interactive"
|
|
503
|
+
aria-hidden="true"
|
|
504
|
+
>
|
|
505
|
+
<!-- Invisible line so the crosshair has data points to snap to -->
|
|
506
|
+
<VisLine :x="x" :y="clicks" color="transparent" :line-width="0" />
|
|
507
|
+
<VisAxis
|
|
508
|
+
type="x"
|
|
509
|
+
:tick-line="false"
|
|
510
|
+
:grid-line="false"
|
|
511
|
+
:domain-line="false"
|
|
512
|
+
:tick-values="tickPlan.indices"
|
|
513
|
+
:tick-format="tickFormat"
|
|
514
|
+
:tick-text-align="TextAlign.Center"
|
|
515
|
+
tick-text-font-size="11px"
|
|
516
|
+
tick-text-color="var(--ui-text-dimmed)"
|
|
517
|
+
/>
|
|
518
|
+
<!-- VisCrosshair renders only the snap-to-point indicator line; the
|
|
519
|
+
tooltip is owned by the parent card (driven by pointermove against
|
|
520
|
+
the wrap div, not by this template callback). VisTooltip is omitted
|
|
521
|
+
because Unovis portals it to document.body and the empty box leaks
|
|
522
|
+
through as a second tooltip on top of UiChartTooltip. -->
|
|
523
|
+
<VisCrosshair :x="x" :y="clicks" color="none" :template="() => ''" />
|
|
524
|
+
</VisXYContainer>
|
|
525
|
+
|
|
526
|
+
<template #fallback>
|
|
527
|
+
<div class="loading-skeleton">
|
|
528
|
+
<div class="flex-1 flex items-end gap-1">
|
|
529
|
+
<div v-for="i in 30" :key="i" class="flex-1">
|
|
530
|
+
<UiSkeleton type="bar" :index="i" />
|
|
531
|
+
</div>
|
|
532
|
+
</div>
|
|
533
|
+
<div class="flex justify-between mt-3">
|
|
534
|
+
<UiSkeleton v-for="i in 5" :key="i" class="h-3" :base="44" :range="8" />
|
|
535
|
+
</div>
|
|
536
|
+
</div>
|
|
537
|
+
</template>
|
|
538
|
+
</ClientOnly>
|
|
539
|
+
<div v-if="!loading && value.length >= 2" class="sr-only">
|
|
540
|
+
<!-- Screen reader equivalent of the visual chart, permitted raw table exception. -->
|
|
541
|
+
<!-- eslint-disable-next-line vue/no-restricted-syntax -->
|
|
542
|
+
<table>
|
|
543
|
+
<caption>Search console performance chart</caption>
|
|
544
|
+
<thead>
|
|
545
|
+
<tr>
|
|
546
|
+
<th scope="col">
|
|
547
|
+
Date
|
|
548
|
+
</th>
|
|
549
|
+
<th scope="col">
|
|
550
|
+
Period
|
|
551
|
+
</th>
|
|
552
|
+
<th v-for="metric in visibleMetrics" :key="metric" scope="col">
|
|
553
|
+
{{ metricLabels[metric] }}
|
|
554
|
+
</th>
|
|
555
|
+
</tr>
|
|
556
|
+
</thead>
|
|
557
|
+
<tbody>
|
|
558
|
+
<tr v-for="row in accessibleRows" :key="`${row.period}-${row.value.date}`">
|
|
559
|
+
<th scope="row">
|
|
560
|
+
{{ row.value.date }}
|
|
561
|
+
</th>
|
|
562
|
+
<td>{{ row.period }}</td>
|
|
563
|
+
<td v-for="metric in visibleMetrics" :key="metric">
|
|
564
|
+
{{ accessibleValue(row.value, metric) }}
|
|
565
|
+
</td>
|
|
566
|
+
</tr>
|
|
567
|
+
</tbody>
|
|
568
|
+
</table>
|
|
569
|
+
</div>
|
|
570
|
+
</div>
|
|
571
|
+
</template>
|
|
572
|
+
|
|
573
|
+
<style scoped>
|
|
574
|
+
[data-ui="ProGraphGsc"] :deep(.unovis-area-group path) {
|
|
575
|
+
stroke: none;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
.gsc-chart {
|
|
579
|
+
display: grid;
|
|
580
|
+
/* minmax(0, …): a bare 1fr track floors at the stacked SVGs' width, so the
|
|
581
|
+
chart grew with the window but never shrank back and pushed the page into
|
|
582
|
+
a horizontal scroll. */
|
|
583
|
+
grid-template-columns: minmax(0, 1fr);
|
|
584
|
+
position: relative;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
.gsc-chart .chart-layer,
|
|
588
|
+
.gsc-chart .loading-skeleton {
|
|
589
|
+
grid-column-start: 1;
|
|
590
|
+
grid-row-start: 1;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/* Data layers are visual only — no pointer events */
|
|
594
|
+
.gsc-chart .chart-layer {
|
|
595
|
+
pointer-events: none;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/* Only the crosshair/axis layer captures mouse interaction */
|
|
599
|
+
.gsc-chart .chart-layer--interactive {
|
|
600
|
+
pointer-events: auto;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/* Subtle crosshair line, no circle markers */
|
|
604
|
+
.gsc-chart .chart-layer--interactive {
|
|
605
|
+
--vis-crosshair-line-stroke-color: var(--ui-border-accented);
|
|
606
|
+
--vis-crosshair-line-stroke-opacity: 0.6;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/* Hide the empty tooltip container (we render tooltip in the parent) */
|
|
610
|
+
.gsc-chart .chart-layer--interactive :deep(.unovis-tooltip) {
|
|
611
|
+
display: none;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/* Zero horizontal margin: anchor edge tick labels inward so they don't clip at
|
|
615
|
+
the svg boundary. Unovis sets text-anchor as an SVG attribute, which CSS
|
|
616
|
+
outranks; d3-axis keeps tick <g>s DOM-ordered by value, so first/last-of-type
|
|
617
|
+
are the leftmost/rightmost ticks. */
|
|
618
|
+
.gsc-chart.tick-edge-first :deep(g.tick:first-of-type > text) {
|
|
619
|
+
text-anchor: start;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
.gsc-chart.tick-edge-last :deep(g.tick:last-of-type > text) {
|
|
623
|
+
text-anchor: end;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/* Estimated data region */
|
|
627
|
+
.estimated-region {
|
|
628
|
+
position: absolute;
|
|
629
|
+
top: 0;
|
|
630
|
+
right: 0;
|
|
631
|
+
pointer-events: none;
|
|
632
|
+
z-index: 5;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
.estimated-tint {
|
|
636
|
+
position: absolute;
|
|
637
|
+
inset: 0;
|
|
638
|
+
background: linear-gradient(
|
|
639
|
+
to right,
|
|
640
|
+
transparent,
|
|
641
|
+
color-mix(in srgb, var(--ui-bg) 60%, transparent) 40%
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
.estimated-separator {
|
|
646
|
+
position: absolute;
|
|
647
|
+
left: 0;
|
|
648
|
+
top: 0;
|
|
649
|
+
bottom: 0;
|
|
650
|
+
width: 1px;
|
|
651
|
+
background: repeating-linear-gradient(
|
|
652
|
+
to bottom,
|
|
653
|
+
var(--ui-text-dimmed) 0,
|
|
654
|
+
var(--ui-text-dimmed) 3px,
|
|
655
|
+
transparent 3px,
|
|
656
|
+
transparent 7px
|
|
657
|
+
);
|
|
658
|
+
opacity: 0.35;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
.loading-skeleton {
|
|
662
|
+
display: flex;
|
|
663
|
+
flex-direction: column;
|
|
664
|
+
justify-content: end;
|
|
665
|
+
padding-bottom: 2rem;
|
|
666
|
+
padding-left: 0.5rem;
|
|
667
|
+
padding-right: 0.5rem;
|
|
668
|
+
}
|
|
669
|
+
</style>
|