It is currently August 10th, 2020, 4:04 pm

Quantization value for histograms

Report bugs with the Rainmeter application and suggest features.
User avatar
balala
Rainmeter Sage
Posts: 11192
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Quantization value for histograms

Post by balala »

Yincognito wrote: July 5th, 2020, 7:47 pm There you go (just 5 value points used, as I didn't want to bother copy pasting too much):
Yep, interesting code, indeed. However me personally still believe the Histogram meter, along with a properly written TransformationMatrix is much simpler. But don't contest your code is also working well. :thumbup:
User avatar
Yincognito
Posts: 2223
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Quantization value for histograms

Post by Yincognito »

balala wrote: July 5th, 2020, 8:08 pm Yep, interesting code, indeed. However me personally still believe the Histogram meter, along with a properly written TransformationMatrix is much simpler. But don't contest your code is also working well. :thumbup:
Actually, it turns out that passing measure values to predecessor measures was not as tricky as I first thought - it's actually very simple (and becomes even shorter if using MeterStyles and removing DynamicVariables=1 lines from where they are not needed):

Code: Select all

[Variables]
H=500

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

---Measures---

[MeasureCPUValue0]
Measure=Calc
Formula=MeasureCPUValue1
MinValue=0
MaxValue=100

[MeasureCPUValue1]
Measure=Calc
Formula=MeasureCPUValue2
MinValue=0
MaxValue=100

[MeasureCPUValue2]
Measure=Calc
Formula=MeasureCPUValue3
MinValue=0
MaxValue=100

[MeasureCPUValue3]
Measure=Calc
Formula=MeasureCPUValue4
MinValue=0
MaxValue=100

[MeasureCPUValue4]
Measure=CPU
MinValue=0
MaxValue=100

---Styles---

[BarStyle]
X=0R
Y=0r
W=(195/5)
H=#H#
BarColor=255,255,255,255
SolidColor=0,0,0,100
BarOrientation=Vertical

---Meters---

[MeterCPUBackgroundImage]
Meter=Image
SolidColor=24,102,10
X=0
Y=0
W=220
H=(#H#+10)

[MeterCPUHistogram]
Meter=Histogram
MeasureName=MeasureCPUValue4
X=5
Y=5
W=5
H=#H#
PrimaryColor=255,255,255,255
SolidColor=0,0,0,100
AntiAlias=1

[MeterImageGap]
Meter=Image
X=0R
Y=0r
W=10
H=#H#
SolidColor=0,0,0,0
AntiAlias=1

[MeterCPUBar0]
Meter=Bar
MeterStyle=BarStyle
MeasureName=MeasureCPUValue0

[MeterCPUBar1]
Meter=Bar
MeterStyle=BarStyle
MeasureName=MeasureCPUValue1

[MeterCPUBar2]
Meter=Bar
MeterStyle=BarStyle
MeasureName=MeasureCPUValue2

[MeterCPUBar3]
Meter=Bar
MeterStyle=BarStyle
MeasureName=MeasureCPUValue3

[MeterCPUBar4]
Meter=Bar
MeterStyle=BarStyle
MeasureName=MeasureCPUValue4

[MeterCPUText]
Meter=String
MeasureName=MeasureCPU
X=110
Y=10R
FontSize=13
FontColor=255,255,255,255
StringAlign=Center
AntiAlias=1
Text=CPU Usage: %1%
Regarding the TransformationMatrix code, while I agree with you that it can be done, it requires enlarging the meter (or its width), if I'm not mistaken (correct me if I'm wrong). My code doesn't need to. Also, I tried setting the things exactly as you said and it didn't work for me (same basis for the code, the histogram example from the manual):

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[MeasureCPU]
Measure=CPU

[MeterCPUBackgroundImage]
Meter=Image
SolidColor=24,102,10
X=0
Y=0
W=220
H=70

[MeterCPUHistogram]
Meter=Histogram
MeasureName=MeasureCPU
X=5
Y=5
W=210
H=60
PrimaryColor=255,255,255,255
SolidColor=0,0,0,100
AntiAlias=1
TransformationMatrix=2;0;0;1;-5;0

[MeterCPUText]
Meter=String
MeasureName=MeasureCPU
X=110
Y=10R
FontSize=13
FontColor=255,255,255,255
StringAlign=Center
AntiAlias=1
Text=CPU Usage: %1%
Last edited by Yincognito on July 5th, 2020, 8:47 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 11192
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Quantization value for histograms

Post by balala »

Yincognito wrote: July 5th, 2020, 8:19 pm Regarding the TransformationMatrix code, while I agree with you that it can be done, it requires enlarging the meter (or its width), if I'm not mistaken (correct me if I'm wrong). My code doesn't need to.
Yes, exactly. And no, you're not mistaken.
Yincognito wrote: July 5th, 2020, 8:19 pm Also, I tried setting the things exactly as you said and it didn't work for me (same basis for the code, the histogram example from the manual):
My description might be mistaken, indeed. Have to dig into it a little bit, to check it.
User avatar
Yincognito
Posts: 2223
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Quantization value for histograms

Post by Yincognito »

balala wrote: July 5th, 2020, 8:37 pm Yes, exactly. And no, you're not mistaken.

My description might be mistaken, indeed. Have to dig into it a little bit, to check it.
Yeah, don't worry, I know for sure it can be done, as in the past I adapted a skin to be able to use a dynamic number of disk drives and I've used TransformationMatrix to shrink and widen the elements in the skin (including histograms). So, no need to bother if you don't want to, you don't need to convince me of it, as I'm already convinced and in full agreement with you. ;-)

P.S. In my code above, the DynamicVariables=1 on the meters were not needed anymore, they were just remnants of the previous code. I updated the code acccordingly.
User avatar
balala
Rainmeter Sage
Posts: 11192
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Quantization value for histograms

Post by balala »

Yincognito wrote: July 5th, 2020, 8:46 pm Yeah, don't worry, I know for sure it can be done,
I didn't say it is not (at least I hope). However it is a little bit more complicated, especially if there have to be too many Bar meters.
User avatar
Yincognito
Posts: 2223
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Quantization value for histograms

Post by Yincognito »

balala wrote: July 6th, 2020, 9:58 am I didn't say it is not (at least I hope). However it is a little bit more complicated, especially if there have to be too many Bar meters.
If you're talking about my Bar implementation, you're correct, it needs to have as many bar meters (and as many corresponding measures) as there are (visible) value points in the histogram - pretty much like an AudioLevel band visualizer skin, which also needs to have as many child measures / meters as there are bands in the parent measure.

...which is why I already started working on the Path Shape method. This will need no more than 5 measures (doing mainly string manipulation to construct the Path option string) and a single Shape meter ... irrespective of how many value points there are in the histogram. So far my work goes well and it's almost finished, but I'm having some trouble with referencing section variables, as I need some references to be literal (in order to "delay" their parsing until the shape is drawn) and others to be "normal".

I'll post the result here when it's done. So far, while the path is fully constructed, the X values in the LineTo segments are not yet correct (the Y values are fine), so that currently leads to something like:
Path Method - Unfinished.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 11192
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Quantization value for histograms

Post by balala »

Yincognito wrote: July 6th, 2020, 1:01 pm I'll post the result here when it's done.
I'm curious and wait for it.
User avatar
Yincognito
Posts: 2223
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Quantization value for histograms

Post by Yincognito »

balala wrote: July 6th, 2020, 2:06 pm I'm curious and wait for it.
Yeah, finally succeeded in making it work, at least from the 5th update onwards. It was a small mistake in the regex substitution, and it took a while to discover. Now I have to correct those first 4 updates. They don't cause that much trouble, it's only that because of those, the first 4 histogram lines in the path are in a diagonal instead of the desired , like the following ones. The histogram works nevertheless. :D

Do you know how to update a measure's value ... without updating the measure itself (and run its substitutions)? Cause this is the key for fixing the first 4 updates, LOL.
User avatar
balala
Rainmeter Sage
Posts: 11192
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Quantization value for histograms

Post by balala »

Yincognito wrote: July 6th, 2020, 3:35 pm Do you know how to update a measure's value ... without updating the measure itself (and run its substitutions)?
Have no idea if I don't see the code, so post it please.
User avatar
Yincognito
Posts: 2223
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Quantization value for histograms

Post by Yincognito »

balala wrote: July 6th, 2020, 5:28 pm Have no idea if I don't see the code, so post it please.
Nevermind, I went for a different approach instead, and formatted the string so that substitutions happen in a certain way. Everything works, but the measure order is important. I guess [MeasureInitialHistogramPath] (which is automatically building the "0 to 0 to 0 to ... to 0" path string) and [MeasureHistogramPath] (which deals with the path string "last in first out" removals and insertions) could be carefully merged to further compact the code and make the measure order unimportant, but that will be a job for another day, if really needed.

So far, my mission is complete, as the code works, no additional measures or meters are needed, every parameter of the Path histogram simulation is adjustable (and only for convenience linked to the equivalent parameter in the actual histogram, so one can notice the similarity). The commented lines write the Path strings to a Test.inc file in the skin's folder - I used those to verify if the results were appropriate.

The code:

Code: Select all

[Variables]
Values=100
Padding=5
W=3
H=100
HistogramColor=255,255,255,255
HistogramBGCol=0,0,0,100
PathSegment="LineTo (#W#*([MeasureLastValueIndex]-1-(0+0))),(#H#-(0/100)*#H#) | LineTo (#W#*([MeasureLastValueIndex]-(0+0))),(#H#-(0/100)*#H#) | "

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

---Measures---

[MeasureFirstValueIndex]
Measure=Calc
Formula=(MeasureFirstValueIndex+1)

[MeasureLastValueIndex]
Group=InitialGroup
Measure=Calc
Formula=(MeasureLastValueIndex+1)

[MeasureInitialHistogramPath]
Group=InitialGroup
Measure=String
String=
IfCondition=(MeasureLastValueIndex<=#Values#)
IfTrueAction=[!SetOption MeasureInitialHistogramPath String "[MeasureInitialHistogramPath]#PathSegment#"][!UpdateMeasureGroup InitialGroup]
IfFalseAction=[!PauseMeasure MeasureInitialHistogramPath][!SetOption MeasureHistogramPath String "[MeasureInitialHistogramPath]"][!UpdateMeasure MeasureHistogramPath]
IfConditionMode=1
;OnUpdateAction=[!WriteKeyValue Variables MeasureInitialHistogramPath "[[MeasureInitialHistogramPath]]" "Test.inc"]
DynamicVariables=1

[MeasureCPU]
Measure=CPU
OnUpdateAction=[!SetOption MeasureHistogramPath String "[MeasureHistogramPath]LineTo (#W#*([MeasureLastValueIndex]-(0+1))),(#H#-([#CURRENTSECTION#]/100)*#H#) | LineTo (#W#*([MeasureLastValueIndex]+1-(0+1))),(#H#-([#CURRENTSECTION#]/100)*#H#) | "]
DynamicVariables=1

[MeasureHistogramPath]
Measure=String
String=
RegExpSubstitute=1
Substitute="(?siU)^(?:LineTo .* \| LineTo .* \| ){1}((?:LineTo .* \| LineTo .* \| ){#Values#})$":"\1","-\(\d+\+":"-([MeasureFirstValueIndex]+"
;OnUpdateAction=[!WriteKeyValue Variables "MeasureHistogramPath[MeasureFirstValueIndex]" "[MeasureHistogramPath]" "Test.inc"]
DynamicVariables=1

---Meters---

[MeterCPUBackgroundImage]
Meter=Image
SolidColor=24,102,10
X=0
Y=0
W=(#Values#+#W#*#Values#+#Padding#*3)
H=(#H#+#Padding#*2)

[MeterCPUHistogram]
Meter=Histogram
MeasureName=MeasureCPU
X=#Padding#
Y=#Padding#
W=#Values#
H=#H#
PrimaryColor=#HistogramColor#
SolidColor=#HistogramBGCol#
AntiAlias=1

[MeterImageGap]
Meter=Image
X=0R
Y=0r
W=#Padding#
H=#H#
SolidColor=0,0,0,0
AntiAlias=1

[MeterCPUShapeHistogram]
Meter=Shape
X=0R
Y=0r
Shape=Rectangle 0,0,(#W#*#Values#),#H# | StrokeWidth 0 | Stroke Color #HistogramBGCol# | Fill Color #HistogramBGCol#
Shape2=Path HistogramPath | StrokeWidth 0 | Stroke Color #HistogramColor# | Fill Color #HistogramColor#
HistogramPath=0,#H# | [MeasureHistogramPath]LineTo (#W#*#Values#),#H# | SetNoStroke 1 | ClosePath 1
DynamicVariables=1

[MeterCPUText]
Meter=String
MeasureName=MeasureCPU
X=((#Values#+#W#*#Values#+#Padding#*3)/2)
Y=(#Padding#*2)R
FontSize=8
FontColor=255,255,255,255
StringAlign=Center
AntiAlias=1
Text=%1%
Result:
Path Histogram.jpg
LEGEND:
Value = number of value points in the Path histogram (i.e. how many "columns" there are in it; for convenience, this applies to the actual histogram as well)
Padding = the padding in the skin; since the Histogram example in the manual was used as a basis for this skin, this one is not essential
W = the width of a histogram "column" (for visual and comparison convenience, this applies to the actual histogram as well)
H = the height of a histogram "column" (for visual and comparison convenience, this applies to the actual histogram as well)

The other three variables are self-explanatory, really. The PathSegment variable is used only to build the initial path string, as a slightly different segment string is used for insertion (in the MeasureCPU's OnUpdateAction).
You do not have the required permissions to view the files attached to this post.