joelniklaus HF Staff commited on
Commit
f5e74b5
·
1 Parent(s): 8a721e9

fix score correlation dark mode issue

Browse files
app/src/content/embeds/score-correlation.html CHANGED
@@ -315,12 +315,18 @@
315
  svg.selectAll('*').remove();
316
 
317
  // Color scale: diverging, reversed so positive = blue
318
- // Wider domain (±0.85) so colors stay readable longer
319
- const colorScale = d3.scaleDiverging()
 
320
  .domain([-0.85, 0, 0.85])
321
  .interpolator(d3.interpolateRdBu)
322
  .clamp(true);
323
- const cellColor = (r) => colorScale(-r);
 
 
 
 
 
324
 
325
  const g = svg.append('g').attr('transform', `translate(${leftMargin},${topMargin})`);
326
 
@@ -396,7 +402,7 @@
396
  .attr('stroke', isDark ? 'rgba(255,255,255,0.06)' : 'rgba(0,0,0,0.04)')
397
  .attr('stroke-width', 0.5);
398
 
399
- const textFill = (r) => Math.abs(r) > 0.5 ? '#fff' : textCol;
400
 
401
  cells.append('text')
402
  .attr('x', (cellW - 1) / 2)
@@ -414,7 +420,7 @@
414
  .attr('text-anchor', 'end')
415
  .attr('font-size', '11px')
416
  .attr('font-weight', '700')
417
- .attr('fill', d => Math.abs(d.r) > 0.5 ? 'rgba(255,255,255,0.8)' : mutedCol)
418
  .text(d => d.p < 0.001 ? '***' : d.p < 0.01 ? '**' : d.p < 0.05 ? '*' : '');
419
 
420
  // --- Row labels (predictors, with hover descriptions) ---
@@ -582,8 +588,13 @@
582
  // Legend
583
  const legend = document.createElement('div');
584
  legend.className = 'legend';
585
- const cs = d3.scaleDiverging().domain([-0.85, 0, 0.85]).interpolator(d3.interpolateRdBu).clamp(true);
586
- const sw = (r) => cs(-r);
 
 
 
 
 
587
  legend.innerHTML = `
588
  <div class="legend-title">Legend</div>
589
  <div class="items">
 
315
  svg.selectAll('*').remove();
316
 
317
  // Color scale: diverging, reversed so positive = blue
318
+ // Custom interpolator that fades to transparent at the midpoint
319
+ // so near-zero cells blend with the page background in both modes
320
+ const baseScale = d3.scaleDiverging()
321
  .domain([-0.85, 0, 0.85])
322
  .interpolator(d3.interpolateRdBu)
323
  .clamp(true);
324
+ const cellColor = (r) => {
325
+ const c = d3.color(baseScale(-r));
326
+ const t = Math.abs(r) / 0.85;
327
+ const alpha = Math.max(0.12, Math.min(1, t * 1.8));
328
+ return `rgba(${c.r},${c.g},${c.b},${alpha})`;
329
+ };
330
 
331
  const g = svg.append('g').attr('transform', `translate(${leftMargin},${topMargin})`);
332
 
 
402
  .attr('stroke', isDark ? 'rgba(255,255,255,0.06)' : 'rgba(0,0,0,0.04)')
403
  .attr('stroke-width', 0.5);
404
 
405
+ const textFill = (r) => Math.abs(r) > 0.45 ? '#fff' : textCol;
406
 
407
  cells.append('text')
408
  .attr('x', (cellW - 1) / 2)
 
420
  .attr('text-anchor', 'end')
421
  .attr('font-size', '11px')
422
  .attr('font-weight', '700')
423
+ .attr('fill', d => Math.abs(d.r) > 0.45 ? 'rgba(255,255,255,0.8)' : mutedCol)
424
  .text(d => d.p < 0.001 ? '***' : d.p < 0.01 ? '**' : d.p < 0.05 ? '*' : '');
425
 
426
  // --- Row labels (predictors, with hover descriptions) ---
 
588
  // Legend
589
  const legend = document.createElement('div');
590
  legend.className = 'legend';
591
+ const csBase = d3.scaleDiverging().domain([-0.85, 0, 0.85]).interpolator(d3.interpolateRdBu).clamp(true);
592
+ const sw = (r) => {
593
+ const rgb = d3.color(csBase(-r));
594
+ const t = Math.abs(r) / 0.85;
595
+ const alpha = Math.max(0.12, Math.min(1, t * 1.8));
596
+ return `rgba(${rgb.r},${rgb.g},${rgb.b},${alpha})`;
597
+ };
598
  legend.innerHTML = `
599
  <div class="legend-title">Legend</div>
600
  <div class="items">