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

Some cleanup.

refs 2589
parent b6dfe82f
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@ package org.fortiss.tooling.spiderchart.plotter;
import static java.util.Objects.requireNonNull;
import static org.fortiss.tooling.spiderchart.gc.Fonts.VERDANA;
import static org.fortiss.tooling.spiderchart.util.AxisUtils.getSegmentPoint;
import static org.fortiss.tooling.spiderchart.util.ChartUtil.enumConstants;
import java.text.DecimalFormat;
......@@ -33,6 +34,7 @@ import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.fortiss.tooling.spiderchart.gc.AbstractChartImage;
import org.fortiss.tooling.spiderchart.gc.Polygon;
......@@ -878,14 +880,12 @@ public final class SpiderChartPlotter extends SpiderChartComponentBase {
drawAxisLabel(graphics, axis, style, centerX, centerY, outerX, outerY);
// draw segment indicators
int segments = style.getSegments();
int segmentX = extentX / segments;
int segmentY = extentY / segments;
for(int s = 1; s <= segments; s++) {
double ratio = (double)s / (double)segments;
// FIXME: use locale info here
String lbl = axis.getAxisRatio(ratio).toString();
drawSegmentIndicator(graphics, lbl, style.getSegmentStyle(), centerX, centerY, s *
segmentX, s * segmentY);
Point segmentPoint = getSegmentPoint(style, s, extentX, extentY);
drawSegmentIndicator(graphics, lbl, style, centerX, centerY, segmentPoint);
}
angleDegree = (angleDegree + segmentDegree) % 360.0;
......@@ -894,8 +894,9 @@ public final class SpiderChartPlotter extends SpiderChartComponentBase {
/** Draws the indicator on the axis. */
private void drawSegmentIndicator(SpiderChartSwtGraphics graphics, String lbl,
FontStyle segmentStyle, int centerX, int centerY, int segmentX, int segmentY) {
AxisStyle axisStyle, int centerX, int centerY, Point segment) {
GC gc = graphics.getGraphics();
FontStyle segmentStyle = axisStyle.getSegmentStyle();
Font oldFont = gc.getFont();
Color oldColor = gc.getForeground();
Font font = createFont(segmentStyle.getFontData());
......@@ -903,19 +904,14 @@ public final class SpiderChartPlotter extends SpiderChartComponentBase {
gc.setFont(font);
gc.setForeground(getSystemColor(segmentStyle.getSwtColor()));
int posX = centerX + segmentX;
int posY = centerY + segmentY;
int posX = centerX + segment.x;
if(posX == centerX) {
posX += 5;
}
// TODO: other cases x
int posY = centerY + segment.y;
if(posY == centerY) {
posY += 5;
}
// TODO: other cases y
gc.drawText(lbl, posX, posY, true);
gc.setForeground(oldColor);
......
/*--------------------------------------------------------------------------+
$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.util;
import org.eclipse.swt.graphics.Point;
import org.fortiss.tooling.spiderchart.model.Axis;
import org.fortiss.tooling.spiderchart.style.AxisStyle;
/**
* Utility methods related to {@link Axis} and {@link AxisStyle}.
*
* @author hoelzl
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class AxisUtils {
/** Returns the segment point on the axis if the the axis displayed with the given extents. */
public static Point getSegmentPoint(AxisStyle style, int segment, int extentX, int extentY) {
int segments = style.getSegments();
int segmentX = extentX / segments;
int segmentY = extentY / segments;
return new Point(segmentX * segment, segmentY * segment);
}
/** Returns the segment point on the axis if the the axis displayed with the given extents. */
public static Point getSegmentPoint(AxisStyle style, int segment, Point extent) {
return getSegmentPoint(style, segment, extent.x, extent.y);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment