Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Contributors:
* Philip Wenig - initial API and implementation
* Frank Buloup - Internationalization
* Lorenz Gerber - DataPoint Labels
*******************************************************************************/
package org.eclipse.swtchart.extensions.core;

Expand Down Expand Up @@ -394,6 +395,7 @@ public ISeries<?> createSeries(ISeriesData seriesData, ISeriesSettings seriesSet
*/
double[] xSeries = seriesData.getXSeries();
double[] ySeries = seriesData.getYSeries();
String[] labels = seriesData.getLabels();

if(xSeries.length == ySeries.length) {
/*
Expand All @@ -405,6 +407,9 @@ public ISeries<?> createSeries(ISeriesData seriesData, ISeriesSettings seriesSet
ISeries<?> series = seriesSet.createSeries(seriesType, id);
series.setXSeries(xSeries);
series.setYSeries(ySeries);
if(labels != null) {
series.setLabels(labels);
}
calculateCoordinates(series);
return series;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Contributors:
* Philip Wenig - initial API and implementation
* Frank Buloup - Internationalization
* Lorenz Gerber - DataPoint Labels
*******************************************************************************/
package org.eclipse.swtchart.extensions.core;

Expand Down Expand Up @@ -105,6 +106,7 @@ public class ChartSettings implements IChartSettings {
private boolean showAxisZeroMarker = false;
private Color colorAxisZeroMarker;
private boolean showSeriesLabelMarker = false;
private boolean showSeriesDataPointLabelMarker = false;
private Color colorSeriesLabelMarker;

private boolean createMenu = true;
Expand Down Expand Up @@ -609,6 +611,18 @@ public void setShowSeriesLabelMarker(boolean showSeriesLabelMarker) {
this.showSeriesLabelMarker = showSeriesLabelMarker;
}

@Override
public boolean isShowSeriesDataPointLabelMarker() {

return showSeriesDataPointLabelMarker;
}

@Override
public void setShowSeriesDataPointLabelMarker(boolean showSeriesDataPointLabelMarker) {

this.showSeriesDataPointLabelMarker = showSeriesDataPointLabelMarker;
}

@Override
public Color getColorSeriesLabelMarker() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Philip Wenig - initial API and implementation
* Lorenz Gerber - DataPoint Labels
*******************************************************************************/
package org.eclipse.swtchart.extensions.core;

Expand Down Expand Up @@ -179,6 +180,10 @@ public interface IChartSettings {

void setShowSeriesLabelMarker(boolean showSeriesLabelMarker);

boolean isShowSeriesDataPointLabelMarker();

void setShowSeriesDataPointLabelMarker(boolean showSeriesDataPointLabelMarker);

boolean isUseSeriesLabelDescription();

void setUseSeriesLabelDescription(boolean useSeriesLabelDescription);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2019 Lablicate GmbH.
* Copyright (c) 2017, 2025 Lablicate GmbH.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -8,7 +8,8 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Philip Wenig - initial API and implementation
* Lorenz Gerber - add DataPoint labels
*******************************************************************************/
package org.eclipse.swtchart.extensions.core;

Expand All @@ -18,5 +19,7 @@ public interface ISeriesData {

double[] getYSeries();

String[] getLabels();

String getId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Christoph Läubrich - rework redraw of the plot area, enhance menu item handling
* Frank Buloup - Internationalization
* Himanshu Balasamanta - Circular charts
* Lorenz Gerber - DataPoint Labels
*******************************************************************************/
package org.eclipse.swtchart.extensions.core;

Expand Down Expand Up @@ -78,6 +79,7 @@
import org.eclipse.swtchart.extensions.internal.marker.LegendMarker;
import org.eclipse.swtchart.extensions.internal.marker.PlotCenterMarker;
import org.eclipse.swtchart.extensions.internal.marker.PositionMarker;
import org.eclipse.swtchart.extensions.internal.marker.SeriesDataPointLabelMarker;
import org.eclipse.swtchart.extensions.internal.marker.SeriesLabelMarker;
import org.eclipse.swtchart.extensions.internal.marker.UserRestrictionMarker;
import org.eclipse.swtchart.extensions.linecharts.LineChart;
Expand Down Expand Up @@ -124,6 +126,7 @@ public class ScrollableChart extends Composite implements IScrollableChart, IEve
private LegendMarker legendMarker;
private AxisZeroMarker axisZeroMarker;
private SeriesLabelMarker seriesLabelMarker;
private SeriesDataPointLabelMarker seriesDataPointLabelMarker;
private UserRestrictionMarker userRestrictionMarker;
/*
* Integer.MAX_VALUE doesn't work under Windows.
Expand Down Expand Up @@ -814,6 +817,7 @@ private void setCustomPaintListener() {
setLegendMarker();
setAxisZeroMarker();
setSeriesLabelMarker();
setSeriesDataPointLabelMarker();
setUserRestrictionMarker();
}

Expand Down Expand Up @@ -918,6 +922,26 @@ private void setSeriesLabelMarker() {
}
}

private void setSeriesDataPointLabelMarker() {

IPlotArea plotArea = baseChart.getPlotArea();
IChartSettings chartSettings = baseChart.getChartSettings();

if(seriesDataPointLabelMarker != null) {
plotArea.removeCustomPaintListener(seriesDataPointLabelMarker);
}

seriesDataPointLabelMarker = new SeriesDataPointLabelMarker(baseChart);
seriesDataPointLabelMarker.setForegroundColor(chartSettings.getColorSeriesLabelMarker());
plotArea.addCustomPaintListener(seriesDataPointLabelMarker);

if(chartSettings.isShowSeriesDataPointLabelMarker()) {
seriesDataPointLabelMarker.setDraw(true);
} else {
seriesDataPointLabelMarker.setDraw(false);
}
}

private void setUserRestrictionMarker() {

IPlotArea plotArea = baseChart.getPlotArea();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Philip Wenig - initial API and implementation
* Lorenz Gerber - add datapoint labels
*******************************************************************************/
package org.eclipse.swtchart.extensions.core;

public class SeriesData implements ISeriesData {

private double[] xSeries;
private double[] ySeries;
private String[] labels;
private String id;

/**
Expand Down Expand Up @@ -51,6 +53,10 @@ public SeriesData(double[] ySeries, int xStart, String id) {
for(int i = 0; i < ySeries.length; i++) {
xSeries[i] = xStart++;
}

for(int i = 0; i < ySeries.length; i++) {
labels[i] = Integer.toString(xStart++);
}
}

/**
Expand All @@ -71,6 +77,28 @@ public SeriesData(double[] xSeries, double[] ySeries, String id) {
this.id = id;
}

/**
* sets the series
*
* @param xSeries
* @param ySeries
* @param labels
* @param id
*/
public SeriesData(double[] xSeries, double[] ySeries, String[] labels, String id) {

assert (xSeries != null);
assert (ySeries != null);
assert (labels != null);
assert (id != null);

this.xSeries = xSeries;
this.ySeries = ySeries;
this.labels = labels;
this.id = id;

}

@Override
public double[] getXSeries() {

Expand All @@ -83,6 +111,12 @@ public double[] getYSeries() {
return ySeries;
}

@Override
public String[] getLabels() {

return labels;
}

@Override
public String getId() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*******************************************************************************
* Copyright (c) 2025 Lablicate GmbH.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Lorenz Gerber - initial API and implementation
*******************************************************************************/
package org.eclipse.swtchart.extensions.internal.marker;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swtchart.ISeries;
import org.eclipse.swtchart.ISeriesSet;
import org.eclipse.swtchart.extensions.core.BaseChart;
import org.eclipse.swtchart.extensions.core.IPointSeriesSettings;
import org.eclipse.swtchart.extensions.core.ISeriesSettings;
import org.eclipse.swtchart.extensions.marker.AbstractBaseChartPaintListener;
import org.eclipse.swtchart.extensions.marker.IBaseChartPaintListener;

public class SeriesDataPointLabelMarker extends AbstractBaseChartPaintListener implements IBaseChartPaintListener {

public SeriesDataPointLabelMarker(BaseChart baseChart) {

super(baseChart);
}

@Override
public void paintControl(PaintEvent e) {

if(isDraw()) {
if(isDraw()) {
BaseChart baseChart = getBaseChart();
ISeriesSet seriesSet = baseChart.getSeriesSet();
ISeries<?>[] series = seriesSet.getSeries();
for(ISeries<?> serie : series) {
String id = serie.getId();
/*
* get label series here
*/
String[] labels = serie.getLabels();
ISeriesSettings seriesSettings = baseChart.getSeriesSettings(id);
if(seriesSettings.isVisible()) {
/*
* Only draw is series is visible.
*/
int symbolSize = 1;
if(seriesSettings instanceof IPointSeriesSettings) {
symbolSize = ((IPointSeriesSettings)seriesSettings).getSymbolSize();
}
/*
* Draw the label
*/
e.gc.setForeground(getForegroundColor());
for(int i = 0; i < serie.getXSeries().length; i++) {
Point point = serie.getPixelCoordinates(i);
if(labels != null && labels.length != 0) {
Point labelSize = e.gc.textExtent(labels[i]);
e.gc.drawText(labels[i], (int)(point.x - labelSize.x / 2.0d), (int)(point.y - labelSize.y - symbolSize / 2.0d), true);
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Lablicate GmbH.
* Copyright (c) 2023, 2025 Lablicate GmbH.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* Philip Wenig - initial API and implementation
* Lorenz Gerber - DataPoint Labels
*******************************************************************************/
package org.eclipse.swtchart.extensions.piecharts;

Expand Down Expand Up @@ -85,4 +86,10 @@ public void setNodeDataModel(NodeDataModel nodeDataModel) {

this.nodeDataModel = nodeDataModel;
}

@Override
public void setLabels(String[] labels) {
// Not implemented yet

}
}
23 changes: 22 additions & 1 deletion org.eclipse.swtchart/src/org/eclipse/swtchart/ISeries.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2023 SWTChart project.
* Copyright (c) 2008, 2025 SWTChart project.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,6 +12,7 @@
* Christoph Läubrich - add support for datamodel
* Frank Buloup - Internationalization
* Philip Wenig - refactoring type model
* Lorenz Gerber - DataPoint Labels
*******************************************************************************/
package org.eclipse.swtchart;

Expand Down Expand Up @@ -136,6 +137,16 @@ public String label() {
*/
void setYSeries(double[] series);

/**
* This is a legacy/convenient method to create series.
* Sets the Data Point Label series.
* A DoubleArraySeriesModel will be created.
*
* @param labels
* the Data Point series
*/
void setLabels(String[] labels);

@Deprecated
void setXDateSeries(Date[] series);

Expand Down Expand Up @@ -165,6 +176,16 @@ public String label() {
*/
double[] getYSeries();

/**
* This is a legacy/convenient method.
* Gets the Data Point Label series. If the Data Point Label series haven't been set yet, empty array will be
* returned.
* Better use getDataModel() to retrieve the data point labels array.
*
* @return the data point label series
*/
String[] getLabels();

/**
* Set the model for this series
*
Expand Down
Loading