Legend tooltips
Этот коммит содержится в:
родитель
f7e548906b
Коммит
3242bc17cb
@ -7,6 +7,8 @@
|
|||||||
export let hoveredEventData;
|
export let hoveredEventData;
|
||||||
export let width;
|
export let width;
|
||||||
|
|
||||||
|
$: console.log(hoveredEventData)
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@ -25,7 +27,6 @@
|
|||||||
<style>
|
<style>
|
||||||
.event-tooltip {
|
.event-tooltip {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
/*border: 1px solid #ccc;*/
|
|
||||||
background: rgba(255, 255, 255, 0.95);
|
background: rgba(255, 255, 255, 0.95);
|
||||||
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
|
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
|||||||
@ -3,6 +3,10 @@
|
|||||||
export let margins
|
export let margins
|
||||||
export let radiusScale
|
export let radiusScale
|
||||||
export let opacityScale
|
export let opacityScale
|
||||||
|
export let tooltipX
|
||||||
|
export let tooltipY
|
||||||
|
export let hoveredLegendData
|
||||||
|
export let showLegendTooltip
|
||||||
|
|
||||||
$: minOpacity = opacityScale.domain()[0]
|
$: minOpacity = opacityScale.domain()[0]
|
||||||
$: maxOpacity = opacityScale.domain()[1]
|
$: maxOpacity = opacityScale.domain()[1]
|
||||||
@ -16,16 +20,39 @@
|
|||||||
maxOpacity]
|
maxOpacity]
|
||||||
|
|
||||||
let height = 70
|
let height = 70
|
||||||
|
|
||||||
|
const tooltipContent = {
|
||||||
|
"breakout_scale": "Breakout Scale represents a range from Category One to Category Six. The smallest point on the visualization represents 'Not Applicable', indicating attributions which lack suitable evidence to justify a Breakout Scale classification.",
|
||||||
|
"attribution_score": "The opacity of attributions corresponds to the 18-point Attribution Score which attempts to qualify the credibility of an attribution."
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleMouseOver(event, id) {
|
||||||
|
console.log(id)
|
||||||
|
showLegendTooltip = true;
|
||||||
|
tooltipX = event.clientX;
|
||||||
|
tooltipY = event.clientY;
|
||||||
|
hoveredLegendData = tooltipContent[id];
|
||||||
|
}
|
||||||
|
function handleMouseOut() {
|
||||||
|
showLegendTooltip = false;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svg {width} height={height}>
|
<svg {width} height={height}>
|
||||||
<g transform={`translate(${margins.left},${0})`}>
|
<g
|
||||||
<a href="#break-out-scale">
|
transform={`translate(${margins.left},${0})`}
|
||||||
|
>
|
||||||
|
<g
|
||||||
|
on:mouseover={(e) => handleMouseOver(e, "breakout_scale")}
|
||||||
|
on:focus={(e) => handleMouseOver(e, "breakout_scale")}
|
||||||
|
on:mouseout={handleMouseOut}
|
||||||
|
on:blur={handleMouseOut}
|
||||||
|
>
|
||||||
<text
|
<text
|
||||||
x={72}
|
x={72}
|
||||||
y={12}
|
y={12}
|
||||||
text-anchor={'middle'}
|
text-anchor={'middle'}
|
||||||
>Breakout Scale</text></a>
|
>Breakout Scale</text>
|
||||||
{#each radiusScale.domain() as rad,i}
|
{#each radiusScale.domain() as rad,i}
|
||||||
<circle
|
<circle
|
||||||
cx={12 - radiusScale(rad) + i*30}
|
cx={12 - radiusScale(rad) + i*30}
|
||||||
@ -34,6 +61,8 @@
|
|||||||
fill={'#555555'}
|
fill={'#555555'}
|
||||||
></circle>
|
></circle>
|
||||||
{/each}
|
{/each}
|
||||||
|
</g>
|
||||||
|
|
||||||
<text
|
<text
|
||||||
x={(width - margins.left - margins.right)/2}
|
x={(width - margins.left - margins.right)/2}
|
||||||
y={12}
|
y={12}
|
||||||
@ -53,6 +82,13 @@
|
|||||||
r={9}
|
r={9}
|
||||||
fill={'#555555'}
|
fill={'#555555'}
|
||||||
></circle>
|
></circle>
|
||||||
|
|
||||||
|
<g
|
||||||
|
on:mouseover={(e) => handleMouseOver(e, "attribution_score")}
|
||||||
|
on:focus={(e) => handleMouseOver(e, "attribution_score")}
|
||||||
|
on:mouseout={handleMouseOut}
|
||||||
|
on:blur={handleMouseOut}
|
||||||
|
>
|
||||||
<text
|
<text
|
||||||
x={width - margins.left - margins.right - 72}
|
x={width - margins.left - margins.right - 72}
|
||||||
y={12}
|
y={12}
|
||||||
@ -67,6 +103,7 @@
|
|||||||
opacity={opacityScale(op)}
|
opacity={opacityScale(op)}
|
||||||
></circle>
|
></circle>
|
||||||
{/each}
|
{/each}
|
||||||
|
</g>
|
||||||
<line
|
<line
|
||||||
x1={0}
|
x1={0}
|
||||||
x2={width}
|
x2={width}
|
||||||
|
|||||||
52
src/lib/components/LegendTooltip.svelte
Обычный файл
52
src/lib/components/LegendTooltip.svelte
Обычный файл
@ -0,0 +1,52 @@
|
|||||||
|
<script>
|
||||||
|
import { fade } from 'svelte/transition';
|
||||||
|
import { utcFormat } from 'd3-time-format';
|
||||||
|
|
||||||
|
export let tooltipX;
|
||||||
|
export let tooltipY;
|
||||||
|
export let hoveredLegendData;
|
||||||
|
export let width;
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
transition:fade="{{ duration: 250 }}"
|
||||||
|
class="event-tooltip"
|
||||||
|
style="
|
||||||
|
top:{tooltipY}px;
|
||||||
|
left:{tooltipX < width - 300 ? tooltipX + 10 : tooltipX - 300 - 10}px;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<!--p class="date">{utcFormat('%B %d, %Y')(hoveredEventData.date)}</p>
|
||||||
|
<h2>{hoveredEventData.Title}</h2-->
|
||||||
|
<p class="description">{hoveredLegendData}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.event-tooltip {
|
||||||
|
position: fixed;
|
||||||
|
background: rgba(255, 255, 255, 0.95);
|
||||||
|
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
|
||||||
|
padding: 5px;
|
||||||
|
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
|
||||||
|
transform: translate(0%, -50%);
|
||||||
|
z-index: 1000;
|
||||||
|
max-width: 300px;
|
||||||
|
max-height: 400px;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
.date {
|
||||||
|
font-size: 0.7rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
margin: 0.2rem 0;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -9,6 +9,7 @@
|
|||||||
import Square from '$lib/components/Square.svelte';
|
import Square from '$lib/components/Square.svelte';
|
||||||
import Tooltip from '$lib/components/Tooltip.svelte';
|
import Tooltip from '$lib/components/Tooltip.svelte';
|
||||||
import EventTooltip from '$lib/components/EventTooltip.svelte';
|
import EventTooltip from '$lib/components/EventTooltip.svelte';
|
||||||
|
import LegendTooltip from '$lib/components/LegendTooltip.svelte';
|
||||||
import { actorNationFilter, timeRangeFilter } from '../../stores/filters';
|
import { actorNationFilter, timeRangeFilter } from '../../stores/filters';
|
||||||
import Legend from './Legend.svelte';
|
import Legend from './Legend.svelte';
|
||||||
|
|
||||||
@ -122,14 +123,25 @@
|
|||||||
// Tooltip
|
// Tooltip
|
||||||
let showTooltip = false;
|
let showTooltip = false;
|
||||||
let showEventTooltip = false;
|
let showEventTooltip = false;
|
||||||
|
let showLegendTooltip = false;
|
||||||
let hoveredCaseData;
|
let hoveredCaseData;
|
||||||
let hoveredEventData;
|
let hoveredEventData;
|
||||||
|
let hoveredLegendData;
|
||||||
let tooltipX;
|
let tooltipX;
|
||||||
let tooltipY;
|
let tooltipY;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="timeline-container" bind:clientWidth={width}>
|
<div class="timeline-container" bind:clientWidth={width}>
|
||||||
<Legend {width} {margins} {radiusScale} {opacityScale}></Legend>
|
<Legend
|
||||||
|
{width}
|
||||||
|
{margins}
|
||||||
|
{radiusScale}
|
||||||
|
{opacityScale}
|
||||||
|
bind:tooltipX
|
||||||
|
bind:tooltipY
|
||||||
|
bind:hoveredLegendData
|
||||||
|
bind:showLegendTooltip
|
||||||
|
></Legend>
|
||||||
<svg {width} {height}>
|
<svg {width} {height}>
|
||||||
{#if xScale}
|
{#if xScale}
|
||||||
<g transform={`translate(${margins.left},${margins.top})`}>
|
<g transform={`translate(${margins.left},${margins.top})`}>
|
||||||
@ -323,6 +335,9 @@
|
|||||||
{#if showEventTooltip}
|
{#if showEventTooltip}
|
||||||
<EventTooltip {tooltipX} {tooltipY} {hoveredEventData} {width} />
|
<EventTooltip {tooltipX} {tooltipY} {hoveredEventData} {width} />
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if showLegendTooltip}
|
||||||
|
<LegendTooltip {tooltipX} {tooltipY} {hoveredLegendData} {width} />
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
Загрузка…
x
Ссылка в новой задаче
Block a user