-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfastchart.stub.php
More file actions
2492 lines (2211 loc) · 98.1 KB
/
Copy pathfastchart.stub.php
File metadata and controls
2492 lines (2211 loc) · 98.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/** @generate-class-entries */
namespace FastChart;
/**
* Chart objects carry their entire state in a native C struct, not in
* PHP properties. Dynamic properties would be silently dropped from
* every render, and serialize() would emit a state-less husk that
* unserializes into a blank chart. Forbid both so misuse fails loudly.
*
* @strict-properties
* @not-serializable
*/
abstract class Chart
{
public const int THEME_LIGHT = 0;
public const int THEME_DARK = 1;
public const int MARKER_NONE = 0;
public const int MARKER_CIRCLE = 1;
public const int MARKER_SQUARE = 2;
public const int MARKER_DIAMOND = 3;
public const int MARKER_CROSS = 4;
public const int MARKER_PLUS = 5;
public const int LEGEND_NONE = 0;
public const int LEGEND_TOP_RIGHT = 1;
public const int LEGEND_TOP_LEFT = 2;
public const int LEGEND_BOTTOM_RIGHT = 3;
public const int LEGEND_BOTTOM_LEFT = 4;
public const int SCALE_LINEAR = 0;
public const int SCALE_LOG = 1;
public const int LABEL_NONE = 0;
public const int LABEL_INSIDE = 1;
public const int LABEL_OUTSIDE = 2;
public const int STYLE_CANDLE = 0;
public const int STYLE_BAR = 1;
public const int STYLE_DIAMOND = 2;
public const int STYLE_I_CAP = 3;
public const int STYLE_HOLLOW = 4;
public const int STYLE_VOLUME = 5;
public const int STYLE_VECTOR = 6;
/** Border-side bitmask for setBorderSides(). OR them together. */
public const int BORDER_NONE = 0;
public const int BORDER_LEFT = 1;
public const int BORDER_RIGHT = 2;
public const int BORDER_TOP = 4;
public const int BORDER_BOTTOM = 8;
public const int BORDER_ALL = 15;
/** Line interpolation modes for setLineInterpolation(). */
public const int INTERP_LINEAR = 0;
public const int INTERP_SMOOTH = 1;
public const int INTERP_STEP_AFTER = 2;
public const int INTERP_STEP_BEFORE = 3;
/** Tick mode for setTickMode(). */
public const int TICK_NONE = 0;
public const int TICK_LABELS = 1;
public const int TICK_POINTS = 2;
public const int TICK_BOTH = 3;
/** Stacking mode for BarChart::setStackMode() / AreaChart. */
public const int STACK_SUM = 0;
public const int STACK_BESIDE = 1;
public const int STACK_LAYER = 2;
/** Pie slice-label positions (extends LABEL_INSIDE / OUTSIDE / NONE). */
public const int LABEL_LEFT = 3;
public const int LABEL_RIGHT = 4;
/** Line dash style for setLineStyle(). */
public const int LINE_SOLID = 0;
public const int LINE_DASHED = 1;
public const int LINE_DOTTED = 2;
/** Gradient direction for setGradientFill(). */
public const int GRADIENT_VERTICAL = 0;
public const int GRADIENT_HORIZONTAL = 1;
/** Date-axis stride units for setDateAxisStride(). */
public const int DATE_DAY = 0;
public const int DATE_WEEK = 1;
public const int DATE_MONTH = 2;
public const int DATE_QUARTER = 3;
public const int DATE_YEAR = 4;
/**
* SVG text emission mode for setSvgTextMode().
*
* `SVG_TEXT_PATHS` (default) flattens every `<text>` element to a
* `<g><path d="..."/></g>` group via FreeType outline
* decomposition. The resulting SVG is self-contained — it renders
* correctly in any SVG rasterizer, including ones that don't
* support text (such as plutovg, which fastchart uses internally
* for PNG/JPG/WebP output). File size grows ~30%+ vs native text.
*
* `SVG_TEXT_NATIVE` emits raw `<text>` elements. Smaller files;
* requires the consumer's renderer to support SVG text and have
* the named font (or a sans-serif fallback) available.
*
* `renderPng()`, `renderJpeg()`, `renderWebp()`, and
* `renderToFile()` for raster formats always use PATHS internally
* regardless of this setting — they go through plutovg.
*/
public const int SVG_TEXT_NATIVE = 0;
public const int SVG_TEXT_PATHS = 1;
/**
* WebP encoder modes selected via `setWebpMode()`.
*
* `WEBP_DRAWING` (default) — `WEBP_PRESET_DRAWING` + `method=2`,
* tuned for chart-shaped content (flat fills, sharp edges, small
* palette). Best speed/size trade-off for most charts.
*
* `WEBP_PHOTO` — `WEBP_PRESET_PHOTO` + `method=4`. Better for
* charts that embed photographic background images via
* `setBackgroundImage()`; libwebp's photo entropy model handles
* gradient and natural-image regions more efficiently than the
* drawing preset.
*
* `WEBP_LOSSLESS` — `lossless=1` + `method=6`. Bit-exact output
* with no perceptual loss. For chart content with limited
* palettes, lossless WebP often produces similar or smaller
* files than lossy at quality 90 and is faster to encode (no
* quality-search pass). Use for archival output or when the
* downstream tooling needs pixel-exact recovery. The `quality`
* parameter to `renderWebp()` is ignored in this mode.
*
* `WEBP_FAST` — `WEBP_PRESET_DRAWING` + `method=0`. Fastest
* encode at the cost of larger files (~10-20% larger than
* DRAWING). Use for short-lived previews and hot paths where
* encode time dominates.
*/
public const int WEBP_DRAWING = 0;
public const int WEBP_PHOTO = 1;
public const int WEBP_LOSSLESS = 2;
public const int WEBP_FAST = 3;
/**
* Optionally pass canvas dimensions at construction so callers
* can skip the `imagecreatetruecolor()` step entirely when they
* use the renderXxx() shortcuts. Both `null` keeps the default
* 800 x 600. setSize() still works and overrides per-instance.
*/
public function __construct(?int $width = null, ?int $height = null) {}
public static function version(): string {}
/**
* Rasterize a caller-supplied SVG document to PNG bytes via the
* same plutosvg + plutovg + libpng pipeline that powers
* `renderPng()`. Useful for converting stitched
* `drawSvgFragment()` output back to raster, or for any
* SVG-bytes → PNG conversion that fastchart can serve in-process
* (no fork / ImageMagick dependency).
*
* Output dimensions are read from the root `<svg>` element's
* `width` / `height` / `viewBox`. Percentage dimensions are
* rejected — fastchart doesn't carry an outer viewport.
*
* **SVG `<text>` elements are not rendered.** plutovg has no
* text engine; fastchart's own SVG output flattens text to
* `<path>` data via `SVG_TEXT_PATHS` mode before rasterizing.
* Caller-supplied SVG must do the same — `<text>` elements
* survive parsing but produce no glyph geometry in the output.
* Use Inkscape's "Object to Path", Illustrator's "Create
* Outlines", or `text-to-path` in your SVG toolchain before
* passing the bytes here.
*
* **Rejected for safety, all throw `\ValueError`:**
* - SVG containing `data:image/` URIs (any case). plutosvg's
* `<image href="data:image/...">` loader decodes the embedded
* raster inline via libpng/libjpeg, bypassing the output
* dimension caps below. Decode embedded images separately
* if your workflow needs them.
* - SVG containing `<use>` elements (any case). plutosvg's
* reference-expansion path is a billion-laughs vector — a
* sub-2-KB SVG can trigger 10^8+ shape renders via nested
* `<use>` fan-out. Inline the referenced content with
* `<g transform="...">` to compose multiple chart fragments
* instead.
*
* Caps: SVG input ≤ 16 MB, ≤ 65,536 elements,
* ≤ 262,144 attributes, and ≤ 256 nesting levels; output
* ≤ 4096 px per side and ≤ 16M total pixels. Malformed XML or
* out-of-range dimensions
* throw `\ValueError`. Rasterizer or encoder failure throws
* `\Error`.
*/
public static function svgToPng(string $svg): string {}
/**
* Rasterize SVG to JPEG bytes. Same constraints as
* `svgToPng()`, plus a flat background color (`$bgRgb`,
* 24-bit RGB, default white `0xFFFFFF`) is composited under
* the rasterized output before JPEG encoding — JPEG has no
* alpha channel, so transparent SVG regions would otherwise
* render as black.
*
* `$quality` is 1..100; default 88 matches the chart-side
* default. The encoder runs libjpeg-turbo with
* `optimize_coding=TRUE` and 4:2:0 chroma subsampling.
*/
public static function svgToJpeg(string $svg, int $quality = 88,
int $bgRgb = 0xFFFFFF): string {}
/**
* Rasterize SVG to WebP bytes. Same constraints as
* `svgToPng()`. `$quality` is 1..100; ignored when
* `$mode === Chart::WEBP_LOSSLESS`. `$mode` is one of
* `WEBP_DRAWING` (default), `WEBP_PHOTO`, `WEBP_LOSSLESS`,
* `WEBP_FAST` — see the `WEBP_*` constants for the per-mode
* encoder configuration.
*/
public static function svgToWebp(string $svg, int $quality = 90,
int $mode = Chart::WEBP_DRAWING): string {}
public function setSize(int $width, int $height): static {}
/**
* Set the chart title. Throws ValueError if $title exceeds 8192
* bytes; glyph-path SVG output replays each glyph inline, so an
* unbounded title balloons the document. The same 8192-byte cap
* applies to every rendered-text setter (axis titles, annotation
* and band/line labels); oversized array-element labels are
* dropped rather than throwing. Graph node labels, hierarchy
* labels, and text annotations each have a 65536-byte aggregate
* budget. A chart accepts at most 128 text annotations.
*/
public function setTitle(string $title): static {}
public function setTheme(int $theme): static {}
public function setBackgroundColor(int $rgb): static {}
public function setPlotBackgroundColor(int $rgb): static {}
public function setSeriesColors(array $colors): static {}
public function setFontPath(string $path): static {}
public function setFontSize(float $size): static {}
public function setCategoryLabels(array $labels): static {}
public function setLegendPosition(int $position): static {}
/**
* Scale of the *value* axis. SCALE_LINEAR (default) or SCALE_LOG
* (base-10, requires strictly positive data).
*
* Misnomer note: the setter is named for the Y axis because every
* chart family except horizontal BarChart puts values on Y.
* BarChart with `setOrientation(BAR_HORIZONTAL)` puts values on
* the X axis, but still consults this setter (i.e. on horizontal
* bar charts, `setYAxisScale(SCALE_LOG)` actually configures the
* X axis). The name is preserved across types so callers don't
* need a chart-specific setter.
*/
public function setYAxisScale(int $scale): static {}
/**
* Strict-mode validation for setSeries() input. When enabled,
* non-numeric / non-null cells in the data array trigger a
* TypeError instead of silently coercing to NaN. Default: off.
*
* Coverage: enforced on `LineChart::setSeries`,
* `AreaChart::setSeries`, `BarChart::setSeries`, and
* `Funnel::setStages`. All other
* array-based setters (Pie::setSlices, Scatter::setPoints,
* Stock::setOhlcv, Gantt::setTasks, BoxPlot::setBoxes,
* Radar/Polar::setSeries, Surface/Contour::setGrid,
* Treemap/Waterfall/Heatmap/Sunburst/Sankey/etc.)
* are best-effort: malformed entries are silently dropped
* (or turned into NaN) even when setStrict(true) is used.
* See docs/README.md "Strict mode coverage and best-effort families".
*/
public function setStrict(bool $strict): static {}
/**
* X-axis title rendered below the X-axis labels. Empty string
* suppresses. Pie ignores. Default: "" (no title).
*/
public function setXAxisTitle(string $title): static {}
/**
* Y-axis title rendered rotated 90deg to the left of the
* Y-axis labels. Empty string suppresses.
*/
public function setYAxisTitle(string $title): static {}
/**
* Rotate the X-axis tick labels. 0, 45, or 90 degrees only;
* other values raise \ValueError. Useful when long date or
* category labels overlap horizontally.
*/
public function setXAxisLabelAngle(int $degrees): static {}
/**
* Force Y-axis bounds and (optionally) tick interval. Pass
* null for any argument to keep the auto-computed value.
* Forced ranges still go through "nice" tick rounding unless
* `$interval` is supplied. If one forced endpoint conflicts with
* the other endpoint after data-driven auto-ranging, rendering
* throws \ValueError.
*/
public function setYAxisRange(?float $min = null, ?float $max = null, ?float $interval = null): static {}
/**
* Enable a secondary Y axis on the right side of the plot.
* Series can opt into the right axis via an `'axis' => 'right'`
* key in the series dict (default 'left'). Independent value
* range and tick scale per axis. Currently honored on
* `LineChart` and `AreaChart`; other types silently ignore.
*/
public function setSecondaryYAxis(bool $enabled): static {}
/**
* Draw a straight reference line across the plot: addHorizontalLine
* at a constant Y value, addVerticalLine at a constant X position.
* `$label` is an optional annotation drawn at the line; `$color`
* is a 24-bit RGB int (null = theme default).
*
* Supported by AreaChart, BarChart, BoxPlot, BubbleChart,
* LineChart, ScatterChart, StockChart, Waterfall, and ParetoChart;
* other chart types accept and silently ignore the call.
*/
public function addHorizontalLine(float $value, ?string $label = null, ?int $color = null): static {}
public function addVerticalLine(float $position, ?string $label = null, ?int $color = null): static {}
/**
* Overlay an external image at data coordinates on the chart.
* Honored on `LineChart` and `AreaChart` (x = fractional category
* index, e.g. 2.5 = halfway between the 3rd and 4th category),
* `BarChart`, `BoxPlot`, `BubbleChart`, `ScatterChart` (x, y in
* data coordinates), and `StockChart` (x = unix timestamp,
* y = price). Other chart types silently ignore the call.
*
* `$path` is opened at draw time through PHP's stream layer
* (which enforces `open_basedir` natively); missing or invalid
* images are silently skipped so a typo doesn't abort the whole
* render. Supported formats: PNG and JPEG only — plutosvg's
* data-URI loader handles those two; WebP / GIF / AVIF sources
* are skipped. `$maxWidth` / `$maxHeight` cap the display size
* while preserving the source aspect ratio (-1 = use the source
* dimension as-is). Source files larger than 8 MiB OR with
* declared dimensions over 4096px on either axis OR a pixel
* product over 16M are silently skipped to bound worker memory
* if the path is fed from untrusted input. Up to 32 icons per
* chart.
*/
public function addIconAt(float $x, float $y, string $path,
int $maxWidth = -1,
int $maxHeight = -1): static {}
/**
* Add a horizontal plot band: a shaded Y-range region drawn behind
* the chart data on Cartesian charts (Line / Area / Bar / Scatter
* / Bubble / Stock / BoxPlot). Useful for "normal range" callouts
* (e.g. healthy heart-rate band, target SLA window). `$low` and
* `$high` are in data Y units; the renderer reorders if needed.
* `$color` is a 24-bit RGB. `$alpha` uses the 0..127 convention
* (0 = opaque, 127 = fully transparent), defaulting to 64 for a
* visible-but-translucent overlay. Up to 16 bands per chart
* (shared budget with addVerticalBand).
*
* Supported by AreaChart, BarChart, BoxPlot, BubbleChart,
* LineChart, ScatterChart, StockChart, Waterfall, and ParetoChart;
* other chart types accept and silently ignore the call.
*/
public function addHorizontalBand(float $low, float $high, int $color,
int $alpha = 64,
?string $label = null): static {}
/**
* Add a vertical plot band: a shaded X-range region drawn behind
* the chart data. Companion to addHorizontalBand. The X-axis
* interpretation depends on the chart type:
* - Line / Area / Bar (vertical) / BoxPlot: fractional category
* index (0 = first category, n_categories = past last). Pass
* 2.0 / 4.0 to span the 3rd through 4th category slots.
* - Scatter / Bubble: data X value.
* - Stock: unix timestamp.
* Color / alpha / label / band cap are identical to
* addHorizontalBand; the two share the 16-band-per-chart budget.
*
* Supported by AreaChart, BarChart, BoxPlot, BubbleChart,
* LineChart, ScatterChart, StockChart, Waterfall, and ParetoChart;
* other chart types accept and silently ignore the call.
*/
public function addVerticalBand(float $low, float $high, int $color,
int $alpha = 64,
?string $label = null): static {}
/**
* Per-element color overrides. Each takes a 24-bit RGB int or
* -1 to revert to the theme palette default.
*/
public function setAxisColor(int $rgb): static {}
public function setGridColor(int $rgb): static {}
public function setBorderColor(int $rgb): static {}
public function setTextColor(int $rgb): static {}
/**
* Per-element font overrides. `setTitleFont` is used for the
* chart title; `setAxisFont` for axis tick labels and axis
* titles; `setLabelFont` for category labels, value labels,
* and pie slice labels. Pass null path to keep using the
* global setFontPath() font; pass null size (or omit it) to keep
* the computed default. A given size must be in 1.0..200.0. The
* two arguments are independent.
*/
public function setTitleFont(?string $path = null, ?float $size = null): static {}
public function setAxisFont(?string $path = null, ?float $size = null): static {}
public function setLabelFont(?string $path = null, ?float $size = null): static {}
/**
* Show numeric value labels next to each data point. For line
* and scatter, labels appear above each marker; for bar, above
* each bar. No-op for pie (use setSliceLabelFormat).
*
* `$format` is an sprintf conversion applied to each value.
* `null` (or omitting the argument) leaves the current format
* unchanged — toggling visibility without disturbing a format set
* earlier. `''` resets to the built-in default ("%g"). A non-empty
* string sets the format (validated for exactly one numeric
* conversion).
*/
public function setShowValues(bool $show, ?string $format = null): static {}
/**
* Render the canvas with a transparent background. The PNG and
* WebP outputs preserve the alpha channel; JPEG collapses to
* white. Default: false.
*/
public function setTransparentBackground(bool $enabled): static {}
/**
* Composite a background image onto the canvas before drawing
* any chart elements. Path is resolved through PHP's filesystem
* policy (`open_basedir`). Supported source formats: PNG and
* JPEG only — plutosvg's data-URI loader handles those two and
* the SVG embed silently skips other formats. The image is
* scaled to fill the entire canvas.
*
* Source-file caps: the loader silently skips files larger
* than 8 MiB OR with declared dimensions over 4096px on either
* axis OR a pixel product over 16M. open_basedir is the
* primary access gate; these caps are defense-in-depth so an
* untrusted path can't make the decoder allocate hundreds of
* MiB on a small file with declared 100000x100000 dimensions.
*/
public function setBackgroundImage(string $path): static {}
/**
* Line interpolation mode. `INTERP_LINEAR` (default) connects
* data points with straight segments. `INTERP_SMOOTH` uses
* Catmull-Rom spline interpolation for a curved through-the-
* points appearance. Affects LineChart series, AreaChart top
* edges, and StockChart SMA overlays.
*/
public function setLineInterpolation(int $mode): static {}
/**
* Force the plot rectangle to specific canvas coordinates,
* bypassing the auto-layout that reserves space for title /
* axes / labels. Useful for pixel-perfect chart placement
* inside a larger composition. Coordinates are inclusive.
* Pass any negative width / height to revert to auto-layout.
*/
public function setPlotRect(int $x0, int $y0, int $x1, int $y1): static {}
/**
* Which sides of the plot border to draw. Bitwise OR of
* `BORDER_LEFT` / `BORDER_RIGHT` / `BORDER_TOP` / `BORDER_BOTTOM`,
* or `BORDER_ALL` (default) / `BORDER_NONE`. The Y-axis line
* is drawn separately and is not affected by this setting.
*/
public function setBorderSides(int $sides): static {}
/**
* Add a series that draws on top of the primary chart's data,
* using the same X axis and (by default) the same Y axis.
* Lets a `BarChart` carry a trend line, an `AreaChart` carry
* a target band, etc. -- the v0.x equivalent of GDChart's
* `COMBO_*` chart types.
*
* `$type` is `'line'` or `'area'`. `$values` is a list of
* numeric values parallel to the primary's categories (or
* matching the candle count for `StockChart`). `$opts` keys:
* - `'color'` => int 0xRRGGBB
* - `'thickness'` => int (line width, default 2)
* - `'axis'` => `'left'` (default) or `'right'` for
* secondary Y axis
*/
public function addOverlaySeries(string $type, array $values, ?array $opts = null): static {}
/**
* Show or hide the X axis line, ticks, and labels entirely.
* Default true. The X-axis title remains independently controlled
* via setXAxisTitle().
*/
public function setXAxisVisible(bool $visible): static {}
/**
* Show or hide the Y axis line, ticks, and labels entirely.
* Default true. The Y-axis title remains independently controlled
* via setYAxisTitle().
*/
public function setYAxisVisible(bool $visible): static {}
/**
* sprintf format string for Y-axis tick labels (e.g., '$%.2f',
* '%d ms'). Empty string reverts to auto-formatting based on
* the tick step. Receives the numeric tick value as its sole
* argument.
*/
public function setYAxisLabelFormat(string $format): static {}
/**
* sprintf format string for X-axis tick labels when the X axis
* is numeric (Stock charts, scatter). Empty string reverts to
* auto-formatting. No effect on category-axis charts -- use
* setCategoryLabels() instead.
*/
public function setXAxisLabelFormat(string $format): static {}
/**
* Tick rendering mode: TICK_NONE suppresses both ticks and
* labels, TICK_LABELS draws only labels (no tick marks),
* TICK_POINTS draws only tick marks (no labels), TICK_BOTH
* (default) draws both.
*/
public function setTickMode(int $mode): static {}
/**
* Bar fill width as a percent of the slot width (1..100).
* 100 means bars touch each other; the GDChart default was 75.
* Affects BarChart and StockChart candle bodies.
*/
public function setBarWidth(int $percent): static {}
/**
* Edge (outline) color for filled shapes -- bars, area fills,
* pie slices. 24-bit RGB or -1 for no outline (default).
*/
public function setEdgeColor(int $rgb): static {}
/**
* When the data range crosses zero, draw a horizontal "shelf"
* line at y=0 in axis color. Helps separate negative bars
* from positive ones visually. Default false.
*/
public function setZeroShelf(bool $enabled): static {}
/**
* Render only every Nth X-axis label, starting from index 0.
* Useful when many category labels overlap. Pass 1 (default)
* to render all labels.
*/
public function setXLabelStride(int $stride): static {}
/**
* Title for the secondary Y axis (when setSecondaryYAxis(true)).
* Rendered rotated 90deg to the right of the right-axis labels.
*/
public function setSecondaryYAxisTitle(string $title): static {}
/**
* Thumbnail mode auto-shrinks fonts and elides labels for tiny
* preview renders. Useful for sparkline-style or grid-of-charts
* layouts. Default false.
*/
public function setThumbnailMode(bool $enabled): static {}
/**
* Per-element text color overrides. Each takes a 24-bit RGB or
* -1 to fall through to setTextColor() / theme. setTitleColor
* is the chart title; setAxisLabelColor is tick labels;
* setAxisTitleColor is X/Y axis titles.
*/
public function setTitleColor(int $rgb): static {}
public function setAxisLabelColor(int $rgb): static {}
public function setAxisTitleColor(int $rgb): static {}
/**
* Two-stop color ramp (low value -> high value). 24-bit RGB ints.
* Used by chart families that map a numeric range to a continuous
* color (SurfaceChart, ContourChart). Default cool blue -> warm
* red. No-op on chart types that don't paint a color ramp.
*/
public function setColorRamp(int $low, int $high): static {}
/**
* Add a free-floating text annotation at canvas coordinates
* (`$x`, `$y` are pixel positions in the rendered image).
* Useful for callouts, watermarks, or labeled regions. Color
* defaults to the configured text color.
*/
public function addTextAnnotation(string $text, int $x, int $y, ?int $color = null): static {}
/**
* Line dash style for line series and overlay lines:
* `LINE_SOLID` (default), `LINE_DASHED`, `LINE_DOTTED`.
* Doesn't affect grid, axis, or annotation lines.
*/
public function setLineStyle(int $style): static {}
/**
* Apply a linear gradient to filled shapes (bars, area fills,
* pie slices). `$from` is the color at the top (or left, for
* horizontal); `$to` is at the bottom (or right). Pass -1 for
* `$from` to disable gradient and revert to solid fills.
*
* Supported by AreaChart, BarChart, ContourChart, PieChart, and
* SurfaceChart; other chart types silently ignore the call.
*/
public function setGradientFill(int $from, int $to = -1, int $direction = Chart::GRADIENT_VERTICAL): static {}
/**
* Add a drop shadow behind filled shapes and text. `$offsetX`
* and `$offsetY` are shadow displacement in pixels. `$color`
* defaults to a 50% opacity black. Pass `setDropShadow(0, 0)`
* to disable.
*
* Supported by AreaChart, BarChart, ContourChart, PieChart, and
* SurfaceChart; other chart types silently ignore the call.
*/
public function setDropShadow(int $offsetX, int $offsetY, ?int $color = null): static {}
/**
* Drop-shadow opacity in the 0..127 alpha space: 0 = fully
* opaque, 127 = fully transparent. Default is 64 (~50% opacity).
* Same convention `imagecolorallocatealpha()` uses, kept for
* source-compat across v0.x callers.
*/
public function setShadowAlpha(int $alpha): static {}
/**
* Calendar-aware date-axis tick stride for charts that use a
* Unix-timestamp X axis (StockChart, etc.). `$unit` is one of
* `DATE_DAY` / `DATE_WEEK` / `DATE_MONTH` / `DATE_QUARTER` /
* `DATE_YEAR`; `$every` is the multiplier (e.g. `every=2,
* unit=DATE_WEEK` = a tick every 14 days, snapped to Mondays).
* Pass `$every = 0` to revert to auto-density labels.
*/
public function setDateAxisStride(int $unit, int $every = 1): static {}
/**
* Output / FreeType DPI for the rendered canvas.
*
* fastchart owns the canvas and scales its physical pixel
* dimensions by `dpi/96` on the raster render paths
* (`renderPng()` / `renderJpeg()` / `renderWebp()` /
* `renderToFile()` for those formats). The `setSize()` value is
* the *logical* size; a chart at `setSize(640, 320)->setDpi(200)`
* is allocated as a 1333×667 pixel canvas. Apparent layout is
* preserved; pixel density doubles. Layout margins, tick marks,
* and label paddings scale proportionally so labels don't crowd
* the canvas edge. SVG output is DPI-invariant (vectors scale
* infinitely) and reports the configured DPI in the PNG `pHYs`
* and JPEG density metadata only.
*
* Common values: 96 (default, web-screen), 192 (2× retina),
* 300 (print). Range is `[24, 1200]`.
*/
public function setDpi(int $dpi): static {}
/**
* Select the SVG text emission mode used by `renderSvg()`,
* `drawSvgFragment()`, and `renderToFile('*.svg')`. One of
* `self::SVG_TEXT_PATHS` (default — self-contained) or
* `self::SVG_TEXT_NATIVE` (compact, requires consumer text
* support). Raster outputs are unaffected (they always use
* PATHS internally).
*/
public function setSvgTextMode(int $mode): static {}
/**
* Set the JPEG encode quality used by `renderJpeg()` and
* `renderToFile('*.jpg' | '*.jpeg')`. Range 1..100; default 88.
* Quality maps onto libjpeg-turbo's `jpeg_set_quality()` with
* `optimize_coding=TRUE` and 4:2:0 chroma subsampling.
*/
public function setJpegQuality(int $quality): static {}
/**
* Set the zlib compression level used by `renderPng()` and
* `renderToFile('*.png')`. Range 0 (store) to 9 (max); the
* default is libpng's own default (6). Chart-shaped content
* compresses ~30-40% faster at level 3 for a 13-22% larger
* file — a worthwhile trade when PNGs are served once and
* discarded.
*/
public function setPngCompressionLevel(int $level): static {}
/**
* Select the WebP encoder mode used by `renderWebp()` and
* `renderToFile('*.webp')`. Pass one of `self::WEBP_DRAWING`
* (default), `WEBP_PHOTO`, `WEBP_LOSSLESS`, or `WEBP_FAST`. See
* the constant docblocks for the trade-offs each mode picks.
* Throws `\ValueError` on any other value.
*/
public function setWebpMode(int $mode): static {}
/** Render to PNG bytes at the configured size. */
public function renderPng(): string {}
/**
* Render to JPEG bytes. When given, `$quality` must be in 1..100;
* pass null (or omit) to use the value set via setJpegQuality()
* (default 88).
*/
public function renderJpeg(?int $quality = null): string {}
/** Render to WebP bytes. `$quality` is 1..100. */
public function renderWebp(int $quality = 90): string {}
/**
* Render and write directly to a file. Format is inferred from
* the path extension: `.png` / `.jpg` / `.jpeg` / `.webp` /
* `.svg` / `.pdf`. `$quality` only applies to JPEG / WebP outputs;
* SVG, PNG, and PDF ignore it. Default `0` means "use the
* per-format default": JPEG uses the value set via
* `setJpegQuality()` (default 88), WebP uses 90. Explicit values
* must be in `1..100`. Returns the byte count written. Only local
* filesystem paths are accepted, and writes replace the destination
* atomically. Honors `open_basedir`. `.pdf` requires the
* `--with-pdfio` build;
* without it, writing a `.pdf` path throws "PDF support not
* compiled in". `.gif` / `.avif` extensions raise a clear
* "dropped in v1.0" Error.
*/
public function renderToFile(string $path, int $quality = 0): int {}
/**
* Render to an SVG document. Returns the full markup including
* `<?xml ...>` prolog and `<svg>` root.
*
* Supported on every concrete `Chart` subclass (LineChart,
* AreaChart, BarChart, PieChart, ScatterChart, BubbleChart,
* RadarChart, PolarChart, SurfaceChart, ContourChart, GaugeChart,
* GanttChart, BoxPlot, Treemap, Funnel, Waterfall, Heatmap,
* LinearMeter, BulletChart, ParetoChart, CalendarHeatmap,
* SunburstChart, SankeyChart, MarimekkoChart, VectorChart,
* ArcDiagram, ChordDiagram, NetworkChart, PopulationPyramid,
* ViolinPlot, CirclePacking, Pictogram, VennDiagram, WordCloud,
* SerpentineTimeline, StockChart). The `Symbol` family (Code128, QrCode)
* exposes the same method on its own abstract base.
*
* The output viewport matches the logical `setSize()` dimensions.
* SVG is DPI-invariant: `setDpi()` still scales the raster canvas
* for `renderPng()` / `renderJpeg()` / etc., but does not multiply
* the SVG viewport — vector strokes scale infinitely, so layout
* and text measurement stay at the 96-DPI baseline regardless of
* the configured DPI.
*
* Text defaults to `SVG_TEXT_PATHS` mode: every `<text>` is
* flattened to a `<g><path d="…"/></g>` group via FreeType
* outline decomposition. The output is self-contained and
* renders identically in any rasterizer including plutovg.
* Call `setSvgTextMode(SVG_TEXT_NATIVE)` to switch to raw
* `<text>` elements with the font family resolved via FreeType
* — smaller files, but consumers need text rendering support.
*/
public function renderSvg(): string {}
/**
* Render to a vector PDF document. Returns the PDF bytes (a
* single page sized to the logical `setSize()` dimensions).
*
* Chart bodies emit PDF path operators directly through the same
* primitive layer as `renderSvg()` — no rasterization — so the
* output stays crisp at any zoom and print resolution. Text is
* flattened to glyph outlines (no font embedding in this release).
*
* Requires the extension to be built `--with-pdfio` against a
* system pdfio install (msweet.org); without it this method throws
* an `Error` ("PDF support not compiled in"). DPI-invariant like
* `renderSvg()`. Gradients fall back to a solid fill and raster
* background images are omitted in this release.
*/
public function renderPdf(): string {}
/**
* Render to an SVG fragment: a single `<g class="fastchart">…</g>`
* group with no outer `<svg>` or XML prolog. Intended for
* stitching multiple charts into one caller-managed SVG document.
* The caller owns the outer viewport / coordinate space.
*
* Gradient and clip-path ids inside a fragment are `fcg1`, `fcc1`,
* … per chart; stitching two fragments that both use gradients or
* clips into ONE host document therefore collides — chart 2's
* `url(#fcg1)` resolves to chart 1's gradient. Pass a distinct
* `$idPrefix` per chart (1-16 chars of `[A-Za-z0-9_-]`, starting
* with a letter or underscore) to namespace the ids (`a_fcg1`).
*
* Available on every concrete `Chart` subclass — same coverage as
* `renderSvg()`.
*/
public function drawSvgFragment(?string $idPrefix = null): string {}
/**
* Attach per-data-point href / tooltip metadata. The array is
* index-aligned with setSeries() / setSlices() / setPoints() —
* entry $i becomes the hot-spot for data point $i. Each entry
* is `['href' => string, 'tooltip' => string?]`. ScatterChart
* already takes per-point href/tooltip on setPoints() directly;
* other chart types use setImageMap() to attach them.
* At most 4096 entries are accepted; href / tooltip strings
* longer than 4096 bytes throw `\ValueError`. Embedded NULs in
* a field silently drop that field.
*
* After a render, call `getImageMap()` to retrieve the matching
* HTML `<map>` markup with `<area>` elements positioned over
* each bar / slice / point.
*/
public function setImageMap(array $entries): static {}
/**
* Return an HTML imagemap describing the clickable hot-spots for
* each rendered data point. The chart must have been rendered at
* least once (renderSvg/renderPng/renderJpeg/renderWebp/renderToFile)
* for this to return non-empty output. Hot-spots are emitted for
* BarChart (rect), PieChart (poly), and ScatterChart (circle);
* other chart types render no hot-spots.
* Map name defaults to 'fastchart'; sanitized to alphanumeric +
* '-' + '_' so it's safe to inline into an `<img usemap="#...">`.
*
* Coordinates are in LOGICAL (setSize) pixels. Raster output at
* `setDpi()` above 96 is physically larger, so either display the
* image at its logical size (`<img width="..." height="...">`) or
* scale the coords by dpi/96 before emitting `<area>` tags.
*/
public function getImageMap(string $name = 'fastchart'): string {}
/**
* Return structured hot-spot data (for custom <map>, JS overlays,
* or server-side link generation). Same contract as getImageMap():
* the chart must have been rendered at least once.
*
* Returns a list of arrays:
* [
* 'shape' => 'rect' | 'circle' | 'poly',
* 'coords' => int[], // HTML <area> form: rect=[left,top,right,bottom],
* // circle=[cx,cy,r], poly=[x1,y1,x2,y2,...]
* 'index' => int, // position in the original setSeries/setSlices/setPoints
* 'href' => string,
* 'tooltip'=> string|null,
* ]
*
* Only entries that had a non-empty allowed href after scheme
* filtering are included (same rules as getImageMap).
* Shape strings are lowercase.
*/
public function getImageMapAreas(): array {}
}
/** @strict-properties */
final class LineChart extends Chart
{
public function setSeries(array $series): static {}
public function setMarkerStyle(int $style): static {}
public function setMarkerSize(int $size): static {}
/**
* Per-point error bar magnitudes. `$errors` is a flat list
* parallel to the primary series: each entry is either a single
* positive number (symmetric ±error) or `[lo, hi]` for an
* asymmetric bar. Pass `[]` to clear. Drawn as vertical stems
* with horizontal caps in the configured axis color. Throws
* `\ValueError` above 2048 entries without changing prior error bars.
*/
public function setErrorBars(array $errors): static {}
}
/** @strict-properties */
final class AreaChart extends Chart
{
/**
* Same data shape as `LineChart::setSeries()`. Each series is
* filled below the line down to the zero baseline (or to the
* Y-axis min, whichever is higher). Multi-series stacks by
* default; pass `setStacked(false)` for overlapping translucent
* fills.
*/
public function setSeries(array $series): static {}
public function setStacked(bool $stacked): static {}
/**
* Fill alpha for non-stacked overlapping areas (0..127, where
* 127 is fully transparent and 0 is fully opaque — the same
* convention `imagecolorallocatealpha()` uses). Default 64.
* Stacked areas are always opaque.
*/
public function setFillOpacity(int $alpha): static {}
/**
* Band mode: with exactly two series, fill the envelope between
* them instead of filling each series down to the baseline.
* series[0] is the upper bound, series[1] is the lower. Useful
* for confidence intervals, min/max ranges, forecast bands.
* Silently no-op when n_series != 2 or setStacked(true) is also
* active; falls back to the per-series fill in that case.
*/
public function setBandMode(bool $enabled): static {}
/**
* Stream graph (ThemeRiver): render a stacked area centered on a
* baseline instead of anchored at zero, so the silhouette flows
* symmetrically. Requires at least two series and a linear Y axis,
* and assumes non-negative data (negatives are clamped to zero for
* the centering). Always stacks on the primary axis; the secondary
* axis is ignored. Silently no-op with fewer than two series.
*/
public function setStreamMode(bool $on): static {}
}
/** @strict-properties */
final class BarChart extends Chart
{
/** Orientation for setOrientation(). */
public const int BAR_VERTICAL = 0;
public const int BAR_HORIZONTAL = 1;
public const int BAR_RADIAL = 2;
/** Glyph style for setBarStyle(). */
public const int BAR_STYLE_BAR = 0;
public const int BAR_STYLE_LOLLIPOP = 1;
public const int BAR_STYLE_DUMBBELL = 2;
public function setSeries(array $series): static {}
public function setStacked(bool $stacked): static {}
/**
* Glyph style for vertical bars. BAR_STYLE_BAR (default) draws
* filled rectangles. BAR_STYLE_LOLLIPOP draws a thin stem from the
* zero baseline to the value with a circle bullet at the tip.
* BAR_STYLE_DUMBBELL requires setFloating(true): it draws a
* connector between each `[$min, $max]` pair with a circle at both
* ends. Both lollipop and dumbbell styles apply to the vertical
* orientation; horizontal bars fall back to filled rectangles.
*/
public function setBarStyle(int $style): static {}
/**
* Bar orientation. BAR_VERTICAL (default) draws traditional
* vertical bars with categories along the X axis. BAR_HORIZONTAL
* draws bars running left-to-right with categories along the Y
* axis -- useful when category labels are long. All other bar
* features (stacking, floating, per-point colors, value labels)
* carry over with X/Y semantics swapped. BAR_RADIAL draws a
* circular ("race track") bar chart: each category is a concentric
* ring (category 0 outermost) and its bar is a thick arc swept
* clockwise from 12 o'clock, the peak value reaching a near-full
* circle. Multiple series stack as concentric sub-bands.
*/
public function setOrientation(int $orientation): static {}
/**
* Stacking algorithm for multi-series bars when stacked mode is
* on: STACK_SUM (default) cumulates bars vertically;
* STACK_LAYER overlays bars front-to-back at the same baseline
* with translucent fills; STACK_BESIDE is equivalent to
* setStacked(false) (side-by-side groups).
*/
public function setStackMode(int $mode): static {}
/**
* Switch the chart to floating-bar mode: each series entry must
* be `[$min, $max]` rather than a scalar, and bars are drawn
* between min and max instead of from zero. Useful for Gantt-style
* timelines, salary-range plots, etc.
*/
public function setFloating(bool $enabled): static {}
}
/** @strict-properties */
final class PieChart extends Chart
{
/**
* Slice data, in either of two shapes: an associative
* `{label => value}` map, or a list of dicts
* `['label' => string, 'value' => float, 'color' => int, 'radius' => float]`
* where `color` and `radius` are optional. Supplying a positive
* `radius` on any slice switches the chart to a variable-radius
* (rose) pie: each slice keeps its value-proportional angle, but its
* outer radius scales with `radius` (normalised to the largest,
* floored so small slices stay visible). Slices without a `radius`
* draw at the full radius.
*/
public function setSlices(array $slices): static {}
public function setDonutHoleRatio(float $ratio): static {}
/**
* Concentric nested-donut rings. Each element is itself a slice
* array in the same shapes setSlices() accepts ({label => value}
* or a list of {value, label?, color?} dicts). The first ring is
* the innermost band, the last the outermost; at most eight rings
* render. When set, the rings replace the flat single-pie slices.