Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the problem that tooltipMarker not show. Closed #234. #237

Merged
merged 1 commit into from
Aug 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});