8000 Fix/dom style when has customized content by xile611 · Pull Request #3637 · VisActor/VChart · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix/dom style when has customized content #3637

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

Merged
merged 7 commits into from
Jan 7, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix style of dom tooltip when tooltip has customized child, fix #3615\n\n",
"type": "none",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "dingling112@gmail.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix error update of dom tooltip when update theme, fix #3619\n\n",
"type": "none",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "dingling112@gmail.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix position of html tooltip when confine is false, fix #3632\n\n",
"type": "none",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "dingling112@gmail.com"
}
7 changes: 4 additions & 3 deletions packages/vchart/src/plugin/components/tooltip-handler/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,10 @@ export abstract class BaseTooltipHandler extends BasePlugin implements ITooltipH

/* 三、确保tooltip在视区内 */
const containerDimSize = dim === 'x' ? containerSize.width : containerSize.height;
const leftOrTop =
-(tooltipParentElementRect[dim] - (chartElementRect?.[dim] ?? 0) / chartElementScale) /
tooltipParentElementScale;
const leftOrTop = tooltipSpec.confine
? -(tooltipParentElementRect[dim] - (chartElementRect?.[dim] ?? 0) / chartElementScale) /
tooltipParentElementScale
: -tooltipParentElementRect[dim] / tooltipParentElementScale;
const rightOrBottom = containerDimSize / tooltipParentElementScale + leftOrTop - boxSize;

// 处理左右
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class DomTooltipHandler extends BaseTooltipHandler {
styleByRow = { ...styleByRow, ...getTextStyle(entry.valueStyle) };
}
} else if (colName === 'shape') {
row.innerHTML = getSvgHtml(entry);
row.innerHTML = getSvgHtml(entry, `${this.id}_${index}`);
}

setStyleToDom(row, styleByRow);
Expand All @@ -299,9 +299,11 @@ export class DomTooltipHandler extends BaseTooltipHandler {
protected _updateDomStyle(sizeKey: 'width' | 'height' = 'width') {
const rootDom = this._rootDom;

const contentDom = rootDom.children[rootDom.children.length - 1];
const contentDom = [...(rootDom.children as any)].find(child =>
child.className.includes(TOOLTIP_CONTENT_BOX_CLASS_NAME)
);

if (contentDom.className.includes(TOOLTIP_CONTENT_BOX_CLASS_NAME)) {
if (contentDom) {
const tooltipSpec = this._component.getSpec() as ITooltipSpec;
const contentStyle: Partial<CSSStyleDeclaration> = {};

Expand Down Expand Up @@ -369,6 +371,14 @@ export class DomTooltipHandler extends BaseTooltipHandler {
reInit() {
super.reInit();
this._initStyle();
if (this._rootDom) {
setStyleToDom(this._rootDom, this._domStyle.panel);
}

if (this.getVisibility()) {
this._updateDomStringByCol(this._tooltipActual);
this._updateDomStyle('height');
}
}

protected _updatePosition({ x, y }: ITooltipPositionActual) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Symbol } from '@visactor/vrender-core';
import { Bounds, isObject, isString } from '@visactor/vutils';
import type { ITooltipShapeActual } from '../../../../typings';

export function getSvgHtml(option: ITooltipShapeActual | undefined, index?: number) {
export function getSvgHtml(option: ITooltipShapeActual | undefined, gradientId?: string) {
if (!option || !option.hasShape || !option.shapeType) {
return '';
}
Expand Down Expand Up @@ -61,7 +61,7 @@ export function getSvgHtml(option: ITooltipShapeActual | undefined, index?: numb
</svg>`;
}
if (isObject(shapeFill)) {
fillString = 'gradientColor' + (index ?? '');
fillString = 'gradientColor' + (gradientId ?? '');
let gradient = '';
const stops = ((shapeFill as IGradientColor).stops ?? [])
.map(s => `<stop offset="${escapeHTML(s.offset.toString())}" stop-color="${escapeHTML(s.color)}"/>`)
Expand Down
Loading
0