use of org.eclipse.swtchart.IAxisSet in project swtchart by eclipse.
the class AbstractExtendedChart method adjustSecondaryYAxes.
@Override
public void adjustSecondaryYAxes() {
IAxisSet axisSet = getAxisSet();
IAxis yAxis = axisSet.getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
Range range = yAxis.getRange();
for (int id : axisSet.getYAxisIds()) {
if (id != BaseChart.ID_PRIMARY_Y_AXIS) {
IAxis axis = axisSet.getYAxis(id);
IAxisSettings axisSettings = yAxisSettingsMap.get(id);
if (axis != null && axisSettings instanceof ISecondaryAxisSettings) {
IAxisScaleConverter axisScaleConverter = ((ISecondaryAxisSettings) axisSettings).getAxisScaleConverter();
axisScaleConverter.setChartDataCoordinates(this);
double start = axisScaleConverter.convertToSecondaryUnit(range.lower);
double end = axisScaleConverter.convertToSecondaryUnit(range.upper);
if (end > start) {
Range adjustedRange = new Range(start, end);
axis.setRange(adjustedRange);
} else {
System.out.println("Can't set secondary y axes range: " + start + "\t" + end);
}
}
}
}
}
use of org.eclipse.swtchart.IAxisSet in project tracecompass by tracecompass.
the class SwtScatterChart method refreshDisplayLabels.
@Override
protected void refreshDisplayLabels() {
/**
* TODO: support for the Y axis too
*/
/* Only refresh if labels are visible */
Chart chart = getChart();
IAxisSet axisSet = chart.getAxisSet();
IAxis xAxis = axisSet.getXAxis(0);
if (!xAxis.getTick().isVisible()) {
return;
}
/*
* Shorten all the labels to 5 characters plus "…" when the longest
* label length is more than 50% of the chart height.
*/
Rectangle rect = chart.getClientArea();
int lengthLimit = (int) (rect.height * 0.40);
GC gc = new GC(getParent());
gc.setFont(xAxis.getTick().getFont());
// labels.
if (!fXStringMap.isEmpty()) {
/* Find the longest category string */
String longestString = Collections.max(fXStringMap.keySet(), Comparator.comparingInt(String::length));
/* Get the length and height of the longest label in pixels */
Point pixels = gc.stringExtent(longestString);
/* Completely arbitrary */
int cutLen = 5;
if (pixels.x > lengthLimit) {
/* We have to cut down some strings */
for (Entry<String, Integer> entry : fXStringMap.entrySet()) {
String reference = checkNotNull(entry.getKey());
if (reference.length() > cutLen) {
String key = reference.substring(0, cutLen) + ELLIPSIS;
fVisibleXMap.remove(reference);
fVisibleXMap.put(key, entry.getValue());
} else {
fVisibleXMap.inverse().remove(entry.getValue());
fVisibleXMap.put(reference, entry.getValue());
}
}
} else {
/* All strings should fit */
resetBiMap(fXStringMap, fVisibleXMap);
}
for (IAxis axis : axisSet.getXAxes()) {
IAxisTick tick = axis.getTick();
tick.setFormat(new LabelFormat(fVisibleXMap));
}
}
/* Cleanup */
gc.dispose();
}
Aggregations