Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tooltip): shared tooltip with scrollbar #5665

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
<div
xmlns="http://www.w3.org/1999/xhtml"
class="g2-tooltip"
style="pointer-events: none; position: absolute; visibility: visible; z-index: 8; transition: visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1), left 0.4s cubic-bezier(0.23, 1, 0.32, 1), top 0.4s cubic-bezier(0.23, 1, 0.32, 1); background-color: rgba(255, 255, 255, 0.96); box-shadow: 0 6px 12px 0 rgba(0, 0, 0, 0.12); border-radius: 4px; color: rgba(0, 0, 0, 0.65); font-size: 12px; line-height: 20px; padding: 12px; min-width: 120px; max-width: 360px; font-family: Roboto-Regular; left: 10px; top: 10px;"
>
<div
class="g2-tooltip-title"
style="color: rgba(0, 0, 0, 0.45); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
CA
</div>
<ul
class="g2-tooltip-list"
style="margin: 0px; list-style-type: none; padding: 0px;"
>
<li
class="g2-tooltip-list-item"
data-index="0"
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;"
>
<span
class="g2-tooltip-list-item-name"
style="display: flex; align-items: center; max-width: 216px;"
>
<span
class="g2-tooltip-list-item-marker"
style="background: rgb(23, 131, 255); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;"
/>
<span
class="g2-tooltip-list-item-name-label"
title="&lt;10"
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
&lt;10
</span>
</span>
<span
class="g2-tooltip-list-item-value"
title="5038433"
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
5038433
</span>
</li>
<li
class="g2-tooltip-list-item"
data-index="1"
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;"
>
<span
class="g2-tooltip-list-item-name"
style="display: flex; align-items: center; max-width: 216px;"
>
<span
class="g2-tooltip-list-item-marker"
style="background: rgb(0, 201, 201); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;"
/>
<span
class="g2-tooltip-list-item-name-label"
title="10-19"
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
10-19
</span>
</span>
<span
class="g2-tooltip-list-item-value"
title="5170341"
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
5170341
</span>
</li>
<li
class="g2-tooltip-list-item"
data-index="2"
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;"
>
<span
class="g2-tooltip-list-item-name"
style="display: flex; align-items: center; max-width: 216px;"
>
<span
class="g2-tooltip-list-item-marker"
style="background: rgb(240, 136, 77); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;"
/>
<span
class="g2-tooltip-list-item-name-label"
title="20-29"
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
20-29
</span>
</span>
<span
class="g2-tooltip-list-item-value"
title="5809455"
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
5809455
</span>
</li>
<li
class="g2-tooltip-list-item"
data-index="3"
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;"
>
<span
class="g2-tooltip-list-item-name"
style="display: flex; align-items: center; max-width: 216px;"
>
<span
class="g2-tooltip-list-item-marker"
style="background: rgb(213, 128, 255); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;"
/>
<span
class="g2-tooltip-list-item-name-label"
title="30-39"
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
30-39
</span>
</span>
<span
class="g2-tooltip-list-item-value"
title="5354112"
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
5354112
</span>
</li>
<li
class="g2-tooltip-list-item"
data-index="4"
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;"
>
<span
class="g2-tooltip-list-item-name"
style="display: flex; align-items: center; max-width: 216px;"
>
<span
class="g2-tooltip-list-item-marker"
style="background: rgb(120, 99, 255); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;"
/>
<span
class="g2-tooltip-list-item-name-label"
title="40-49"
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
40-49
</span>
</span>
<span
class="g2-tooltip-list-item-value"
title="5179258"
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
5179258
</span>
</li>
<li
class="g2-tooltip-list-item"
data-index="5"
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;"
>
<span
class="g2-tooltip-list-item-name"
style="display: flex; align-items: center; max-width: 216px;"
>
<span
class="g2-tooltip-list-item-marker"
style="background: rgb(96, 196, 45); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;"
/>
<span
class="g2-tooltip-list-item-name-label"
title="50-59"
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
50-59
</span>
</span>
<span
class="g2-tooltip-list-item-value"
title="5042094"
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
5042094
</span>
</li>
<li
class="g2-tooltip-list-item"
data-index="6"
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;"
>
<span
class="g2-tooltip-list-item-name"
style="display: flex; align-items: center; max-width: 216px;"
>
<span
class="g2-tooltip-list-item-marker"
style="background: rgb(189, 143, 36); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;"
/>
<span
class="g2-tooltip-list-item-name-label"
title="60-69"
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
60-69
</span>
</span>
<span
class="g2-tooltip-list-item-value"
title="3737461"
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
3737461
</span>
</li>
<li
class="g2-tooltip-list-item"
data-index="7"
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;"
>
<span
class="g2-tooltip-list-item-name"
style="display: flex; align-items: center; max-width: 216px;"
>
<span
class="g2-tooltip-list-item-marker"
style="background: rgb(255, 128, 202); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;"
/>
<span
class="g2-tooltip-list-item-name-label"
title="70-79"
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
70-79
</span>
</span>
<span
class="g2-tooltip-list-item-value"
title="2011678"
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
2011678
</span>
</li>
<li
class="g2-tooltip-list-item"
data-index="8"
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;"
>
<span
class="g2-tooltip-list-item-name"
style="display: flex; align-items: center; max-width: 216px;"
>
<span
class="g2-tooltip-list-item-marker"
style="background: rgb(36, 145, 179); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;"
/>
<span
class="g2-tooltip-list-item-name-label"
title="≥80"
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
≥80
</span>
</span>
<span
class="g2-tooltip-list-item-value"
title="1311374"
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"
>
1311374
</span>
</li>
</ul>
</div>
1 change: 1 addition & 0 deletions __tests__/plots/tooltip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ export { alphabetIntervalTooltipRenderUpdate } from './alphabet-interval-tooltip
export { mockIntervalShared } from './mock-interval-shared';
export { stateAgesIntervalCustomStyle } from './stateages-interval-custom-style';
export { mockTooltipClosest } from './mock-tooltip-closest';
export { stateAgesIntervalScrollbar } from './stateages-interval-scrollbar';
26 changes: 26 additions & 0 deletions __tests__/plots/tooltip/stateages-interval-scrollbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { G2Spec } from '../../../src';
import { tooltipSteps } from './utils';

export function stateAgesIntervalScrollbar(): G2Spec {
return {
type: 'interval',
transform: [
{ type: 'sortX', by: 'y', reverse: true, reducer: 'sum', slice: 6 },
{ type: 'dodgeX' },
],
data: {
type: 'fetch',
value: 'data/stateages.csv',
},
legend: false,
encode: {
x: 'state',
y: 'population',
color: 'age',
},
interaction: { tooltip: { shared: true } },
scrollbar: { x: { ratio: 0.5 } },
};
}

stateAgesIntervalScrollbar.steps = tooltipSteps(0);
6 changes: 1 addition & 5 deletions src/interaction/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ export function createColorKey(view) {
}

export function createXKey(view) {
const { x: scaleX } = view.scale;
return (element) => {
const { x } = element.__data__;
return scaleX.invert(x);
};
return (element) => element.__data__.x;
}

export function createDatumof(view: G2ViewDescriptor | G2ViewDescriptor[]) {
Expand Down
Loading