Compare commits

..
26 Commits
Author SHA1 Message Date
4DBug 7199224d9b LineStripRange / MarkersFillRange / MarkersLineRange: inline any getter (read through Get, plain arrays still read directly) and per-index colours, not only two plain arrays with one colour (RangeSource replaces PlainXY; same math) (demo, lib lowq: Subplots 6.0 -> 4.3 ms with the locator memo, Tools 3.7 -> 3.1, Custom 1.9 -> 1.7; draw data unchanged) 2026-10-21 02:55:34 -05:00
4DBug 5ba892eb97 Locator_Default: restore the previous call's ticks when nothing that feeds it changed (no other ticks on the ticker, same range / pixels / orientation / Formatter_Default format / font + size) instead of formatting and measuring every label again; any AddTick invalidates (bench implot scene lib 0.70 -> 0.65 ms; draw data unchanged, also with frame-varying range, size, format, custom ticks, font size and tags) 2026-10-21 02:50:11 -05:00
4DBug 4045d8a63a Range renderers for heatmaps and shaded plots, per-index colours in LineStripRange, plain arrays read directly in the histogram loops: HeatmapRange (HeatmapRender + LerpTable + transforms + PrimRectFill inlined), ShadedRange (ShadedRender + XYGet + transforms + GetCol inlined), PlainData() for ImMinMaxIndexer / PlotHistogram / PlotHistogram2D / heatmap values, same math (demo Plots tab lib 13.5 -> 9.3 ms: Histogram 2D 3.6 -> 1.4, Heatmaps 1.9 -> 0.8 ms; draw data unchanged, all demo tab hashes + bench implot hash identical) 2026-10-21 02:41:11 -05:00
4DBug f6c782b1f6 @native on the indexers (IdxAt0-3, LinAt, ConstAt), getters (XYGet, OverrideX/YGet, LoopGet, XYZGet), fitters (Fitter1/X/Y, ExtendFit/ExtendFitWith), ImMinMaxIndexer, ImStdDev, PlotHistogram, PlotHistogram2D and LerpTable: the per-point paths no longer drop to the interpreter (demo Plots tab, all headers open: lib 17.6 -> 13.5 ms; Histogram 2D 8.6 -> 3.6 ms, Heatmaps 3.1 -> 1.9 ms; draw data unchanged) 2026-10-21 02:40:57 -05:00
4DBug 0811513c9d BeginPlot: resolve the cached axis colours once per plot (X1) and copy them to the other five axes instead of resolving the auto colour chain per axis (bench implot scene, items stubbed: 0.457 -> 0.422 ms; draw data unchanged) 2026-10-21 02:26:50 -05:00
4DBug 5777ab0d5a LÖVE port: love/ (generated by tools/love.sh), marked linguist-generated; submodule URLs -> GitHub 2026-10-17 13:15:46 -05:00
4DBug e30281f9fb Line strip and marker renderers: RenderRange draws a whole reserved run in one call when the getter reads two plain arrays (no axis transform functions, one colour), point read/transform/cull/PrimLine inlined with the same math (plot bench PlotLine 1000 pts 0.28 -> 0.15 ms, markers 0.15 -> 0.11 ms, vertices unchanged) 2026-10-17 12:23:37 -05:00
4DBug 262ef1c5df example: demo window only 2026-10-17 06:05:39 -05:00
4DBug d2926394d6 Example: live sine + demo windows; run example in tools/test.sh; README usage, API differences, status 2026-10-17 03:12:17 -05:00
4DBug cab1498a82 Port remaining demos (Tables, ItemStylingAndSpec, OffsetAndStride, CustomDataAndGetters, TickLabels, CustomStyles, CustomRendering, LegendPopups, ColormapWidgets, CustomPlottersAndTooltips); enable PlotPolygon demo 2026-10-17 03:07:55 -05:00
4DBug 2584bb36f3 Demo: port subplot, legend, drag tool, querying, annotation, tag and DnD demos 2026-10-17 03:04:22 -05:00
4DBug b4f236082f Port ImPlot demo: Demo_MarkersAndText..Demo_AutoFittingData (markers/text, NaN, per-index colors, log/symlog/time/custom scales, multiple/linked/constrained/equal axes, auto-fitting) 2026-10-17 02:59:39 -05:00
4DBug 5f2944c6ac Port missing query/clip/misc APIs (IsAxisHovered, IsPlotSelected, GetPlotSelection, SetAxis/SetAxes, PushPlotClipRect, HideNextItem, ...) 2026-10-17 02:56:17 -05:00
4DBug fd3e0eb16b Port ImPlot demo: ShowDemoWindow (menu, tabs, tool windows) and Demo_Help..Demo_RealtimePlots; stubs for the rest 2026-10-17 02:46:14 -05:00
4DBug 5ec0151f7e Port AddColormap (+ style editor custom colormap builder), ShowDatePicker/ShowTimePicker with PickerTimeMin/Max and time axis context menu, ShowAltLegend, ShowMetricsWindow 2026-10-17 02:38:58 -05:00
4DBug cafabe12af Port BeginSubplots/EndSubplots, BeginAlignedPlots/EndAlignedPlots, drag & drop utils, BeginLegendPopup/EndLegendPopup, ShowStyleEditor/ShowStyleSelector/ShowColormapSelector/ShowInputMapSelector/ShowUserGuide, crosshairs, axis side switch, equal-aspect fit 2026-10-17 02:33:10 -05:00
4DBug 0af1d4d3ad Port DragPoint, DragLineX/Y, DragRect, Annotation, TagX/TagY, SetupMouseText + mouse position text, LabelAxisValue, GetPlotMousePos 2026-10-17 02:25:55 -05:00
4DBug df162337a6 Port SetupAxisScale (Linear/Time/Log10/SymLog/custom transforms), Locator_Log10/SymLog/Time, ImPlotTime utils and date/time formatting, SetupAxisTicks, SetupAxisFormat formatter overload, SetupAxisLimitsConstraints/ZoomConstraints 2026-10-17 02:20:17 -05:00
4DBug 3acb454feb Port PlotPieChart, PlotHeatmap, PlotHistogram, PlotHistogram2D (CalculateBins/ImPlotBin), PlotImage, ColormapScale/Slider/Button/Icon, RenderColorBar 2026-10-17 02:15:53 -05:00
4DBug 6eb44ef497 Port PlotErrorBars, PlotStems, PlotInfLines, PlotText, PlotDummy, PlotDigital, PlotBubbles 2026-10-17 02:09:14 -05:00
4DBug 37ac7c43f4 Port PlotStairs, PlotShaded, PlotBars, PlotBarGroups with stairs/bars renderers, FitterBarV/H, PrimRectLine 2026-10-17 02:04:56 -05:00
4DBug a55186c520 Port items (ImPlotItem/ItemGroup/NextItemData, BeginItem/EndItem), getters/indexers, fitters, transformers, line/segment/shaded/marker renderers, PlotLine/PlotScatter, legend rendering + click-to-toggle, SetupLegend 2026-10-17 01:53:50 -05:00
4DBug 4dea841b3e Port UpdateInput (pan, zoom, box select, fit), ImPlotInputMap, plot/axis context menus, SetNextAxis*, SetupAxisLinks/PushLinks/PullLinks 2026-10-17 01:43:58 -05:00
4DBug b19d3bd008 Port ImPlotAxis, ImPlotPlot, ImPlotTicker, default locator/formatter, Setup*, BeginPlot/EndPlot rendering, plot/pixel transforms 2026-10-17 01:39:07 -05:00
4DBug d677896c1a Port enums, ImPlotPoint/Range/Rect, ImPlotStyle, context, style and colormap API 2026-10-17 01:33:21 -05:00
4DBug b9130d3876 Scaffold: upstream @ 851cdbd, core submodule, test runner, example 2026-10-16 23:47:09 -05:00
23 changed files with 26848 additions and 7 deletions

No files matched your search

+1
View File
@@ -1,2 +1,3 @@
.gitattributes export-ignore .gitattributes export-ignore
tools/upstream/** linguist-vendored=true tools/upstream/** linguist-vendored=true
love/** linguist-generated=true
+1 -1
View File
@@ -1,3 +1,3 @@
[submodule "tools/core"] [submodule "tools/core"]
path = tools/core path = tools/core
url = https://git.bug.tools/bug/imgui-luau.git url = https://github.com/4DBug/imgui-luau.git
+9958 -1
View File
File diff suppressed because it is too large. Load diff
+2988
View File
File diff suppressed because it is too large. Load diff
+41 -1
View File
@@ -5,13 +5,53 @@ Immediate-mode 2D plotting for imgui-luau (Roblox / LÖVE).
Luau port of [ImPlot](https://github.com/epezent/implot) for [imgui-luau](https://git.bug.tools/bug/imgui-luau) ([GitHub](https://github.com/4DBug/imgui-luau)). Luau port of [ImPlot](https://github.com/epezent/implot) for [imgui-luau](https://git.bug.tools/bug/imgui-luau) ([GitHub](https://github.com/4DBug/imgui-luau)).
Mirrors: [git.bug.tools](https://git.bug.tools/bug/implot-luau) / [GitHub](https://github.com/4DBug/implot-luau). Mirrors: [git.bug.tools](https://git.bug.tools/bug/implot-luau) / [GitHub](https://github.com/4DBug/implot-luau).
**Status: work in progress.** **Status:** near-complete port of ImPlot (all plot types, axes/scales, subplots, legends, drag tools, styles/colormaps) and the full ImPlot demo (`ImPlotDemo.lua`).
## Usage
```lua ```lua
local G = require(ReplicatedStorage.ImGui) local G = require(ReplicatedStorage.ImGui)
local ImPlot = require(ReplicatedStorage.ImPlot)(G) local ImPlot = require(ReplicatedStorage.ImPlot)(G)
require(ReplicatedStorage.ImPlotDemo)(G, ImPlot) -- optional, adds ImPlot.ShowDemoWindow
local ImGui = G.ImGui
ImGui.CreateContext()
ImPlot.CreateContext()
-- each frame, between ImGui.NewFrame() and ImGui.Render():
ImGui.Begin("My Window")
if ImPlot.BeginPlot("My Plot") then
ImPlot.PlotLine("sin", Xs, Ys) -- or PlotLine(label, Values[, Count, XScale, X0])
ImPlot.EndPlot()
end
ImGui.End()
ImPlot.ShowDemoWindow(true)
``` ```
Full LocalScript: `examples/roblox/main.client.luau` (ImPlot demo window).
## API differences from C++
- **Pointer args become return values.** Values are passed in and the new values returned, e.g.
`x, y, modified, clicked, hovered, held = ImPlot.DragPoint(id, x, y, col, radius, flags)`,
`value, modified, clicked, hovered, held = ImPlot.DragLineX(id, value, ...)`,
`p_open = ImPlot.ShowDemoWindow(p_open)` (same for `ShowMetricsWindow`).
- **Overloads are dispatched at runtime** on argument types: `PlotLine(label, xs, ys[, count, spec])` vs
`PlotLine(label, values[, count, xscale, x0, spec])`; getter variants keep the `G` suffix (`PlotLineG(label, fn, data, count, spec)`, `fn(idx, data) -> x, y`).
- **Arrays are 1-based Luau tables.** `Count` defaults to the table length. `Offset` and `Stride` (set via spec) are
counted in **elements**, not bytes; `Offset` is 0-based like C++ (ring-buffer index).
- **Specs** may be `nil`, a plain table (`{ LineColor = ..., Offset = ... }`) or an `ImPlotSpec`.
- **`SetNextLineStyle` / `SetNextFillStyle` / `SetNextMarkerStyle` / `SetNextErrorBarStyle`** (obsolete upstream) are
kept for compatibility and applied on top of the spec of the next plot item.
- Enums are tables (`ImPlot.ImAxis.X1`, `G.ImGuiCond.Always`, ...).
- Port-specific deviations are tagged `[Port]` in the source.
## TODO
- Upstream TODOs carried over as-is (e.g. per-style `AxisBg*`/`AxisTick` colors, half-locked axis ranges, tick-count heuristics).
- No LÖVE example yet (only `examples/roblox`).
- Performance tuning for very large datasets.
## Development ## Development
```sh ```sh
+2 -1
View File
@@ -4,7 +4,8 @@
"$className": "DataModel", "$className": "DataModel",
"ReplicatedStorage": { "ReplicatedStorage": {
"ImGui": { "$path": "tools/core/build/ImGuiTyped.luau", "Impl": { "$path": "tools/core/build/ImGui.luau" } }, "ImGui": { "$path": "tools/core/build/ImGuiTyped.luau", "Impl": { "$path": "tools/core/build/ImGui.luau" } },
"ImPlot": { "$path": "ImPlot.lua" } "ImPlot": { "$path": "ImPlot.lua" },
"ImPlotDemo": { "$path": "ImPlotDemo.lua" }
}, },
"StarterPlayer": { "StarterPlayerScripts": { "ImPlotExample": { "$path": "examples/roblox/main.client.luau" } } } "StarterPlayer": { "StarterPlayerScripts": { "ImPlotExample": { "$path": "examples/roblox/main.client.luau" } } }
} }
+5 -2
View File
@@ -1,15 +1,18 @@
-- ImPlot demo window.
local RS = game:GetService("ReplicatedStorage") local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService") local RunService = game:GetService("RunService")
local G = require(RS:WaitForChild("ImGui")) local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G) local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
require(RS:WaitForChild("ImPlotDemo"))(G, ImPlot)
local ImGui = G.ImGui local ImGui = G.ImGui
ImGui.CreateContext() ImGui.CreateContext()
G.ImGui_ImplRoblox.Init(game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")) ImPlot.CreateContext()
G.ImGui_ImplRoblox.Init() -- defaults to LocalPlayer.PlayerGui
RunService.RenderStepped:Connect(function() RunService.RenderStepped:Connect(function()
G.ImGui_ImplRoblox.NewFrame() G.ImGui_ImplRoblox.NewFrame()
ImGui.NewFrame() ImGui.NewFrame()
-- ImPlot example goes here ImPlot.ShowDemoWindow()
ImGui.Render() ImGui.Render()
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData()) G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
end) end)
+9939
View File
File diff suppressed because it is too large. Load diff
+2990
View File
File diff suppressed because it is too large. Load diff
+52
View File
@@ -0,0 +1,52 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
local ImGui, ImVec2 = G.ImGui, G.ImVec2
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
ImPlot.CreateContext()
local function near(a, b, eps) return math.abs(a - b) <= (eps or 1e-6) end
local frame, done = 0, false
game:GetService("RunService").Stepped:Connect(function()
if done then return end
frame += 1
G.ImGui_ImplRoblox.NewFrame()
ImGui.GetIO().DeltaTime = 1 / 60
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(10, 10), G.ImGuiCond.Always)
ImGui.SetNextWindowSize(ImVec2(500, 400), G.ImGuiCond.Always)
ImGui.Begin("Plots")
if ImPlot.BeginPlot("My Plot##p", ImVec2(-1, -1)) then
ImPlot.SetupAxes("x label", "y label")
ImPlot.SetupAxisFormat(ImPlot.ImAxis.Y1, "%.2f")
ImPlot.SetupAxesLimits(0, 10, -1, 1, ImPlot.ImPlotCond.Always)
local lim = ImPlot.GetPlotLimits()
assert(lim.X.Min == 0 and lim.X.Max == 10 and lim.Y.Min == -1 and lim.Y.Max == 1, "limits")
local pos, size = ImPlot.GetPlotPos(), ImPlot.GetPlotSize()
assert(size.x > 100 and size.y > 100, "plot size")
-- corners map to the plot rect (y axis points up)
local p0 = ImPlot.PlotToPixels(0, -1)
assert(near(p0.x, pos.x) and near(p0.y, pos.y + size.y), "PlotToPixels min corner")
local p = ImPlot.PlotToPixels(ImPlot.ImPlotPoint(3.25, 0.5))
local q = ImPlot.PixelsToPlot(p)
assert(near(q.x, 3.25, 1e-4) and near(q.y, 0.5, 1e-4), "round trip")
assert(type(ImPlot.IsPlotHovered()) == "boolean")
local ax = ImPlot.internal.GetCurrentPlot().Axes[ImPlot.ImAxis.Y1]
assert(ax.Ticker:TickCount() > 0 and ax.Ticker.Ticks[1].Text:find("%.%d%d$"), "y tick format")
ImPlot.EndPlot()
end
local dl = ImGui.GetWindowDrawList()
ImGui.End()
ImGui.Render()
assert(dl.VtxBuffer.Size > 0, "draw list has vertices")
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if frame == 30 then
done = true
ImPlot.DestroyContext()
print("OK")
end
end)
+69
View File
@@ -0,0 +1,69 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
local ImGui, ImVec2 = G.ImGui, G.ImVec2
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
ImPlot.CreateContext()
local io = ImGui.GetIO()
local N = 20
local xs, ys, ys2 = table.create(N), table.create(N), table.create(N)
for i = 1, N do
xs[i] = i - 1
ys[i] = math.sin(i * 0.3) * 3 + 4
ys2[i] = ys[i] - 2
end
local groups = { 1, 2, 3, 4, 2, 3, 1, -1, 3, 1, 2, 2 } -- 3 items x 4 groups
local labels = { "a", "b", "c" }
local cases = {
function() ImPlot.PlotStairs("stairs", xs, ys, N) end,
function() ImPlot.PlotStairs("stairs", ys, { Flags = ImPlot.ImPlotStairsFlags.PreStep + ImPlot.ImPlotStairsFlags.Shaded }) end,
function() ImPlot.PlotShaded("shaded", ys, N, 0, 1, 0) end,
function() ImPlot.PlotShaded("shaded", xs, ys, N, -math.huge) end,
function() ImPlot.PlotShaded("shaded", xs, ys, ys2, N) end,
function() ImPlot.PlotShadedG("shaded", function(i) return i, ys[i + 1] end, nil, function(i) return i, 0 end, nil, N) end,
function() ImPlot.PlotBars("bars", ys, N, 0.5) end,
function() ImPlot.PlotBars("bars", xs, ys, N, 0.5, { Flags = ImPlot.ImPlotBarsFlags.Horizontal }) end,
function() ImPlot.PlotBarsG("bars", function(i) return i, ys[i + 1] end, nil, N, 0.5) end,
function() ImPlot.PlotBarGroups(labels, groups, 3, 4, 0.67, 0) end,
function() ImPlot.PlotBarGroups(labels, groups, 3, 4, 0.67, 0, { Flags = ImPlot.ImPlotBarGroupsFlags.Stacked }) end,
function() ImPlot.PlotBarGroups(labels, groups, 3, 4, { Flags = ImPlot.ImPlotBarGroupsFlags.Horizontal + ImPlot.ImPlotBarGroupsFlags.Stacked }) end,
}
local ci, frame, base, done = 1, 0, 0, false
game:GetService("RunService").Stepped:Connect(function()
if done then return end
frame += 1
G.ImGui_ImplRoblox.NewFrame()
io.DeltaTime = 1 / 60
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(10, 10), G.ImGuiCond.Always)
ImGui.SetNextWindowSize(ImVec2(500, 400), G.ImGuiCond.Always)
ImGui.Begin("Plots")
if ImPlot.BeginPlot("Bars##" .. ci, ImVec2(-1, -1)) then
if frame > 1 then cases[ci]() end
ImPlot.EndPlot()
end
local dl = ImGui.GetWindowDrawList()
ImGui.End()
ImGui.Render()
local n = dl.VtxBuffer.Size
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if frame == 1 then
base = n
elseif frame == 11 then
assert(n > base + 16, "case " .. ci .. " adds vertices: " .. base .. " -> " .. n)
assert(ImPlot.internal.GetCurrentPlot() == nil)
ci += 1
frame = 0
if ci > #cases then
done = true
ImPlot.DestroyContext()
print("OK")
end
end
end)
+77
View File
@@ -0,0 +1,77 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
require(RS:WaitForChild("ImPlotDemo"))(G, ImPlot)
local ImGui = G.ImGui
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
ImPlot.CreateContext()
local io = ImGui.GetIO()
-- force every DemoHeader open, and select one tab per phase
local TreeNodeEx, BeginTabItem = ImGui.TreeNodeEx, ImGui.BeginTabItem
ImGui.TreeNodeEx = function(label, ...)
ImGui.SetNextItemOpen(true)
return TreeNodeEx(label, ...)
end
local tabs = { "Plots", "Subplots", "Axes", "Tools", "Custom", "Config", "Help" }
local tab, seen = 1, {}
ImGui.BeginTabItem = function(label, p_open, flags)
if label == tabs[tab] then flags = bit32.bor(flags or 0, G.ImGuiTabItemFlags.SetSelected) end
local r = BeginTabItem(label, p_open, flags)
if r then seen[label] = true end
return r
end
local BeginPlot, plotted = ImPlot.BeginPlot, {}
ImPlot.BeginPlot = function(title, ...)
local r = BeginPlot(title, ...)
if r then plotted[title] = true end
return r
end
local BeginSubplots, subplotted = ImPlot.BeginSubplots, {}
ImPlot.BeginSubplots = function(title, ...)
local r = BeginSubplots(title, ...)
if r then subplotted[title] = true end
return r
end
local frame, done = 0, false
game:GetService("RunService").Stepped:Connect(function()
if done then return end
frame += 1
tab = math.floor((frame - 1) / 14) % #tabs + 1
G.ImGui_ImplRoblox.NewFrame()
io.DeltaTime = 1 / 60
io.DisplaySize = G.ImVec2(1000, 30000)
ImGui.NewFrame()
-- tall window so every open demo is visible (clipped plots return false from BeginPlot)
if frame > 1 then ImGui.SetWindowSize("ImPlot Demo", G.ImVec2(900, 30000)) end
assert(ImPlot.ShowDemoWindow(true) == true)
ImGui.Render()
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if frame == 100 then
done = true
for _, t in tabs do assert(seen[t], "tab never opened: " .. t) end
-- every ported Plots/Axes/Config demo submitted its plot
for _, p in { "Line Plots", "Stock Prices", "Shaded Plots", "Scatter Plot", "Bubble Plot", "##Scrolling", "##Rolling",
"Stairstep Plot", "Bar Plot", "Bar Group", "PolitiFact: Who Lies More?", "##ErrorBars", "Stem Plots", "##Infinite",
"##Pie1", "##Pie2", "##Heatmap1", "##Heatmap2", "##Histograms", "##Hist2D", "##Digital", "##image", "Preview",
"##MarkerStyles", "##NaNValues", "Colorful Lines", "Colorful Shaded Plots", "Colorful Scatter", "Colorful Bubbles",
"Colorful Stairstep Plot", "Colorful Bar Plot", "Colorful Stem Plots", "Colorful Infinite Lines", "Log Plot",
"SymLog Plot", "##Time", "Sqrt", "Multi-Axis Plot", "Plot A", "Plot B", "##AxisConstraints", "##EqualAxes",
"##DataFitting", "##Legend", "##Bezier", "##lines", "##Main", "##rect", "##Centroid", "##Annotations",
"##Tags", "##DND1", "##DND2", "Polygon Plot", "##spark", "##SpecStyling", "##strideoffset",
"##Custom Data", "##Ticks", "seaborn style", "##CustomRend", "Right Click the Legend", "Candlestick Chart" } do
assert(plotted[p], "plot never began: " .. p)
end
for _, p in { "My Subplots", "##ItemSharing", "##AxisLinking" } do
assert(subplotted[p], "subplots never began: " .. p)
end
ImPlot.DestroyContext()
print("OK")
end
end)
+75
View File
@@ -0,0 +1,75 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
local ImGui, ImVec2, ImVec4 = G.ImGui, G.ImVec2, G.ImVec4
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
ImPlot.CreateContext()
local io = ImGui.GetIO()
local frame, done = 0, false
local px, py = 5, 5 -- DragPoint
local lx = 2 -- DragLineX
local ly = 8 -- DragLineY
local rect = ImPlot.ImPlotRect(7, 9, 1, 2) -- clear of the point and line grab areas
local pt_pix, line_pix
local any_modified, line_modified = false, false
game:GetService("RunService").Stepped:Connect(function()
if done then return end
frame += 1
G.ImGui_ImplRoblox.NewFrame()
io.DeltaTime = 1 / 60
-- drag the point by +40px x / +40px y, then the line by +30px x
if pt_pix then
if frame == 10 then io:AddMousePosEvent(pt_pix.x, pt_pix.y)
elseif frame == 11 then io:AddMouseButtonEvent(0, true)
elseif frame >= 12 and frame <= 15 then io:AddMousePosEvent(pt_pix.x + (frame - 11) * 10, pt_pix.y + (frame - 11) * 10)
elseif frame == 16 then io:AddMouseButtonEvent(0, false)
elseif frame == 20 then io:AddMousePosEvent(line_pix, pt_pix.y - 60)
elseif frame == 21 then io:AddMouseButtonEvent(0, true)
elseif frame >= 22 and frame <= 24 then io:AddMousePosEvent(line_pix + (frame - 21) * 10, pt_pix.y - 60)
elseif frame == 25 then io:AddMouseButtonEvent(0, false)
end
end
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(10, 10), G.ImGuiCond.Always)
ImGui.SetNextWindowSize(ImVec2(500, 400), G.ImGuiCond.Always)
ImGui.Begin("Plots")
if ImPlot.BeginPlot("Drag##p", ImVec2(-1, -1)) then
ImPlot.SetupAxesLimits(0, 10, 0, 10, ImPlot.ImPlotCond.Always)
ImPlot.SetupMouseText(ImPlot.ImPlotLocation.North, ImPlot.ImPlotMouseTextFlags.ShowAlways)
local m, m2
px, py, m = ImPlot.DragPoint(0, px, py, ImVec4(1, 0, 0, 1), 6)
any_modified = any_modified or m
lx, m2 = ImPlot.DragLineX(1, lx, ImVec4(0, 1, 0, 1))
line_modified = line_modified or m2
ly = ImPlot.DragLineY(2, ly, ImVec4(0, 0, 1, 1))
local _, _, hov = ImPlot.DragRect(3, rect, ImVec4(1, 1, 0, 1))
assert(type(hov) == "boolean", "DragRect out_hovered")
ImPlot.Annotation(px, py, ImVec4(0.2, 0.2, 0.2, 1), ImVec2(10, -10), true)
ImPlot.Annotation(5, 5, ImVec4(0, 0, 0, 0), ImVec2(0, 0), false, "center %d", 5)
ImPlot.TagX(lx, ImVec4(0, 1, 0, 1), true)
ImPlot.TagY(ly, ImVec4(0, 0, 1, 1), "y=%.1f", ly)
pt_pix = ImPlot.PlotToPixels(5, 5)
if frame < 20 then line_pix = ImPlot.PlotToPixels(lx, 0).x end
ImPlot.EndPlot()
end
ImGui.End()
ImGui.Render()
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if frame == 9 then
assert(px == 5 and py == 5 and lx == 2, "untouched before input")
elseif frame == 18 then
assert(any_modified, "DragPoint reported modified")
assert(px > 5 and py < 5, "DragPoint moved (x right, y down)")
assert(lx == 2, "line untouched by point drag")
elseif frame == 30 then
assert(line_modified, "DragLineX reported modified")
assert(lx > 2, "DragLineX moved right")
done = true
ImPlot.DestroyContext()
print("OK")
end
end)
+87
View File
@@ -0,0 +1,87 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
local ImGui, ImVec2, ImVec4 = G.ImGui, G.ImVec2, G.ImVec4
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
ImPlot.CreateContext()
local io = ImGui.GetIO()
local N = 20
local xs, ys, heat = table.create(N), table.create(N), table.create(N)
for i = 1, N do
xs[i] = math.sin(i * 0.7) * 2
ys[i] = math.cos(i * 1.3) * 2
heat[i] = i
end
-- known histogram input: 4 bins over [0, 4): counts 1, 2, 3, 1 -> max 3
local hist = { 0.5, 1.5, 1.5, 2.5, 2.5, 2.5, 3.5 }
local hist_max, hist_max_sturges, hist_max_cum
local labels = { "a", "b", "c" }
local pie = { 0.2, 0.3, 0.5 }
-- each case: draw function, optional check run after the 10th plotted frame (nil -> must add vertices)
local cases = {
{ function() ImPlot.PlotPieChart(labels, pie, 3, 0.5, 0.5, 0.4) end },
{ function() ImPlot.PlotPieChart(labels, { 1, 2, 3 }, 3, 0.5, 0.5, 0.4, function(v, d) return d .. v end, "v=", 0,
{ Flags = ImPlot.ImPlotPieChartFlags.Exploding }) end },
{ function() ImPlot.PlotHeatmap("heat", heat, 4, 5) end },
{ function() ImPlot.PlotHeatmap("heat", heat, 4, 5, 0, 20, false, nil, nil, { Flags = ImPlot.ImPlotHeatmapFlags.ColMajor }) end },
{ function() hist_max = ImPlot.PlotHistogram("hist", hist, nil, 4, 1.0, ImPlot.ImPlotRange(0, 4)) end },
{ function() hist_max_sturges = ImPlot.PlotHistogram("hist", hist) end },
{ function() hist_max_cum = ImPlot.PlotHistogram("hist", hist, nil, 4, 1.0, ImPlot.ImPlotRange(0, 4),
{ Flags = ImPlot.ImPlotHistogramFlags.Cumulative + ImPlot.ImPlotHistogramFlags.Horizontal }) end },
{ function() ImPlot.PlotHistogram2D("h2d", xs, ys) end },
{ function() ImPlot.PlotHistogram2D("h2d", xs, ys, N, ImPlot.ImPlotBin.Scott, 5, ImPlot.ImPlotRect(-2, 2, -2, 2)) end },
{ function() ImPlot.PlotImage("img", ImGui.GetIO().Fonts.TexRef, ImPlot.ImPlotPoint(0, 0), ImPlot.ImPlotPoint(1, 1)) end },
-- widgets outside the plot
{ function()
ImPlot.ColormapScale("scale", 0, 20, ImVec2(80, 150))
ImPlot.ColormapScale("scale2", 20, 0, ImVec2(0, 150), "%.0f", ImPlot.ImPlotColormapScaleFlags.Opposite)
ImPlot.ColormapButton("btn")
local t, _ = ImPlot.ColormapSlider("slider", 0.5, ImVec4(0, 0, 0, 0))
assert(t == 0.5)
ImPlot.ColormapIcon(0)
end, true },
}
local ci, frame, base, done = 1, 0, 0, false
game:GetService("RunService").Stepped:Connect(function()
if done then return end
frame += 1
G.ImGui_ImplRoblox.NewFrame()
io.DeltaTime = 1 / 60
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(10, 10), G.ImGuiCond.Always)
ImGui.SetNextWindowSize(ImVec2(500, 400), G.ImGuiCond.Always)
ImGui.Begin("Plots")
local c = cases[ci]
if c[2] and frame > 1 then c[1]() end
if ImPlot.BeginPlot("Misc##" .. ci, ImVec2(-1, -1)) then
if not c[2] and frame > 1 then c[1]() end
ImPlot.EndPlot()
end
local dl = ImGui.GetWindowDrawList()
ImGui.End()
ImGui.Render()
local n = dl.VtxBuffer.Size
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if frame == 1 then
base = n
elseif frame == 11 then
assert(n > base + 16, "case " .. ci .. " adds vertices: " .. base .. " -> " .. n)
assert(ImPlot.internal.GetCurrentPlot() == nil)
ci += 1
frame = 0
if ci > #cases then
done = true
assert(hist_max == 3, "PlotHistogram max bin count: " .. tostring(hist_max))
assert(hist_max_sturges == 3, "PlotHistogram Sturges max: " .. tostring(hist_max_sturges))
assert(hist_max_cum == 7, "PlotHistogram cumulative max: " .. tostring(hist_max_cum))
ImPlot.DestroyContext()
print("OK")
end
end
end)
+80
View File
@@ -0,0 +1,80 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
local ImGui, ImVec2 = G.ImGui, G.ImVec2
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
ImPlot.CreateContext()
local io = ImGui.GetIO()
local function near(a, b) return math.abs(a - b) <= 1e-6 end
assert(ImPlot.GetInputMap().Pan == 0 and ImPlot.GetInputMap().Select == 1, "default input map")
ImPlot.MapInputReverse(); assert(ImPlot.GetInputMap().Pan == 1, "reverse map")
ImPlot.MapInputDefault()
local frame, done = 0, false
local lim, pos, size
local start, after_pan, after_zoom
local link = { 0 }
game:GetService("RunService").Stepped:Connect(function()
if done then return end
frame += 1
G.ImGui_ImplRoblox.NewFrame()
io.DeltaTime = 1 / 60
if pos then
local cx, cy = pos.x + size.x * 0.5, pos.y + size.y * 0.5
-- left drag: press, move right/down by 40px, release
if frame == 10 then io:AddMousePosEvent(cx, cy)
elseif frame == 11 then io:AddMouseButtonEvent(0, true)
elseif frame >= 12 and frame <= 15 then io:AddMousePosEvent(cx + (frame - 11) * 10, cy + (frame - 11) * 10)
elseif frame == 16 then io:AddMouseButtonEvent(0, false)
-- wheel zoom in
elseif frame == 20 then io:AddMouseWheelEvent(0, 1)
-- double click refits
elseif frame == 40 or frame == 42 then io:AddMouseButtonEvent(0, true)
elseif frame == 41 or frame == 43 then io:AddMouseButtonEvent(0, false)
end
end
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(10, 10), G.ImGuiCond.Always)
ImGui.SetNextWindowSize(ImVec2(500, 400), G.ImGuiCond.Always)
ImGui.Begin("Plots")
if frame == 1 then ImPlot.SetNextAxesLimits(0, 10, 0, 10) end
if ImPlot.BeginPlot("Input##p", ImVec2(-1, -1)) then
ImPlot.SetupAxisLinks(ImPlot.ImAxis.X1, link, nil)
-- fake data extents [2, 4] so a fit is observable
local plot = ImPlot.internal.GetCurrentPlot()
for _, i in { ImPlot.ImAxis.X1, ImPlot.ImAxis.Y1 } do
plot.Axes[i]:ExtendFit(2); plot.Axes[i]:ExtendFit(4)
end
lim = ImPlot.GetPlotLimits()
pos, size = ImPlot.GetPlotPos(), ImPlot.GetPlotSize()
ImPlot.EndPlot()
end
ImGui.End()
ImGui.Render()
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if frame == 9 then
start = { lim.X.Min, lim.X.Max, lim.Y.Min, lim.Y.Max }
assert(start[1] == 0 and start[2] == 10, "SetNextAxesLimits")
elseif frame == 18 then
after_pan = { lim.X.Min, lim.X.Max, lim.Y.Min, lim.Y.Max }
-- dragged right -> x shifts left; dragged down -> y shifts up
assert(after_pan[1] < start[1] and after_pan[2] < start[2], "pan x")
assert(after_pan[3] > start[3] and after_pan[4] > start[4], "pan y")
assert(math.abs((after_pan[2] - after_pan[1]) - 10) < 1e-6, "pan keeps range")
assert(link[1] == after_pan[1], "link pushed")
elseif frame == 25 then
after_zoom = { lim.X.Min, lim.X.Max, lim.Y.Min, lim.Y.Max }
assert(after_zoom[2] - after_zoom[1] < 10 - 1e-3, "zoom x shrinks")
assert(after_zoom[4] - after_zoom[3] < 10 - 1e-3, "zoom y shrinks")
elseif frame == 50 then
assert(near(lim.X.Min, 2) and near(lim.X.Max, 4), "double click refit x")
assert(near(lim.Y.Min, 2) and near(lim.Y.Max, 4), "double click refit y")
done = true
ImPlot.DestroyContext()
print("OK")
end
end)
+80
View File
@@ -0,0 +1,80 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
local ImGui, ImVec2 = G.ImGui, G.ImVec2
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
ImPlot.CreateContext()
local io = ImGui.GetIO()
local function near(a, b) return math.abs(a - b) <= 1e-6 end
local N = 1000
local xs, ys = table.create(N), table.create(N)
local ymin, ymax = math.huge, -math.huge
for i = 1, N do
xs[i] = (i - 1) * 0.01
ys[i] = math.sin(i * 0.02) * 3 + 1
ymin = math.min(ymin, ys[i]); ymax = math.max(ymax, ys[i])
end
local frame, done = 0, false
local vtx = {}
local lim, legend_rect, line_item, scatter_item
game:GetService("RunService").Stepped:Connect(function()
if done then return end
frame += 1
G.ImGui_ImplRoblox.NewFrame()
io.DeltaTime = 1 / 60
if legend_rect then
-- click the first legend entry (the line)
local h = ImGui.GetTextLineHeight()
local cx, cy = legend_rect.Min.x + 5 + h * 0.5, legend_rect.Min.y + 5 + h * 0.5
if frame == 20 then io:AddMousePosEvent(cx, cy)
elseif frame == 22 then io:AddMouseButtonEvent(0, true)
elseif frame == 24 then io:AddMouseButtonEvent(0, false)
end
end
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(10, 10), G.ImGuiCond.Always)
ImGui.SetNextWindowSize(ImVec2(500, 400), G.ImGuiCond.Always)
ImGui.Begin("Plots")
if frame == 5 then ImPlot.SetNextAxesToFit() end
if ImPlot.BeginPlot("Line##p", ImVec2(-1, -1)) then
if frame >= 5 then
ImPlot.SetNextLineStyle(nil, 2)
ImPlot.PlotLine("line", xs, ys, N)
ImPlot.SetNextMarkerStyle(ImPlot.ImPlotMarker.Square, 3)
ImPlot.PlotScatter("scatter", ys, N, 0.01, 0, { Offset = 0 })
line_item = ImPlot.internal.GetItem("line")
scatter_item = ImPlot.internal.GetItem("scatter")
end
lim = ImPlot.GetPlotLimits()
local plot = ImPlot.internal.GetCurrentPlot()
ImPlot.EndPlot()
if frame >= 6 then legend_rect = plot.Items.Legend.Rect end
end
local dl = ImGui.GetWindowDrawList()
ImGui.End()
ImGui.Render()
vtx[frame] = dl.VtxBuffer.Size
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if frame == 10 then
-- 999 line segments * 4 verts + 1000 square markers * 4 verts
assert(vtx[10] - vtx[4] >= 999 * 4 + N * 4, "vertex count grows: " .. vtx[4] .. " -> " .. vtx[10])
assert(near(lim.X.Min, 0) and near(lim.X.Max, (N - 1) * 0.01), "fit x " .. lim.X.Min .. " " .. lim.X.Max)
assert(near(lim.Y.Min, ymin) and near(lim.Y.Max, ymax), "fit y " .. lim.Y.Min .. " " .. lim.Y.Max)
assert(line_item and line_item.Show and scatter_item.Show, "items shown")
assert(line_item.Color ~= scatter_item.Color, "colormap advances")
assert(scatter_item.Marker == ImPlot.ImPlotMarker.Square, "marker override")
assert(ImPlot.internal.GetCurrentPlot() == nil)
elseif frame == 30 then
assert(not line_item.Show, "legend click hides line")
assert(scatter_item.Show, "scatter still shown")
assert(vtx[10] - vtx[30] >= 999 * 4 - 100, "vertex count drops: " .. vtx[10] .. " -> " .. vtx[30])
done = true
ImPlot.DestroyContext()
print("OK")
end
end)
+82
View File
@@ -0,0 +1,82 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
local ImGui, ImVec2 = G.ImGui, G.ImVec2
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
ImPlot.CreateContext()
local io = ImGui.GetIO()
local N = 20
local xs, ys, err, err2, bits, szs = table.create(N), table.create(N), table.create(N), table.create(N), table.create(N), table.create(N)
for i = 1, N do
xs[i] = i - 1
ys[i] = math.sin(i * 0.3) * 3 + 4
err[i] = 0.5
err2[i] = 0.25
bits[i] = (i // 3) % 2
szs[i] = 0.3
end
-- each case: draw function, optional check run after the 10th plotted frame (nil -> must add vertices)
local cases = {
{ function() ImPlot.PlotErrorBars("err", xs, ys, err, N) end },
{ function() ImPlot.PlotErrorBars("err", xs, ys, err, err2, N, { Flags = ImPlot.ImPlotErrorBarsFlags.Horizontal }) end },
{ function() ImPlot.PlotStems("stems", ys) end },
{ function() ImPlot.PlotStems("stems", xs, ys, N, 1, { Flags = ImPlot.ImPlotStemsFlags.Horizontal }) end },
{ function() ImPlot.PlotInfLines("inf", { 1, 3, 5 }) end },
{ function() ImPlot.PlotInfLines("inf", { 1, 3, 5 }, { Flags = ImPlot.ImPlotInfLinesFlags.Horizontal }) end },
{ function() ImPlot.PlotText("hello", 0.5, 0.5) end },
{ function() ImPlot.PlotText("hello", 0.5, 0.5, ImVec2(5, 5), { Flags = ImPlot.ImPlotTextFlags.Vertical }) end },
{ function() ImPlot.PlotDigital("digital", xs, bits, N) end },
{ function() ImPlot.PlotDigitalG("digital", function(i) return i, bits[i + 1] end, nil, N) end },
{ function() ImPlot.PlotBubbles("bubbles", ys, szs) end },
{ function() ImPlot.PlotBubbles("bubbles", xs, ys, szs, N) end },
{ function() ImPlot.PlotDummy("dummy") end, true },
}
local ci, frame, base, done = 1, 0, 0, false
local dummy_ok = false
game:GetService("RunService").Stepped:Connect(function()
if done then return end
frame += 1
G.ImGui_ImplRoblox.NewFrame()
io.DeltaTime = 1 / 60
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(10, 10), G.ImGuiCond.Always)
ImGui.SetNextWindowSize(ImVec2(500, 400), G.ImGuiCond.Always)
ImGui.Begin("Plots")
local c = cases[ci]
if ImPlot.BeginPlot("Misc##" .. ci, ImVec2(-1, -1)) then
if frame > 1 then c[1]() end
if c[2] and frame == 11 then
local plot = ImPlot.internal.GetCurrentPlot()
dummy_ok = plot.Items:GetLegendCount() == 1 and plot.Items:GetLegendLabel(0) == "dummy"
end
ImPlot.EndPlot()
end
local dl = ImGui.GetWindowDrawList()
ImGui.End()
ImGui.Render()
local n = dl.VtxBuffer.Size
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if frame == 1 then
base = n
elseif frame == 11 then
if c[2] then
assert(dummy_ok, "PlotDummy legend entry exists")
else
assert(n > base + 16, "case " .. ci .. " adds vertices: " .. base .. " -> " .. n)
end
assert(ImPlot.internal.GetCurrentPlot() == nil)
ci += 1
frame = 0
if ci > #cases then
done = true
ImPlot.DestroyContext()
print("OK")
end
end
end)
+53
View File
@@ -0,0 +1,53 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
local ImGui, ImVec2, ImVec4 = G.ImGui, G.ImVec2, G.ImVec4
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
ImPlot.CreateContext()
local io = ImGui.GetIO()
-- AddColormap (ImVec4 and ImU32 overloads)
local n0 = ImPlot.GetColormapCount()
local cm = ImPlot.AddColormap("MyCmap", { ImVec4(1, 0, 0, 1), ImVec4(0, 1, 0, 1), ImVec4(0, 0, 1, 1) }, 3, true)
assert(cm == n0 and ImPlot.GetColormapCount() == n0 + 1 and ImPlot.GetColormapIndex("MyCmap") == cm)
local c = ImPlot.GetColormapColor(1, cm)
assert(c.x == 0 and c.y == 1 and c.z == 0 and c.w == 1)
local cm2 = ImPlot.AddColormap("MyCmapU32", { G.IM_COL32(10, 20, 30, 255), G.IM_COL32(40, 50, 60, 255) }, 2, false)
assert(ImPlot.GetColormapColorU32(1, cm2) == G.IM_COL32(40, 50, 60, 255))
local t = ImPlot.internal.MakeTime(2024, 2, 15)
local level, frame, open = 0, 0, true
game:GetService("RunService").Stepped:Connect(function()
if frame >= 10 then return end
frame += 1
G.ImGui_ImplRoblox.NewFrame()
io.DeltaTime = 1 / 60
ImGui.NewFrame()
open = ImPlot.ShowMetricsWindow(open)
ImGui.Begin("Pickers")
local _
_, level, t = ImPlot.ShowDatePicker("date", level, t, t, nil)
_, t = ImPlot.ShowTimePicker("time", t)
if ImPlot.BeginPlot("P", ImVec2(200, 150)) then
ImPlot.SetupAxisScale(ImPlot.ImAxis.X1, ImPlot.ImPlotScale.Time)
ImPlot.PlotLine("l", { 1, 2, 3 })
local axis = ImPlot.internal.GetCurrentPlot().Axes[ImPlot.ImAxis.X1]
ImPlot.EndPlot()
ImPlot.internal.ShowAxisContextMenu(axis, nil, true) -- time branch
axis:SetRange(0, 86400)
assert(axis.PickerTimeMax.S == 86400)
end
ImPlot.ShowAltLegend("P")
ImPlot.ShowStyleEditor()
ImGui.End()
ImGui.Render()
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if frame == 10 then
assert(level == 0 and ImPlot.internal.GetYear(t) == 2024)
ImPlot.DestroyContext()
print("OK")
end
end)
+109
View File
@@ -0,0 +1,109 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
local ImGui, ImVec2 = G.ImGui, G.ImVec2
local ImAxis, ImPlotScale, Cond = ImPlot.ImAxis, ImPlot.ImPlotScale, ImPlot.ImPlotCond
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
ImPlot.CreateContext()
local I = ImPlot.internal
-- time utils
local t = I.MakeTime(2021, 2, 15, 13, 45, 30)
assert(I.FormatDateTime(t, I.ImPlotDateTimeSpec(I.ImPlotDateFmt.DayMoYr, I.ImPlotTimeFmt.HrMinS)) == "3/15/21 1:45:30pm", "FormatDateTime")
assert(I.FormatDate(t, I.ImPlotDateFmt.DayMoYr, true) == "2021-03-15", "iso date")
assert(I.FloorTime(t, I.ImPlotTimeUnit.Day).S == I.MakeTime(2021, 2, 15).S, "FloorTime")
assert(I.CeilTime(t, I.ImPlotTimeUnit.Mo).S == I.MakeTime(2021, 3, 1).S, "CeilTime")
assert(I.RoundTime(t, I.ImPlotTimeUnit.Hr).S == I.MakeTime(2021, 2, 15, 14).S, "RoundTime")
assert(I.MakeTime(1970).S == 0, "epoch")
local function labels(ax)
local n, out = 0, {}
for i = 1, ax.Ticker:TickCount() do
local tk = ax.Ticker.Ticks[i]
if tk.ShowLabel and tk.Text then n += 1; out[#out + 1] = tk.Text end
end
return n, out
end
local frame, done = 0, false
game:GetService("RunService").Stepped:Connect(function()
if done then return end
frame += 1
G.ImGui_ImplRoblox.NewFrame()
ImGui.GetIO().DeltaTime = 1 / 60
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(10, 10), G.ImGuiCond.Always)
ImGui.SetNextWindowSize(ImVec2(600, 900), G.ImGuiCond.Always)
ImGui.Begin("Plots")
if ImPlot.BeginPlot("Log##p", ImVec2(-1, 280)) then
ImPlot.SetupAxes("x", "y")
ImPlot.SetupAxisScale(ImAxis.Y1, ImPlotScale.Log10)
ImPlot.SetupAxesLimits(0, 1, 1, 1e6, Cond.Always)
ImPlot.PlotLine("l", { 1, 10, 100 }, { 1, 1000, 1e6 })
local ax = I.GetCurrentPlot().Axes[ImAxis.Y1]
local majors = 0
for i = 1, ax.Ticker:TickCount() do
local tk = ax.Ticker.Ticks[i]
if tk.Major then
majors += 1
local e = math.log10(tk.PlotPos)
assert(math.abs(e - math.floor(e + 0.5)) < 1e-9, "log major at power of 10")
end
end
assert(majors >= 2, "log majors")
-- log transform: 1000 is the vertical midpoint
local mid = ImPlot.PlotToPixels(0, 1000).y
local p0, p1 = ImPlot.PlotToPixels(0, 1).y, ImPlot.PlotToPixels(0, 1e6).y
assert(math.abs(mid - (p0 + p1) / 2) < 1, "log transform")
ImPlot.EndPlot()
end
if ImPlot.BeginPlot("Time##p", ImVec2(-1, 280)) then
ImPlot.SetupAxes("t", "y")
ImPlot.SetupAxisScale(ImAxis.X1, ImPlotScale.Time)
local t0 = I.MakeTime(2021, 0, 1).S
ImPlot.SetupAxesLimits(t0, t0 + 86400, 0, 1, Cond.Always)
local ax = I.GetCurrentPlot().Axes[ImAxis.X1]
ImPlot.EndPlot()
local n, out = labels(ax)
assert(n >= 3, "time labels")
local found = false
for _, s in out do if s:find("1/1/21") then found = true end end
assert(found, "time date label: " .. table.concat(out, ","))
end
if ImPlot.BeginPlot("Ticks##p", ImVec2(-1, 280)) then
ImPlot.SetupAxes("x", "y")
ImPlot.SetupAxisTicks(ImAxis.X1, { 0, 0.5, 1 }, 3, { "lo", "mid", "hi" }, false)
ImPlot.SetupAxisTicks(ImAxis.Y1, 0, 1, 5, nil, false)
ImPlot.SetupAxisFormat(ImAxis.Y1, function(v) return string.format("<%g>", v) end)
ImPlot.SetupAxisLimitsConstraints(ImAxis.X1, 0, 1)
ImPlot.SetupAxisZoomConstraints(ImAxis.X1, 0.5, 1)
ImPlot.SetupAxesLimits(-5, 5, 0, 1, Cond.Always)
local plot = I.GetCurrentPlot()
ImPlot.EndPlot()
local n, out = labels(plot.Axes[ImAxis.X1])
assert(n == 3 and out[1] == "lo" and out[3] == "hi", "custom tick labels")
assert(labels(plot.Axes[ImAxis.Y1]) == 5, "custom y tick count")
local r = plot.Axes[ImAxis.X1].Range
assert(r.Min >= 0 and r.Max <= 1, "limits constraints")
end
if ImPlot.BeginPlot("SymLog##p", ImVec2(-1, 200)) then
ImPlot.SetupAxes("x", "y")
ImPlot.SetupAxisScale(ImAxis.X1, ImPlotScale.SymLog)
ImPlot.SetupAxesLimits(-100, 100, 0, 1, Cond.Always)
assert(I.GetCurrentPlot().Axes[ImAxis.X1].Ticker:TickCount() == 0)
ImPlot.EndPlot()
end
local dl = ImGui.GetWindowDrawList()
ImGui.End()
ImGui.Render()
assert(dl.VtxBuffer.Size > 0, "draw list has vertices")
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if frame == 10 then
done = true
ImPlot.DestroyContext()
print("OK")
end
end)
+52
View File
@@ -0,0 +1,52 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
-- context create/destroy
assert(ImPlot.GetCurrentContext() == nil)
local ctx = ImPlot.CreateContext()
assert(ImPlot.GetCurrentContext() == ctx)
-- enums
assert(ImPlot.ImPlotFlags.CanvasOnly == 55)
assert(ImPlot.ImPlotAxisFlags.Lock == 49152)
assert(ImPlot.ImPlotMarker.None == -2 and ImPlot.ImPlotMarker.COUNT == 12)
assert(ImPlot.ImPlotLocation.SouthEast == 10)
-- push/pop style var
local style = ImPlot.GetStyle()
assert(style.PlotBorderSize == 1 and style.PlotPadding.x == 10)
ImPlot.PushStyleVar(ImPlot.ImPlotStyleVar.PlotBorderSize, 3)
ImPlot.PushStyleVar(ImPlot.ImPlotStyleVar.PlotPadding, G.ImVec2(1, 2))
assert(style.PlotBorderSize == 3 and style.PlotPadding.y == 2)
ImPlot.PopStyleVar(2)
assert(style.PlotBorderSize == 1 and style.PlotPadding.x == 10 and style.PlotPadding.y == 10)
-- push/pop style color
ImPlot.PushStyleColor(ImPlot.ImPlotCol.Selection, G.IM_COL32(255, 0, 0, 255))
assert(ImPlot.GetStyleColorU32(ImPlot.ImPlotCol.Selection) == G.IM_COL32(255, 0, 0, 255))
ImPlot.PopStyleColor()
assert(ImPlot.GetStyleColorU32(ImPlot.ImPlotCol.Selection) == G.IM_COL32(255, 255, 0, 255))
ImPlot.StyleColorsDark(); ImPlot.StyleColorsLight(); ImPlot.StyleColorsClassic(); ImPlot.StyleColorsAuto()
-- colormaps
assert(ImPlot.GetColormapCount() == 16)
assert(ImPlot.GetColormapName(ImPlot.ImPlotColormap.Viridis) == "Viridis")
assert(ImPlot.GetColormapIndex("Greys") == 15 and ImPlot.GetColormapIndex("nope") == -1)
assert(ImPlot.GetColormapSize() == 10)
assert(ImPlot.GetColormapColorU32(0) == G.IM_COL32(76, 114, 176, 255))
assert(ImPlot.GetColormapColorU32(11) == G.IM_COL32(221, 132, 82, 255)) -- wraps
local c = ImPlot.GetColormapColor(1, ImPlot.ImPlotColormap.Dark)
assert(math.abs(c.x - 55/255) < 1e-6 and math.abs(c.z - 184/255) < 1e-6 and c.w == 1)
ImPlot.PushColormap("Jet")
assert(ImPlot.GetColormapSize() == 11)
assert(ImPlot.SampleColormapU32(0) == G.IM_COL32(0, 0, 170, 255))
assert(ImPlot.SampleColormapU32(1) == G.IM_COL32(255, 0, 0, 255))
ImPlot.PopColormap()
assert(ImPlot.GetStyle().Colormap == ImPlot.ImPlotColormap.Deep)
-- Greys midpoint: idx = (int)(255*0.5+0.5) = 128 -> ImMixU32(white, black, 128) = (255*128)>>8 = 127 per channel
assert(ImPlot.SampleColormapU32(0.5, ImPlot.ImPlotColormap.Greys) == G.IM_COL32(127, 127, 127, 255))
ImPlot.DestroyContext()
assert(ImPlot.GetCurrentContext() == nil)
print("OK")
+73
View File
@@ -0,0 +1,73 @@
local RS = game:GetService("ReplicatedStorage")
local G = require(RS:WaitForChild("ImGui"))
local ImPlot = require(RS:WaitForChild("ImPlot"))(G)
local ImGui, ImVec2 = G.ImGui, G.ImVec2
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
ImPlot.CreateContext()
local io = ImGui.GetIO()
local xs, ys = {}, {}
for i = 1, 50 do xs[i] = i; ys[i] = math.sin(i * 0.2) end
local rows, cols = { 1, 2 }, { 1, 1 }
local flags = bit32.bor(ImPlot.ImPlotSubplotFlags.ShareItems, ImPlot.ImPlotSubplotFlags.LinkAllX)
local frame, done = 0, false
game:GetService("RunService").Stepped:Connect(function()
if done then return end
frame += 1
G.ImGui_ImplRoblox.NewFrame()
io.DeltaTime = 1 / 60
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(10, 10), G.ImGuiCond.Always)
ImGui.SetNextWindowSize(ImVec2(600, 700), G.ImGuiCond.Always)
ImGui.Begin("Subplots")
local dl = ImGui.GetWindowDrawList()
local cells = 0
if ImPlot.BeginSubplots("My Subplots", 2, 2, ImVec2(-1, 250), flags, rows, cols) then
for i = 1, 4 do
if ImPlot.BeginPlot("##p" .. i) then
local before = dl.VtxBuffer.Size
ImPlot.PlotLine("sin", xs, ys, #xs)
assert(dl.VtxBuffer.Size > before, "subplot " .. i .. " added vertices")
ImPlot.EndPlot()
cells += 1
end
end
ImPlot.EndSubplots()
end
assert(cells == 4, "all 4 subplots began")
local aligned = 0
-- smoke: aligned plots, legend popup, drag/drop target
if ImPlot.BeginAlignedPlots("AlignGroup") then
for i = 1, 2 do
if ImPlot.BeginPlot("##a" .. i, ImVec2(-1, 150), ImPlot.ImPlotFlags.Crosshairs + ImPlot.ImPlotFlags.Equal) then
ImPlot.PlotLine("cos", xs, ys, #xs)
aligned += 1
if ImPlot.BeginLegendPopup("cos") then ImPlot.EndLegendPopup() end
if ImPlot.BeginDragDropTargetPlot() then ImPlot.EndDragDropTarget() end
ImPlot.EndPlot()
end
end
ImPlot.EndAlignedPlots()
end
assert(aligned == 2, "aligned plots began")
ImGui.End()
ImGui.SetNextWindowPos(ImVec2(620, 10), G.ImGuiCond.Always)
ImGui.SetNextWindowSize(ImVec2(500, 600), G.ImGuiCond.Always)
ImGui.Begin("Style")
ImPlot.ShowStyleEditor()
ImPlot.ShowUserGuide()
ImGui.End()
ImGui.Render()
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if frame == 10 then
done = true
ImPlot.DestroyContext()
print("OK")
end
end)
Executable
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env sh
# Regenerates love/: Lua 5.1 (LÖVE/LuaJIT) copies of the Luau sources. Needs darklua + python3.
set -e
cd "$(dirname "$0")/.."
mkdir -p love
CFG=$(mktemp)
echo '{ "generator": "retain_lines", "rules": ["remove_types", "remove_compound_assignment", "remove_if_expression", "remove_continue", "remove_interpolated_string", "remove_floor_division"] }' > "$CFG"
for f in ImPlot.lua ImPlotDemo.lua; do
out="love/$(basename "$f")"
darklua process -c "$CFG" "$f" "$out"
python3 - "$out" <<'PY'
import re, sys
p = sys.argv[1]; src = open(p).read()
src = re.sub(r"^\s*@native\s*$", "", src, flags=re.M)
# Luau generalized iteration: for k, v in t do -> for k, v in __iter(t) do
src = re.sub(r"^([ \t]*for[ \t]+[\w][\w, \t]*[ \t]in[ \t]+)([^\n]*?)([ \t]+do\b)", r"\1__iter(\2)\3", src, flags=re.M)
head = ("-- GENERATED by tools/love.sh from the Luau source - do not edit\n"
"local function __iter(t, ...) if type(t) ~= 'table' or (getmetatable(t) and getmetatable(t).__call) then return t, ... end "
"local n, i, k = #t, 0, nil return function() if i < n then i = i + 1 return i, t[i] end "
"repeat k = next(t, k) until k == nil or type(k) ~= 'number' or k < 1 or k > n or k % 1 ~= 0 if k ~= nil then return k, t[k] end end end "
"table.create = table.create or function(n, v) local t = {} if v ~= nil then for i = 1, n do t[i] = v end end return t end "
"table.clone = table.clone or function(t) local c = {} for k, v in pairs(t) do c[k] = v end return setmetatable(c, getmetatable(t)) end "
"math.clamp = math.clamp or function(x, a, b) return math.max(a, math.min(b, x)) end "
"math.sign = math.sign or function(x) return x > 0 and 1 or (x < 0 and -1 or 0) end "
"math.round = math.round or function(x) return x >= 0 and math.floor(x + 0.5) or math.ceil(x - 0.5) end\n")
open(p, "w").write(head + src)
PY
done
rm -f "$CFG"
+5 -1
View File
@@ -3,7 +3,11 @@
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
fail=0 fail=0
for t in tests/t_*.luau; do for t in tests/t_*.luau; do
out=$(python3 tools/core/tools/test/run.py --module ImPlot=ImPlot.lua --main "$t" --quiet --roblox 2>&1) out=$(python3 tools/core/tools/test/run.py --module ImPlot=ImPlot.lua --module ImPlotDemo=ImPlotDemo.lua --main "$t" --quiet --roblox 2>&1)
if echo "$out" | grep -q "^OK"; then echo "PASS $t"; else echo "FAIL $t"; echo "$out" | tail -20; fail=1; fi if echo "$out" | grep -q "^OK"; then echo "PASS $t"; else echo "FAIL $t"; echo "$out" | tail -20; fail=1; fi
done done
# example LocalScript: 400 frames of random input (mock drives Stepped, not RenderStepped)
ex=$(mktemp --suffix=.luau); sed 's/RenderStepped/Stepped/' examples/roblox/main.client.luau > "$ex"
out=$(python3 tools/core/tools/test/run.py --module ImPlot=ImPlot.lua --module ImPlotDemo=ImPlotDemo.lua --main "$ex" --roblox 2>&1); rm -f "$ex"
if echo "$out" | grep -q "^avg frame"; then echo "PASS examples/roblox/main.client.luau"; else echo "FAIL examples/roblox/main.client.luau"; echo "$out" | tail -20; fail=1; fi
exit $fail exit $fail