any_sparklines 2.2.1 copy "any_sparklines: ^2.2.1" to clipboard
any_sparklines: ^2.2.1 copied to clipboard

Feature-rich and highly optimized sparklines for Flutter

Sparklines #

Tests

Feature-rich, highly optimized sparklines for Flutter. Line, bar, pie, and between-line charts with shared layouts, animation, and flexible styling.

App Screenshot


Core concepts #

Layouts #

  • AbsoluteLayout — Data coordinates map 1:1 to pixels; origin bottom-left, Y up.
  • RelativeLayout — Data is scaled to explicit bounds. Use RelativeLayout.normalized() (0–1), RelativeLayout.signed() (-1–1), or RelativeLayout.full() (auto from data). Set minX/maxX/minY/maxY to double.infinity or double.negativeInfinity to derive from chart data. Identical layout instances are resolved once and shared across all charts using them.
  • RelativeDimension — For RelativeLayout, use relativeTo: RelativeDimension.width or RelativeDimension.height so lengths (e.g. stroke width) scale with chart size; none uses absolute values.

Rotation, flip, and origin #

  • ChartRotationd0, d90, d180, d270 (clockwise). For d90/d270, logical width/height are swapped so the chart fills the widget.
  • ChartFlipnone, vertically, horizontally, both. Flip charts around axes; applied after rotation.
  • originOffset applied before rotation; use to position charts.

Crop and visibility #

  • crop — When true, rendering is clipped to chart bounds. Chart-level crop overrides the widget default.
  • visible — Per-chart; when false, the chart is skipped.

DataPoint #

  • x — X coordinate.
  • y — Base Y (e.g. stacked base).
  • dy — Delta from base; fy = y + dy is the value used for drawing.
  • data — Extensible Map<Type, IDataPointData?> for per-point metadata. Keys are type tokens; values implement IDataPointData (supports lerpTo for animation). Use point.of<M>() for type-safe access.

Common data entries (via extension getters or of<M>()):

  • styleIDataPointStyle? (e.g. CircleDataPointStyle) for point markers.
  • thicknessIThicknessOverride? (size, color, gradient, align) to override chart thickness for this point.
  • pieOffsetIPieOffset? for pie slice offset.
  • DataPointMetaid, key, label for tooltips or identification.

Thickness (global and per-point) #

  • ThicknessDatasize, color, optional gradient (overrides color), align: ThicknessData.alignInside (-1), alignCenter (0), alignOutside (1).
  • ThicknessOverride on DataPoint — Same fields; overrides chart thickness for that point.

Border and border radius #

  • IChartBorderborder (ThicknessData?), borderRadius (double?). Used by BarData and PieData.

Area fill (line charts) #

  • areaColor / areaGradient — Fill below the line (from line down to base Y). Gradient takes precedence over color.
  • areaFillType — Optional PathFillType for the fill.

Line charts #

LineDataline, thickness, areaColor/areaGradient, areaFillType, lineType, pointStyle.

Line types #

  • LinearLineData — Straight segments; optional isStrokeCapRound, isStrokeJoinRound.
  • SteppedLineData — Step at fraction between points: stepJumpAt 0→prev, 1→next; constructors .start(), .middle(), .end().
  • CurvedLineData — Smooth curve; smoothness 0.0–1.0 (default 0.35).

Between-line charts #

BetweenLineData — Fills the area between two lines. from, to (both LineData), areaColor, areaGradient, areaFillType. Uses same layout; both lines share the same coordinate system.

Bar charts #

BarDatabars (List<DataPoint>; fy = top, y = base), thickness, border, borderRadius, pointStyle. Bars are drawn from y to fy; use DataPointPipeline for stacking.

Pie charts #

PieData — Each DataPoint is one arc: x = radius, y = start angle, dy = sweep (end = y + dy). Angles in radians. thickness, padAngle (gap between slices), pieOffset, border, borderRadius, pointStyle. Bounds are computed from slice geometry.


DataPoint pipeline #

DataPointPipeline — Build transformed lists for stacking/normalization; reuse one pipeline for multiple series so shared state (e.g. stacking) is consistent.

  • stack({ spacing }) — Stack points by x; each point’s y becomes the running sum at that x, dy stays the value. Optional spacing adds gap between stacked segments.
  • normalize({ total, threshold?, spacing?, thresholdPoint? }) — Scale dy so sum of abs(dy) equals total (default 1.0). threshold repeatedly drops smallest segment until none below threshold; thresholdPoint receives accumulated dy of removed points. spacing reserves gap between segments.
  • normalize2pi({ total, threshold?, spacing?, thresholdPoint? }) — Same as normalize with default total 2π for angles.

IThresholdPoints / ThresholdPoints — When normalize removes below-threshold points and uses thresholdPoint, the aggregate point’s data contains ThresholdPoints(removed) so you can access the original points via point.of<IThresholdPoints>()?.thresholdPoints.

final pipeline = DataPointPipeline().stack().normalize(total: 1.0);
final seriesA = pipeline.build(rawPointsA);
final seriesB = pipeline.build(rawPointsB);

Widget options #

SparklinesChart

  • charts — List of ISparklinesData (e.g. LineData, BarData, PieData, BetweenLineData).
  • layout — Default IChartLayout (e.g. AbsoluteLayout(), RelativeLayout.full()).
  • crop — Default clip-to-bounds.
  • width / height — Fixed size; one can be null and filled by layout.
  • aspectRatio — Used when both width and height are null.
  • animate — Enable data-driven animation (default true).
  • animationDuration — Default 300 ms.
  • animationCurve — Default Curves.easeInOut.

Charts implement ILerpTo for smooth transitions when data changes.


Extending #

  • IDataPointStyle + IDataPointRenderer — Custom point markers.
  • IChartRenderer — Custom chart types.
  • ILineTypeData + ILineTypeRenderer — Custom line path and stroke.
  • IChartLayout — Custom coordinate systems; implement resolve(), transform(), transformScalar().
0
likes
0
points
584
downloads

Publisher

unverified uploader

Weekly Downloads

Feature-rich and highly optimized sparklines for Flutter

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, vector_math

More

Packages that depend on any_sparklines