thibaud frere commited on
Commit ·
cb92d91
1
Parent(s): 95e6b80
update
Browse filesFiles changed (2)
118 unmodified lines1191201211221221231241251261271281281291301311321331341341351363 unmodified lines14014114214414314414514614714814915074 unmodified lines2252262272282292302312322332342352362372382392292402312412422432446 unmodified lines25125225324425425525625720 unmodified lines278279280271281282283284118 unmodified lines display: 'flex', gap: '16px', alignItems: 'center', justifyContent: 'flex-start', justifyContent: 'space-between', width: '100%' });
const labelMetric = document.createElement('label'); Object.assign(labelMetric.style, { fontSize: '12px', color: 'var(--muted-color)', display: 'flex', alignItems: 'center', gap: '6px', whiteSpace: 'nowrap', padding: '6px 10px' fontSize: '12px', color: 'var(--muted-color)', display: 'flex', alignItems: 'center', gap: '6px', whiteSpace: 'nowrap', padding: '6px 10px', marginLeft: 'auto' }); labelMetric.textContent = 'Metric'; const selectMetric = document.createElement('select'); Object.assign(selectMetric.style, { fontSize: '12px' }); labelMetric.appendChild(selectMetric); controls.appendChild(labelMetric);
// Inline legend on the right of the select const legendInline = document.createElement('div');3 unmodified lines gap: '8px', alignItems: 'center', flexWrap: 'nowrap', fontSize: '11px' fontSize: '11px', marginLeft: '8px' }); controls.appendChild(legendInline); controls.appendChild(labelMetric);
// Create SVG const svg = d3.select(container).append('svg')74 unmodified lines xScale.range([0, innerWidth]); yScale.range([innerHeight, 0]);
// Compute integer ticks for Y const yDomain = yScale.domain(); const yMin = Math.min(yDomain[0], yDomain[1]); const yMax = Math.max(yDomain[0], yDomain[1]); let yStep = Math.max(1, Math.round((yMax - yMin) / 6)); if (!isFinite(yStep) || yStep <= 0) yStep = 1; let yIntTicks = []; for (let v = Math.ceil(yMin); v <= Math.floor(yMax); v += yStep) { yIntTicks.push(v); } if (yIntTicks.length === 0) { yIntTicks = [Math.round(yMin), Math.round(yMax)]; }
// Grid (horizontal) gGrid.selectAll('*').remove(); const yTicks = yScale.ticks(6); gGrid.selectAll('line') .data(yTicks) .data(yIntTicks) .join('line') .attr('x1', 0) .attr('x2', innerWidth)6 unmodified lines // Axes gAxes.selectAll('*').remove(); const xAxis = d3.axisBottom(xScale).ticks(8).tickSizeOuter(0); const yAxis = d3.axisLeft(yScale).ticks(6).tickSizeOuter(0).tickFormat(d3.format('.2f')); const yAxis = d3.axisLeft(yScale).tickValues(yIntTicks).tickSizeOuter(0).tickFormat(d3.format('d')); gAxes.append('g') .attr('transform', `translate(0,${innerHeight})`) .call(xAxis)20 unmodified lines gAxes.append('text') .attr('class', 'axis-label axis-label--y') .attr('text-anchor', 'middle') .attr('transform', `translate(${-52},${innerHeight/2}) rotate(-90)`) .attr('transform', `translate(${-44},${innerHeight/2}) rotate(-90)`) .style('font-size', '12px') .style('fill', tickColor) .text('Value');76 unmodified lines77787980808182838485858687888990919192939394959619 unmodified lines11611711811911912012112210 unmodified lines13313413513613713813914014114214376 unmodified lines }));
// Layout let width=800, height=460; const margin = { top: 8, right: 24, bottom: 60, left: 24 }; let width=800, height=450; const margin = { top: 0, right: 24, bottom: 32, left: 24 }; const CAPTION_GAP = 28; // espace entre titre et donut (augmenté) const LEGEND_GAP = 8; // espace entre donut et légende (réduit) const updateSize = () => { width = container.clientWidth || 800; height = Math.max(320, Math.round(width/2.5)); height = Math.max(260, Math.round(width/3.4)); svg.attr('width', width).attr('height', height); gRoot.attr('transform', `translate(${margin.left},${margin.top})`); return { innerWidth: width - margin.left - margin.right, innerHeight: height - margin.top - margin.bottom }; };
function renderLegend(categories, colorOf, innerWidth, innerHeight){ function renderLegend(categories, colorOf, innerWidth, legendY){ const legendHeight = 60; gLegend.attr('x', 0).attr('y', innerHeight + LEGEND_GAP).attr('width', innerWidth).attr('height', legendHeight); gLegend.attr('x', 0).attr('y', legendY).attr('width', innerWidth).attr('height', legendHeight); const root = gLegend.selectAll('div').data([0]).join('xhtml:div'); root.html(`<div class="items">${categories.map(c => `<div class="item"><span class="swatch" style="background:${colorOf(c)}"></span><span style="font-weight:500">${c}</span></div>`).join('')}</div>`); }19 unmodified lines return pool[idx % pool.length] || primary; };
renderLegend(categories, colorOf, innerWidth, innerHeight); // Legend will be positioned after radius is known
// Clear plots gPlots.selectAll('*').remove();10 unmodified lines const arc = d3.arc().innerRadius(innerR).outerRadius(radius).cornerRadius(3); const arcLabel = d3.arc().innerRadius((innerR + radius) / 2).outerRadius((innerR + radius) / 2);
// Now that radius is known, position legend just beneath donuts const tempCy = innerHeight / 2; const legendY = tempCy + radius + (CAPTION_GAP * 2); renderLegend(categories, colorOf, innerWidth, legendY);
const captions = new Map(METRICS.map(m => [m.key, `${m.title}`]));
METRICS.forEach((metric, idx) => {app/src/content/embeds/d3-line.html+18-8
app/src/content/embeds/d3-pie.html+10-5