thibaud frere commited on
Commit ·
cb92d91
1
Parent(s): 95e6b80
update
Browse filesFiles changed (2)
118 unmodified lines1191201211221231241251261271281291301311321331341351361373 unmodified lines14114214314414514614714814974 unmodified lines2242252262272282292302312322332346 unmodified lines24124224324424524624720 unmodified lines268269270271272273274118 unmodified linesdisplay: 'flex',gap: '16px',alignItems: 'center',justifyContent: 'flex-start',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'});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 selectconst legendInline = document.createElement('div');3 unmodified linesgap: '8px',alignItems: 'center',flexWrap: 'nowrap',fontSize: '11px'});controls.appendChild(legendInline);// Create SVGconst svg = d3.select(container).append('svg')74 unmodified linesxScale.range([0, innerWidth]);yScale.range([innerHeight, 0]);// Grid (horizontal)gGrid.selectAll('*').remove();const yTicks = yScale.ticks(6);gGrid.selectAll('line').data(yTicks).join('line').attr('x1', 0).attr('x2', innerWidth)6 unmodified lines// AxesgAxes.selectAll('*').remove();const xAxis = d3.axisBottom(xScale).ticks(8).tickSizeOuter(0);const yAxis = d3.axisLeft(yScale).ticks(6).tickSizeOuter(0).tickFormat(d3.format('.2f'));gAxes.append('g').attr('transform', `translate(0,${innerHeight})`).call(xAxis)20 unmodified linesgAxes.append('text').attr('class', 'axis-label axis-label--y').attr('text-anchor', 'middle').attr('transform', `translate(${-52},${innerHeight/2}) rotate(-90)`).style('font-size', '12px').style('fill', tickColor).text('Value');118 unmodified lines1191201211221231241251261271281291301311321331341351363 unmodified lines14014114214314414514614714814915074 unmodified lines2252262272282292302312322332342352362372382392402412422432446 unmodified lines25125225325425525625720 unmodified lines278279280281282283284118 unmodified linesdisplay: 'flex',gap: '16px',alignItems: 'center',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', marginLeft: 'auto'});labelMetric.textContent = 'Metric';const selectMetric = document.createElement('select');Object.assign(selectMetric.style, { fontSize: '12px' });labelMetric.appendChild(selectMetric);// Inline legend on the right of the selectconst legendInline = document.createElement('div');3 unmodified linesgap: '8px',alignItems: 'center',flexWrap: 'nowrap',fontSize: '11px',marginLeft: '8px'});controls.appendChild(legendInline);controls.appendChild(labelMetric);// Create SVGconst svg = d3.select(container).append('svg')74 unmodified linesxScale.range([0, innerWidth]);yScale.range([innerHeight, 0]);// Compute integer ticks for Yconst 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();gGrid.selectAll('line').data(yIntTicks).join('line').attr('x1', 0).attr('x2', innerWidth)6 unmodified lines// AxesgAxes.selectAll('*').remove();const xAxis = d3.axisBottom(xScale).ticks(8).tickSizeOuter(0);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 linesgAxes.append('text').attr('class', 'axis-label axis-label--y').attr('text-anchor', 'middle').attr('transform', `translate(${-44},${innerHeight/2}) rotate(-90)`).style('font-size', '12px').style('fill', tickColor).text('Value');
76 unmodified lines777879808182838485868788899091929394959619 unmodified lines11611711811912012112210 unmodified lines13313413513613713876 unmodified lines}));// Layoutlet width=800, height=460; const margin = { top: 8, right: 24, bottom: 60, 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));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){const legendHeight = 60;gLegend.attr('x', 0).attr('y', innerHeight + LEGEND_GAP).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 linesreturn pool[idx % pool.length] || primary;};renderLegend(categories, colorOf, innerWidth, innerHeight);// Clear plotsgPlots.selectAll('*').remove();10 unmodified linesconst arc = d3.arc().innerRadius(innerR).outerRadius(radius).cornerRadius(3);const arcLabel = d3.arc().innerRadius((innerR + radius) / 2).outerRadius((innerR + radius) / 2);const captions = new Map(METRICS.map(m => [m.key, `${m.title}`]));METRICS.forEach((metric, idx) => {76 unmodified lines777879808182838485868788899091929394959619 unmodified lines11611711811912012112210 unmodified lines13313413513613713813914014114214376 unmodified lines}));// Layoutlet 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(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, legendY){const legendHeight = 60;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 linesreturn pool[idx % pool.length] || primary;};// Legend will be positioned after radius is known// Clear plotsgPlots.selectAll('*').remove();10 unmodified linesconst 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 donutsconst 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