-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from alercebroker/fix/various-arrangements
Fix various arrangements
- Loading branch information
Showing
3 changed files
with
127 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
export function customToolTip(context) { | ||
let tooltipEl = document.getElementById('chartjs-tooltip'); | ||
|
||
if(!tooltipEl){ | ||
tooltipEl = document.createElement('div') | ||
tooltipEl.id = 'chartjs-tooltip'; | ||
tooltipEl.innerHTML = '<table></table>'; | ||
document.body.appendChild(tooltipEl); | ||
} | ||
|
||
let tooltipModel = context.tooltip; | ||
|
||
if(tooltipModel.opacity === 0){ | ||
tooltipEl.style.opacity = 0; | ||
return; | ||
} | ||
|
||
tooltipEl.classList.remove('above', 'below', 'no-transform'); | ||
if(tooltipModel.yAlign){ | ||
tooltipEl.classList.add(tooltipModel.yAlign); | ||
} else { | ||
tooltipEl.classList.add('no-transform') | ||
} | ||
|
||
function getBody(bodyItem) { | ||
return bodyItem.lines; | ||
} | ||
|
||
// set Text | ||
if(tooltipModel.body){ | ||
let titleLines = tooltipModel.title || []; | ||
let bodyLines = tooltipModel.body.map(getBody); | ||
|
||
let innerHtml = '<thead>'; | ||
|
||
titleLines.forEach(function(title) { | ||
innerHtml += '<tr><th style="color: #fff; width: 140px; height: 12px;padding: 4px;">' + title + ' (score)' + '</th></tr>'; | ||
}); | ||
|
||
innerHtml += '</thead><tbody>'; | ||
|
||
/** invertir objecto */ | ||
innerHtml += '<tr><td style="color: #fff; height: 12px; max-width: 100%;">' + bodyLines[0][0] + '</td></tr>' | ||
|
||
let style = "" | ||
for (let index = bodyLines.length - 1; index >= 1; index--){ | ||
style = ' color: #fff;'; | ||
style = style + ' max-width: 100%;'; | ||
style = style + ' height: 12px;'; | ||
innerHtml += '<tr><td style="' + style + '">' + bodyLines[index][0] + '</td></tr>'; | ||
} | ||
|
||
innerHtml += '</tbody>'; | ||
|
||
let tableRoot = tooltipEl.querySelector('table'); | ||
tableRoot.innerHTML = innerHtml; | ||
} | ||
|
||
let position = context.chart.canvas.getBoundingClientRect(); | ||
let bodyFont = Chart.helpers.toFont(tooltipModel.options.bodyFont); | ||
|
||
// Display, position, and set styles for font | ||
tooltipEl.style.opacity = 1; | ||
tooltipEl.style.backgroundColor = 'rgba(50, 50, 50, 0.7)' | ||
tooltipEl.style.position = 'absolute'; | ||
tooltipEl.style.left = position.left + window.scrollX + tooltipModel.caretX + 'px'; | ||
tooltipEl.style.bottom = (window.innerHeight - (position.top + window.scrollY + tooltipModel.caretY)) + 'px'; | ||
tooltipEl.style.font = bodyFont.string; | ||
tooltipEl.style.pointerEvents = 'none'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<script id="htmx-script" src="https://unpkg.com/[email protected]"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | ||
<script type="module" src="{{API_URL}}/static/probability.js"></script> | ||
<link rel="stylesheet" href="{{API_URL}}/static/probability.css"> | ||
|
||
|
@@ -39,16 +38,33 @@ | |
|
||
</div> | ||
|
||
<div class="md:tw-w-[80%] md:tw-h-[80%] sm:tw-w-[100%] sm:tw-h-[100%] tw-mx-auto tw-relative"> | ||
<div class="md:tw-w-[365px] md:tw-h-[250px] sm:tw-w-[100%] sm:tw-h-[100%] tw-mx-auto tw-relative"> | ||
<canvas id="myChart"></canvas> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
|
||
<script type="module"> | ||
import { init } from "{{API_URL}}/static/probability.js"; | ||
init(); | ||
import { init, elementReady } from "{{API_URL}}/static/probability.js"; | ||
function loadScript(src) { | ||
return new Promise((resolve, reject) => { | ||
const script = document.createElement('script'); | ||
script.src = src; | ||
script.onload = resolve; | ||
script.onerror = reject; | ||
document.head.appendChild(script); | ||
}); | ||
} | ||
loadScript("https://cdn.jsdelivr.net/npm/chart.js") | ||
.then(() => elementReady('#probabilities-app')) | ||
.then((el) => { | ||
init(); | ||
}) | ||
.catch((error) => console.error('Failed to load Chart.js:', error)); | ||
</script> | ||
|
||
<script id="probabilities-data" type="application/json"> | ||
|