Skip to content
Snippets Groups Projects
Commit c80af774 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Axis working.

refs 2589
parent be4be9f4
Branches
Tags
No related merge requests found
...@@ -551,7 +551,7 @@ public final class SpiderChartOld { ...@@ -551,7 +551,7 @@ public final class SpiderChartOld {
if(plotter != null) { if(plotter != null) {
plotter.plotBackground(graphics); plotter.plotBackground(graphics);
plotter.plotAxes(graphics); plotter.drawAxes(graphics);
plotter.plot(graphics); plotter.plot(graphics);
// FIXME: break out // FIXME: break out
// return; // return;
......
...@@ -17,8 +17,6 @@ $Id$ ...@@ -17,8 +17,6 @@ $Id$
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.spiderchart.example; package org.fortiss.tooling.spiderchart.example;
import static org.fortiss.tooling.spiderchart.style.LineStyle.SOLID_BLACK_1PT;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
...@@ -29,6 +27,7 @@ import org.fortiss.tooling.spiderchart.model.SpiderChart; ...@@ -29,6 +27,7 @@ import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartLegend; import org.fortiss.tooling.spiderchart.plotter.SpiderChartLegend;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartPlotter; import org.fortiss.tooling.spiderchart.plotter.SpiderChartPlotter;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartTitle; import org.fortiss.tooling.spiderchart.plotter.SpiderChartTitle;
import org.fortiss.tooling.spiderchart.style.AxisStyle;
import org.fortiss.tooling.spiderchart.swt.SpiderChartViewer; import org.fortiss.tooling.spiderchart.swt.SpiderChartViewer;
/** /**
...@@ -85,12 +84,12 @@ public final class Sample { ...@@ -85,12 +84,12 @@ public final class Sample {
legend.setSwtForegroundColor(SWT.COLOR_BLUE); legend.setSwtForegroundColor(SWT.COLOR_BLUE);
SpiderChartPlotter plotter = new SpiderChartPlotter(spiderChart); SpiderChartPlotter plotter = new SpiderChartPlotter(spiderChart);
plotter.setAxisStyle(battery, SOLID_BLACK_1PT); plotter.setAxisStyle(battery, AxisStyle.DEFAULT);
plotter.setAxisStyle(camera, SOLID_BLACK_1PT); plotter.setAxisStyle(camera, AxisStyle.DEFAULT);
plotter.setAxisStyle(display, SOLID_BLACK_1PT); plotter.setAxisStyle(display, AxisStyle.DEFAULT);
plotter.setAxisStyle(memory, SOLID_BLACK_1PT); plotter.setAxisStyle(memory, AxisStyle.DEFAULT);
plotter.setAxisStyle(brand, SOLID_BLACK_1PT); plotter.setAxisStyle(brand, AxisStyle.DEFAULT);
plotter.setAxisStyle(screen, SOLID_BLACK_1PT); plotter.setAxisStyle(screen, AxisStyle.DEFAULT);
SpiderChartBuilder scBuilder = new SpiderChartBuilder(title, legend, plotter); SpiderChartBuilder scBuilder = new SpiderChartBuilder(title, legend, plotter);
viewer = scBuilder.createViewer(shell); viewer = scBuilder.createViewer(shell);
......
...@@ -163,4 +163,9 @@ public abstract class SpiderChartComponentBase { ...@@ -163,4 +163,9 @@ public abstract class SpiderChartComponentBase {
public final int getHeight() { public final int getHeight() {
return height; return height;
} }
/** Returns the font data. */
public FontData getFontData() {
return fontData;
}
} }
...@@ -32,6 +32,7 @@ import org.eclipse.swt.SWT; ...@@ -32,6 +32,7 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.fortiss.tooling.spiderchart.gc.AbstractChartImage; import org.fortiss.tooling.spiderchart.gc.AbstractChartImage;
import org.fortiss.tooling.spiderchart.gc.Polygon; import org.fortiss.tooling.spiderchart.gc.Polygon;
...@@ -42,6 +43,7 @@ import org.fortiss.tooling.spiderchart.model.SpiderChart; ...@@ -42,6 +43,7 @@ import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.scale.SpiderChartScale; import org.fortiss.tooling.spiderchart.scale.SpiderChartScale;
import org.fortiss.tooling.spiderchart.sequence.DataSequence; import org.fortiss.tooling.spiderchart.sequence.DataSequence;
import org.fortiss.tooling.spiderchart.sequence.LineDataSequence; import org.fortiss.tooling.spiderchart.sequence.LineDataSequence;
import org.fortiss.tooling.spiderchart.style.AxisStyle;
import org.fortiss.tooling.spiderchart.style.FillStyle; import org.fortiss.tooling.spiderchart.style.FillStyle;
import org.fortiss.tooling.spiderchart.style.LineStyle; import org.fortiss.tooling.spiderchart.style.LineStyle;
...@@ -56,7 +58,7 @@ import org.fortiss.tooling.spiderchart.style.LineStyle; ...@@ -56,7 +58,7 @@ import org.fortiss.tooling.spiderchart.style.LineStyle;
public final class SpiderChartPlotter extends SpiderChartComponentBase { public final class SpiderChartPlotter extends SpiderChartComponentBase {
/** The map for style information of axes. */ /** The map for style information of axes. */
private Map<Axis, LineStyle> axisStyle = new HashMap<Axis, LineStyle>(); private Map<Axis, AxisStyle> axisStyle = new HashMap<Axis, AxisStyle>();
/** The map for style information of data series. */ /** The map for style information of data series. */
private Map<DataSeries, LineStyle> dataSeriesStyle = new HashMap<DataSeries, LineStyle>(); private Map<DataSeries, LineStyle> dataSeriesStyle = new HashMap<DataSeries, LineStyle>();
/** Spider Chart Background Image */ /** Spider Chart Background Image */
...@@ -872,7 +874,7 @@ public final class SpiderChartPlotter extends SpiderChartComponentBase { ...@@ -872,7 +874,7 @@ public final class SpiderChartPlotter extends SpiderChartComponentBase {
} }
/** Plots the axes of the spider chart. */ /** Plots the axes of the spider chart. */
public void plotAxes(SpiderChartSwtGraphics graphics) { public void drawAxes(SpiderChartSwtGraphics graphics) {
List<Axis> axes = chart.getAxes(); List<Axis> axes = chart.getAxes();
int size = axes.size(); int size = axes.size();
double segmentDegree = 360.0 / size; double segmentDegree = 360.0 / size;
...@@ -890,18 +892,59 @@ public final class SpiderChartPlotter extends SpiderChartComponentBase { ...@@ -890,18 +892,59 @@ public final class SpiderChartPlotter extends SpiderChartComponentBase {
for(int i = 0; i < size; i++) { for(int i = 0; i < size; i++) {
Axis axis = axes.get(i); Axis axis = axes.get(i);
// draw line
double angleRad = Math.PI * angleDegree / 180.0; double angleRad = Math.PI * angleDegree / 180.0;
int outerX = centerX + (int)(Math.cos(angleRad) * extent); int outerX = centerX + (int)(Math.cos(angleRad) * extent);
int outerY = centerY + (int)(Math.sin(angleRad) * extent); int outerY = centerY + (int)(Math.sin(angleRad) * extent);
LineStyle style = axisStyle.get(axis); AxisStyle style = axisStyle.get(axis);
style.draw(graphics, centerX, centerY, outerX, outerY); style.getLineStyle().draw(graphics, centerX, centerY, outerX, outerY);
// draw label
drawAxisLabel(graphics, axis, style, centerX, centerY, outerX, outerY);
// TODO: draw segment labels
angleDegree = (angleDegree + segmentDegree) % 360.0; angleDegree = (angleDegree + segmentDegree) % 360.0;
} }
} }
/** Draws the axis label at the correct position. */
private void drawAxisLabel(SpiderChartSwtGraphics graphics, Axis axis, AxisStyle style,
int centerX, int centerY, int outerX, int outerY) {
String axisLabel = axis.getName();
FontData fontData = style.getLabelStyle().getFontData();
GC gc = graphics.getGraphics();
Font font = new Font(Display.getCurrent(), fontData);
Font oldFont = gc.getFont();
gc.setFont(font);
Color oldColor = gc.getForeground();
gc.setForeground(Display.getCurrent().getSystemColor(style.getLabelStyle().getSwtColor()));
int textExtent = graphics.getGraphics().textExtent(axisLabel).x;
if(outerX > centerX) {
outerX += 5;
} else if(outerX < centerX) {
outerX = outerX - 5 - textExtent;
} else {
outerX = outerX - textExtent / 2;
}
if(outerY > centerY) {
outerY = outerY + 5;
} else if(outerY < centerY) {
outerY = outerY - 5 - fontData.getHeight();
} else {
outerY = outerY - fontData.getHeight() / 2;
}
gc.drawString(axisLabel, outerX, outerY, true);
gc.setFont(oldFont);
gc.setForeground(oldColor);
font.dispose();
}
/** Sets the style for the given axis. */ /** Sets the style for the given axis. */
public void setAxisStyle(Axis axis, LineStyle style) { public void setAxisStyle(Axis axis, AxisStyle style) {
axisStyle.put(axis, style); axisStyle.put(axis, style);
} }
......
...@@ -20,7 +20,9 @@ package org.fortiss.tooling.spiderchart.plotter; ...@@ -20,7 +20,9 @@ package org.fortiss.tooling.spiderchart.plotter;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.fortiss.tooling.spiderchart.gc.swt.SpiderChartSwtGraphics; import org.fortiss.tooling.spiderchart.gc.swt.SpiderChartSwtGraphics;
import org.fortiss.tooling.spiderchart.model.SpiderChart; import org.fortiss.tooling.spiderchart.model.SpiderChart;
...@@ -51,19 +53,20 @@ public final class SpiderChartTitle extends SpiderChartComponentBase { ...@@ -51,19 +53,20 @@ public final class SpiderChartTitle extends SpiderChartComponentBase {
if(text == null) { if(text == null) {
return; return;
} }
GC gc = g.getGraphics();
Font ontheflyFont = createFont();
int toCenterX = (this.width - g.getFontWidth(null, text)) / 2; Font oldFont = gc.getFont();
if(toCenterX < 0) { Color oldColor = gc.getForeground();
toCenterX = 0;
}
int toCenterY = (this.height - g.getFontHeight()) / 2;
if(toCenterY < 0) {
toCenterY = 0;
}
Font ontheflyFont = createFont(); gc.setFont(ontheflyFont);
g.drawText(text, this.x + toCenterX, this.y + toCenterY + g.getFontHeight(), int toCenterX = (getWidth() + gc.textExtent(text).x) / 2;
getForegroundColor(), ontheflyFont); int toCenterY = (getHeight() + getFontData().getHeight()) / 2;
gc.drawString(text, getX() + toCenterX, getY() + toCenterY + g.getFontHeight(), true);
gc.setForeground(oldColor);
gc.setFont(oldFont);
ontheflyFont.dispose(); ontheflyFont.dispose();
} }
......
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2016 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.spiderchart.style;
import static java.util.Objects.requireNonNull;
import static org.fortiss.tooling.spiderchart.style.FontStyle.BLACK_VERDANA_12PT;
import static org.fortiss.tooling.spiderchart.style.FontStyle.BLACK_VERDANA_8PT;
import static org.fortiss.tooling.spiderchart.style.LineStyle.SOLID_BLACK_1PT;
/**
* Class for all style attributes for spider chart axes.
* <P>
* If {@link #segmentStyle} is non-null then {@link #segments} indicators will be drawn.
*
* @author hoelzl
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class AxisStyle {
/** Default axis style with solid black line, a single segment, and Verdana fonts. */
public static final AxisStyle DEFAULT = new AxisStyle(SOLID_BLACK_1PT,
BLACK_VERDANA_12PT, 1, BLACK_VERDANA_8PT);
/** The line style. */
private LineStyle lineStyle;
/** The axis label style. */
private FontStyle labelStyle;
/** The number of segments to be drawn. */
private int segments;
/** The font style of the segment labels. */
private FontStyle segmentStyle;
/** Constructor. */
public AxisStyle(LineStyle lineStyle, FontStyle labelStyle) {
this(lineStyle, labelStyle, 0, null);
}
/** Constructor. */
public AxisStyle(LineStyle lineStyle, FontStyle labelStyle, int numSegments,
FontStyle segmentStyle) {
this.lineStyle = requireNonNull(lineStyle);
this.labelStyle = requireNonNull(labelStyle);
this.segments = Math.max(1, numSegments);
this.segmentStyle = segmentStyle;
}
/** Returns the line style. */
public LineStyle getLineStyle() {
return lineStyle;
}
/** Returns the label style. */
public FontStyle getLabelStyle() {
return labelStyle;
}
/** Returns the number of segments. */
public int getSegments() {
return segments;
}
/** Returns the segment style. */
public FontStyle getSegmentStyle() {
return segmentStyle;
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2016 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.spiderchart.style;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
/**
* Class for style attributes of fonts (FontData and SWT color).
*
* @author hoelzl
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public final class FontStyle {
/** Black Verdana 14 point. */
public static final FontStyle BLACK_VERDANA_14PT = new FontStyle(new FontData("Verdana", 14,
SWT.NORMAL), SWT.COLOR_BLACK);
/** Black Verdana 12 point. */
public static final FontStyle BLACK_VERDANA_12PT = new FontStyle(new FontData("Verdana", 12,
SWT.NORMAL), SWT.COLOR_BLACK);
/** Black Verdana 10 point. */
public static final FontStyle BLACK_VERDANA_10PT = new FontStyle(new FontData("Verdana", 10,
SWT.NORMAL), SWT.COLOR_BLACK);
/** Black Verdana 8 point. */
public static final FontStyle BLACK_VERDANA_8PT = new FontStyle(new FontData("Verdana", 8,
SWT.NORMAL), SWT.COLOR_BLACK);
/** The font data. */
private final FontData fontData;
/** The SWT color. */
private final int swtColor;
/** Constructor. */
public FontStyle(FontData fontData, int swtColor) {
this.fontData = fontData;
this.swtColor = swtColor;
}
/** Returns font data. */
public FontData getFontData() {
return fontData;
}
/** Returns SWT color. */
public int getSwtColor() {
return swtColor;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment