Page 1 of 1

LuaGuiElement for graphs like production/electricity

Posted: Sun Sep 13, 2020 10:26 pm
by sparr
I'd like to be able to present a multi-series line graph in a mod gui, like the built-in graphs for production and electricity. I imagine this would involve a new LuaGuiElement type, and a new method for updating the graph data.

Code: Select all

data = {
    foo={5,5,5,7,5,6,6,6,8},
    bar={1,2,3,1,2,3,1,2,3},
}
graph = someframe.add{type="graph"}
graph.update_data(data)
... [one or many ticks later] ...
graph.update_data(new_data)
The vertical axis would automatically scale and label based on the data, like the existing graphs.

Some way to provide horizontal axis labels would be needed, but I suspect the internal representation of the graph would lend itself to some specific lua representation that I don't want to guess at.

Re: LuaGuiElement for graphs like production/electricity

Posted: Tue Oct 13, 2020 1:32 am
by raiguard
+1. I would like to use graphs as well!

Re: LuaGuiElement for graphs like production/electricity

Posted: Fri Oct 16, 2020 4:47 pm
by Rseding91
I could implement this but it would have absolutely terrible performance and most likely a super complex/annoying API to use... both of those combined means it would take a lot of time to do and very few people would make use of it.

So, I don't really see this happening.

Re: LuaGuiElement for graphs like production/electricity

Posted: Fri Feb 25, 2022 6:00 pm
by sparr
For anyone who comes here later looking for this feature, here's a mod with some functionality you might be able to use:

https://mods.factorio.com/mod/timeseries
https://mods.factorio.com/mod/timeseries_fixfor110