CalculationFinished Event

What is the CalculationFinished event?

The CalculationFinished event is a custom browser event that gets automatically dispatched when a calculation process completes. This event allows you to programmatically detect when calculations are done and access the results.

When is this event triggered?

The event is fired immediately after any calculation finishes processing.

How do I listen for this event?

You can listen for the CalculationFinished event using a standard event listener:

window.addEventListener('CalculationFinished', (event) => {
  const result = event.detail;
  console.log('Calculation completed:', result);
  
  // Your custom logic here
  handleCalculationResult(result);
});

What data does the event contain?

The calculation results are available in the event.detail property.

[
    {
        "unit": {
            "svg": "<svg image>",
            "svgM": null,
            "zero": {
                "left": 457.015,
                "bottom": 563.5
            },
            "imageSize": {
                "width": 891,
                "height": 891
            },
            "name": "5m x 5m",
            "id": "<unit-id>",
            "unitDetails": {
                "id": "<unit-id>",
                "name": "5m x 5m",
                "unit": {
                    "ID": "unit-id",
                    "unitName": "5m x 5m",
                    "unitWidth": "5",
                    "unitHeight": "2.4",
                    "unitDepth": "5"
                },
                "dimensions": {
                    "width": 500,
                    "depth": 500,
                    "height": 240
                }
            }
        },
        "items": [
            {
                "id": "bbq",
                "x": -88.248457,
                "y": -80.79013988439307,
                "orientation": "turned",
                "scale": false,
                "width": 49.5,
                "volume": 0.50642262,
                "quantity": 1,
                "image": null
            }
        ],
        "totalItemsWeight": 908.4,
        "totalVolume": 15.765080274,
        "animationDone": true
    }
]

Best Practices

  • Always add the event listener before initiating calculations to ensure you don't miss the event.

  • Remove event listeners when they're no longer needed to prevent memory leaks.

Browser Compatibility

This feature uses the standard CustomEvent API, which is supported in all modern browsers. For older browser support, you may need a polyfill.

Last updated

Was this helpful?