Linear Scale Indicator Label Position

I'm using a Linear Scale in Vision to put a marker on a progress bar. Unfortunately I'm very limited for space so the standard (black) location of the "123" label won't fit. What's the easiest way to get something with labels on the side (red)? Is there a way modify the linear scale or do I have to create something from scratch?

image

What kind of data does the progress bar and marker represent?

progress bar = position
marker(s) = setpoints

1 Like

A paintable canvas could paint the indicators and labels any way you want.

Example:
The left side of the canvas is aligned with the progress bar.
image

Add a custom dataset property to the canvas to store the setpoints
image

Add columns to the custom dataset property for the setpoint value and the indicator color:

Paint the indicators and labels using the canvas's repaint event handler:

from java.awt.geom import GeneralPath
graphics = event.graphics

# A custom property on the paintable canvas
setPoints = event.source.setPoints
progressBar = event.source.parent.getComponent('Progress Bar')

# The total number of integers the progress bar represents
barMin = progressBar.minimum
barMax = progressBar.maximum
barRange = barMax - barMin

# The y coordinate of the progress bar if it were inside the canvas
relativeY = progressBar.y - event.source.y

# How far above the progress bar the indicator will be placed(in pixels)
indicatorGap = 5

# How far from the indicator to place the wedge
labelGap = 10

# The width and height of the indicator
indicatorDiameter = 10

# Don't divide by zero
if barRange != 0:
	# Calculate how the ratio of pixels to increments
	pixelIncrements = float(progressBar.width) / float(barRange)
else:
	pixelIncrements = 0

# Iterate through all of the setpoints and paint the indicators
for row in xrange(setPoints.rowCount):
	
	# Calculate where to place the wedge
	setPoint = setPoints.getValueAt(row, 'Value')
	offset = setPoint - barMin # How far from the left edge is the setpoint
	locationX = int(offset * pixelIncrements) # Convert to pixels
	locationY = relativeY - indicatorGap
	
	# Define and paint the wedge
	wedge = GeneralPath()
	wedge.moveTo(locationX, locationY)
	wedge.lineTo(locationX - (indicatorDiameter / 2), locationY - indicatorDiameter)
	wedge.lineTo(locationX + (indicatorDiameter / 2), locationY - indicatorDiameter)
	wedge.lineTo(locationX, locationY)
	graphics.setColor(system.gui.color(setPoints.getValueAt(row, 'Color')))
	graphics.fill(wedge)
	
	# Draw the label
	graphics.drawString(unicode(setPoint), locationX + labelGap, locationY)

Result:
image

2 Likes

That's perfect, much appreciated!

1 Like