Skip to content

Commit

Permalink
Adding some awesome transitions to the tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
ruhley committed Nov 19, 2015
1 parent e274053 commit 1e6d6d0
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 39 deletions.
7 changes: 7 additions & 0 deletions dc.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
fill-opacity: .8;
}

.dc-chart .pie-slice path {
stroke-width: 1;
stroke: #FFFFFF;
}


.dc-chart .pie-path {
fill:none;
stroke-width: 2px;
Expand Down Expand Up @@ -297,6 +303,7 @@ g.dc-legend-item.fadeout {
border: 2px solid #000000;
pointer-events: none;
user-select: none;
opacity: 0.8;
}

.dc-title:before,
Expand Down
39 changes: 30 additions & 9 deletions dc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dc.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dc.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dc.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dc.min.js.map

Large diffs are not rendered by default.

39 changes: 30 additions & 9 deletions src/base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1303,23 +1303,40 @@ dc.baseMixin = function (_chart) {
data = d.data;
}

var tooltip = d3.select('body')
.append('div')
.attr('class', 'dc-title')
.html(_title(data));
// get the tooltip
var tooltip = d3.select('.dc-title');

// the tooltip doesn't exist, so create it
if (tooltip.empty()) {
tooltip = d3.select('body')
.append('div')
.attr('class', 'dc-title')
.style('opacity', 0);
}

var style = {
'border-color': _chart.getColor(d.layer ? d : data, i),
};
// cancel any transitions
tooltip.interrupt();

// set the content of the tooltip
tooltip.html(_title(data));

// set the standard styles
tooltip.style('border-color', _chart.getColor(d.layer ? d : data, i));

// calculate the position of the tooltip
var tooltipBounding = tooltip.node().getBoundingClientRect();
var style = {
opacity: 1,
};

// if a pie chart
if (arc) {
var gBounding = _chart.g().node().getBoundingClientRect();
var centroid = arc.centroid(d);

style.left = gBounding.left + (gBounding.width / 2) - (tooltipBounding.width / 2) + centroid[0];
style.top = gBounding.top + (gBounding.height / 2) - tooltipBounding.height - 10 + centroid[1];
// all other charts
} else {
var elBounding = element.getBoundingClientRect();

Expand All @@ -1330,11 +1347,15 @@ dc.baseMixin = function (_chart) {
style.top += 'px';
style.left += 'px';

tooltip.style(style);
// move the tooltip into position
dc.transition(tooltip, _chart.transitionDuration() / 1.5)
.style(style);
};

_chart._removeTitle = function() {
d3.selectAll('.dc-title').remove();
dc.transition(d3.select('.dc-title'), _chart.transitionDuration() / 1.5)
.style('opacity', 0)
.remove();
};

/**
Expand Down
7 changes: 7 additions & 0 deletions web/css/dc.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
fill-opacity: .8;
}

.dc-chart .pie-slice path {
stroke-width: 1;
stroke: #FFFFFF;
}


.dc-chart .pie-path {
fill:none;
stroke-width: 2px;
Expand Down Expand Up @@ -297,6 +303,7 @@ g.dc-legend-item.fadeout {
border: 2px solid #000000;
pointer-events: none;
user-select: none;
opacity: 0.8;
}

.dc-title:before,
Expand Down
2 changes: 1 addition & 1 deletion web/css/dc.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1e6d6d0

Please sign in to comment.