Module

Chartjs.Colors

Package
purescript-chartjs
Repository
philippedev101/purescript-chartjs

Gradient, pattern, color, and image-point-style utilities for Chart.js datasets — everything that can't go through the plain JSON serialization path and needs the overlay merge.

#ColorStop Source

type ColorStop = { color :: String, offset :: Number }

A gradient color stop with an offset (0–1) and CSS color string.

#createLinearGradient Source

createLinearGradient :: HTMLCanvasElement -> { x0 :: Number, x1 :: Number, y0 :: Number, y1 :: Number } -> Array ColorStop -> Effect CanvasGradient

Create a linear gradient on a canvas.

#createRadialGradient Source

createRadialGradient :: HTMLCanvasElement -> { r0 :: Number, r1 :: Number, x0 :: Number, x1 :: Number, y0 :: Number, y1 :: Number } -> Array ColorStop -> Effect CanvasGradient

Create a radial gradient on a canvas.

#createPattern Source

createPattern :: HTMLCanvasElement -> Foreign -> String -> Effect CanvasPattern

Create a pattern on a canvas from an image element.

#colorToForeign Source

colorToForeign :: Color -> Foreign

Convert a Color to a Foreign value for direct JS use.

#scriptableIndexableColorToForeign Source

scriptableIndexableColorToForeign :: ScriptableIndexable Color -> Foreign

Convert a ScriptableIndexable Color to Foreign. SIVal / SIArray pass through colorToForeign directly; SIFn is wrapped as a JS closure via Chartjs.Scriptable.scriptableIndexableToForeign so the color returned by the PS function is colorToForeign-encoded before Chart.js sees it.

#pointStyleToForeign Source

pointStyleToForeign :: PointStyle -> Foreign

Convert a PointStyle to a Foreign value for direct JS use. String variants become strings, PSFalse becomes the JS boolean false, and PSImage passes through the wrapped HTMLImageElement / HTMLCanvasElement reference unchanged.

#indexablePointStyleToForeign Source

indexablePointStyleToForeign :: Indexable PointStyle -> Foreign

Convert an Indexable PointStyle to Foreign. Retained for backwards compatibility — new code should use scriptableIndexablePointStyleToForeign since all PointStyle dataset fields are now ScriptableIndexable after #22.

#scriptableIndexablePointStyleToForeign Source

scriptableIndexablePointStyleToForeign :: ScriptableIndexable PointStyle -> Foreign

Convert a ScriptableIndexable PointStyle to Foreign. SIFn functions are wrapped as JS closures whose return value is passed through pointStyleToForeign so the live Chart.js call site sees an already- encoded point style (string or image reference).

#extractDatasetOverlay Source

extractDatasetOverlay :: forall r. Record (DatasetCommonRow r) -> Maybe Foreign

Extract non-JSON fields from a dataset (or dataset-defaults record) as a Foreign object. Covers:

  • gradient/pattern colors and scriptable color functions (#21)
  • image point styles (#17) and scriptable pointStyle functions (#22)
  • per-segment line styling (#23, moved to JSON path in #32)
  • scriptable numeric / boolean / enum / compound fields (#22) — SIFn / SFn forms of borderWidth, borderRadius, border- Skipped, inflateAmount, base, pointRadius, radius, offset, rotation, borderAlign, circular, fill, etc.

Returns Nothing when every one of these fields contains only JSON-compatible values.

Row-polymorphic in r so the same extractor works on both Dataset (which adds label + data on top of DatasetCommonRow ()) and DatasetDefaults (which closes the row with ()). This is what lets extractDatasetsDefaultsOverlay reuse the dataset logic without duplication.

#extractDatasetOverlays Source

extractDatasetOverlays :: forall r. Array (Record (DatasetCommonRow r)) -> Maybe (Array Foreign)

Extract dataset overlays for every dataset in the config. Covers the same categories as extractDatasetOverlay: gradient/pattern colors, scriptable color functions, and image point styles. Returns Nothing if no dataset has any non-JSON values, signalling the overlay merge can be skipped entirely.

#extractDatasetsDefaultsOverlay Source

extractDatasetsDefaultsOverlay :: DatasetsDefaults -> Maybe Foreign

Extract overlays from per-chart-type DatasetsDefaults entries (options.datasets.{line,bar,bubble,...}). Returns Nothing when every chart-type slot is either Nothing or contains only JSON- compatible values. Otherwise returns a Foreign object keyed by chart type string whose values are the per-type dataset overlays from extractDatasetOverlay — the same shape mergeOverlays in FFI.js already understands for regular dataset overlays, just namespaced into a different merge target.

Without this helper, a consumer writing SIFn, a gradient, an image point style on DatasetDefaults would silently lose the value: the JSON encoder emits null for the non-serializable form, and if nothing routes the real value onto config.options.datasets[type], Chart.js falls back to its built- in palette.