How To: "Cycling" Charts

Posted on
Tue Jan 05, 2021 11:39 am
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

How To: "Cycling" Charts

What do I mean by cycling? I mean being able to replace one chart image with another chart image in "real time". This method works really well, but in order to implement it, you'll likely have to do a bit of refactoring if you're already using the plugin. It just might be worth it...

  1. Disable all your chart devices (not required, but this will keep log messages to a minimum.)
  2. Make the location of where your images are saved in the main plugin preferences to reflect your version of Indigo:
    Code: Select all
    /Library/Application Support/Perceptive Automation/Indigo 7.5/IndigoWebServer/images/controls/
  3. Change the figure save names of your existing charts to account for the new path. For example, if your save path was (like mine) saving images to the .../static/ images folder, change the save name of your exiting chart(s) from 'save_name.png' to '/static/save_name.png'. Of course, use your image names in place of 'save_name'.
  4. Repeat this process for all your chart devices.
  5. Re-enable your chart devices.
That's all the refactoring that's required. This change now allows you to choose to save your images to the devices, static, or variables folder on a case by case basis.

Now on to the "replaceable" image bit. For the purposes of this example, we'll start fresh, but you could refactor existing images to do the same thing. Say you have two items with similar charts that you want to display on one control page and cycle through them rather than displaying them individually--for example, a weather chart at home and at the lake house.

  1. Create your first chart as desired, and make the figure save name to be something like my_chart+.png. Make sure to include the '+'. That's important.
  2. Create a duplicate of your first chart, change the save name to follow the same scheme--in this case, my_chart+1.png and change the source to your second source.
  3. Repeat this process for the remaining charts. Since we only have two, we're done.
  4. Create an Indigo variable called image_switcher (or whatever), and set its value to zero.
  5. On your control page, add a new control page item linked to the image_switcher variable, select the "as image" option and select my_chart+.png. You are actually displaying the variable on the control page, but you're displaying its value as an image.
  6. Still with the same image selected, select 'Server Actions', 'Script and File Actions', 'Execute Script'.
  7. In the embedded script window, add the following Python Code (you'll need to adjust it to reflect the number of charts you're cycling through):
    Code: Select all
    val = int(indigo.variables['image_switcher'].value)

    if val == 1:
        val = 0
    else:
        val +=1

    indigo.variable.updateValue('image_switcher', str(val))
That's it. Once your chart images are built, you'll be able to cycle through them by simply tapping (or clicking) on the image in the browser, Indigo Touch, Domotics Pad, etc.

You may not have to take all of these steps depending on how your installation was configured. Also, for the curious, there are variations that you can use--like using button images to cycle the charts (to provide a visual cue that the image can be cycled), or use a timer to change the 'image_switcher' variable every few seconds and skip the embedded code all together. There may be a slight delay when changing the image_switcher value externally, but the tap method works instantly.

Note: you may get a warning message when you restart the plugin that your image save path may not match the current Indigo version. If your images are appearing where you want them to, you can ignore this warning.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Jan 06, 2021 8:16 am
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: How To: "Cycling" Charts

Short video showing this technique in action.

https://youtu.be/IdRo7IqNQTE

The video is a little overly zoomed in, but I'm too lazy to redo it.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests