https://github.com/seniru/linegraph-tfm
Lite, Reusable and customizable line charts for Transformice
https://github.com/seniru/linegraph-tfm
charts customizable library linegraph-tfm lite transformice
Last synced: about 2 months ago
JSON representation
Lite, Reusable and customizable line charts for Transformice
- Host: GitHub
- URL: https://github.com/seniru/linegraph-tfm
- Owner: Seniru
- License: mit
- Created: 2019-08-24T07:20:08.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-28T04:34:25.000Z (over 5 years ago)
- Last Synced: 2025-03-25T21:21:24.355Z (2 months ago)
- Topics: charts, customizable, library, linegraph-tfm, lite, transformice
- Language: Lua
- Homepage:
- Size: 194 KB
- Stars: 10
- Watchers: 3
- Forks: 2
- Open Issues: 30
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
Lite, Reusable and customizable line charts for Transformice!
![]()
![]()
![]()
![]()
![]()
### Features
- Reusable
- Lightweight
- Customizable
- Real time!
- Class based
- Easy### What's new! :fireworks: :fireworks: :fireworks:
- Now you can add multiple Series to the same graph. Check out the
[documentation](https://github.com/Seniru/LineGraph-TFM/blob/master/documentation.md) for more information!
### Usage
```lua
--insert the library code before the script
--then call LineChart.init()
LineChart.init()
--then call LineChart(id, x, y, w, h) to create a new chart
chart = LineChart(1, 200, 50, 400, 200)
--create a new series to insert into the created chart.
series1 = Series({1,2,3}, {1,2,3}, "series1")
--add it to the chart
chart:addSeries(series1)
--set the labels to display (optional)
chart:showLabels()
--display the chart
chart:show()
-- this should show a linear chart ...
```
Check the [documentation](https://github.com/Seniru/LineGraph-TFM/blob/master/documentation.md) for more### Demos
```lua
LineChart.init() --initialzingx = range(-5, 5, 0.5)
y = map(x, function(x) return math.tan(x) end)chart = LineChart(1, 200, 50, 400, 200) --instantiation
series1 = Series(x, y, "y = tan x", 0xFFCC00) -- creates a new series with yellowish-orange color
chart:addSeries(series1)
chart:setGraphColor(0xFFFFFF, 0xFFFFFF) --sets graph color to white
chart:show() --display the chart```
```lua
LineChart.init() --initializingx = range(-5, 5, 0.5)
y = map(x, function(x) return 2 * x * x end)chart = LineChart(1, 200, 50, 400, 200) --instantiation
chart:addSeries(Series(x, y, "y = 2x^2", 0xCC89FF)) --adds a new series with color purple
chart:setGraphColor(0xFFFFFF, 0xFFFFFF) --sets graph color to white
chart:show() --display the chart
```
Real time Graphs!
![]()
```lua
LineChart.init()chart = LineChart(1, 200, 50, 400, 200) --instantiation
series1 = Series({0}, {0}, "Real time", 0xDD32CC) --creates a new series
chart:setGraphColor(0xFFFFFF, 0xFFFFFF) --sets graph color to white
chart:addSeries(series1) --adds the new seriescurrX = 0
--the real time mageic is here!
function eventLoop(l, r)
local x = range(currX, currX + 10, 0.1) --creates the x coordinates
local y = map(x, function(x) return math.sin(x) * x * x * math.tanh(x) end ) --maps x values to the specified function
series1:setData(x, y) --set new data to the series
chart:show() --displays it
currX = currX + 0.5 --this cause x coordinate to move by 0.5 every 500ms
end
```
![]()
Multi-Series Graphs!
```lua
LineChart.init()chart = LineChart(1, 200, 50, 400, 200) --creates the chart (container for the series)
chart:setGraphColor(0xFFFFFF, 0xFFFFFF) --sets graph color to white
xData = range(0, 20, 1) --creates a list of numbers from 0 to 20series1 = Series(xData, xData, "linear") --creates a linear series
series2 = Series(xData, map(xData, function(x) return math.cos(x) end), "y = cos x") --creates a series which maps 'y' values to the 'tan x' value
series3 = Series(xData, map(xData, function(x) return math.random(x) end), "random") --creates a series which maps 'y' values randomly to 'x'--add all the series
chart:addSeries(series1)
chart:addSeries(series2)
chart:addSeries(series3)chart:showLabels() --show the labels
chart:show() --show the plots!
```
![]()
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Seniru Pasan Indira
💻 📖 🎨
Lautenschlager
💻
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!