Jump to content
  • Synchronizing Zoom Sliders Across Visuals in Spotfire


    Use IronPython to synchronize zoom sliders across visualizations

    When working with multiple visualizations in Spotfire, ensuring consistency in the zoom range can be crucial for a comprehensive analysis. However, Spotfire doesn't inherently provide a direct mechanism to sync zoom sliders between different visuals. In this article, we'll explore a solution that involves HTML, JavaScript, and Python scripts to achieve synchronized zoom sliders.

    rtasImage.gif

    HTML Structure

    The HTML structure involves the usage of Spotfire controls and a hidden div to hold the active visual's title.

    <div style="position:fixed;left:-1000px" id="activeVisual">    
      <SpotfireControl id="input button" />
    </div> <br> <span id="syncBtn">    
      <SpotfireControl id="replace with button to run sync.py" />
    </span>
    <SpotfireControl id="optional reset button that runs reset.py" />
     

    JavaScript

    A JavaScript function (getActiveVisual) is triggered on mouseover of the synchronization button. This function fetches the title of the active visual and updates an input control in a hidden div.

     

    function getActiveVisual() {
      vis = document.querySelector(".sfpc-active .sf-element-visual-title").innerText.trim();
      inp = document.querySelector("#activeVisual input");
      inp.value = vis;
      inp.focus();
      inp.blur();
    }
    document.getElementById("syncBtn").onmouseover = getActiveVisual;
     

    Python Scripts

    Two Python scripts (sync.ip and reset.ip) handle the synchronization and reset of zoom sliders, respectively. These scripts utilize Spotfire's API to interact with visuals.

    sync.py

    from Spotfire.Dxp.Application.Visuals import AxisRange, ScatterPlot
    
    # Detect which visual is "active"
    sourceVisualTitle = Document.Properties["activeVisualTitle"]
    
    visX = None
    
    # Iterate through all visuals on the active page
    for visual in Document.ActivePageReference.Visuals:
        if visual.Title == sourceVisualTitle:
            visX = visual
    
    # Cast visual script parameters to ScatterPlot object
    scatterX = visX.As[ScatterPlot]()
    scatterA = visA.As[ScatterPlot]()
    scatterB = visB.As[ScatterPlot]()
    scatterC = visC.As[ScatterPlot]()
    
    # Create a reference to the Y axis ZoomRange from the first visual (A)
    zoomXy = scatterX.YAxis.ZoomRange
    
    # Create an AxisRange object based on visual X range settings for Y axis
    axisRangeX = AxisRange(zoomXy.Low, zoomXy.High)
    
    # Apply scatterA, B, and C to the selected axisRange
    scatterA.YAxis.ZoomRange = axisRangeX
    scatterB.YAxis.ZoomRange = axisRangeX
    scatterC.YAxis.ZoomRange = axisRangeX
     

    reset.py

    from Spotfire.Dxp.Application.Visuals import AxisRange, ScatterPlot
    
    # Cast visual parameters to ScatterPlot object
    scatterA = visA.As[ScatterPlot]()
    scatterB = visB.As[ScatterPlot]()
    scatterC = visC.As[ScatterPlot]()
    
    # Reset scatterA, B, and C ranges
    scatterA.YAxis.ZoomRange = AxisRange.DefaultRange
    scatterB.YAxis.ZoomRange = AxisRange.DefaultRange
    scatterC.YAxis.ZoomRange = AxisRange.DefaultRange
     

     

    By combining these HTML, JavaScript, and Python elements, you can create a seamless experience for synchronizing zoom sliders across different visuals in Spotfire, enhancing your data exploration and analysis capabilities.

    Sync_Zoom_Sliders.dxp

    • Like 1

    User Feedback

    Recommended Comments


×
×
  • Create New...