-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #387 - Line Series - Area Strict Option (Experimental)
- Loading branch information
1 parent
abf12ea
commit b8aa92c
Showing
9 changed files
with
813 additions
and
14 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
....extensions.examples/src/org/eclipse/swtchart/extensions/examples/charts/DemoChart1a.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020, 2024 SWTChart project. | ||
* | ||
* 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: | ||
* Yash Bharatiya - initial API and implementation | ||
* Philip Wenig - menu demo extension | ||
*******************************************************************************/ | ||
package org.eclipse.swtchart.extensions.examples.charts; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.graphics.Image; | ||
import org.eclipse.swt.layout.FillLayout; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.swtchart.extensions.core.IChartSettings; | ||
import org.eclipse.swtchart.extensions.core.ISeriesSettings; | ||
import org.eclipse.swtchart.extensions.core.ResourceSupport; | ||
import org.eclipse.swtchart.extensions.core.ScrollableChart; | ||
import org.eclipse.swtchart.extensions.examples.parts.LineSeries_1a_Part; | ||
import org.eclipse.swtchart.extensions.examples.support.SeriesConverter; | ||
import org.eclipse.swtchart.extensions.linecharts.ILineSeriesSettings; | ||
import org.eclipse.swtchart.extensions.menu.IChartMenuEntry; | ||
|
||
public class DemoChart1a { | ||
|
||
private static final String CATEGORY = "Settings"; | ||
|
||
public static void main(String args[]) { | ||
|
||
Display display = new Display(); | ||
Shell shell = new Shell(display); | ||
shell.setText("Area Strict Example (Experimental)"); | ||
shell.setSize(500, 400); | ||
shell.setLayout(new FillLayout()); | ||
// | ||
ScrollableChart scrollableChart = new LineSeries_1a_Part(shell); | ||
scrollableChart.setLayoutData(new GridData(GridData.FILL_BOTH)); | ||
// | ||
shell.open(); | ||
/* | ||
* Demo Chart Background (experimental) | ||
*/ | ||
IChartSettings chartSettings = scrollableChart.getChartSettings(); | ||
chartSettings.setTitle(""); | ||
chartSettings.setTitleVisible(false); | ||
chartSettings.setTitleColor(display.getSystemColor(SWT.COLOR_BLACK)); | ||
chartSettings.setLegendExtendedVisible(false); | ||
chartSettings.setBufferSelection(true); | ||
chartSettings.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); | ||
chartSettings.setBackgroundChart(display.getSystemColor(SWT.COLOR_WHITE)); | ||
chartSettings.setBackgroundPlotArea(display.getSystemColor(SWT.COLOR_WHITE)); | ||
addOrientationOption(chartSettings); | ||
addAreaStrictOption(chartSettings); | ||
scrollableChart.applySettings(chartSettings); | ||
// | ||
while(!shell.isDisposed()) { | ||
if(!display.readAndDispatch()) { | ||
display.sleep(); | ||
} | ||
} | ||
display.dispose(); | ||
} | ||
|
||
private static void addOrientationOption(IChartSettings chartSettings) { | ||
|
||
chartSettings.addMenuEntry(new IChartMenuEntry() { | ||
|
||
@Override | ||
public String getName() { | ||
|
||
return "Orientation (Toggle)"; | ||
} | ||
|
||
@Override | ||
public String getCategory() { | ||
|
||
return CATEGORY; | ||
} | ||
|
||
@Override | ||
public Image getIcon() { | ||
|
||
return ResourceSupport.getImage(ResourceSupport.ICON_FIGURE); | ||
} | ||
|
||
@Override | ||
public void execute(Shell shell, ScrollableChart scrollableChart) { | ||
|
||
IChartSettings chartSettings = scrollableChart.getChartSettings(); | ||
int selection = chartSettings.getOrientation() == SWT.HORIZONTAL ? SWT.VERTICAL : SWT.HORIZONTAL; | ||
chartSettings.setOrientation(selection); | ||
scrollableChart.applySettings(chartSettings); | ||
} | ||
}); | ||
} | ||
|
||
private static void addAreaStrictOption(IChartSettings chartSettings) { | ||
|
||
chartSettings.addMenuEntry(new IChartMenuEntry() { | ||
|
||
@Override | ||
public String getName() { | ||
|
||
return "Area Strict (Toggle)"; | ||
} | ||
|
||
@Override | ||
public String getCategory() { | ||
|
||
return CATEGORY; | ||
} | ||
|
||
@Override | ||
public Image getIcon() { | ||
|
||
return ResourceSupport.getImage(ResourceSupport.ICON_FIGURE); | ||
} | ||
|
||
@Override | ||
public void execute(Shell shell, ScrollableChart scrollableChart) { | ||
|
||
ISeriesSettings seriesSettings = scrollableChart.getBaseChart().getSeriesSettings(SeriesConverter.LINE_SERIES_1_SELECTED_PEAK_1); | ||
if(seriesSettings instanceof ILineSeriesSettings lineSeriesSettings) { | ||
lineSeriesSettings.setAreaStrict(!lineSeriesSettings.isAreaStrict()); | ||
} | ||
scrollableChart.getBaseChart().applySeriesSettings(); | ||
} | ||
}); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...sions.examples/src/org/eclipse/swtchart/extensions/examples/parts/LineSeries_1a_Part.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017, 2024 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: | ||
* Philip Wenig - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.swtchart.extensions.examples.parts; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swtchart.ILineSeries.PlotSymbolType; | ||
import org.eclipse.swtchart.customcharts.core.ChromatogramChart; | ||
import org.eclipse.swtchart.extensions.core.IChartSettings; | ||
import org.eclipse.swtchart.extensions.core.ISeriesData; | ||
import org.eclipse.swtchart.extensions.examples.support.SeriesConverter; | ||
import org.eclipse.swtchart.extensions.linecharts.ILineSeriesData; | ||
import org.eclipse.swtchart.extensions.linecharts.ILineSeriesSettings; | ||
import org.eclipse.swtchart.extensions.linecharts.LineSeriesData; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
public class LineSeries_1a_Part extends ChromatogramChart { | ||
|
||
@Inject | ||
public LineSeries_1a_Part(Composite parent) { | ||
|
||
super(parent, SWT.NONE); | ||
// | ||
try { | ||
initialize(); | ||
} catch(Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void initialize() throws Exception { | ||
|
||
/* | ||
* Chart Settings | ||
*/ | ||
IChartSettings chartSettings = getChartSettings(); | ||
chartSettings.setOrientation(SWT.HORIZONTAL); | ||
chartSettings.setCreateMenu(true); | ||
chartSettings.getRangeRestriction().setForceZeroMinY(true); | ||
applySettings(chartSettings); | ||
/* | ||
* Create series. | ||
*/ | ||
List<ILineSeriesData> lineSeriesDataList = new ArrayList<>(); | ||
// | ||
ISeriesData seriesData; | ||
ILineSeriesData lineSeriesData; | ||
ILineSeriesSettings lineSeriesSettings; | ||
ILineSeriesSettings lineSeriesSettingsHighlight; | ||
/* | ||
* Chromatogram [0] | ||
*/ | ||
seriesData = SeriesConverter.getSeriesXY(SeriesConverter.LINE_SERIES_1A); | ||
lineSeriesData = new LineSeriesData(seriesData); | ||
lineSeriesSettings = lineSeriesData.getSettings(); | ||
lineSeriesSettings.setEnableArea(true); | ||
lineSeriesSettingsHighlight = (ILineSeriesSettings)lineSeriesSettings.getSeriesSettingsHighlight(); | ||
lineSeriesSettingsHighlight.setLineWidth(2); | ||
lineSeriesDataList.add(lineSeriesData); | ||
/* | ||
* Peak 1 | ||
*/ | ||
seriesData = SeriesConverter.getSeriesXY(SeriesConverter.LINE_SERIES_1_SELECTED_PEAK_1); | ||
lineSeriesData = new LineSeriesData(seriesData); | ||
lineSeriesSettings = lineSeriesData.getSettings(); | ||
lineSeriesSettings.setEnableArea(true); | ||
lineSeriesSettings.setAreaStrict(true); | ||
lineSeriesSettings.setSymbolType(PlotSymbolType.CIRCLE); | ||
lineSeriesSettings.setSymbolColor(getDisplay().getSystemColor(SWT.COLOR_DARK_RED)); | ||
lineSeriesSettings.setSymbolSize(2); | ||
lineSeriesSettings.setLineColor(getDisplay().getSystemColor(SWT.COLOR_DARK_RED)); | ||
lineSeriesSettingsHighlight = (ILineSeriesSettings)lineSeriesSettings.getSeriesSettingsHighlight(); | ||
lineSeriesSettingsHighlight.setLineWidth(2); | ||
lineSeriesDataList.add(lineSeriesData); | ||
/* | ||
* Set series. | ||
*/ | ||
addSeriesData(lineSeriesDataList); | ||
} | ||
} |
Oops, something went wrong.