-
Notifications
You must be signed in to change notification settings - Fork 0
Charts
Three chart types: line, bar, and pie. Multi-series support, reactive data via suppliers, hover tooltip with the value at the hovered index. All three accept a shared ChartOptions for axis labels, legend toggle, value formatter, and color palette.
import org.triggersstudio.moddinglib.client.ui.chart.ChartSeries;
import org.triggersstudio.moddinglib.client.ui.chart.PieSlice;
import org.triggersstudio.moddinglib.client.ui.chart.ChartOptions;A line / bar series — label, color, and a Supplier<List<Double>> re-read every frame so reactive data flows into the chart without restarting it.
public record ChartSeries(String label, int color, Supplier<List<Double>> values) {}ChartSeries cpu = new ChartSeries(
"CPU %",
0xFF_00_AA_FF,
() -> samples.cpuHistory());A pie slice — label, color, and a DoubleSupplier re-read every frame.
public record PieSlice(String label, int color, DoubleSupplier value) {}PieSlice diskUsed = new PieSlice("Used", 0xFF_FF_88_00, () -> usedGb);
PieSlice diskFree = new PieSlice("Free", 0xFF_00_AA_00, () -> totalGb - usedGb);Builder with sensible defaults that fit a 0xFF_1A_1A_1A background.
ChartOptions opts = ChartOptions.builder()
.xLabels(List.of("Mon", "Tue", "Wed", "Thu", "Fri"))
.showLegend(true)
.showGrid(true)
.showAxis(true)
.yMin(0)
.yMax(100)
// .yRange(0, 100) — shorthand for yMin + yMax
.valueFormatter(v -> String.format("%.1f%%", v))
.textColor(0xFF_AA_AA_AA)
.gridColor(0xFF_33_33_33)
.axisColor(0xFF_55_55_55)
.tooltipBgColor(0xEE_15_15_15)
.tooltipTextColor(WHITE)
.build();ChartOptions.DEFAULT is the no-arg .build(); pass it (or just omit the options arg) when you don't need overrides.
| Option | Default | Notes |
|---|---|---|
xLabels |
empty | When set, drives the X axis tick labels. |
showLegend |
true |
Toggles the colored legend strip. |
showGrid |
true |
Toggles horizontal gridlines. |
showAxis |
true |
Toggles axis lines + tick labels. |
yMin, yMax
|
auto from data | Hard-set the Y range — useful for percentage charts. |
valueFormatter |
smart (integer if whole, %.2f otherwise) |
Used in tooltips and axis ticks. |
textColor |
0xFF_AA_AA_AA |
Ticks, legend labels. |
gridColor |
0xFF_33_33_33 |
Gridlines. |
axisColor |
0xFF_55_55_55 |
Axis lines. |
tooltipBgColor |
0xEE_15_15_15 |
Hover tooltip background. |
tooltipTextColor |
0xFF_FF_FF_FF |
Hover tooltip foreground. |
Multi-series line plot. Hovering snaps a vertical guide to the closest data index and shows a tooltip listing each series's value at that index.
LineChart(List<ChartSeries> series)
LineChart(List<ChartSeries> series, ChartOptions options)
LineChart(List<ChartSeries> series, ChartOptions options, Style style)
LineChart(List<ChartSeries> series, Style style)LineChart(
List.of(
new ChartSeries("CPU", 0xFF_00_AA_FF, () -> cpuHistory),
new ChartSeries("RAM", 0xFF_FF_88_00, () -> ramHistory)),
ChartOptions.builder()
.xLabels(labels)
.yRange(0, 100)
.valueFormatter(v -> String.format("%.0f%%", v))
.build(),
Style.width(400).height(220).build()
);Grouped bars per category. With multiple series, bars are placed side-by-side within each category. The baseline sits at clamp(0, yMin, yMax), so negative values render below the axis correctly. Per-bar hit-testing drives the hover tooltip.
BarChart(List<ChartSeries> series)
BarChart(List<ChartSeries> series, ChartOptions options)
BarChart(List<ChartSeries> series, ChartOptions options, Style style)
BarChart(List<ChartSeries> series, Style style)BarChart(
List.of(
new ChartSeries("Q1", 0xFF_00_AA_FF, () -> q1Values),
new ChartSeries("Q2", 0xFF_FF_88_00, () -> q2Values)),
ChartOptions.builder()
.xLabels(List.of("North", "South", "East", "West"))
.build(),
Style.height(200).build()
);Side-legend layout — slices on the left, labeled legend on the right. Hover hit-testing uses atan2 plus a distance check so only points actually inside the disk register.
PieChart(List<PieSlice> slices)
PieChart(List<PieSlice> slices, ChartOptions options)
PieChart(List<PieSlice> slices, ChartOptions options, Style style)
PieChart(List<PieSlice> slices, Style style)PieChart(
List.of(
new PieSlice("Used", 0xFF_FF_88_00, () -> usedGb),
new PieSlice("Free", 0xFF_00_AA_00, () -> totalGb - usedGb)),
ChartOptions.builder()
.valueFormatter(v -> String.format("%.0f GB", v))
.build(),
Style.width(280).height(180).build()
);