Skip to content

Commit

Permalink
Fixed #228 - CircularLegend uses internal classes of the base package
Browse files Browse the repository at this point in the history
  • Loading branch information
eselmeister committed Sep 9, 2020
1 parent 5108d1e commit d61f136
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swtchart.ISeries.SeriesType;
import org.eclipse.swtchart.extensions.core.ChartSettings;
import org.eclipse.swtchart.extensions.core.CircularLegend;
import org.eclipse.swtchart.extensions.piecharts.CircularSeriesData;
import org.eclipse.swtchart.extensions.piecharts.ICircularSeriesSettings;
import org.eclipse.swtchart.extensions.piecharts.PieChart;
import org.eclipse.swtchart.model.Node;
import org.eclipse.swtchart.support.CircularLegend;

public class ParallelPieCharts {

Expand All @@ -38,10 +38,11 @@ public class ParallelPieCharts {
private int noOfCharts;
private int noOfSlices;
private String[] legendLabels;
private String[] pieTitles;
// private String[] pieTitles; // It's not used yet.
private CircularSeriesData[] dataArray;

public ParallelPieCharts(Composite parent, SeriesType type, boolean redraw) {

composite = parent;
redrawOnClick = redraw;
seriesType = type;
Expand All @@ -56,9 +57,11 @@ public ParallelPieCharts(Composite parent, SeriesType type, boolean redraw) {
* For the first one, 'a' will be 1 and 'b' will be 4. For the second chart 'a'
* will be 2 and 'b' will be 5. For the third 'a' will be 3 and 'b' will be 6.
*
* @param labels The titles of each series. (These are not the same as titles
* given to pies.)
* @param val New values.
* @param labels
* The titles of each series. (These are not the same as titles
* given to pies.)
* @param val
* New values.
*/
public void addPieChartSeries(String labels[], double val[][]) {

Expand All @@ -68,11 +71,11 @@ public void addPieChartSeries(String labels[], double val[][]) {
double[] values = new double[noOfSlices];
dataArray = new CircularSeriesData[noOfCharts];
// create the charts independently
for (int i = 0; i != noOfCharts; i++) {
for(int i = 0; i != noOfCharts; i++) {
dataArray[i] = new CircularSeriesData();
dataArray[i].getSettings().setSeriesType(seriesType);
values = new double[noOfSlices];
for (int j = 0; j != noOfSlices; j++) {
for(int j = 0; j != noOfSlices; j++) {
values[j] = val[j][i];
}
dataArray[i].setSeries(legendLabels, values);
Expand All @@ -83,9 +86,9 @@ public void addPieChartSeries(String labels[], double val[][]) {
setSettings(i);
}
// add them to linked scrollable charts
for (int i = 0; i != noOfCharts; i++) {
for (int j = 0; j != noOfCharts; j++) {
if (i == j)
for(int i = 0; i != noOfCharts; i++) {
for(int j = 0; j != noOfCharts; j++) {
if(i == j)
continue;
linkedPieCharts.get(i).addLinkedScrollableChart(linkedPieCharts.get(j));
}
Expand All @@ -94,20 +97,23 @@ public void addPieChartSeries(String labels[], double val[][]) {

/**
*
* @param parentId the id to which we want to introduce the child to in each
* chart.
* @param childId the child we wish to introduce
* @param vals values of the child in each chart.
* @param parentId
* the id to which we want to introduce the child to in each
* chart.
* @param childId
* the child we wish to introduce
* @param vals
* values of the child in each chart.
*
* Throws error if vals.length is not equal to number of charts.
* Throws error if vals.length is not equal to number of charts.
*/
public void addChild(String parentId, String childId, double[] vals) {

if (vals.length != noOfCharts) {
if(vals.length != noOfCharts) {
// throw error
return;
}
for (int i = 0; i != noOfCharts; i++) {
for(int i = 0; i != noOfCharts; i++) {
Node parent = dataArray[i].getNodeById(parentId);
parent.addChild(childId, vals[i]);
setSettings(i);
Expand All @@ -116,40 +122,45 @@ public void addChild(String parentId, String childId, double[] vals) {

/**
*
* @param parentId the id of node to which we want to add the children in each
* chart.
* @param childrenId the id of the children we wish to add.
* @param vals each array in it should represent the values of the
* corresponding child node (present at the same index) in
* each of the charts.
* @param parentId
* the id of node to which we want to add the children in each
* chart.
* @param childrenId
* the id of the children we wish to add.
* @param vals
* each array in it should represent the values of the
* corresponding child node (present at the same index) in
* each of the charts.
*/
public void addChildren(String parentId, String[] childrenId, double[][] vals) {
if (vals.length != noOfCharts || vals[0].length != childrenId.length) {

if(vals.length != noOfCharts || vals[0].length != childrenId.length) {
// throw error
return;
}
for (int i = 0; i != childrenId.length; i++) {
for(int i = 0; i != childrenId.length; i++) {
addChild(parentId, childrenId[i], vals[i]);
setSettings(i);
}
}

public void setChartTitles(String[] titles) {

this.pieTitles = titles;
// this.pieTitles = titles; // It's not used yet.
int length = Math.min(noOfCharts, titles.length);
for (int i = 0; i != length; i++) {
for(int i = 0; i != length; i++) {
linkedPieCharts.get(i).getChartSettings().setTitle(titles[i]);
PieChart pieChart = linkedPieCharts.get(i);
ChartSettings chartSettings = (ChartSettings) pieChart.getChartSettings();
ChartSettings chartSettings = (ChartSettings)pieChart.getChartSettings();
chartSettings.setTitleColor(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
pieChart.applySettings(chartSettings);
}
}

public void setRedrawOnClick(boolean redrawOnClick) {

this.redrawOnClick = redrawOnClick;
for (int i = 0; i != noOfCharts; i++) {
for(int i = 0; i != noOfCharts; i++) {
setSettings(i);
}
}
Expand All @@ -158,18 +169,19 @@ public void setRedrawOnClick(boolean redrawOnClick) {
* settings for this
*/
private void setSettings(int index) {

// is legend common
PieChart pieChart = linkedPieCharts.get(index);
pieChart.setLayoutData(new GridData(GridData.FILL_BOTH));
if (index == noOfCharts - 1) {
if (legend == null) {
if(index == noOfCharts - 1) {
if(legend == null) {
legend = new CircularLegend(composite, SWT.NONE);
}
legend.setChart(pieChart.getBaseChart());
legend.updateLayoutData();
legend.setVisible(true);
}
ChartSettings chartSettings = (ChartSettings) pieChart.getChartSettings();
ChartSettings chartSettings = (ChartSettings)pieChart.getChartSettings();
chartSettings.setLegendVisible(false);
chartSettings.setTitleColor(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
chartSettings.setLegendExtendedVisible(false);
Expand All @@ -180,7 +192,7 @@ private void setSettings(int index) {
private void setCircularSettings(CircularSeriesData circularSeriesData) {

ICircularSeriesSettings settings = circularSeriesData.getSettings();
if (redrawOnClick) {
if(redrawOnClick) {
settings.setRedrawOnClick(true);
settings.setBorderColor(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
} else {
Expand Down
3 changes: 2 additions & 1 deletion org.eclipse.swtchart/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ Export-Package: org.eclipse.swtchart,
org.eclipse.swtchart.internal.axis;x-friends:="org.eclipse.swtchart.export",
org.eclipse.swtchart.internal.compress,
org.eclipse.swtchart.internal.series,
org.eclipse.swtchart.model
org.eclipse.swtchart.model,
org.eclipse.swtchart.support
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* Himanshu Balasamanta: Orignal API and implementation
*******************************************************************************/
package org.eclipse.swtchart.extensions.core;
package org.eclipse.swtchart.support;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -57,7 +57,7 @@ public class CircularLegend extends Composite implements ILegend, PaintListener
/** the width of area to draw symbol */
private static final int SYMBOL_WIDTH = 20;
/** the line width */
private static final int LINE_WIDTH = 2;
// private static final int LINE_WIDTH = 2; // it's not used yet.
/** the default foreground */
private static final Color DEFAULT_FOREGROUND = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
/** the default background */
Expand Down

2 comments on commit d61f136

@himanshu-balasamanta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh.. Ok

@eselmeister
Copy link
Contributor Author

@eselmeister eselmeister commented on d61f136 Sep 9, 2020 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.