Skip to content

Commit a24f997

Browse files
author
Adam Kasprowicz
committed
#118 tooltip not visible
1 parent 863f4ea commit a24f997

File tree

7 files changed

+395
-361
lines changed

7 files changed

+395
-361
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ function buildDomWrapper(el, options) {
759759
if (options.title && options.showTitle) {
760760
html += `<div class="keen-dataviz-title ${options.theme}-title">${options.title}</div>`;
761761
}
762-
html += `<div class="${options.theme}-rendering ${options.theme}-rendering-${align}">${container}</div>`;
762+
html += `<div class="keen-dataviz-rendering keen-dataviz-rendering-${align} ${options.theme}-rendering ${options.theme}-rendering-${align}">${container}</div>`;
763763
if (options.notes) {
764764
html += `<div class="keen-dataviz-notes ${options.theme}-notes">${options.notes}</div>`;
765765
}

lib/libraries/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,45 @@ export default function(lib) {
2929
}, delay);
3030
});
3131

32+
// FIX for c3 tooltip bug - REMOVE when https://github.com/c3js/c3/pull/2476 is merged
33+
if (c3.chart && c3.chart.internal && c3.chart.internal.fn) {
34+
c3.chart.internal.fn.horizontalDistance = function(data, pos) {
35+
var $$ = this,
36+
config = $$.config,
37+
xIndex = config.axis_rotated ? 1 : 0,
38+
x = $$.x(data.x);
39+
return Math.abs(x - pos[xIndex]);
40+
};
41+
c3.chart.internal.fn.findClosest = function (values, pos) {
42+
const CLASS = c3.chart.internal.fn.CLASS;
43+
var $$ = this,
44+
minDist = $$.config.point_sensitivity,
45+
minDist = Infinity,
46+
closest;
47+
// find mouseovering bar
48+
values.filter(function (v) {
49+
return v && $$.isBarType(v.id);
50+
}).forEach(function (v) {
51+
var shape = $$.main.select('.' + CLASS.bars + $$.getTargetSelectorSuffix(v.id) + ' .' + CLASS.bar + '-' + v.index).node();
52+
if (!closest && $$.isWithinBar($$.d3.mouse(shape), shape)) {
53+
closest = v;
54+
}
55+
});
56+
// find closest point from non-bar
57+
values.filter(function (v) {
58+
return v && !$$.isBarType(v.id);
59+
}).forEach(function (v) {
60+
var d = $$.dist(v, pos);
61+
var d = $$.horizontalDistance(v, pos);
62+
if (d < minDist) {
63+
minDist = d;
64+
closest = v;
65+
}
66+
});
67+
return closest;
68+
};
69+
}
70+
3271
return defineC3();
3372
};
3473

@@ -276,6 +315,7 @@ function defineC3(){
276315

277316
// Render artifacts
278317
this.view._artifacts['c3'] = c3.generate(c3options);
318+
279319
c3PaginatingLegend.call(this, {...options, onLegendRendered: () => {
280320
const legendElement = this.el().querySelector('.keen-c3-legend');
281321
if (legendElement) {

0 commit comments

Comments
 (0)