Debian Codegraph @

html_renderer/src/components/TimelineCanvasViewTooltip.svelte

raw
1 <script context="module" lang="ts">
2 import { get } from "svelte/store";
3
4 export interface TooltipFrameInfo {
5 name: string
6 time: number
7 selfTime: number
8 totalTime: number
9 precision: number
10 location: string
11 locationColor: string
12 }
13 function getTimeMode(f: TooltipFrameInfo) {
14 if (f.selfTime == f.time) {
15 return 'self'
16 } else if (f.selfTime / f.time > 1e-3) {
17 return 'both'
18 } else {
19 return 'time'
20 }
21 }
22 export function estimateWidth(ctx: CanvasRenderingContext2D, f: TooltipFrameInfo) {
23 ctx.font = FONT
24 const timeWidth = getTimeMode(f) == 'both' ? 140 : 70
25 const nameWidth = ctx.measureText(f.name).width
26 const locationWidth = ctx.measureText(f.location).width + 46
27 const padding = 10 + 10
28 let width = Math.max(timeWidth, nameWidth, locationWidth) + padding
29 if (width > 310) {
30 width = 310
31 }
32 return width
33 }
34 const MAX_WIDTH = 310
35 const FONT = '400 13px Source Sans Pro, sans-serif'
36 </script>
37
38 <script lang="ts">
39 import { colorForFrameProportionOfTotal } from "../lib/color";
40 import { htmlForStringWithWBRAtSlashes } from "../lib/utils";
41
42 export let f: TooltipFrameInfo
43
44 let locationHTML
45 $: locationHTML = htmlForStringWithWBRAtSlashes(f.location)
46
47 let timeMode: 'time' | 'self' | 'both'
48 $: timeMode = getTimeMode(f)
49
50 function formatTime(time: number) {
51 const color = colorForFrameProportionOfTotal(time / f.totalTime)
52 return `<span style="color: ${color}">${time.toFixed(f.precision)}</span>`
53 }
54 </script>
55
56 <div class="timeline-canvas-view-tooltip"
57 style={`font: ${FONT}; max-width: ${MAX_WIDTH}px;`}>
58 <div class="name">{f.name}</div>
59 {#if timeMode == 'both'}
60 <div class="label">time</div>
61 <div class="time-row">
62 <div class="time-val">{@html formatTime(f.time)}</div>
63 {#if (f.selfTime / f.time) > 1e-3 }
64 <div class="label">self</div>
65 <div class="time-val">{@html formatTime (f.selfTime)}</div>
66 {/if}
67 </div>
68 {:else}
69 <div class="label">{timeMode == 'self' ? 'self' : 'time'}</div>
70 <div class="time-val">{@html formatTime(f.time)}</div>
71 {/if}
72 <div class="label">loc</div>
73 <div class="location-row">
74 <div class="location-color" style={`background: ${f.locationColor}`}></div>
75 {@html locationHTML}
76 </div>
77 </div>
78
79 <style lang="scss">
80 .timeline-canvas-view-tooltip {
81 box-sizing: border-box;
82 width: max-content;
83 border-radius: 2px;
84 border: 1px solid rgba(255, 255, 255, 0.09);
85 background: #202325;
86 box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
87
88 display: grid;
89 grid-template-columns: minmax(auto, 33px) minmax(auto, 1fr);
90 gap: 1px 0;
91
92 padding: 4px 10px;
93 padding-bottom: 7px;
94
95 color: white;
96
97 .name {
98 grid-column: span 2;
99 line-break: anywhere;
100 }
101 .label {
102 color: rgba(255, 255, 255, 0.5);
103 margin-right: 8px;
104 }
105 .time-val {
106 margin-right: 10px;
107 font-weight: 600;
108 }
109 .time-row {
110 display: flex;
111 justify-content: start;
112 }
113 .location-color {
114 width: 9px;
115 height: 9px;
116 margin-right: 3px;
117 border-radius: 2px;
118 position: relative;
119 display: inline-block;
120
121 &::before {
122 content: '';
123 position: absolute;
124 top: 0;
125 left: 0;
126 right: 0;
127 bottom: 0;
128 border: 1px solid #383838;
129 mix-blend-mode: color-dodge;
130 border-radius: 2px;
131 }
132 }
133 }
134 </style>