Database-BI
view release on metacpan or search on metacpan
templates/web/en-us/canvas.html.tt view on Meta::CPAN
applySpan(card, sp.x, w, sp.y, h);
/* The size on the card follows the grip: a drag that leaves the card 7
* columns wide says so while it is being dragged, not only once it is let
* go. The numbers come from the drag rather than from a measurement, so
* nothing has to be read back mid-drag. */
if (w !== shownW || h !== shownH) {
shownW = w;
shownH = h;
updateSizeBadge(card, { w: w, h: h });
}
}
function onResizeEnd() {
document.removeEventListener('pointermove', onResizeMove);
document.removeEventListener('pointerup', onResizeEnd);
card.classList.remove('resizing');
document.body.style.userSelect = '';
/* A press that left the size where it was has nothing to save, and
* saving it anyway would write a layout no one asked for. */
if (!changed) return;
/* The same tidy-up the keyboard does: what the card grew over is pushed
* down, so the layout that is saved is one the server will take. */
pushApart(card);
/* A drag changes the same value the keyboard does. */
var handle = card.querySelector('.visual-resize-handle');
if (handle) updateResizeAria(handle, card);
saveLayout();
}
document.addEventListener('pointermove', onResizeMove);
document.addEventListener('pointerup', onResizeEnd);
}
function initResizeHandles(root) {
if (!grid || !anaId) return;
(root || grid).querySelectorAll('.visual-resize-handle').forEach(function (handle) {
handle.addEventListener('pointerdown', onResizeStart);
handle.addEventListener('keydown', onResizeKey);
handle.addEventListener('blur', flushSave);
var card = handle.closest('.visual-card');
if (card) updateResizeAria(handle, card);
});
}
fitTextRows();
initResizeHandles();
/* ---- the size menu (3.2): width and height without a drag ----
*
* Each entry is a width in grid columns or a height in grid rows, applied
* through commitSize, so the menu and the corner grip end in the same layout
* and the same PATCH. Focus stays on the menu after a choice, which is where
* the reader already is: the size can be changed again, or tabbed away from,
* without hunting for the card again. The first option is not a choice but
* the size the card is; it is what the menu shows when the size came from
* somewhere else (a drag, an arrow key, a reload), while a choice made here
* stays selected, so the arrow keys walk the entries one after another
* instead of being pulled back to the top after every one.
*/
function initSizeMenus(root) {
if (!grid || !anaId) return;
(root || grid).querySelectorAll('.visual-size-select').forEach(function (sel) {
var card = sel.closest('.visual-card');
if (!card) return;
updateSizeControls(card);
sel.addEventListener('change', function () {
var raw = sel.value;
var index = sel.selectedIndex;
/* The first option says what the card is, not what it should
* become: choosing it again is not a choice. */
if (!raw) return;
var st = resizeState(card);
var isRow = raw.charAt(0) === 'h';
var value = parseInt(isRow ? raw.slice(1) : raw, 10);
/* Choosing the size the card already is should do nothing rather
* than re-announce itself, and leave the entry selected so the next
* arrow key carries on down the list. */
if (isNaN(value) || value === (isRow ? st.h : st.w)) return;
if (isRow) commitSize(card, st.w, value);
else commitSize(card, value, st.h);
/* The entry that was chosen stays chosen: the commit re-selects the
* summary, and a reader stepping down the list with the arrow keys
* would otherwise be pulled back to the top after every change. */
sel.selectedIndex = index;
});
});
}
initSizeMenus();
/* ---- cross-filter (3.3 URL-stage) ----
*
* Semantics: self-highlighting.
* - Clicking a mark on visual N navigates to ?cf=col:eq:val&cv=N.
* - On reload the server filters every visual except the source (cv=N).
* - The source card gets a blue border (.cf-source) to show it is the
* filter origin and is intentionally shown unfiltered.
* - Multi-select not supported: each click replaces any prior cross-filter.
* - Cross-filter respects each visual's own saved filters because the
* server applies ?cf= on top of them (see canvas_render in Dashboard.pm).
*
* extractCfValue(d) extracts the categorical value from a D3 datum.
* HTML::D3 uses these shapes depending on chart kind:
* bar/treemap : d = [label, value] (positional array)
* pie : d = { data:[label,value], ... } (pie arc datum)
* stacked : d = { cat, seg, val }
* combo/line : d = { x, bar_val, line_val } or { label, value }
* scatter : d = [x, y] -- less useful for CF; skipped when val==NaN
*/
function extractCfValue(d) {
if (d === undefined || d === null) return null;
/* A stacked segment's datum is a position in its group -- [row, column]
* -- carrying the row it came from in .data, so the category has to be
* read before the array is taken as the value: the array holds indexes,
* and the first of them is why every segment used to filter by "0". */
if (d.data && typeof d.data === 'object' && !Array.isArray(d.data)
&& d.data.cat !== undefined) {
return String(d.data.cat);
}
if (Array.isArray(d) && d.length >= 1) {
var v = d[0];
return (v !== null && v !== undefined) ? String(v) : null;
}
if (d.data) {
if (Array.isArray(d.data) && d.data.length >= 1) return String(d.data[0]);
if (d.data.label !== undefined) return String(d.data.label);
/* A treemap hands out a hierarchy node, and the category is the leaf
* it names: the id is the whole path down the tree
* ("Root/Gadget Pro"), so the part after the last slash is the tile. */
if (d.data.id !== undefined) {
var parts = String(d.data.id).split('/');
return parts[parts.length - 1] || null;
}
}
if (d.cat !== undefined) return String(d.cat);
if (d.label !== undefined) return String(d.label);
if (d.x !== undefined) return String(d.x);
return null;
}
/* The URL a cross-filter click asks for: one filter, replacing whatever
* filter is in force, and the card that was clicked named as the source so
* the server draws it in full and marks it. Everything else in the query
* string -- a bound parameter, a calculated column, a drill path -- is kept,
* because a click on a mark says what to filter by, not what to forget.
*
* The value goes in as it is, because searchParams encodes what it is given:
* encoding it here as well turned "Gadget Pro" into Gadget%2520Pro, and the
* canvas then filtered for a value no row has. */
templates/web/en-us/canvas.html.tt view on Meta::CPAN
script.textContent = old.textContent;
old.parentNode.replaceChild(script, old);
});
}
function headHas(tag, attr, value) {
var nodes = document.head.querySelectorAll(tag);
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].getAttribute(attr) === value) return true;
}
return false;
}
/* Add the stylesheet and script a map needs, once per page, and resolve
* when Leaflet is ready - the map's init script runs after this and needs
* it. A card with no head resolves at once. */
function loadCardAssets(head) {
if (!head) return Promise.resolve(true);
var template = document.createElement('template');
template.innerHTML = head;
Array.prototype.slice.call(template.content.children).forEach(function (node) {
if (node.tagName === 'LINK' && node.getAttribute('href')) {
var href = node.getAttribute('href');
if (headHas('link', 'href', href)) return;
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = href;
document.head.appendChild(link);
} else if (node.tagName === 'SCRIPT' && node.getAttribute('src')) {
var src = node.getAttribute('src');
if (headHas('script', 'src', src)) return;
var script = document.createElement('script');
script.src = src;
document.head.appendChild(script);
} else if (node.tagName === 'STYLE') {
document.head.appendChild(node.cloneNode(true));
}
});
if (window.L) return Promise.resolve(true);
return new Promise(function (resolve) {
var waited = 0;
var timer = setInterval(function () {
waited += 50;
if (window.L || waited >= 5000) {
clearInterval(timer);
resolve(!!window.L);
}
}, 50);
});
}
function appendCard(json) {
var card = buildCard(json);
grid.appendChild(card);
fitTextRows();
initMoveHandles(card);
initResizeHandles(card);
initSizeMenus(card);
updateVisualCount();
var title = json.title || ('Visual ' + (json.visual + 1));
var count = grid.querySelectorAll('.visual-card').length;
card.focus();
announce((KIND_NAMES[json.kind] || 'Visual') + ' "' + title
+ '" added at the end of the canvas. ' + count + ' visual'
+ (count === 1 ? '' : 's') + ' on the canvas.');
var lib = drawLib(json.kind);
loadCardAssets(json.head).then(function (ready) {
if (lib && !libLoaded(lib)) {
announceLibMissing(lib, json.kind, title);
return;
}
if (!ready) {
announceLibMissing(lib || DRAW_LIBS.map, json.kind, title);
return;
}
runCardScripts(card, json.nonce);
setTimeout(function () {
initCrossFilters(card);
initDownloadButtons(card);
}, 50);
if (!lib) return;
whenDrawn(card, json.kind, function (drawn) {
if (drawn) {
announce((KIND_NAMES[json.kind] || 'Visual') + ' "' + title
+ '" finished drawing.');
} else {
announce((KIND_NAMES[json.kind] || 'Visual') + ' "' + title
+ '" was added, but it did not finish drawing.');
}
});
});
}
/* ---- changing a map card's columns in place ----
*
* A map card that plotted the wrong column should not have to be deleted
* and added again. The edit control on the card opens the card's own
* encoding - a place column, or a latitude and longitude - and PATCHES
* the visual at its index: the place in the layout, the size and the
* title stay, and only the body is replaced. The server draws the
* replacement through the same pipeline and URL state as the card being
* replaced; the map's script is re-run the way an appended card's is.
*/
var editPanel = document.getElementById('me-panel');
var editForm = document.getElementById('me-form');
var editLoc = document.getElementById('me-loc');
var editLoc2 = document.getElementById('me-loc2');
var editLat = document.getElementById('me-lat');
var editLon = document.getElementById('me-lon');
var editSave = document.getElementById('me-save');
var editCancel = document.getElementById('me-cancel');
var editError = document.getElementById('me-error');
if (editPanel && editForm && editLoc && editLat && editLon && editSave && editError) {
var editTarget = null; /* { card, btn, index } */
( run in 1.705 second using v1.01-cache-2.11-cpan-60884a8df76 )