Skip to content

Commit

Permalink
fix: fix the problem that tooltipMarker not show. Closed #234.
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Aug 12, 2018
1 parent e5088dd commit 334eb76
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/plugin/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ class TooltipController {
shapes.push(type);
}
});
if (geoms.length && chart.get('coord').type === 'cartesian') {
const coordType = chart.get('coord').type;
if (geoms.length && (coordType === 'cartesian' || coordType === 'rect')) {
if (shapes.length === 1 && [ 'line', 'area', 'path', 'point' ].indexOf(shapes[0]) !== -1) {
Util.mix(defaultCfg, {
showCrosshairs: true
Expand Down Expand Up @@ -344,7 +345,7 @@ class TooltipController {
if ([ 'line', 'area', 'path' ].indexOf(type) !== -1) {
tooltipMarkerType = 'circle';
tooltipMarkerItems.push(tooltipItem);
} else if (type === 'interval' && coord.type === 'cartesian') {
} else if (type === 'interval' && (coord.type === 'cartesian' || coord.type === 'rect')) {
tooltipMarkerType = 'rect';
tooltipItem.width = geom.getSize(record._origin);
tooltipMarkerItems.push(tooltipItem);
Expand Down
45 changes: 45 additions & 0 deletions test/bug/issue-234-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const expect = require('chai').expect;
const F2 = require('../../src/core');
require('../../src/geom/interval');
const Tooltip = require('../../src/plugin/tooltip');

const canvas = document.createElement('canvas');
canvas.width = 360;
canvas.height = 360;
canvas.id = 'issue234';
document.body.appendChild(canvas);

describe('issue 234', () => {
it('tooltimarker', () => {
const data = [
{ day: '周一', value: 300 },
{ day: '周二', value: 400 },
{ day: '周三', value: 350 },
{ day: '周四', value: 500 },
{ day: '周五', value: 490 },
{ day: '周六', value: 600 },
{ day: '周日', value: 900 }
];
const chart = new F2.Chart({
id: 'issue234',
plugins: Tooltip,
pixelRatio: window.devicePixelRatio
});
chart.source(data);
chart.coord('rect', {
transposed: true
});
chart.interval().position('day*value');
chart.render();

const point = chart.getPosition({ day: '周五', value: 490 });
chart.showTooltip(point);

const tooltip = chart.get('tooltipController').tooltip;
const markerGroup = tooltip.markerGroup;
expect(markerGroup.get('children').length).to.equal(1);

const tooltipMarker = markerGroup.get('children')[0];
expect(tooltipMarker.get('type')).to.equal('rect');
});
});

0 comments on commit 334eb76

Please sign in to comment.