(xscale, box)
| 416 | } |
| 417 | |
| 418 | function drawBox(xscale, box) { |
| 419 | const srcIndex = box.src; |
| 420 | const src = stacks.Sources[srcIndex]; |
| 421 | |
| 422 | function makeRect(cl, x, y, w, h) { |
| 423 | const r = document.createElement('div'); |
| 424 | r.style.left = x+'px'; |
| 425 | r.style.top = y+'px'; |
| 426 | r.style.width = w+'px'; |
| 427 | r.style.height = h+'px'; |
| 428 | r.classList.add(cl); |
| 429 | return r; |
| 430 | } |
| 431 | |
| 432 | // Background |
| 433 | const w = box.width - 1; // Leave 1px gap |
| 434 | const r = makeRect('boxbg', box.x, box.y, w, ROW); |
| 435 | if (!diff) r.style.background = makeColor(src.Color); |
| 436 | addElem(srcIndex, r); |
| 437 | if (!src.Inlined) { |
| 438 | r.classList.add('not-inlined'); |
| 439 | } |
| 440 | |
| 441 | // Positive/negative indicator for diff mode. |
| 442 | if (diff) { |
| 443 | const delta = box.sumpos - box.sumneg; |
| 444 | const partWidth = xscale * Math.abs(delta); |
| 445 | if (partWidth >= MIN_WIDTH) { |
| 446 | r.appendChild(makeRect((delta < 0 ? 'negative' : 'positive'), |
| 447 | 0, 0, partWidth, ROW-1)); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | // Label |
| 452 | if (box.width >= MIN_TEXT_WIDTH) { |
| 453 | const t = document.createElement('div'); |
| 454 | t.classList.add('boxtext'); |
| 455 | fitText(t, box.width-2*TEXT_MARGIN, src.Display); |
| 456 | r.appendChild(t); |
| 457 | } |
| 458 | |
| 459 | onClick(r, () => { switchPivots(pprofQuoteMeta(src.UniqueName)); }); |
| 460 | r.addEventListener('mouseenter', () => { handleEnter(box, r); }); |
| 461 | r.addEventListener('mouseleave', () => { handleLeave(box); }); |
| 462 | r.addEventListener('contextmenu', (e) => { showActionMenu(e, box); }); |
| 463 | return r; |
| 464 | } |
| 465 | |
| 466 | // Handle clicks, but only if the mouse did not move during the click. |
| 467 | function onClick(target, handler) { |
no test coverage detected
searching dependent graphs…