Skip to content

Commit

Permalink
fix: tooltip names mixing
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosNicolau committed Dec 24, 2024
1 parent 8a109ef commit 9c494af
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions explorer/assets/vendor/charts/batch_size.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const batchSizeCustomOptions = (options, data) => {

options.plugins.tooltip.external = (context) =>
alignedTooltip(context, {
name: "batch-size",
title: "Batch size",
items: [
{ title: "Cost", id: "cost" },
Expand Down
1 change: 1 addition & 0 deletions explorer/assets/vendor/charts/cost_per_proof.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const costPerProofCustomOptions = (options, data) => {

options.plugins.tooltip.external = (context) =>
alignedTooltip(context, {
name: "cost-per-proof",
title: "Cost per proof",
items: [
{ title: "Cost", id: "cost" },
Expand Down
8 changes: 5 additions & 3 deletions explorer/assets/vendor/charts/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const tooltipComponent = ({ title, isTooltipClickable, items }) => `
*
* @param {Object} context - The chart.js context, typically passed as `this` within chart hooks.
* @param {Object} params - An object containing configuration for the tooltip.
* @param {Object} params.name - A string that serves as an identifier for the tooltip.
* @param {string} params.title - The title text to display in the tooltip.
* @param {Array} params.items - An array of items (with ids) to be displayed inside the tooltip.
* @param {Array} params.onTooltipClick - A callback that receives `tooltipModel` and gets triggered when the tooltip is clicked.
Expand All @@ -36,6 +37,7 @@ const tooltipComponent = ({ title, isTooltipClickable, items }) => `
*
* @example
* alignedTooltip(context, {
* name: "my-chart",
* title: "Tooltip Title",
* items: [{ title: "Cost", id: "cost_id" }, { title: "Timestamp", id: "timestamp_id" }],
* onTooltipClick: (tooltipModel) => {
Expand All @@ -58,15 +60,15 @@ const tooltipComponent = ({ title, isTooltipClickable, items }) => `
*/
export const alignedTooltip = (
context,
{ title, items, onTooltipClick, onTooltipUpdate }
{ name, title, items, onTooltipClick, onTooltipUpdate }
) => {
const tooltipModel = context.tooltip;
let tooltipEl = document.getElementById("chartjs-tooltip");
let tooltipEl = document.getElementById(`chartjs-tooltip-${name}`);
if (!tooltipEl) {
tooltipEl = document.createElement("div");
tooltipEl.style = "transition: opacity 0.3s;";
tooltipEl.style = "transition: left 0.1s;";
tooltipEl.id = "chartjs-tooltip";
tooltipEl.id = `chartjs-tooltip-${name}`;
tooltipEl.innerHTML = tooltipComponent({
title,
isTooltipClickable: !!onTooltipClick,
Expand Down

0 comments on commit 9c494af

Please sign in to comment.