Skip to content

Commit

Permalink
Fix for c3js#2798. Hide title when there is no data is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoover authored and Hoover committed Oct 5, 2020
1 parent 6bfb579 commit 6e10da6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 41 deletions.
54 changes: 17 additions & 37 deletions htdocs/samples/chart_pie.html
Expand Up @@ -8,45 +8,25 @@
<script src="https://d3js.org/d3.v5.min.js" charset="utf-8"></script>
<script src="../js/c3.js"></script>
<script>
console.log("here1")
var chart = c3.generate({
data: {
columns: [
// ["setosa", 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.4, 0.4, 0.3, 0.3, 0.3, 0.2, 0.4, 0.2, 0.5, 0.2, 0.2, 0.4, 0.2, 0.2, 0.2, 0.2, 0.4, 0.1, 0.2, 0.2, 0.2, 0.2, 0.1, 0.2, 0.2, 0.3, 0.3, 0.2, 0.6, 0.4, 0.3, 0.2, 0.2, 0.2, 0.2],
["versicolor", 1.4, 1.5, 1.5, 1.3, 1.5, 1.3, 1.6, 1.0, 1.3, 1.4, 1.0, 1.5, 1.0, 1.4, 1.3, 1.4, 1.5, 1.0, 1.5, 1.1, 1.8, 1.3, 1.5, 1.2, 1.3, 1.4, 1.4, 1.7, 1.5, 1.0, 1.1, 1.0, 1.2, 1.6, 1.5, 1.6, 1.5, 1.3, 1.3, 1.3, 1.2, 1.4, 1.2, 1.0, 1.3, 1.2, 1.3, 1.3, 1.1, 1.3],
["virginica", 2.5, 1.9, 2.1, 1.8, 2.2, 2.1, 1.7, 1.8, 1.8, 2.5, 2.0, 1.9, 2.1, 2.0, 2.4, 2.3, 1.8, 2.2, 2.3, 1.5, 2.3, 2.0, 2.0, 1.8, 2.1, 1.8, 1.8, 1.8, 2.1, 1.6, 1.9, 2.0, 2.2, 1.5, 1.4, 2.3, 2.4, 1.8, 1.8, 2.1, 2.4, 2.3, 1.9, 2.3, 2.5, 2.3, 1.9, 2.0, 2.3, 1.8],
["setosa", 30],
// ["versicolor", 40],
// ["virginica", 50],
],
type : 'pie',
onmouseover: function (d, i) { console.log("onmouseover", d, i, this); },
onmouseout: function (d, i) { console.log("onmouseout", d, i, this); },
onclick: function (d, i) { console.log("onclick", d, i, this); },
},
axis: {
x: {
label: 'Sepal.Width'
},
y: {
label: 'Petal.Width'
}
data: {
columns: [
['data1', 30],
['data2', 120],
],
type : 'donut',
empty : {
label: {
text: "No Data"
}
}
});

setTimeout(function () {
chart.load({
columns: [
["setosa", 130],
]
});
}, 1000);

setTimeout(function () {
chart.unload({
ids: 'virginica'
});
}, 2000);
},
donut: {
title: "Iris Petal Width"
}
});

</script>
</body>
</html>
</html>
5 changes: 1 addition & 4 deletions src/arc.ts
Expand Up @@ -702,10 +702,7 @@ ChartInternal.prototype.redrawArc = function(
.style('opacity', function(d) {
return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0
})
main
.select('.' + CLASS.chartArcsTitle)
.style('opacity', $$.hasType('donut') || hasGaugeType ? 1 : 0)


if (hasGaugeType) {
let index = 0
const backgroundArc = $$.arcs
Expand Down
5 changes: 5 additions & 0 deletions src/core.ts
Expand Up @@ -732,6 +732,11 @@ ChartInternal.prototype.redraw = function(options, transitions) {
.transition()
.style('opacity', targetsToShow.length ? 0 : 1)

// Only show arc title if chart type is donut or gauge and if there are any data to show
main
.select('.' + CLASS.chartArcsTitle)
.style('opacity', ($$.hasType('donut') || $$.hasType('gauge')) && targetsToShow.length > 0 ? 1 : 0)

// event rect
if (withEventRect) {
$$.redrawEventRect()
Expand Down

0 comments on commit 6e10da6

Please sign in to comment.