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

Update line-customTooltips.html (Re issue #4038 ) #4039

Merged
merged 5 commits into from
Mar 22, 2017
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
9 changes: 5 additions & 4 deletions samples/tooltips/custom-line.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
tooltipEl = document.createElement('div');
tooltipEl.id = 'chartjs-tooltip';
tooltipEl.innerHTML = "<table></table>"
document.body.appendChild(tooltipEl);
this._chart.canvas.parentNode.appendChild(tooltipEl);
}

// Hide if no tooltip
Expand Down Expand Up @@ -95,12 +95,13 @@
tableRoot.innerHTML = innerHtml;
}

var position = this._chart.canvas.getBoundingClientRect();
var positionY = this._chart.canvas.offsetTop;
var positionX = this._chart.canvas.offsetLeft;

// Display, position, and set styles for font
tooltipEl.style.opacity = 1;
tooltipEl.style.left = position.left + tooltip.caretX + 'px';
tooltipEl.style.top = position.top + tooltip.caretY + 'px';
tooltipEl.style.left = positionX + tooltip.caretX + 'px';
tooltipEl.style.top = positionY + tooltip.caretY + 'px';
tooltipEl.style.fontFamily = tooltip._fontFamily;
tooltipEl.style.fontSize = tooltip.fontSize;
tooltipEl.style.fontStyle = tooltip._fontStyle;
Expand Down
16 changes: 8 additions & 8 deletions samples/tooltips/custom-pie.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@

<body>
<div id="canvas-holder" style="width: 300px;">
<canvas id="chart-area" width="300" height="300" />
</div>

<div id="chartjs-tooltip">
<table></table>
<canvas id="chart-area" width="300" height="300"></canvas>
<div id="chartjs-tooltip">
<table></table>
</div>
</div>

<script>
Expand Down Expand Up @@ -92,12 +91,13 @@
tableRoot.innerHTML = innerHtml;
}

var position = this._chart.canvas.getBoundingClientRect();
var positionY = this._chart.canvas.offsetTop;
var positionX = this._chart.canvas.offsetLeft;

// Display, position, and set styles for font
tooltipEl.style.opacity = 1;
tooltipEl.style.left = position.left + tooltip.caretX + 'px';
tooltipEl.style.top = position.top + tooltip.caretY + 'px';
tooltipEl.style.left = positionX + tooltip.caretX + 'px';
tooltipEl.style.top = positionY + tooltip.caretY + 'px';
tooltipEl.style.fontFamily = tooltip._fontFamily;
tooltipEl.style.fontSize = tooltip.fontSize;
tooltipEl.style.fontStyle = tooltip._fontStyle;
Expand Down
11 changes: 7 additions & 4 deletions samples/tooltips/custom-points.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
<body>
<div id="canvas-holder1" style="width:75%;">
<canvas id="chart1"></canvas>
<div class="chartjs-tooltip" id="tooltip-0"></div>
<div class="chartjs-tooltip" id="tooltip-1"></div>
</div>
<div class="chartjs-tooltip" id="tooltip-0"></div>
<div class="chartjs-tooltip" id="tooltip-1"></div>
<script>
var customTooltips = function (tooltip) {
$(this._chart.canvas).css("cursor", "pointer");

var positionY = this._chart.canvas.offsetTop;
var positionX = this._chart.canvas.offsetLeft;

$(".chartjs-tooltip").css({
opacity: 0,
});
Expand All @@ -60,8 +63,8 @@
$tooltip.html(content);
$tooltip.css({
opacity: 1,
top: dataPoint.y + "px",
left: dataPoint.x + "px",
top: positionY + dataPoint.y + "px",
left: positionX + dataPoint.x + "px",
});
});
}
Expand Down