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

[Bug] #643

Open
thichmautim opened this issue Jan 19, 2025 · 1 comment
Open

[Bug] #643

thichmautim opened this issue Jan 19, 2025 · 1 comment

Comments

@thichmautim
Copy link

Version

9.8.12

Steps to Reproduce

我发现当在 iOS 设备上使用 KLineCharts 库时,priceMark 的价格标记在垂直方向上没有居中对齐。请看图片。

Image

Current Behavior

出现了如上图所示的偏移现象。

Expected Behavior

调整为两边对称。

Environment

- OS: iOS 18.2.1
- Browser: WebView IOS
- Framework: Flutter

Any additional comments?

No response

@thichmautim
Copy link
Author

thichmautim commented Feb 3, 2025

Temporary solution:

file : /src/extension/figure/text.ts

export function drawText(
  ctx: CanvasRenderingContext2D,
  attrs: TextAttrs | TextAttrs[],
  styles: Partial<TextStyle>,
): void {
  let texts: TextAttrs[] = []
  texts = texts.concat(attrs)
  let {
    color = 'currentColor',
    size = 12,
    family,
    weight,
    paddingLeft = 0,
    paddingTop = 0,
    paddingRight = 0,
  } = styles
  const rects = texts.map((text) => getTextRect(text, styles))
  drawRect(ctx, rects, { ...styles, color: styles.backgroundColor })

  ctx.fillStyle = color
  ctx.textAlign = 'left'
  ctx.textBaseline = 'top'
  ctx.font = createFont(size, weight, family)

  // Fix bug where content is not centered vertically on iOS devices //
  if (isIOS()) {
    paddingTop -= 2
  }

  texts.forEach((text, index) => {
    const rect = rects[index]
    ctx.fillText(
      text.text,
      rect.x + paddingLeft,
      rect.y + paddingTop,
      rect.width - paddingLeft - paddingRight,
    )
  })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant