Skip to content

Commit 9b5e9ec

Browse files
authored
fix: chart default options (#1594)
1 parent bd0e6e8 commit 9b5e9ec

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

src/unfold/static/unfold/css/styles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/unfold/static/unfold/js/app.js

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@ const DEFAULT_CHART_OPTIONS = {
416416
pointBorderWidth: 0,
417417
pointStyle: false,
418418
},
419+
pie: {
420+
borderWidth: 0,
421+
},
422+
doughnut: {
423+
borderWidth: 0,
424+
},
419425
},
420426
plugins: {
421427
legend: {
@@ -436,6 +442,13 @@ const DEFAULT_CHART_OPTIONS = {
436442
},
437443
scales: {
438444
x: {
445+
display: function (context) {
446+
if (["pie", "doughnut", "radar"].includes(context.chart.config.type)) {
447+
return false;
448+
}
449+
450+
return true;
451+
},
439452
border: {
440453
dash: [5, 5],
441454
dashOffset: 2,
@@ -456,6 +469,13 @@ const DEFAULT_CHART_OPTIONS = {
456469
},
457470
},
458471
y: {
472+
display: function (context) {
473+
if (["pie", "doughnut", "radar"].includes(context.chart.config.type)) {
474+
return false;
475+
}
476+
477+
return true;
478+
},
459479
border: {
460480
dash: [5, 5],
461481
dashOffset: 5,
@@ -512,8 +532,17 @@ const renderCharts = () => {
512532
const borderColor = hasDarkClass ? baseColorDark : baseColorLight;
513533

514534
for (const chart of charts) {
515-
chart.options.scales.x.grid.color = borderColor;
516-
chart.options.scales.y.grid.color = borderColor;
535+
if (chart.options.scales.x) {
536+
chart.options.scales.x.grid.color = borderColor;
537+
}
538+
539+
if (chart.options.scales.y) {
540+
chart.options.scales.y.grid.color = borderColor;
541+
}
542+
543+
if (chart.options.scales.r) {
544+
chart.options.scales.r.grid.color = borderColor;
545+
}
517546
chart.update();
518547
}
519548
};
@@ -556,11 +585,30 @@ const renderCharts = () => {
556585
processColor("backgroundColor");
557586
}
558587

588+
CHART_OPTIONS = { ...DEFAULT_CHART_OPTIONS };
589+
if (type === "radar") {
590+
CHART_OPTIONS.scales = {
591+
r: {
592+
ticks: {
593+
backdropColor: "transparent",
594+
},
595+
pointLabels: {
596+
color: "#9ca3af",
597+
font: {
598+
size: 12,
599+
},
600+
},
601+
},
602+
};
603+
}
604+
Chart.defaults.font.family = "Inter";
605+
Chart.defaults.font.size = 12;
606+
559607
charts.push(
560608
new Chart(ctx, {
561609
type: type || "bar",
562610
data: parsedData,
563-
options: options ? JSON.parse(options) : { ...DEFAULT_CHART_OPTIONS },
611+
options: options ? JSON.parse(options) : { ...CHART_OPTIONS },
564612
})
565613
);
566614
}

src/unfold/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@source inline("{md:,lg:,2xl:,}relative {md:,lg:,2xl:,}flex {md:,lg:,2xl:,}absolute {md:,lg:,2xl:,}sticky");
1717
@source inline("{-,}{lg:,}m{t,r,b,l,x,y,}-{0..24} {-,}{lg:,}p{t,r,b,l,x,y,}-{0..24}");
1818
@source inline("{md:,lg:,}border-{0,2} {md:,lg:,}border-{t,r,b,l}-{0,2}");
19-
@source inline("{hover:,dark:,}bg-primary-{50,{100..900..100},950}");
19+
@source inline("{!,}{hover:,dark:,}bg-primary-{50,{100..900..100},950}");
2020
@source inline("{hover:,dark:,}border-base-{50,{100..900..100},950} {hover:,dark:,}border-transparent");
2121
@source inline("{hover:,dark:,}bg-base-{50,{100..900..100},950}");
2222
@source inline("{md:,lg:,}{min-h,h,min-w,w}-{1..8} {md:,lg:,}w-{1/2,1/3,2/3,1/4,2/4,3/4,1/5,2/5,3/5,4/5,1/6,2/6,3/6,4/6,5/6,1/7,2/7,3/7,4/7,5/7,6/7}");

0 commit comments

Comments
 (0)