Liquid 水波图
用圆形水位和波纹表现 0 到 1 的容量、完成率或占用比例。
何时使用
- 需要在卡片中突出一个容量、占用或完成比例时。
- 希望用比环形进度更具视觉识别度的水位表达单一比例时。
- 需要比较多个指标或显示精确刻度时改用 Gauge 仪表盘 或 Progress 进度条。
在线体验
Gallery 在 Gauge 页面中展示低水位和高水位水波图;同一 gallery 场景可切换主题和暗色变体。
基本用法
Liquid() 接收 0 到 1 的比例,默认显示两位小数的百分比和动态波纹。Title() 为比例添加说明。
package main
import (
"github.com/tangoui/tango/ui"
"github.com/tangoui/tango/ui/chart"
)
func page(c *ui.Context) {
chart.Liquid(c, 0.3).Title("容量").Show()
}常见用法
静态水波
Still() 停止波纹运动,适合截图和静态报告。启用减少动效或设置 Animate(false) 时,波纹也会保持静止。
package main
import (
"github.com/tangoui/tango/ui"
"github.com/tangoui/tango/ui/chart"
)
func stillLiquid(c *ui.Context) {
chart.Liquid(c, 0.78).Title("存储使用率").Still().Show()
}自定义格式和尺寸
Format() 控制中心值和悬停提示的文本,Height() 设置绘图区高度;比例仍然按 0 到 1 传入。
package main
import (
"github.com/tangoui/tango/ui"
"github.com/tangoui/tango/ui/chart"
)
func formattedLiquid(c *ui.Context) {
chart.Liquid(c, 0.625).Format(chart.Percent(1)).Height(240).Title("同步进度").Show()
}颜色和无障碍
Colors() 覆盖水波颜色,A11yLabel() 提供完整语义;状态文字不要只依赖水位颜色。
package main
import (
"github.com/tangoui/tango/ui"
"github.com/tangoui/tango/ui/chart"
"github.com/tangoui/tango/ui/theme"
)
func accessibleLiquid(c *ui.Context) {
chart.Liquid(c, 0.42).Colors(theme.Hex("#1677ff")).Title("容量").A11yLabel("容量使用率 42%").Still().Show()
}静态展示和交互
水波默认支持悬停提示;静态大屏可用 NoTooltip(),异步数据到达前可用 Loading(true)。
package main
import (
"github.com/tangoui/tango/ui"
"github.com/tangoui/tango/ui/chart"
)
func staticLiquid(c *ui.Context) {
chart.Liquid(c, 0.42).Title("容量").NoTooltip().Loading(false).Show()
}主题与样式
Liquid 使用主题首个系列色、容器表面和文字对比度计算水波层;可用 Colors() 调整颜色,或用 Style(func(*chart.Style) { ... }) 做单图样式覆盖。暗色和 shadcn 主题会使用各自的背景与文字令牌,中心文字仍应保持可读。
注意事项
- 传入值是比例而不是百分数,业务层应先把原始容量换算为 0 到 1 并校验分母为零;绘制会将超范围值限制在可视范围内。
- 动态波纹会持续唤醒 UI;静态导出、低动效偏好或不需要动画时调用
Still()。 - 即时模式下把比例放在外部状态,条件切换多个水波图时用稳定
Key();异步状态用Loading(true)而不是暂时显示 0%。 A11yLabel()与Title()应说明指标和单位;RTL 需要反向波纹方向时才调用Mirror()。
示例代码
以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。
API
签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。
入口函数
chart.Liquid
func Liquid(c *ui.Context, ratio float64) *LiquidWLiquid starts a water wave gauge at ratio 0..1.
返回 *LiquidW,可链式调用的方法见 LiquidW 方法。
LiquidW 方法
chart.LiquidW:LiquidW builds a liquid fill (water wave) gauge.
| 方法 | 说明 | 签名 |
|---|---|---|
A11yLabel | A11yLabel sets the accessible name of the chart (default: its title or the localized chart kind, e.g. "折线图"). (来自嵌入的 common[LiquidW]) | A11yLabel(s string) *LiquidW |
Animate | Animate enables (default) or disables entry and update transitions. (来自嵌入的 common[LiquidW]) | Animate(on bool) *LiquidW |
Colors | Colors overrides the palette. (来自嵌入的 common[LiquidW]) | Colors(cs ...theme.Color) *LiquidW |
Format | Format sets the value formatter used by the value axis, tooltip and labels (default: thousands separators). (来自嵌入的 common[LiquidW]) | Format(f Formatter) *LiquidW |
Height | Height sets the chart height in logical pixels (the width follows the parent). (来自嵌入的 common[LiquidW]) | Height(h float32) *LiquidW |
Key | Key gives the chart a stable identity (legend and animation state) when charts are added or removed around it. (来自嵌入的 common[LiquidW]) | Key(k any) *LiquidW |
Label | Label shows data labels on the marks. (来自嵌入的 common[LiquidW]) | Label() *LiquidW |
Layout | Layout applies layout options to the chart box (Grow, Margin ...). (来自嵌入的 common[LiquidW]) | Layout(o ...layout.Option) *LiquidW |
Legend | Legend places (or with LegendNone hides) the legend. (来自嵌入的 common[LiquidW]) | Legend(p LegendPos) *LiquidW |
Loading | Loading shows a spinner over the chart (or in place of it without data). (来自嵌入的 common[LiquidW]) | Loading(on bool) *LiquidW |
Mirror | Mirror draws the plot right to left: the x axis runs from the right, the value axis sits on the right, bars, lines, areas and points are mirrored (so categories read in reverse order), and pie, donut, radar and gauge start at the mirrored angle and sweep counter-clockwise. (来自嵌入的 common[LiquidW]) | Mirror() *LiquidW |
NoTooltip | NoTooltip disables the hover tooltip and crosshair. (来自嵌入的 common[LiquidW]) | NoTooltip() *LiquidW |
Show | Show builds the chart. | Show() View |
Still | Still stops the wave motion (static screenshots, reduced motion). | Still() *LiquidW |
Style | Style tweaks the resolved chart style for this chart only. (来自嵌入的 common[LiquidW]) | Style(fn func(*Style)) *LiquidW |
Title | Title sets the caption under the percentage. | Title(s string) *LiquidW |