use of org.eclipse.tracecompass.internal.tmf.chart.ui.format.LabelFormat 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();
}
use of org.eclipse.tracecompass.internal.tmf.chart.ui.format.LabelFormat in project tracecompass by tracecompass.
the class SwtScatterChart method configureAxes.
@Override
protected void configureAxes() {
/* Format X axes */
Stream.of(getChart().getAxisSet().getXAxes()).forEach(a -> {
IAxisTick tick = checkNotNull(a.getTick());
Format format;
/* Give a continuous formatter if the descriptors are numericals */
if (getXDescriptorsInfo().areNumerical()) {
format = getContinuousAxisFormatter(fXRanges, getXDescriptorsInfo());
} else {
fVisibleXMap = HashBiMap.create(fXStringMap);
format = new LabelFormat(fVisibleXMap);
updateTickMark(fVisibleXMap, tick, getChart().getPlotArea().getSize().x);
}
tick.setFormat(format);
});
/* Format Y axes */
Stream.of(getChart().getAxisSet().getYAxes()).forEach(a -> {
IAxisTick tick = checkNotNull(a.getTick());
Format format;
/* Give a continuous formatter if the descriptors are numericals. */
if (getYDescriptorsInfo().areNumerical()) {
format = getContinuousAxisFormatter(fYRanges, getYDescriptorsInfo());
} else {
fVisibleYMap = HashBiMap.create(fYStringMap);
format = new LabelFormat(fVisibleYMap);
updateTickMark(fVisibleYMap, tick, getChart().getPlotArea().getSize().y);
}
tick.setFormat(format);
});
}
Aggregations