-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: tooltip 调整 #2460
Merged
Merged
fix: tooltip 调整 #2460
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ export default class Tooltip extends Controller<TooltipOption> { | |
return 'tooltip'; | ||
} | ||
|
||
public init() { } | ||
public init() {} | ||
|
||
public render() { | ||
const option = this.view.getOptions().tooltip; | ||
|
@@ -59,7 +59,8 @@ export default class Tooltip extends Controller<TooltipOption> { | |
*/ | ||
public showTooltip(point: Point) { | ||
this.point = point; | ||
if (!this.isVisible) { // 如果设置 tooltip(false) 则始终不显示 | ||
if (!this.isVisible) { | ||
// 如果设置 tooltip(false) 则始终不显示 | ||
return; | ||
} | ||
const view = this.view; | ||
|
@@ -99,10 +100,17 @@ export default class Tooltip extends Controller<TooltipOption> { | |
// 延迟生成 | ||
this.renderTooltip(); | ||
} | ||
this.tooltip.update(mix({}, cfg, { | ||
items, | ||
title, | ||
}, follow ? point : {})); | ||
this.tooltip.update( | ||
mix( | ||
{}, | ||
cfg, | ||
{ | ||
items, | ||
title, | ||
}, | ||
follow ? point : {} | ||
) | ||
); | ||
this.tooltip.show(); | ||
} | ||
|
||
|
@@ -309,7 +317,8 @@ export default class Tooltip extends Controller<TooltipOption> { | |
return []; | ||
} | ||
|
||
public layout() { } | ||
public layout() {} | ||
|
||
public update() { | ||
if (this.point) { | ||
this.showTooltip(this.point); | ||
|
@@ -429,11 +438,15 @@ export default class Tooltip extends Controller<TooltipOption> { | |
start = center; | ||
} | ||
|
||
const cfg = deepMix({ | ||
start, | ||
end, | ||
container: this.getTooltipCrosshairsGroup(), | ||
}, get(tooltipCfg, 'crosshairs', {}), this.getCrosshairsText('x', point, tooltipCfg)); | ||
const cfg = deepMix( | ||
{ | ||
start, | ||
end, | ||
container: this.getTooltipCrosshairsGroup(), | ||
}, | ||
get(tooltipCfg, 'crosshairs', {}), | ||
this.getCrosshairsText('x', point, tooltipCfg) | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我不太喜欢这种格式化的 style... 要不后面单独提一个 prettier 的 commit 吧,不要将 fix/feat 的代码和格式化的代码提到一个 commit 里。 |
||
delete cfg.type; // 与 Crosshairs 组件的 type 冲突故删除 | ||
|
||
let xCrosshair = this.xCrosshair; | ||
|
@@ -495,16 +508,23 @@ export default class Tooltip extends Controller<TooltipOption> { | |
type = 'Circle'; | ||
} | ||
|
||
cfg = deepMix({ | ||
container: this.getTooltipCrosshairsGroup() | ||
}, cfg, get(tooltipCfg, 'crosshairs', {}), this.getCrosshairsText('y', point, tooltipCfg)); | ||
cfg = deepMix( | ||
{ | ||
container: this.getTooltipCrosshairsGroup(), | ||
}, | ||
cfg, | ||
get(tooltipCfg, 'crosshairs', {}), | ||
this.getCrosshairsText('y', point, tooltipCfg) | ||
); | ||
delete cfg.type; // 与 Crosshairs 组件的 type 冲突故删除 | ||
|
||
let yCrosshair = this.yCrosshair; | ||
if (yCrosshair) { | ||
// 如果坐标系发生直角坐标系与极坐标的切换操作 | ||
if ((coordinate.isRect && yCrosshair.get('type') === 'circle') | ||
|| (!coordinate.isRect && yCrosshair.get('type') === 'line')) { | ||
if ( | ||
(coordinate.isRect && yCrosshair.get('type') === 'circle') || | ||
(!coordinate.isRect && yCrosshair.get('type') === 'line') | ||
) { | ||
yCrosshair = new Crosshair[type](cfg); | ||
yCrosshair.init(); | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ function hasClass(dom, className) { | |
return false; | ||
} | ||
let cls = ''; | ||
if (!dom.className) { return false; } | ||
if (!dom.className) { | ||
return false; | ||
} | ||
if (!isNil(dom.className.baseVal)) { | ||
cls = dom.className.baseVal; | ||
} else { | ||
|
@@ -77,13 +79,6 @@ class TooltipAction extends Action { | |
// 锁定 tooltip 时不隐藏 | ||
return; | ||
} | ||
|
||
const event = this.context.event; | ||
const toElement = get(event, [ 'gEvent', 'originalEvent', 'toElement' ]); | ||
if (toElement && (hasClass(toElement, 'g2-tooltip') || isParent(toElement, 'g2-tooltip'))) { | ||
// 当鼠标滑入 tooltip 内容框时不隐藏 | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @simaQ 主要改了这一行了,帮忙看看~ |
||
this.hideTooltip(view); | ||
this.location = null; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个格式化效果也没有很好啊~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对呀。。。