local vec2 = datumhue.math.vec2local color = datumhue.colorlocal canvas = datumhue.draw.new({ width = 400, height = 300 })
canvas:mount({ width = 400, height = 300 })
local plot = canvas:chart({ margin = { left = 40, bottom = 40 } })
local mark =
plot:line({ points = { vec2(0, 1), vec2(4, 3), vec2(8, 2) } })
Fields 1
Field
Type
Access
Description
visible
boolean
read/write
True while the mark is drawn. Assign to show or hide — a hidden mark stops drawing until shown again and re-renders on the next frame when shown; a rule's value label follows the toggle.
Change the mark's appearance or data. Hidden marks stop drawing until shown again; showing one re-renders it on the next frame. Errors when called on a handle that isn't a mark.
Example
-- Keys left out keep their value.
mark:update({ color = color("#e69875"), width = 4, name = "North" })
Row nearest to the data-space query point. Line / points / area marks answer with the nearest source row (row is the row of the source data, or the position in the inline points); histograms with the bin containing the query x (row is the bin's position, y the bin height); heatmaps with the nearest cell (row is the cell's position); box marks with the category nearest along the band axis (row is the entry's position, value the median); bars marks with the category whose band slot is nearest along the band axis (row is the category's position, value sums the category's series values). Rule / text / band marks carry no data rows and answer nil.
Example
-- The query is in data units; row counts from 1, in the mark's-- points, and distance is in pixels.datumhue.time.wait_frames(1)
local hit = mark:nearest(vec2(3.8, 2.9))
print(hit.row, hit.x, hit.y) --> 2 4.0 3.0
Append a single data-space point to a line / points / area mark whose source is inline points. A scale whose domain is pending, or that only this mark's points have filled since it was (a script, a gesture or another mark on the scale ends that), refits to the mark's points after the push, as a constructor's points fit it: a mark created with points = {} fills its scales point by point, and past max_points they follow the points it holds. Any other scale widens to cover the point; a pinned scale stays as it is, a follow scale slides its window with the points, and a time or band scale is not fitted. When the mark was constructed with max_points = N, it keeps the newest N points, dropping the oldest as each new one arrives. Errors on data-bound marks — those reshape via mark:replace_data, not push.
Example
-- Each point widens the scales to cover it, as a constructor's-- points do; with max_points, the oldest point goes once the mark-- holds that many.local recent = plot:line({ points = {}, max_points = 3, width = 3 })
recent:push_point(vec2(4, 1.5))
recent:push_point(vec2(6, 3.5))
recent:push_point({ x = 8, y = 2.5 })
recent:push_point({ x = 10, y = 4 })
print(plot.x_scale.domain.max, plot.y_scale.domain.max) --> 10.0 4.0
Swap the underlying data source on a data-bound mark of any kind. Line / points / area marks keep their x_column / y_column and re-render against the new source; aggregating marks (bars, histogram, histogram2d, heatmap, box) keep their column / bin / aggregate bindings and re-aggregate from the new source. Scale domains reset and refit once the new data loads, and a line / area mark with series_column re-partitions its series. Errors on marks built from inline values (recreate those), on inline-points marks (reshape via mark:update({points=...})), and on marks built from a view (update the data through the view).
Example
-- The mark keeps its columns and draws the new rows.local monday = datumhue.bytes("hour,loaves\n6,4\n7,9\n8,5\n"):csv()
local tuesday = datumhue.bytes("hour,loaves\n6,8\n7,3\n8,7\n"):csv()
local sold = plot:line({
data = monday,
x_column = "hour",
y_column = "loaves",
width = 3,
})
sold:replace_data(tuesday)