Optimization of “pens” deactivation in Easy Chart

Hi all,

I am working with an Easy Chart in Ignition and I need to disable (change to False) the “enabled” column of the pens only in the rows between index 76 and 87 when the component is hidden (hidden=True). I tried several approaches, but they all result in excessive memory consumption or the application crashes.

Here are the steps I want to accomplish:

  • Detect when the hidden property of the parent component changes to True.
  • Disable the enabled column in the rows between index 76 and 87.
  • Keep the rest of the dataset unchanged and avoid traversing the entire dataset to optimize performance.

Property Change on EasyChart Component:

	# Get the value of the 'hidden' property from the parent component
hidden = event.source.parent.hidden

# Check if hidden is True
if hidden:
    # Get the dataset of pens from the Easy Chart
    pens = event.source.pens
    
    # Modify only the rows between 76 and 87 directly in column 7 ('enabled')
    for rowIndex in range(76, 88):  # Only rows 76 to 87
        # Check if the value of column 7 ('enabled') is True
        if pens.getValueAt(rowIndex, 7):  # Assuming that column 7 is 'enabled'
            # Disable the pen in column 7 (set to False)
            pens = system.dataset.setValue(pens, rowIndex, 7, False)
    
    # Assign the updated 'pens' dataset to the Easy Chart
    event.source.pens = pens

I welcome any suggestions to improve performance and prevent the application from becoming unresponsive.

thanks!

Is that your entire script? You're not filtering by property name if so, which would lead to an infinite loop as the change event fires a property change, causing the script to fire again, etc.

2 Likes

Thanks for your observation, I am not filtering by property name in the script. That makes a lot of sense because I am updating the pens in the script itself, which is probably causing the event to fire again in an infinite loop.

I'm going to adjust the script to specifically filter by changes in the hidden property of the parent component and make sure the script only runs when that property changes, avoiding the infinite loop.

# Ensure the script only runs when the 'hidden' property changes
if event.propertyName == "hidden":
    hidden = event.source.parent.hidden

    if hidden:
        pens = event.source.pens
        # Modify only the rows between 76 and 87 directly in column 7 ('enabled')
        for rowIndex in range(76, 88):  # Only rows 76 to 87
            if pens.getValueAt(rowIndex, 7):  # Check if the pen in column 7 is enabled
                pens = system.dataset.setValue(pens, rowIndex, 7, False)  # Disable the pen

        # Assign the updated 'pens' dataset to the Easy Chart
        event.source.pens = pens

I would write it like this:

# If the property name is hidden and the new value is true...
# Ran from the parent container's propertyChange event handler
if event.propertyName == "hidden" and event.newValue:
	pens = event.source.getComponent('Easy Chart').pens
	# [...]
2 Likes

ok I had made a mistake and I was making the property change on the Easy chart itself when I should have done it on the root Container which is where the custom hidden is, that's why it didn't work.

thanks for your recommendations,

1 Like