from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil

# Which trace parm is this for?
#trace_parm = "trace_0_visible"
trace_parm = PVUtil.getString(pvs[1])

# Locate graph widget in the display based on name
graph_widget = widget.getDisplayModel().runtimeChildren().getChildByName(
    "time-history")

if PVUtil.getLong(pvs[0]) == 1:
    state = True
else:
    state = False

graph_widget.setPropertyValue(trace_parm, state)
from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil

sizex = PVUtil.getLong(pvs[1])
sizey = PVUtil.getLong(pvs[2])
minx = PVUtil.getLong(pvs[3])
miny = PVUtil.getLong(pvs[4])

widget.setPropertyValue("x_axis.maximum", sizex + minx)
widget.setPropertyValue("x_axis.minimum", minx)
widget.setPropertyValue("data_width", sizex)

widget.setPropertyValue("y_axis.maximum", miny)
widget.setPropertyValue("y_axis.minimum", sizey + miny)
widget.setPropertyValue("data_height", sizey)
from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil

sizex = PVUtil.getLong(pvs[1])
sizey = PVUtil.getLong(pvs[2])

max_widget_height = 337
max_widget_width = 450

aspect_ratio = 1.0 * sizex / sizey

if aspect_ratio > 1 and (max_widget_width / aspect_ratio <= max_widget_height):
    widget.setPropertyValue("height", max_widget_width / aspect_ratio)
    widget.setPropertyValue("width", max_widget_width)
elif aspect_ratio > 1 and (max_widget_width / aspect_ratio >
                           max_widget_height):
    widget.setPropertyValue("height", max_widget_height)
    widget.setPropertyValue("width", max_widget_height * aspect_ratio)
elif aspect_ratio < 1:
    widget.setPropertyValue("width", max_widget_height * aspect_ratio)
    widget.setPropertyValue("height", max_widget_height)
else:
    widget.setPropertyValue("height", max_widget_height)
    widget.setPropertyValue("width", max_widget_height)