Current progress:

This shows the skin with autoscaling turned on. The white number is the highest number in the current set, and all the other bar heights are scaled relative to that value.
Current script options
- Define the width and height of the graph
- Define the width of a single bar and the size of the gap between bars
- Define the X and Y position of the first bar meter
- Flip the histogram horizontally and/or vertically
- Define which measure in the skin file will be used for the graph
- Optional autoscaling (sort of like in Rainmeter's built-in histogram but not quite)
I'm still using the script to write the image meters into the skin file. This has causes two separate problems:
- If you change the the width of the histogram or the width of the bars so that the number of bars is smaller, the excess image meters stay in the skin and still appear...
- On first run or after the number of bars changes (either smaller or larger) the script throw "nil reference" errors, like there is a gap between the meters being created and the meters being added to the tables (even though it's all done at the same time).
There is also an interesting point in the autoscaling code - the if/else blocks appear to be redundant:
Code: Select all
if Values[i] == maxV then
h = height
else
h = math.ceil((Values[i]/maxV)*height)
end
Many thanks to Smurfier for cleaning up my Lua script! Much prettier now.
Current script code:
Code: Select all
function Initialize()
-- Tables to hold the meter handles and the 'h' for each meter
Meters = {}
Values = {}
-- grabs the various appearance options
gap = SELF:GetNumberOption('Gap',0)
height = SELF:GetNumberOption('Height',10) - gap*2
direction = SELF:GetNumberOption('FlipX',0) == 1
orient = SELF:GetNumberOption('FlipY',0) == 1
auto = SELF:GetNumberOption('Relative',0) == 1
xStrt = SELF:GetOption('Xstart')
yStrt = SELF:GetOption('Ystart')
-- Gets the width of the histogram and divides that by the size of one bar
-- (including a gap) to get the number of bars in the histogram
numBars = math.floor(SELF:GetNumberOption('Width',10) / (gap + SELF:GetNumberOption('BarWidth',1)))
measure = SKIN:GetMeasure(SELF:GetOption('Msr'))
-- for debug
print(numBars .. ' | ' .. height .. ' | ' .. tostring(auto))
for i=1,numBars do
SKIN:Bang('!WriteKeyValue',i,'Meter','IMAGE')
SKIN:Bang('!WriteKeyValue',i,'MeterStyle','sBar')
Meters[i] = SKIN:GetMeter(i)
Values[i] = 0
end
-- makes the X/Y of the first meter different (histogram 'start' position)
SKIN:Bang('!WriteKeyValue',1,'X',xStrt)
SKIN:Bang('!WriteKeyValue',1,'Y',yStrt)
end
function Update()
if direction then
-- if the chart should move from left to right...
table.remove(Values)
table.insert(Values, 1, measure:GetRelativeValue())
else
-- if the chart should move from right to left...
table.remove(Values, 1)
table.insert(Values, measure:GetRelativeValue())
end
-- find the largest value in the Values table, to use for autoscaling later
maxV = 0
for i,v in ipairs(Values) do
maxV = math.max(maxV,v)
end
-- iterates through the meters and sets their 'H' values from the Values table
for i=1, numBars do
if auto then
if Values[i] == maxV then
h = height
else
h = math.ceil((Values[i]/maxV)*height)
end
else
h = math.ceil(Values[i]*height)
end
-- used b/c Meter:SetH() would not work
SKIN:Bang('!SetOption ' .. Meters[i]:GetName() .. ' H ' .. h)
-- note: Lua (X and Y or Z) same as C++/Java (X ? Y : Z)
Meters[i]:SetY(orient and gap or (height - h + gap))
end
return math.floor(maxV*100) -- could use this value in skin (not currently implemented)
end
Code: Select all
[Rainmeter]
Update=1000
[Metadata]
Name=HistoBar (Test)
Author=FlyingHyrax
Information=
Version=beta
License=CC BY-NC-SA 3.0
[Variables]
SkinHeight=80
SkinWidth=500
Gap=1
BarWidth=4
BarColor=0,0,0,200
[mScript]
Measure=Script
ScriptFile=#@#histbarscript.lua
Gap=#Gap#
BarWidth=#BarWidth#
Height=#SkinHeight#
Width=#SkinWidth#
Msr=mCPU
FlipX=1
FlipY=0
Xstart=#*Gap*#
Ystart=0
Relative=1
firstRun=1
[mCPU]
Measure=CPU
Processor=0
[sBar]
SolidColor=#BarColor#
X=#Gap#R
Y=0
W=#BarWidth#
H=#SkinHeight#
Group=bars
[holder]
Meter=IMAGE
X=0
Y=0
W=(#SkinWidth#)+(#Gap#)
H=#SkinHeight#
SolidColor=0,0,0,50
[string]
Meter=STRING
MeasureName=mScript
X=#SkinWidth#
Y=#Gap#
StringAlign=RIGHTTOP
FontFace=Consolas
FontSize=18
FontColor=250,250,250,2500
AntiAlias=1
Thanks!
Old: