Aloha,
Today I will tell you something about customs skins for TilesFX. This year at CodeOne in San Francisco the Oracle team created a really nice Raspberry Pi SuperComputer. And for this Pi cluster the guys from Gluon created a dashboard that monitors the cpu and memory usage and also the temperature of each Pi.
Lucky me they decided to go with TilesFX to create the dashboard but they had the problem that there was no skin that was good enough to visualize the CPU and memory usage in one Tile.
So they asked me if I could help them out with a skin and so I've created the CpuMemTileSkin which looks as follows:
If you would like to make use of the skin feel free to take the code from this gist.
To use the skin you first need to set it up as follows:
Random rnd = new Random();
ChartData cpuItem = new ChartData("CPU", Bright.RED);
ChartData memItem = new ChartData("MEM", Bright.BLUE);
GradientLookup gradient = new GradientLookup(Arrays.asList(
new Stop(0.0, Bright.GREEN),
new Stop(0.4, Bright.YELLOW),
new Stop(0.8, Bright.RED)));
Tile cpuMemTile = TileBuilder.create()
.skinType(SkinType.CUSTOM)
.prefSize(200, 200)
.unit("\u0025")
.title("Node XY")
.chartData(memItem, cpuItem)
.build();
cpuMemTile.setSkin(new CpuMemTileSkin(cpuMemTile);
// Creating random values for cpu and mem
double cpu = rnd.nextDouble() * 100.0;
double mem = rnd.nextDouble() * 100.0;
// Set the cpu color related to it's value and set the value
cpuItem.setFillColor(gradient.getColorAt(cpu / 100));
cpuItem.setValue(cpu);
// Set the mem color related to it's value and set the value
memItem.setFillColor(gradient.getColorAt(mem / 100));
memItem.setValue(mem);
So you set up two ChartData objects, one for cpu and one for mem and add them to the tiles chartData property in the TileBuilder.
Then you create a GradientLookup to change the color of each bar dependent on the current value (from green over yellow to red).
When this is done you can set the color and value of each bar by changing the value of the ChartData objects and that's all you need to do to make use of the custom TilesFX skin.
I hope this will help one or the other of you and if you have created a nice TilesFX skin please let me know...I'm always keen on seeing new stuff... :)
That's it for today...so keep coding... :)
No comments:
Post a Comment