use of org.eclipse.swtchart.IAxisTick in project netxms by netxms.
the class LineChart method setTimeRange.
/**
* Set time range
*
* @param from start time
* @param to end time
*/
public void setTimeRange(final Date from, final Date to) {
if (zoomedToSelectionX) {
delayedRangeFrom = from;
delayedRangeTo = to;
return;
}
delayedRangeFrom = null;
delayedRangeTo = null;
timeFrom = from.getTime();
timeTo = to.getTime();
getAxisSet().getXAxis(0).setRange(new Range(timeFrom, timeTo));
int seconds = (int) ((timeTo - timeFrom) / 1000);
DateFormat format;
int angle;
if (seconds <= 600) {
format = DateFormatFactory.getTimeFormat();
angle = 0;
} else if (seconds <= 86400) {
format = DateFormatFactory.getShortTimeFormat();
angle = 0;
} else if (seconds <= 86400 * 7) {
format = new SimpleDateFormat("E " + DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT));
angle = 0;
} else {
format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
angle = 45;
}
IAxisTick xTick = getAxisSet().getXAxis(0).getTick();
xTick.setFormat(format);
xTick.setTickLabelAngle(angle);
}
use of org.eclipse.swtchart.IAxisTick in project swtchart by eclipse.
the class ScrollableChart method setAxisSettings.
private void setAxisSettings(IAxis axis, IAxisSettings axisSettings) {
if (axis != null && axisSettings != null) {
//
String axisText = axisSettings.getTitle();
ITitle title = axis.getTitle();
title.setText(axisText);
title.setVisible(axisSettings.isVisible());
//
IAxisTick axisTick = axis.getTick();
axisTick.setFormat(axisSettings.getDecimalFormat());
axisTick.setVisible(axisSettings.isVisible());
//
IGrid grid = axis.getGrid();
grid.setForeground(axisSettings.getGridColor());
grid.setStyle(axisSettings.getGridLineStyle());
//
axis.setPosition(axisSettings.getPosition());
/*
* Set the color on demand.
*/
Color color = axisSettings.getColor();
if (color != null) {
title.setForeground(color);
axisTick.setForeground(color);
}
/*
* Add a space between the scale and the label.
*/
Font font = title.getFont();
int length = axisText.length() - 1;
StyleRange styleRange = new StyleRange();
styleRange.length = (length > 0) ? length : 0;
styleRange.background = baseChart.getBackground();
styleRange.foreground = (color != null) ? color : baseChart.getForeground();
styleRange.font = font;
styleRange.rise = getAxisExtraSpaceTitle(axis, axisSettings);
title.setStyleRanges(new StyleRange[] { styleRange });
//
axis.enableLogScale(axisSettings.isEnableLogScale());
/*
* Apply primary axis specific settings.
*/
if (axisSettings instanceof IPrimaryAxisSettings) {
IPrimaryAxisSettings primaryAxisSettings = (IPrimaryAxisSettings) axisSettings;
axis.enableLogScale(primaryAxisSettings.isEnableLogScale());
/*
* Category is only valid for the X-Axis.
*/
if (axis.getDirection() == Direction.X) {
axis.enableCategory(primaryAxisSettings.isEnableCategory());
axis.setCategorySeries(primaryAxisSettings.getCategorySeries());
}
}
}
}
use of org.eclipse.swtchart.IAxisTick in project tracecompass by tracecompass.
the class SwtBarChart method configureAxes.
@Override
protected void configureAxes() {
/* Format X axes */
Stream.of(getChart().getAxisSet().getXAxes()).forEach(a -> {
a.enableCategory(true);
a.setCategorySeries(fCategories);
});
/* Format Y axes */
Stream.of(getChart().getAxisSet().getYAxes()).forEach(a -> {
IAxisTick tick = a.getTick();
tick.setFormat(getContinuousAxisFormatter(fYRanges, getYDescriptorsInfo()));
});
}
use of org.eclipse.swtchart.IAxisTick 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.swtchart.IAxisTick 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