Skip to content

Commit fa6adb7

Browse files
committed
Add button tooltips
Signed-off-by: Jay Wang <[email protected]>
1 parent 0af49ef commit fa6adb7

File tree

7 files changed

+146
-6
lines changed

7 files changed

+146
-6
lines changed

src/components/page/page.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
background-size: 15px 15px; */
1717

1818
background-color: #ffffff;
19-
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='450' height='450' viewBox='0 0 800 800'%3E%3Cg fill='none' stroke='%23EDEEE7' stroke-width='1'%3E%3Cpath d='M769 229L1037 260.9M927 880L731 737 520 660 309 538 40 599 295 764 126.5 879.5 40 599-197 493 102 382-31 229 126.5 79.5-69-63'/%3E%3Cpath d='M-31 229L237 261 390 382 603 493 308.5 537.5 101.5 381.5M370 905L295 764'/%3E%3Cpath d='M520 660L578 842 731 737 840 599 603 493 520 660 295 764 309 538 390 382 539 269 769 229 577.5 41.5 370 105 295 -36 126.5 79.5 237 261 102 382 40 599 -69 737 127 880'/%3E%3Cpath d='M520-140L578.5 42.5 731-63M603 493L539 269 237 261 370 105M902 382L539 269M390 382L102 382'/%3E%3Cpath d='M-222 42L126.5 79.5 370 105 539 269 577.5 41.5 927 80 769 229 902 382 603 493 731 737M295-36L577.5 41.5M578 842L295 764M40-201L127 80M102 382L-261 269'/%3E%3C/g%3E%3Cg fill='hsl%28232%2C%20100%25%2C%2094%25%29'%3E%3Ccircle cx='769' cy='229' r='5'/%3E%3Ccircle cx='539' cy='269' r='5'/%3E%3Ccircle cx='603' cy='493' r='5'/%3E%3Ccircle cx='731' cy='737' r='5'/%3E%3Ccircle cx='520' cy='660' r='5'/%3E%3Ccircle cx='309' cy='538' r='5'/%3E%3Ccircle cx='295' cy='764' r='5'/%3E%3Ccircle cx='40' cy='599' r='5'/%3E%3Ccircle cx='102' cy='382' r='5'/%3E%3Ccircle cx='127' cy='80' r='5'/%3E%3Ccircle cx='370' cy='105' r='5'/%3E%3Ccircle cx='578' cy='42' r='5'/%3E%3Ccircle cx='237' cy='261' r='5'/%3E%3Ccircle cx='390' cy='382' r='5'/%3E%3C/g%3E%3C/svg%3E");
19+
/* background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='450' height='450' viewBox='0 0 800 800'%3E%3Cg fill='none' stroke='%23EDEEE7' stroke-width='1'%3E%3Cpath d='M769 229L1037 260.9M927 880L731 737 520 660 309 538 40 599 295 764 126.5 879.5 40 599-197 493 102 382-31 229 126.5 79.5-69-63'/%3E%3Cpath d='M-31 229L237 261 390 382 603 493 308.5 537.5 101.5 381.5M370 905L295 764'/%3E%3Cpath d='M520 660L578 842 731 737 840 599 603 493 520 660 295 764 309 538 390 382 539 269 769 229 577.5 41.5 370 105 295 -36 126.5 79.5 237 261 102 382 40 599 -69 737 127 880'/%3E%3Cpath d='M520-140L578.5 42.5 731-63M603 493L539 269 237 261 370 105M902 382L539 269M390 382L102 382'/%3E%3Cpath d='M-222 42L126.5 79.5 370 105 539 269 577.5 41.5 927 80 769 229 902 382 603 493 731 737M295-36L577.5 41.5M578 842L295 764M40-201L127 80M102 382L-261 269'/%3E%3C/g%3E%3Cg fill='hsl%28232%2C%20100%25%2C%2094%25%29'%3E%3Ccircle cx='769' cy='229' r='5'/%3E%3Ccircle cx='539' cy='269' r='5'/%3E%3Ccircle cx='603' cy='493' r='5'/%3E%3Ccircle cx='731' cy='737' r='5'/%3E%3Ccircle cx='520' cy='660' r='5'/%3E%3Ccircle cx='309' cy='538' r='5'/%3E%3Ccircle cx='295' cy='764' r='5'/%3E%3Ccircle cx='40' cy='599' r='5'/%3E%3Ccircle cx='102' cy='382' r='5'/%3E%3Ccircle cx='127' cy='80' r='5'/%3E%3Ccircle cx='370' cy='105' r='5'/%3E%3Ccircle cx='578' cy='42' r='5'/%3E%3Ccircle cx='237' cy='261' r='5'/%3E%3Ccircle cx='390' cy='382' r='5'/%3E%3C/g%3E%3C/svg%3E"); */
2020
}
2121

2222
.headline {

src/components/paper-view/paper-view.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class RecRecPaperView extends LitElement {
113113
this.notifyParentPapers(this.papers);
114114

115115
this.isCompleted = true;
116-
console.log(this.papers);
116+
// console.log(this.papers);
117117
}
118118

119119
formatPaperAuthor(paper: SemanticPaper) {

src/components/recommender-view/recommender-view.css

+28
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,24 @@ button {
444444
opacity 150ms linear,
445445
transform 150ms linear;
446446

447+
&#description-overlay {
448+
transition:
449+
opacity 100ms linear,
450+
transform 100ms linear;
451+
}
452+
447453
&[placement='right'] {
448454
transform-origin: left center;
449455
}
450456

457+
&[placement='bottom'] {
458+
transform-origin: top center;
459+
}
460+
461+
&[placement='top'] {
462+
transform-origin: bottom center;
463+
}
464+
451465
&.hidden {
452466
opacity: 0;
453467
pointer-events: none;
@@ -472,6 +486,20 @@ button {
472486
flex-flow: column;
473487
}
474488

489+
.description {
490+
display: flex;
491+
flex-direction: row;
492+
align-items: center;
493+
gap: 5px;
494+
495+
.external-icon {
496+
margin-top: 2px;
497+
width: 0.7em;
498+
height: 0.7em;
499+
color: var(--gray-400);
500+
}
501+
}
502+
475503
.table-title {
476504
padding: 0 2px;
477505
display: flex;

src/components/recommender-view/recommender-view.ts

+111-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import componentCSS from './recommender-view.css?inline';
3838
import iconHIndex from '../../images/icon-hindex-c.svg?raw';
3939
import iconFile from '../../images/icon-file-c.svg?raw';
4040
import iconCiteTimes from '../../images/icon-cite-times-c.svg?raw';
41+
import iconExternal from '../../images/icon-external-link.svg?raw';
42+
import iconClick from '../../images/icon-click.svg?raw';
4143

4244
const DEV_MODE = true;
4345
const MAX_RECOMMENDER_NUM = 500;
@@ -84,6 +86,8 @@ interface SliderRange {
8486
initialValue: number;
8587
}
8688

89+
let descriptionTooltipTimer: number | null = null;
90+
8791
/**
8892
* Recommender view element.
8993
*/
@@ -181,12 +185,18 @@ export class RecRecRecommenderView extends LitElement {
181185
@query('#paper-overlay')
182186
paperOverlayElement: HTMLElement | undefined;
183187

188+
@query('#description-overlay')
189+
descriptionOverlayElement: HTMLElement | undefined;
190+
184191
@state()
185192
overlayPaperCounts: [string, number][];
186193

187194
@state()
188195
overlayPaperCountsType: 'citeTimes' | 'paperCount' = 'citeTimes';
189196

197+
@state()
198+
overlayDescriptionType: 'citeTimes' | 'paperCount' | 'hIndex' = 'citeTimes';
199+
190200
curClickedCiteTimeAuthorID: string | null = null;
191201
overlayCleanup = () => {};
192202

@@ -514,7 +524,7 @@ export class RecRecRecommenderView extends LitElement {
514524
let maxHIndex = -Infinity;
515525

516526
for (const [i, chunk] of authorIDChunks.entries()) {
517-
console.log(`Chunk: ${i}`);
527+
// console.log(`Chunk: ${i}`);
518528
const startTime = performance.now();
519529

520530
let retry = 3;
@@ -759,6 +769,9 @@ export class RecRecRecommenderView extends LitElement {
759769
return;
760770
}
761771

772+
// Hide the description tooltip
773+
this.citeTimeButtonMouseLeft(e);
774+
762775
if (this.curClickedCiteTimeAuthorID === recommender.authorID) {
763776
// This overlay is already shown. We hide it if the user clicks the button (again)
764777
this.paperOverlayElement.classList.add('hidden');
@@ -801,6 +814,57 @@ export class RecRecRecommenderView extends LitElement {
801814
this.paperOverlayElement.classList.remove('hidden');
802815
}
803816

817+
citeTimeButtonMouseEntered(
818+
e: MouseEvent,
819+
type: 'paperCount' | 'citeTimes' | 'hIndex'
820+
) {
821+
e.stopPropagation();
822+
e.preventDefault();
823+
824+
if (!this.descriptionOverlayElement) {
825+
console.error('descriptionOverlayElement are not initialized yet.');
826+
return;
827+
}
828+
829+
const anchor = e.currentTarget as HTMLElement;
830+
831+
if (descriptionTooltipTimer) {
832+
clearTimeout(descriptionTooltipTimer);
833+
}
834+
835+
descriptionTooltipTimer = setTimeout(async () => {
836+
this.overlayDescriptionType = type;
837+
await this.updateComplete;
838+
839+
updatePopperOverlay(
840+
this.descriptionOverlayElement!,
841+
anchor,
842+
'top',
843+
true,
844+
10,
845+
300
846+
);
847+
848+
this.descriptionOverlayElement!.classList.remove('hidden');
849+
}, 500);
850+
}
851+
852+
citeTimeButtonMouseLeft(e: MouseEvent) {
853+
e.stopPropagation();
854+
e.preventDefault();
855+
856+
if (!this.descriptionOverlayElement) {
857+
console.error('descriptionOverlayElement are not initialized yet.');
858+
return;
859+
}
860+
861+
if (descriptionTooltipTimer) {
862+
clearTimeout(descriptionTooltipTimer);
863+
}
864+
865+
this.descriptionOverlayElement.classList.add('hidden');
866+
}
867+
804868
citeTimeBlurred() {
805869
if (!this.paperOverlayElement) {
806870
console.error('paperOverlayElement are not initialized yet.');
@@ -914,6 +978,11 @@ export class RecRecRecommenderView extends LitElement {
914978
tabindex="0"
915979
@click=${(e: MouseEvent) =>
916980
this.citeTimeButtonClicked(e, recommender, 'paperCount')}
981+
@mouseenter=${(e: MouseEvent) =>
982+
this.citeTimeButtonMouseEntered(e, 'paperCount')}
983+
@mouseleave=${(e: MouseEvent) => {
984+
this.citeTimeButtonMouseLeft(e);
985+
}}
917986
@touchstart=${(e: TouchEvent) => {
918987
e.stopPropagation();
919988
}}
@@ -928,6 +997,11 @@ export class RecRecRecommenderView extends LitElement {
928997
tabindex="0"
929998
@click=${(e: MouseEvent) =>
930999
this.citeTimeButtonClicked(e, recommender, 'citeTimes')}
1000+
@mouseenter=${(e: MouseEvent) =>
1001+
this.citeTimeButtonMouseEntered(e, 'citeTimes')}
1002+
@mouseleave=${(e: MouseEvent) => {
1003+
this.citeTimeButtonMouseLeft(e);
1004+
}}
9311005
@touchstart=${(e: TouchEvent) => {
9321006
e.stopPropagation();
9331007
}}
@@ -940,6 +1014,11 @@ export class RecRecRecommenderView extends LitElement {
9401014
<a
9411015
class="info-block info-icon"
9421016
href="${recommender.url!}"
1017+
@mouseenter=${(e: MouseEvent) =>
1018+
this.citeTimeButtonMouseEntered(e, 'hIndex')}
1019+
@mouseleave=${(e: MouseEvent) => {
1020+
this.citeTimeButtonMouseLeft(e);
1021+
}}
9431022
target="_blank"
9441023
>
9451024
<span class="svg-icon">${unsafeHTML(iconHIndex)}</span>
@@ -1104,6 +1183,28 @@ export class RecRecRecommenderView extends LitElement {
11041183
</div>
11051184
`;
11061185

1186+
// Compile the description overlay
1187+
let description = 'Papers by this recommender citing my work';
1188+
let descriptionIcon = html`<span class="svg-icon"
1189+
>${unsafeHTML(iconClick)}</span
1190+
>`;
1191+
1192+
if (this.overlayDescriptionType === 'citeTimes') {
1193+
description = 'Total citations by this recommender';
1194+
} else if (this.overlayDescriptionType === 'hIndex') {
1195+
description = 'H-Index';
1196+
descriptionIcon = html`<span class="svg-icon external-icon"
1197+
>${unsafeHTML(iconExternal)}</span
1198+
>`;
1199+
}
1200+
1201+
const descriptionOverlay = html`
1202+
<div class="description">
1203+
<span>${description}</span>
1204+
${descriptionIcon}
1205+
</div>
1206+
`;
1207+
11071208
return html`
11081209
<div class="recommender-view">
11091210
${progressRing} ${MOBILE_MODE ? controlPopBar : controlSideBar}
@@ -1149,6 +1250,15 @@ export class RecRecRecommenderView extends LitElement {
11491250
</div>
11501251
<div class="popper-arrow"></div>
11511252
</div>
1253+
1254+
<div
1255+
id="description-overlay"
1256+
class="popper-tooltip hidden"
1257+
role="tooltip"
1258+
>
1259+
<div class="popper-content">${descriptionOverlay}</div>
1260+
<div class="popper-arrow"></div>
1261+
</div>
11521262
</div>
11531263
`;
11541264
}

src/components/recrec/recrec.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
box-sizing: border-box;
88

99
/* overflow: hidden; */
10-
/* border: 1px solid var(--gray-400); */
10+
border: 1px solid var(--gray-300);
1111
overflow: hidden;
1212
border-radius: var(--border-radius);
1313
background: white;
14-
box-shadow:
14+
/* box-shadow:
1515
0 0 2px hsla(0, 0%, 0%, 0.1),
1616
0 0 10px hsla(0, 0%, 0%, 0.04),
1717
0 0 15px hsla(0, 0%, 0%, 0.04),
18-
0 0 30px hsla(0, 0%, 0%, 0.04);
18+
0 0 30px hsla(0, 0%, 0%, 0.04); */
1919
}
2020

2121
button {

src/images/icon-click.svg

+1
Loading

src/images/icon-external-link.svg

+1
Loading

0 commit comments

Comments
 (0)