Skip to content

Commit

Permalink
[#1602] Chart > tooltip > Row Padding 옵션 추가
Browse files Browse the repository at this point in the history
##############################################
- tooltipDOMHeight이 결정되도록 로직 수정
  • Loading branch information
jhee564 committed Feb 13, 2024
1 parent 6648752 commit ea8a496
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/components/chart/plugins/plugins.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Util from '../helpers/helpers.util';
const LINE_SPACING = 8;
const VALUE_MARGIN = 50;
const SCROLL_WIDTH = 17;
const HEADER_DOM_PADDING = 15;

const modules = {
/**
Expand Down Expand Up @@ -173,19 +174,21 @@ const modules = {
this.tooltipHeaderDOM.style.height = 'auto';
this.tooltipDOM.style.height = 'auto';
this.tooltipBodyDOM.style.height = `${contentsHeight + 6}px`;
this.tooltipDOM.style.display = 'block';


// set tooltipDOM's positions
const bodyWidth = document.body.clientWidth;
const bodyHeight = document.body.clientHeight;
const distanceMouseAndTooltip = 20;
const tooltipDOMSize = this.tooltipDOM?.getBoundingClientRect();
const tooltipDOMHeight = this.tooltipDOM?.offsetHeight
|| (opt?.fontSize?.title ?? 16 + HEADER_DOM_PADDING) + contentsHeight;
const maximumPosX = bodyWidth - contentsWidth - distanceMouseAndTooltip;
const maximumPosY = bodyHeight - tooltipDOMSize.height - distanceMouseAndTooltip;
const maximumPosY = bodyHeight - tooltipDOMHeight - distanceMouseAndTooltip;
const expectedPosX = mouseX + distanceMouseAndTooltip;
const expectedPosY = mouseY + distanceMouseAndTooltip;
const reversedPosX = mouseX - contentsWidth - distanceMouseAndTooltip;
const reversedPosY = mouseY - tooltipDOMSize.height - distanceMouseAndTooltip;
const reversedPosY = mouseY - tooltipDOMHeight - distanceMouseAndTooltip;
this.tooltipDOM.style.left = expectedPosX > maximumPosX
? `${reversedPosX}px`
: `${expectedPosX}px`;
Expand Down

0 comments on commit ea8a496

Please sign in to comment.