Lines - Create scrolling bar charts

Post your working scripts, libraries and tools for AHK v1.1 and older
skrommel
Posts: 17
Joined: 15 Sep 2014, 06:15

Lines - Create scrolling bar charts

18 Jul 2017, 17:34

:) Lines - Create scrolling bar charts.
Lines.gif
Lines.gif (138.18 KiB) Viewed 3182 times
I needed a live status update of my network's ping time, so I found I could use the Progress control to fake it.
And to have multiple status bars, I finally took the time to learn to use objects and arrays.

To use it just run Lines_init for each bar, with a new variable as the first paramater:

Code: Select all

Lines_init(variable,gui_width,gui_height,line_width,max_value,"color")
Then create a Loop and run Lines_update for each bar to update them with new values:

Code: Select all

Lines_Update(variable,new_value)
I guess a graphical version using GDIP would be faster, but there's much to be said for simplicity!

Skrommel

Code: Select all

;Lines.ahk
; Creates a scrolling bar chart using the Progress control
;
; Syntax:
; Lines_init(variable,gui_width,gui_height,line_width,max_value,"color")
; Lines_Update(variable,new_value)
;
;Skrommel @ 2017

#NoEnv
#SingleInstance,Force
SetBatchLines,-1
SetWinDelay,0
SetControlDelay,0

;Example
Lines_init(bar1,20,20,1,1000,"Blue")
Lines_init(bar2,30,30,2,2000,"Red")
Lines_Init(bar3,40,40,3,3000,"Green")
Gui,Show,,Lines

Loop
{
  Random,new_value,1,1000
  Lines_Update(bar1,new_value)

  Random,new_value,1,2000
  Lines_Update(bar2,new_value)

  Random,new_value,1,3000
  Lines_Update(bar3,new_value)

  Sleep,100
}

Lines_Init(ByRef lines="",gui_width=50,gui_height=20,width=1,max=1000,color="Blue")
{  
  lines:={}
  lines.counter:=0
  lines.gui_width:=gui_width
  lines.gui_height:=gui_height
  lines.width:=width
  lines.height:=Object()
  lines.ctrl:=Object()
  lines.max:=max
  lines.color:=color

  Loop,% gui_width
  {
    Gui,Add,Progress,% "XP+" width+1 " W" width+2 " H" lines.gui_height " C" lines.color " HWNDhwnd Vertical Range0-" lines.gui_height,% A_Index*lines.gui_height/lines.gui_width
    lines.ctrl[A_Index]:=hwnd
  }
}

Lines_Update(ByRef lines,new_value)
{
  lines.counter+=1
  If (lines.counter>lines.gui_width)
    lines.counter:=1
  height:=Ceil(new_value*lines.gui_height/lines.max)+1  ;+1 to always show a line
  If (height>lines.gui_height)
    height:=lines.gui_height                            ;cutoff for large values
  If (lines.counter=1)
    height:=0                                           ;creates a visible gap
  lines.height[lines.gui_width]:=height
  
  Loop,% lines.gui_width
  {
    GuiControl,,% lines.ctrl[A_Index],% lines.height[A_Index]
    lines.height[A_Index]:=lines.height[A_Index+1]
  }
  Return
}

GuiClose:
ExitApp
Last edited by skrommel on 19 Jul 2017, 16:19, edited 4 times in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Lines - Create scrolling bar charts

18 Jul 2017, 17:40

Thanks for this, looks nice. Btw did you write DetachVideo? It seemed pretty amazing that you could just pull Flash out of a window. I wonder how you ever found out how to do that. Cheers.

[EDIT:] Yep, tested it, still works (e.g. on BBC iPlayer, although YouTube doesn't use a Flash control any more, and it grabs the whole IE control), it actually pulls out *any* control under the cursor. It all makes sense when you look at the source code.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
skrommel
Posts: 17
Joined: 15 Sep 2014, 06:15

Re: Lines - Create scrolling bar charts

18 Jul 2017, 17:57

:) Thanks, jeeswg! Yes, http://www.donationcoder.com/Software/S ... etachVideo is mine, but I haven't used it for years! It's just a simple SetParent to move the video to a gui, but I was very surprised the first time it actually worked! :)

These days I use https://www.centbrowser.com that has the video breakout function built in + a lot more!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Lines - Create scrolling bar charts

18 Jul 2017, 18:20

Haha that's great, it was pretty wow when I first tested it out. I was going over some old scripts recently, and I was meaning to check out DetachVideo. I remember trying out Barnacle back in the day as well, and it was interesting to see toolbar controls in AutoHotkey, I wanted to create a 'Notepad with toolbar buttons' (and other GUIs with toolbars). I did have some floating images as buttons at one point.

Btw I liked the name Skrommel, and it reminded me of this Dutch theme tune I got in an mp3 collection, called Dommel.

I was looking at the screenshots just now, great language: 'Lag snarvei', 'uten navn', 'Rediger', Norwegian apparently! Cheers. Nice to see you back on the forums.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
skrommel
Posts: 17
Joined: 15 Sep 2014, 06:15

Re: Lines - Create scrolling bar charts

18 Jul 2017, 18:33

Barnacle was another surprise creation! :) Using the windows's own menu to create a drawing surface for a toolbar worked quite well, I really should revisit it using GDIP, or maybe try embedding a proper AutoHotkey gui in there. Oh how the years have flown by!
User avatar
tidbit
Posts: 1273
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Lines - Create scrolling bar charts

18 Jul 2017, 20:12

holy crap! skrommel is here!
Welcome back! :o
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Lines - Create scrolling bar charts

18 Jul 2017, 21:00

I'm interested in this idea, so this is what I tried: :P

Code: Select all

line1 := New lines("", 100, 30, 1)
line2 := New lines("x+50", 200, 50, 3, "blue")
Gui, Show, w400

Loop {
	Random, new_value, 1, 100
	line1.add(new_value)

	Random, new_value, 1, 100
	line2.add(new_value)

	Sleep, 100
}
Return

class lines
{
	__New(position, ctrl_width, ctrl_height, line_width := 1, color := "red", range := "0-100")
	{
		this.hwnd := []
		this.val := []

		w := line_width + 2
		Loop, % ctrl_width/(w+1) {
			pos := (A_Index = 1) ? position : "xp+" (line_width+1)
			Gui, Add, Progress, c%color% Vertical w%w% h%ctrl_height% %pos% Range%range% hwndhctrl, 0
			this.hwnd.push(hctrl)
			this.val.push(0)
		}
	}

	add(value)
	{
		this.val.RemoveAt(1)
		this.val.push(value)
		for i, v in this.val {
			GuiControl,, % this.hwnd[i], %v%
		}
	}
}

GuiClose:
ExitApp
skrommel
Posts: 17
Joined: 15 Sep 2014, 06:15

Re: Lines - Create scrolling bar charts

19 Jul 2017, 11:39

That saves a lot of work not moving the data around, tmplinshi! :) Looks like I'll have to revisit the AutoHotkey help file!
shiro_design
Posts: 14
Joined: 21 Apr 2019, 13:57

Re: Lines - Create scrolling bar charts

06 May 2019, 11:01

@skrommel

Is Barnacle still being supported. Its a very useful app.I How do i move this toolbar over to the right? At the moment its ontop of my programs menu. So i cant select anything. If i could move it over to the right by a few pixels that would help a lot. I also want to create some buttons that would allow me to control play and stop controls in different program windows. I want when i press play for examlpe it to click play in one app then switch to the other and press play in that one as well.
shiro_design
Posts: 14
Joined: 21 Apr 2019, 13:57

Re: Lines - Create scrolling bar charts

06 May 2019, 11:05

@skrommel

I'd like to donate if you can support me with this.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 135 guests