I will cut to the chase: I'm currently writing a Rainmeter skin here that will measure the amount of network activity, using the Net measures. I'm intending the skin to just display a graph of the network usage (with the maximum arbitrarily set at 1 gigabit), and then display the exact amount in a tooltip when you hover over the entire skin (a background image). Problem is, the Net measures return the network usage value only in bytes, and Autoscale doesn't work on Image meters; I have resorted to attempting to use this piece of Lua code to do the scaling, but I'm no good with Lua (never tried it before in my own Rainmeter skins) and I have no idea how to make it work. In particular, I'm not sure how I can pass the value of the Net measure into the Lua script, and then have the tooltip display the returned result of the Lua script.
This is what my current Rainmeter code looks like:
Code: Select all
[Rainmeter]
AccurateText=1
[MeasureNetIn]
; This measures the amount of incoming (receiving) network traffic, with MaxValue set at 1Gb as the maximum on the Y axis for the graph.
; Measurement is done across all network adapters on the system to give an overall value of incoming network traffic to the system as a whole,
; instead of focusing on any one specific or "best" network adapter.
; Hence, Interface is set to 0 for this purpose.
Measure=NetIn
Interface=0
; 1000000000 bits = 1 gigabit
; Rainmeter will always use bits instead of bytes for MaxValue, and internally recalculate the measure result to bytes automatically,
; regardless of how UseBits is set.
MaxValue=1000000000
[NetInScaled]
Measure=Script
Script=#@#\AutoScale.lua
NetValue=[MeasureNetIn]
[BG]
; This defines the size of the skin itself.
; The image used is defined in the variant skins themselves.
Meter=Image
ImageName=#@#\BG.png
Tile=1
W=200
H=50
TooltipText="Network activity (receiving): [NetInScaled]."
DynamicVariables=1
[Label]
; This is the background text on the widget.
Meter=STRING
X=13
Y=1
FontColor=58,58,58
FontFace=Segoe UI Light
FontSize=25
StringAlign=Left
StringStyle=NORMAL
AntiAlias=1
DynamicVariables=1
Text="Net (In)"
; The graph consists of two parts: a Line meter and a Histogram meter.
; The Line meter is used to visually display the peaks of the graphs, while the Histogram meter is used to "fill in" the graph beneath the Line meter.
[NetInGraphMax]
Meter=Line
MeasureName=MeasureNetIn
X=0
Y=0
W=200
H=50
AntiAlias=1
LineColor=255,255,255
GraphStart=Right
Autoscale=0
DynamicVariables=1
[NetInGraph]
Meter=Histogram
MeasureName=MeasureNetIn
X=0
Y=0
W=200
H=50
AntiAlias=1
PrimaryColor=255,255,255, 48
GraphStart=Right
Autoscale=0
DynamicVariables=1
Code: Select all
function Update()
iNetUnScaled = SELF:GetValue('NetValue')
NetScaled = AutoScale(iNetUnscaled, 2)
return NetScaled
end
function AutoScale(num, idp)
assert(tonumber(num), 'AutoScale expects a number.')
local scales = {'B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'}
local places = idp or 0
local scale = ""
local scaled = 0
for i, v in ipairs(scales) do
if (num < (1024 ^ i)) or (i == #scales) then
scale = v
scaled = Round(num / 1024 ^ (i - 1), places)
break
end
end
return scaled, scale
end
function Round(num, idp)
assert(tonumber(num), 'Round expects a number.')
local mult = 10 ^ (idp or 0)
if num >= 0 then
return math.floor(num * mult + 0.5) / mult
else
return math.ceil(num * mult - 0.5) / mult
end
end