moonchartkit

Accessible SVG and Markdown report artifacts for MoonBit.

report
svg
accessibility
markdown
ci
moon add cosettese/moonchartkit@0.2.0
Download zip
Author
Version
0.2.0
License
Apache-2.0
Last updated
last month
Downloads
13
README

#MoonChartKit

MoonChartKit 是面向 MoonBit 的无障碍 SVG 报告工件与文档可视化基础库。它服务于 README、CI 报告、Issue、PR、静态文档和小型状态面板,不试图替代完整统计绘图库。

#核心价值

  • 多表示交付:一次生成 SVG、替代文本和 Markdown 数据表。
  • 无障碍语义:SVG 包含 <title><desc>role="img" 和 ARIA 关联。
  • 结构化审计:自动检查可访问名称、描述、ARIA 与脚本风险。
  • 安全嵌入:标题、描述、标签和主题文本统一转义。
  • 后端中立:输出纯字符串,不依赖浏览器、DOM、Canvas 或文件系统。

#无障碍报告工件

test {
let artifact = render_accessible_report(
"Build Health",
"CI status by target",
[
DataPoint::new("Native", 12),
DataPoint::new("Wasm", 18),
],
[10, 12, 15, 18],
)

assert_true(artifact.audit.passed())
assert_true(artifact.svg.contains("aria-labelledby="))
assert_true(artifact.markdown.contains("| Native |"))
}

ReportArtifact 包含:

  • svg:可直接嵌入 HTML 或文档的无障碍图形;
  • markdown:对屏幕阅读器、纯文本环境和代码评审友好的数据表;
  • alt_text:紧凑的自然语言摘要;
  • summary:结构化统计;
  • audit:可自动纳入 CI 的质量检查。

#其他组件

  • 柱状图、折线图和 sparkline
  • Metric Card、Progress Bar
  • 组合 Dashboard
  • Atelier 和 Midnight 主题
  • XML 转义与图表摘要 JSON

#运行与验收

moon check --target all moon test --target wasm moon run cmd/main moon run cmd/bench

#
ChartSize

pub(all) struct ChartSize {
width : Int
height : Int
padding : Int
} derive(Eq,
Debug
)

#
ChartSize::new

fn ChartSize::new(width : Int, height : Int, padding : Int) -> ChartSize

#
ChartSize::plot_area

fn ChartSize::plot_area(self : ChartSize) -> PlotArea

#
ChartSummary

pub(all) struct ChartSummary {
count : Int
total : Int
max : Int
average : Int
} derive(Eq,
Debug
)

#
ChartSummary::from_points

fn ChartSummary::from_points(points : Array[DataPoint]) -> ChartSummary

#
ChartSummary::to_json

fn ChartSummary::to_json(self : ChartSummary) -> String

#
ChartTheme

pub(all) struct ChartTheme {
background : String
foreground : String
accent : String
accent_alt : String
grid : String
font_family : String
radius : Int
} derive(Eq,
Debug
)

#
ChartTheme::atelier

fn ChartTheme::atelier() -> ChartTheme

#
ChartTheme::midnight

fn ChartTheme::midnight() -> ChartTheme

#
DataPoint

pub(all) struct DataPoint {
label : String
value : Int
} derive(Eq,
Debug
)

#
DataPoint::new

fn DataPoint::new(label : String, value : Int) -> DataPoint

#
PlotArea

pub(all) struct PlotArea {
x : Int
y : Int
width : Int
height : Int
} derive(Eq,
Debug
)

#
ReportArtifact

pub(all) struct ReportArtifact {
svg : String
markdown : String
alt_text : String
summary : ChartSummary
audit : SvgAudit
} derive(Eq,
Debug
)

A report bundle with visual and non-visual representations.

#
SvgAudit

pub(all) struct SvgAudit {
has_title : Bool
has_description : Bool
has_aria_labelledby : Bool
has_role_img : Bool
has_unsafe_script : Bool
issue_count : Int
} derive(Eq,
Debug
)

Structural accessibility and safety checks for generated SVG.

#
SvgAudit::passed

fn SvgAudit::passed(self : SvgAudit) -> Bool

#
audit_svg

fn audit_svg(svg : String) -> SvgAudit

Audits the accessibility contract used by MoonChartKit report artifacts.

#
escape_label

fn escape_label(value : String) -> String

#
max_value

fn max_value(points : Array[DataPoint]) -> Int

#
percent_of

fn percent_of(value : Int, total : Int) -> Int

#
render_accessible_report

fn render_accessible_report(title : String, description : String, points : Array[DataPoint], trend : Array[Int], size? : ChartSize, theme? : ChartTheme) -> ReportArtifact

Generates an accessible SVG report and a Markdown data fallback.

#
render_bar_chart

fn render_bar_chart(points : Array[DataPoint], title? : String, size? : ChartSize, theme? : ChartTheme) -> String

#
render_dashboard

fn render_dashboard(title : String, points : Array[DataPoint], trend : Array[Int], size? : ChartSize, theme? : ChartTheme) -> String

#
render_line_chart

fn render_line_chart(points : Array[DataPoint], title? : String, size? : ChartSize, theme? : ChartTheme) -> String

#
render_metric_card

fn render_metric_card(title : String, value : String, caption? : String, size? : ChartSize, theme? : ChartTheme) -> String

#
render_progress_bar

fn render_progress_bar(label : String, value : Int, max : Int, size? : ChartSize, theme? : ChartTheme) -> String

#
render_sparkline

fn render_sparkline(values : Array[Int], size? : ChartSize, theme? : ChartTheme) -> String

#
total_value

fn total_value(points : Array[DataPoint]) -> Int