定制 candycore/sugar-charts 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

candycore/sugar-charts

最新稳定版本:v0.2.0

Composer 安装命令:

composer require candycore/sugar-charts

包简介

PHP port of NimbleMarkets/ntcharts — terminal charts (canvas, sparkline, bar, line, heatmap, scatter, time-series, OHLC, streamline, waveline) for SugarCraft.

README 文档

README

sugar-charts

SugarCharts

CI codecov Packagist Version License PHP

demo

composer require sugarcraft/sugar-charts

PHP port of NimbleMarkets/ntcharts — terminal charts for SugarCraft. v0 ships the canvas foundation plus three self-contained chart types.

use SugarCraft\Charts\Sparkline\Sparkline;
use SugarCraft\Charts\BarChart\BarChart;
use SugarCraft\Charts\LineChart\LineChart;

echo Sparkline::new([1, 3, 2, 8, 5, 4, 7, 6], 8)->view() . PHP_EOL;
// ▁▃▂█▅▄▇▆

echo BarChart::new([['cpu', 0.7], ['mem', 0.4], ['disk', 0.9]], 20, 5)->view() . PHP_EOL;
// 0.9 ┤   ▏  █
// 0.7 ┤█  ▏  █
// 0.4 ┤█  █  █
//     └────────
//      cpu mem disk

echo LineChart::new([1, 4, 2, 8, 6, 3, 7], 30, 6)->view() . PHP_EOL;

Charts also expose short-form aliases on the most-used setters: data / size / min / max / point / xRange / yRange / colors / palette / bars / barWidth / showLabels / showAxis, etc. The upstream-mirroring with* long forms still work; pick the form that reads best at the call site.

Components

Component Role Notable knobs
Charts\Canvas\Canvas Fixed-size cell grid; each cell holds a rune + optional Sprinkles Style. setCell / setLines / setString / setRunes / fill / fillLine / shiftUp / shiftDown / shiftLeft / shiftRight / setCellStyle / getCellStyle
Charts\Canvas\BrailleGrid Sub-cell scratch buffer (2 cols × 4 rows of dots per cell). Paint dots, then copy to a Canvas. set / unset / toggle / isSet / rune / paint(Canvas, x0, y0, ?Style) / clear
Charts\Canvas\Graph Drawing primitives over a Canvas. drawHLine / drawVLine / drawXYAxis / drawXYAxisLabel / drawString / drawLine / drawLinePoints / fillRect / drawColumn / drawColumns / drawRows / drawCandlestick / drawBrailleRune / drawBraillePatterns / drawVerticalLineUp / drawVerticalLineDown / drawHorizontalLineLeft / drawHorizontalLineRight / getCirclePoints / getCirclePointsWithLimit / getFullCirclePoints / getFullCirclePointsWithLimit / getLinePointsWithLimit
Charts\Sparkline\Sparkline Single-row series renderer using the 8 Unicode bar glyphs. push / pushAll / clear / withMin / withMax / withStyle(?Style) / withNoAutoMaxValue(bool) / withWidth
Charts\BarChart\BarChart Labeled vertical bars; auto-scales to a configurable min / max. withBarWidth / withBarGap / withNoAutoBarWidth / push(Bar|array) / pushAll(iterable) / clear
Charts\LineChart\LineChart Single-series ASCII plot drawn onto a Canvas with configurable axes. withYRange / withXRange / withXYRange / autoAdjustRange / withXLabelFormatter / withYLabelFormatter / withAxes / withXLabels / withYLabels
Charts\LineChart\TimeSeries LineChart variant accepting [\DateTimeImmutable, value] tuples. push / withPoints / withTimeFormat / withXLabelCount / withTimeRange(?start, ?end) / getTimeRange()
Charts\LineChart\Streamline Single-row streaming line — auto-windowed to width. push / pushAll / clear / withSize / withMin / withMax / withYRange
Charts\LineChart\Wavelinechart XY scatter / wave plot driven by (x, y) pairs. push / pushAll / clear / withSize / withXRange / withYRange / withXYRange / withPoint
Charts\Heatmap\Heatmap 2D grid coloured by value with optional palette / legend. withSize / withMin / withMax / withPalette / withLegend / withColors(cold, hot) / withColorProfile / withCellStyle(?Style) / withAutoValueRange(bool) / pushPoint(HeatPoint) / pushAll
Charts\OHLC\OHLC Candlestick chart for (high, open, close, low) rows. withSize / withCandleStyle / withWickStyle
Charts\Scatter\Scatter XY scatter plot. push / pushAll / withSize / withMin / withMax
Charts\Picture\Picture Inline image renderer (Sixel today; Kitty / iTerm2 protocols pending). withFromFile / withDimensions / view

Graph primitives at a glance

Graph is a static-method utility — every draw call takes a Canvas plus coordinates in canvas (cell) space (top-left origin). Pair with BrailleGrid for sub-cell precision:

use SugarCraft\Charts\Canvas\{Canvas, BrailleGrid, Graph};

$canvas = new Canvas(40, 8);
Graph::drawXYAxis($canvas, 1, 6, 38);
Graph::drawString($canvas, 4, 0, 'Demo');

// Sub-cell line via BrailleGrid.
$grid = new BrailleGrid(38, 6);
foreach (Graph::getLinePointsWithLimit(0, 0, 75, 23, limit: 200) as [$x, $y]) {
    $grid->set($x, $y);
}
$grid->paint($canvas, 1, 0);
echo $canvas->view();

Palette / colour profile

Heatmap::withPalette([Color, …]) interpolates between an arbitrary number of stops (≥ 2). withColors(Color $cold, Color $hot) is the two-stop shortcut. withColorProfile(ColorProfile) overrides the auto-detected output profile when piping to non-tty / Sixel-capable sinks. Heatmap::withCellStyle(Style) overlays additional attributes (bold / background / etc.) on top of every cell's foreground gradient.

Demos

Bar chart

bar

Heatmap

heatmap

Line chart

line

OHLC (candlestick)

ohlc

Picture (Sixel)

picture

Scatter

scatter

Sparkline

sparkline

Time series

timeseries

Status

Component State
Canvas, BrailleGrid, Graph primitives 🟢 v1
Sparkline 🟢 v1
BarChart 🟢 v1 (multi-bar grouped datasets pending)
LineChart 🟢 v1 (zoom/pan + dataset styles pending)
TimeSeries 🟢 v1 (multi-dataset + update-handler variants pending)
Streamline, Wavelinechart 🟢 v1
Heatmap 🟢 v1 (default-color-scale getter/setter pending)
OHLC 🟡 candlestick rendering only — volume sub-pane + multi-series pending
Scatter 🟡 single-dataset only — per-point rune/style sets pending
Picture 🟡 Sixel renderer only — Kitty graphics protocol + iTerm2 inline + half-block fallback pending

Test

cd sugar-charts && composer install && vendor/bin/phpunit

candycore/sugar-charts 适用场景与选型建议

candycore/sugar-charts 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「charts」 「terminal」 「graphs」 「heatmap」 「sparkline」 「time-series」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 candycore/sugar-charts 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 candycore/sugar-charts 我们能提供哪些服务?
定制开发 / 二次开发

基于 candycore/sugar-charts 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 54
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-07