Skip to content

Commit

Permalink
Fixed #367 - Custom Series - add support for rectangle and line
Browse files Browse the repository at this point in the history
  • Loading branch information
eselmeister committed Sep 1, 2023
1 parent 7eb8c43 commit ffe34bb
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*******************************************************************************
* Copyright (c) 2023 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.model;

import java.util.Objects;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;

public abstract class AbstractElement implements IElement {

private double x = 0.0d;
private double y = 0.0d;
private Color color = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
private int alpha = 255;

@Override
public double getX() {

return x;
}

@Override
public void setX(double x) {

this.x = x;
}

@Override
public double getY() {

return y;
}

@Override
public void setY(double y) {

this.y = y;
}

@Override
public Color getColor() {

return color;
}

@Override
public void setColor(Color color) {

this.color = color;
}

@Override
public int getAlpha() {

return alpha;
}

@Override
public void setAlpha(int alpha) {

this.alpha = alpha;
}

@Override
public int hashCode() {

return Objects.hash(color, x, y);
}

@Override
public boolean equals(Object obj) {

if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
AbstractElement other = (AbstractElement)obj;
return Objects.equals(color, other.color) && Double.doubleToLongBits(x) == Double.doubleToLongBits(other.x) && Double.doubleToLongBits(y) == Double.doubleToLongBits(other.y);
}

@Override
public String toString() {

return "AbstractElement [x=" + x + ", y=" + y + ", color=" + color + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public void setDraw(boolean draw) {
this.draw = draw;
}

@Override
public void clear() {

textElements.clear();
graphicElements.clear();
}

@Override
public Set<ITextElement> getTextElements() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2023 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.model;

import org.eclipse.swtchart.LineStyle;

public class ElementLine extends AbstractElement implements IGraphicElement {

private double x2 = 0.0d;
private double y2 = 0.0d;
private LineStyle lineStyle = LineStyle.SOLID;
private int lineWidth = 1;

public double getX2() {

return x2;
}

public void setX2(double x2) {

this.x2 = x2;
}

public double getY2() {

return y2;
}

public void setY2(double y2) {

this.y2 = y2;
}

public LineStyle getLineStyle() {

return lineStyle;
}

public void setLineStyle(LineStyle lineStyle) {

this.lineStyle = lineStyle;
}

public int getLineWidth() {

return lineWidth;
}

public void setLineWidth(int lineWidth) {

this.lineWidth = lineWidth;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2023 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.model;

public class ElementRectangle extends AbstractElement implements IGraphicElement {

private double width = 0.0d;
private double height = 0.0d;

public double getWidth() {

return width;
}

public void setWidth(double width) {

this.width = width;
}

public double getHeight() {

return height;
}

public void setHeight(double height) {

this.height = height;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface ICustomSeries {

void setDraw(boolean draw);

void clear();

Set<ITextElement> getTextElements();

Set<IGraphicElement> getGraphicElements();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright (c) 2023 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.model;

import org.eclipse.swt.graphics.Color;

public interface IElement {

double POSITION_TOP_Y = Double.NEGATIVE_INFINITY;
double POSITION_BOTTOM_Y = Double.POSITIVE_INFINITY;
double POSITION_LEFT_X = Double.NEGATIVE_INFINITY;
double POSITION_RIGHT_X = Double.POSITIVE_INFINITY;
double MAX_HEIGHT = Double.POSITIVE_INFINITY;
double MAX_WIDTH = Double.POSITIVE_INFINITY;

double getX();

void setX(double x);

double getY();

void setY(double y);

Color getColor();

void setColor(Color color);

int getAlpha();

void setAlpha(int alpha);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
*******************************************************************************/
package org.eclipse.swtchart.extensions.model;

public interface IGraphicElement {
public interface IGraphicElement extends IElement {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,13 @@
*******************************************************************************/
package org.eclipse.swtchart.extensions.model;

import org.eclipse.swt.graphics.Color;

public interface ITextElement {
public interface ITextElement extends IElement {

String getLabel();

void setLabel(String label);

Color getColor();

void setColor(Color color);


int getRotation();

void setRotation(int rotation);

double getX();

void setX(double x);

double getY();

void setY(double y);
}
Loading

0 comments on commit ffe34bb

Please sign in to comment.