DatumHuePlatform v0.0.24datumhue.com
Contents

handle9 methods, 2 fields

Scale

The data-domain side of a chart mapping (linear, log, band, or time). Created by chart scale constructors; drives dependent marks and axes. Each plot area using the scale, as its own, an axis's or a mark's, assigns its own pixel range, so sharing one handle across areas links their domains while every area keeps its own geometry.

Obtained from
datumhue.chart.scale.linear, datumhue.chart.scale.log, datumhue.chart.scale.band, datumhue.chart.scale.time, PlotArea.x_scale, PlotArea.y_scale
Accepted by
DrawCanvas:chart, DrawCanvas:charts, PlotArea:line, PlotArea:points, PlotArea:area, PlotArea:bars, PlotArea:histogram, PlotArea:heatmap and 4 more

The examples on this page start from:

lua
local vec2 = datumhue.math.vec2
local canvas = datumhue.draw.new({ width = 400, height = 300 })
canvas:mount({ width = 400, height = 300 })
local scale = datumhue.chart.scale.linear({})
local plot = canvas:chart({})
plot:line({ points = { vec2(0, 1), vec2(100, 2) }, x_scale = scale })
-- A mark's own scale maps once its area lays it out, a frame later.
datumhue.time.wait_frames(1)

Fields 2

FieldTypeAccessDescription
domaintable | "auto" | nilread/writeResolved domain {min = N, max = N}, or nil while pending. Assign {min = N, max = N} or "auto"; dependent marks and axes re-render. Band scales read and assign the ordered category array instead (same list as categories).
Example
-- Assigning pins the domain; "auto" leaves it pending until the
-- scale is fitted to data.
scale.domain = { min = -50, max = 50 }
print(scale.domain.min, scale.domain.max) --> -50.0 50.0
scale.domain = "auto"
print(scale.domain) --> nil
categoriesstring[]?read-onlyOrdered category names of a band scale — the construction domain plus any categories marks discovered from their data by the time of the read. nil on linear / log / time scales, which map a numeric continuum and keep no category list.

Methods 9

Scale:map

method
Scale:map(value: number | string) -> number?

Data value → pixel position, resolved through the plot area using this scale. nil while pending (no domain, or no area has laid the scale out). Raises when areas with different pixel ranges share the scale — convert through area:data_to_world then.

Example
-- To canvas pixels across the area, which spans the 400-wide canvas,
-- centered.
print(scale:map(0), scale:map(50), scale:map(100)) --> -200.0 0.0 200.0

Scale:invert

method
Scale:invert(pixel: number) -> number | string | nil

Pixel position → data value, resolved through the plot area using this scale. Band scales return the name of the category whose slot contains the pixel. nil while pending or outside every slot. Raises when areas with different pixel ranges share the scale — convert through area:world_to_data then.

Example
-- From canvas pixels back to a data value.
print(scale:invert(-100)) --> 25.0

Scale:fit

methodsuspends
Scale:fit(data: DataHandle, column: string, force?: boolean) -> Scale

Scan a column for min/max and set the domain. Returns self. Linear / log / time only. By default only writes if the domain is still pending, so a user pan / zoom during a long-running fit isn't overwritten when the scan finishes. Pass force = true to always apply.

Example
-- Fits a pending domain only, unless forced, so the fit never undoes
-- a pan or zoom made while the data loaded.
local loaves = datumhue.bytes("grams\n790\n812\n805\n"):csv()
scale:fit(loaves, "grams")
print(scale.domain.min, scale.domain.max) --> 0.0 100.0
scale:fit(loaves, "grams", true)
print(scale.domain.min, scale.domain.max) --> 790.0 812.0

Scale:reset

methodsuspends
Scale:reset(data: DataHandle, column: string) -> Scale

Clear the domain and then refit from column. Equivalent to assigning domain = "auto" immediately followed by fit(data, column, true), but as one call. Returns self.

Example
local loaves = datumhue.bytes("grams\n790\n812\n805\n"):csv()
scale:reset(loaves, "grams")
print(scale.domain.min, scale.domain.max) --> 790.0 812.0

Scale:bandwidth

method
Scale:bandwidth() -> number?

Width of one band, minus padding, resolved through the plot area using this scale. Band only; nil for numeric scales or while no area has laid the scale out. Raises when areas with different pixel ranges share the scale.

Scale:index_of

method
Scale:index_of(name: string) -> integer?

1-based category position for name, or nil if absent (band scales only). This is an ordinal for display/iteration; to position a mark, pass the category *name* to scale:map, not this number.

Example
-- 1-based, for listing; to place a mark, pass map the name itself.
local days = datumhue.chart.scale.band({ domain = { "Mon", "Tue" } })
print(days:index_of("Tue"), days:index_of("Sun")) --> 2 nil

Scale:animate

method
Scale:animate(options: chart.AnimateOptions)

Ease the domain toward a target over a duration; dependent marks and axes re-render every frame. Pins the domain like a direct assignment. A scale whose domain is still pending snaps to the target immediately; a new call replaces an in-flight animation from the current domain. Errors on band scales.

Example
-- Eases to the new domain over the duration, in seconds.
scale:animate({
    domain = { min = 0, max = 10 },
    duration = 0.5,
    easing = "quadratic_out",
})
datumhue.time.sleep(0.6)
print(scale.domain.max) --> 10.0

options chart.AnimateOptions options 3 keys

KeyTypeDefaultDescription
domain requiredtableno defaultTarget domain {min, max} (epoch-ms on time scales).
durationnumber0.4Animation length in seconds; must be positive.
easingEasing"cubic_in_out"Easing curve.

Scale:on_change

method
Scale:on_change(fn: fun(scale: Scale)) -> Subscription

Subscribe to changes of the scale's resolved domain — assignment, pan / zoom, fit / reset, animation frames, and band-category updates all count. Fires at most once per frame while the domain is changing (a continuous pan delivers one call per frame). Subscribing does not fire for the domain the scale already has. Multiple subscriptions can be active on one scale.

Scale:remove

method
Scale:remove()

Destroy the scale.

datumhue.com

(c) 2026 Shuusei AB. Quote excerpts of this manual, with attribution to DatumHue, in your own documentation, tutorials, course materials, reviews, and other writing or video. Republishing it in whole or in substantial part needs written permission: support@datumhue.com.

Victor Mono is licensed under the SIL Open Font License 1.1
Copyright (c) 2024, Rune Bjørnerås (https://github.com/rubjo)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Try

    ↑↓ selectEnter openTab filter

    Settings

    Theme
    Text
    Print

    Keyboard shortcuts

    / or Ctrl KSearch
    ↑ ↓ EnterPick a result
    TabNext result filter
    j kNext or previous entry
    [ ]Previous or next page
    yCopy a link to the current entry
    ?These shortcuts
    EscClose

    On this page