Skip to content

Commit 0eb3a49

Browse files
committed
tune chart palette
1 parent 37f9dc1 commit 0eb3a49

1 file changed

Lines changed: 45 additions & 28 deletions

File tree

src/components/ChartContainer.jsx

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -176,28 +176,45 @@ export default function ChartContainer({
176176
}
177177
}, [parsedData, onXRangeChange]);
178178

179-
// Use a modern palette inspired by Tableau 10
180-
const colors = [
181-
'#4e79a7', // blue
182-
'#f28e2c', // orange
183-
'#e15759', // red
184-
'#76b7b2', // teal
185-
'#59a14f', // green
186-
'#edc948', // yellow
187-
'#b07aa1', // purple
188-
'#ff9da7', // pink
189-
'#9c755f', // brown
190-
'#bab0ab' // gray
179+
// Matplotlib tab10 palette with slightly reduced saturation
180+
const baseColors = [
181+
'#1f77b4', // blue
182+
'#ff7f0e', // orange
183+
'#2ca02c', // green
184+
'#d62728', // red
185+
'#9467bd', // purple
186+
'#8c564b', // brown
187+
'#e377c2', // pink
188+
'#7f7f7f', // gray
189+
'#bcbd22', // olive
190+
'#17becf' // cyan
191191
];
192+
193+
const lightenColor = (hex, factor = 0.2) => {
194+
const r = parseInt(hex.slice(1, 3), 16);
195+
const g = parseInt(hex.slice(3, 5), 16);
196+
const b = parseInt(hex.slice(5, 7), 16);
197+
const nr = Math.round(r + (255 - r) * factor)
198+
.toString(16)
199+
.padStart(2, '0');
200+
const ng = Math.round(g + (255 - g) * factor)
201+
.toString(16)
202+
.padStart(2, '0');
203+
const nb = Math.round(b + (255 - b) * factor)
204+
.toString(16)
205+
.padStart(2, '0');
206+
return `#${nr}${ng}${nb}`;
207+
};
192208
const createChartData = dataArray => ({
193209
datasets: dataArray.map((item, index) => {
194-
const color = colors[index % colors.length];
210+
const base = baseColors[index % baseColors.length];
211+
const color = lightenColor(base, 0.2);
195212
return {
196213
label: item.name?.replace(/\.(log|txt)$/i, '') || `File ${index + 1}`,
197214
data: item.data,
198215
borderColor: color,
199216
backgroundColor: `${color}33`,
200-
borderWidth: 2,
217+
borderWidth: 1.5,
201218
fill: false,
202219
tension: 0,
203220
pointRadius: 0,
@@ -399,18 +416,18 @@ export default function ChartContainer({
399416
{
400417
label: `${title} 差值`,
401418
data: comparisonData,
402-
borderColor: '#e15759',
403-
backgroundColor: '#e15759',
404-
borderWidth: 2,
419+
borderColor: lightenColor('#d62728', 0.2),
420+
backgroundColor: lightenColor('#d62728', 0.2),
421+
borderWidth: 1.5,
405422
fill: false,
406423
tension: 0,
407424
pointRadius: 0,
408425
pointHoverRadius: 4,
409-
pointBackgroundColor: '#e15759',
410-
pointBorderColor: '#e15759',
426+
pointBackgroundColor: lightenColor('#d62728', 0.2),
427+
pointBorderColor: lightenColor('#d62728', 0.2),
411428
pointBorderWidth: 1,
412-
pointHoverBackgroundColor: '#e15759',
413-
pointHoverBorderColor: '#e15759',
429+
pointHoverBackgroundColor: lightenColor('#d62728', 0.2),
430+
pointHoverBorderColor: lightenColor('#d62728', 0.2),
414431
pointHoverBorderWidth: 1,
415432
animation: false,
416433
animations: { colors: false, x: false, y: false },
@@ -421,19 +438,19 @@ export default function ChartContainer({
421438
datasets.push({
422439
label: 'Baseline',
423440
data: baselineData,
424-
borderColor: '#76b7b2',
425-
backgroundColor: '#76b7b2',
426-
borderWidth: 2,
441+
borderColor: lightenColor('#17becf', 0.2),
442+
backgroundColor: lightenColor('#17becf', 0.2),
443+
borderWidth: 1.5,
427444
borderDash: [5, 5],
428445
fill: false,
429446
tension: 0,
430447
pointRadius: 0,
431448
pointHoverRadius: 4,
432-
pointBackgroundColor: '#76b7b2',
433-
pointBorderColor: '#76b7b2',
449+
pointBackgroundColor: lightenColor('#17becf', 0.2),
450+
pointBorderColor: lightenColor('#17becf', 0.2),
434451
pointBorderWidth: 1,
435-
pointHoverBackgroundColor: '#76b7b2',
436-
pointHoverBorderColor: '#76b7b2',
452+
pointHoverBackgroundColor: lightenColor('#17becf', 0.2),
453+
pointHoverBorderColor: lightenColor('#17becf', 0.2),
437454
pointHoverBorderWidth: 1,
438455
animation: false,
439456
animations: { colors: false, x: false, y: false },

0 commit comments

Comments
 (0)