add Line2D graphic

This commit is contained in:
wyq 2024-02-19 18:30:39 +08:00
parent 58603e0413
commit bfa8c9b731
18 changed files with 431 additions and 123 deletions

View File

@ -26,6 +26,7 @@ import org.meteoinfo.geo.drawing.Draw;
import org.meteoinfo.geometry.graphic.Graphic; import org.meteoinfo.geometry.graphic.Graphic;
import org.meteoinfo.geometry.graphic.GraphicCollection; import org.meteoinfo.geometry.graphic.GraphicCollection;
import org.meteoinfo.geometry.graphic.ImageGraphic; import org.meteoinfo.geometry.graphic.ImageGraphic;
import org.meteoinfo.geometry.graphic.Line2DGraphic;
import org.meteoinfo.geometry.legend.*; import org.meteoinfo.geometry.legend.*;
import org.meteoinfo.geometry.shape.Polygon; import org.meteoinfo.geometry.shape.Polygon;
import org.meteoinfo.geometry.shape.Shape; import org.meteoinfo.geometry.shape.Shape;
@ -275,6 +276,11 @@ public class Plot2D extends AbstractPlot2D {
} }
for (int i = 0; i < graphic.getNumGraphics(); i++) { for (int i = 0; i < graphic.getNumGraphics(); i++) {
Graphic gg = graphic.getGraphicN(i); Graphic gg = graphic.getGraphicN(i);
if (gg instanceof Line2DGraphic) {
this.drawLine2D(g, (Line2DGraphic) gg, area);
break;
}
if (!graphic.isSingleLegend()) { if (!graphic.isSingleLegend()) {
cb = gg.getLegend(); cb = gg.getLegend();
} }
@ -435,6 +441,25 @@ public class Plot2D extends AbstractPlot2D {
Draw.drawArrow(pf, aPS, aPB, g, zoom); Draw.drawArrow(pf, aPS, aPB, g, zoom);
} }
private void drawLine2D(Graphics2D g, Line2DGraphic line2D, Rectangle2D area) {
if (line2D.isCurve()) {
drawCurveline(g, (PolylineShape) line2D.getShape(), (PolylineBreak) line2D.getLegend(), area);
} else {
BreakTypes breakType = line2D.getLegend().getBreakType();
switch (breakType) {
case POINT_BREAK:
drawPolyline(g, (PolylineShape) line2D.getShape(), (PointBreak) line2D.getLegend(), area);
break;
case COLOR_BREAK_COLLECTION:
drawPolyline(g, (PolylineShape) line2D.getShape(), (ColorBreakCollection) line2D.getLegend(), area);
break;
default:
drawPolyline(g, (PolylineShape) line2D.getShape(), (PolylineBreak) line2D.getLegend(), area);
break;
}
}
}
private void drawPolyline(Graphics2D g, PolylineShape aPLS, PointBreak aPB, Rectangle2D area) { private void drawPolyline(Graphics2D g, PolylineShape aPLS, PointBreak aPB, Rectangle2D area) {
for (Polyline aline : aPLS.getPolylines()) { for (Polyline aline : aPLS.getPolylines()) {
double[] sXY; double[] sXY;
@ -512,7 +537,7 @@ public class Plot2D extends AbstractPlot2D {
} }
} }
private void drawCurveline(Graphics2D g, CurveLineShape aPLS, PolylineBreak aPLB, Rectangle2D area) { private void drawCurveline(Graphics2D g, PolylineShape aPLS, PolylineBreak aPLB, Rectangle2D area) {
for (Polyline aline : aPLS.getPolylines()) { for (Polyline aline : aPLS.getPolylines()) {
double[] sXY; double[] sXY;
PointF[] points = new PointF[aline.getPointList().size()]; PointF[] points = new PointF[aline.getPointList().size()];

View File

@ -67,7 +67,7 @@ import java.util.zip.ZipInputStream;
public static String getVersion(){ public static String getVersion(){
String version = GlobalUtil.class.getPackage().getImplementationVersion(); String version = GlobalUtil.class.getPackage().getImplementationVersion();
if (version == null || version.equals("")) { if (version == null || version.equals("")) {
version = "3.7.9"; version = "3.7.10";
} }
return version; return version;
} }

View File

@ -3139,10 +3139,12 @@ public class Draw {
drawArrowLine(points, (ArrowLineBreak) aPLB, g); drawArrowLine(points, (ArrowLineBreak) aPLB, g);
} else { } else {
if (aPLB.isUsingDashStyle()) { if (aPLB.isUsingDashStyle()) {
g.setColor(aPLB.getColor()); if (aPLB.isDrawPolyline()) {
float[] dashPattern = getDashPattern(aPLB.getStyle()); g.setColor(aPLB.getColor());
g.setStroke(new BasicStroke(aPLB.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f)); float[] dashPattern = getDashPattern(aPLB.getStyle());
drawPolyline(points, g); g.setStroke(new BasicStroke(aPLB.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f));
drawPolyline(points, g);
}
//Draw symbol //Draw symbol
if (aPLB.isDrawSymbol()) { if (aPLB.isDrawSymbol()) {

View File

@ -33,8 +33,8 @@ package org.meteoinfo.geometry.graphic;
public class Graphic { public class Graphic {
// <editor-fold desc="Variables"> // <editor-fold desc="Variables">
private Shape _shape = null; protected Shape shape = null;
private ColorBreak _legend = null; protected ColorBreak legend = null;
private ResizeAbility _resizeAbility = ResizeAbility.RESIZE_ALL; private ResizeAbility _resizeAbility = ResizeAbility.RESIZE_ALL;
// </editor-fold> // </editor-fold>
// <editor-fold desc="Constructor"> // <editor-fold desc="Constructor">
@ -52,8 +52,8 @@ package org.meteoinfo.geometry.graphic;
* @param legend a legend * @param legend a legend
*/ */
public Graphic(Shape shape, ColorBreak legend) { public Graphic(Shape shape, ColorBreak legend) {
_shape = shape; this.shape = shape;
_legend = legend; this.legend = legend;
updateResizeAbility(); updateResizeAbility();
} }
// </editor-fold> // </editor-fold>
@ -65,7 +65,7 @@ package org.meteoinfo.geometry.graphic;
* @return Shape * @return Shape
*/ */
public Shape getShape() { public Shape getShape() {
return _shape; return shape;
} }
/** /**
@ -74,7 +74,7 @@ package org.meteoinfo.geometry.graphic;
* @param aShape a shape * @param aShape a shape
*/ */
public void setShape(Shape aShape) { public void setShape(Shape aShape) {
_shape = aShape; shape = aShape;
updateResizeAbility(); updateResizeAbility();
} }
@ -84,11 +84,11 @@ package org.meteoinfo.geometry.graphic;
* @return Legend * @return Legend
*/ */
public ColorBreak getLegend() { public ColorBreak getLegend() {
return _legend; return legend;
} }
public void setLegend(ColorBreak legend) { public void setLegend(ColorBreak legend) {
_legend = legend; this.legend = legend;
updateResizeAbility(); updateResizeAbility();
} }
@ -107,7 +107,7 @@ package org.meteoinfo.geometry.graphic;
* @return The extent * @return The extent
*/ */
public Extent getExtent() { public Extent getExtent() {
return this._shape.getExtent(); return this.shape.getExtent();
} }
/** /**
@ -115,7 +115,7 @@ package org.meteoinfo.geometry.graphic;
* @param value The extent * @param value The extent
*/ */
public void setExtent(Extent value){ public void setExtent(Extent value){
this._shape.setExtent(value); this.shape.setExtent(value);
} }
/** /**
@ -136,6 +136,15 @@ package org.meteoinfo.geometry.graphic;
// </editor-fold> // </editor-fold>
// <editor-fold desc="Methods"> // <editor-fold desc="Methods">
/**
* Get shape type
* @return The shape type
*/
public ShapeTypes getShapeType(){
return shape.getShapeType();
}
/** /**
* Get graphics number * Get graphics number
* @return 1 * @return 1
@ -164,10 +173,10 @@ package org.meteoinfo.geometry.graphic;
} }
private void updateResizeAbility() { private void updateResizeAbility() {
if (_shape != null && _legend != null) { if (shape != null && legend != null) {
switch (_shape.getShapeType()) { switch (shape.getShapeType()) {
case POINT: case POINT:
switch (_legend.getBreakType()) { switch (legend.getBreakType()) {
case POINT_BREAK: case POINT_BREAK:
_resizeAbility = ResizeAbility.SAME_WIDTH_HEIGHT; _resizeAbility = ResizeAbility.SAME_WIDTH_HEIGHT;
break; break;
@ -195,8 +204,8 @@ package org.meteoinfo.geometry.graphic;
* @param newY New Y * @param newY New Y
*/ */
public void verticeMoveUpdate(int vIdx, double newX, double newY) { public void verticeMoveUpdate(int vIdx, double newX, double newY) {
List<PointD> points = (List<PointD>)_shape.getPoints(); List<PointD> points = (List<PointD>) shape.getPoints();
switch (_shape.getShapeType()){ switch (shape.getShapeType()){
case POLYGON: case POLYGON:
case CURVE_POLYGON: case CURVE_POLYGON:
case RECTANGLE: case RECTANGLE:
@ -219,7 +228,7 @@ package org.meteoinfo.geometry.graphic;
aP.X = newX; aP.X = newX;
aP.Y = newY; aP.Y = newY;
//points.set(vIdx, aP); //points.set(vIdx, aP);
_shape.setPoints(points); shape.setPoints(points);
} }
/** /**
@ -229,9 +238,9 @@ package org.meteoinfo.geometry.graphic;
* @param point The add vertice * @param point The add vertice
*/ */
public void verticeAddUpdate(int vIdx, PointD point) { public void verticeAddUpdate(int vIdx, PointD point) {
List<PointD> points = (List<PointD>)_shape.getPoints(); List<PointD> points = (List<PointD>) shape.getPoints();
points.add(vIdx, point); points.add(vIdx, point);
_shape.setPoints(points); shape.setPoints(points);
} }
/** /**
@ -240,9 +249,9 @@ package org.meteoinfo.geometry.graphic;
* @param vIdx Vertice index * @param vIdx Vertice index
*/ */
public void verticeRemoveUpdate(int vIdx) { public void verticeRemoveUpdate(int vIdx) {
List<PointD> points = (List<PointD>)_shape.getPoints(); List<PointD> points = (List<PointD>) shape.getPoints();
points.remove(vIdx); points.remove(vIdx);
_shape.setPoints(points); shape.setPoints(points);
} }
/** /**
@ -252,8 +261,8 @@ package org.meteoinfo.geometry.graphic;
*/ */
public void exportToXML(Document doc, Element parent) { public void exportToXML(Document doc, Element parent) {
Element graphic = doc.createElement("Graphic"); Element graphic = doc.createElement("Graphic");
addShape(doc, graphic, _shape); addShape(doc, graphic, shape);
addLegend(doc, graphic, _legend, _shape.getShapeType()); addLegend(doc, graphic, legend, shape.getShapeType());
parent.appendChild(graphic); parent.appendChild(graphic);
} }
@ -508,10 +517,10 @@ package org.meteoinfo.geometry.graphic;
*/ */
public void importFromXML(Element graphicNode) { public void importFromXML(Element graphicNode) {
Node shape = graphicNode.getElementsByTagName("Shape").item(0); Node shape = graphicNode.getElementsByTagName("Shape").item(0);
_shape = loadShape(shape); this.shape = loadShape(shape);
Node legend = graphicNode.getElementsByTagName("Legend").item(0); Node legend = graphicNode.getElementsByTagName("Legend").item(0);
_legend = loadLegend(legend, _shape.getShapeType()); this.legend = loadLegend(legend, this.shape.getShapeType());
updateResizeAbility(); updateResizeAbility();
} }

View File

@ -554,6 +554,7 @@ public class GraphicCollection extends Graphic implements Iterator {
* *
* @return Shape type * @return Shape type
*/ */
@Override
public ShapeTypes getShapeType() { public ShapeTypes getShapeType() {
return this.graphics.get(0).getShape().getShapeType(); return this.graphics.get(0).getShape().getShapeType();
} }

View File

@ -0,0 +1,152 @@
package org.meteoinfo.geometry.graphic;
import org.meteoinfo.common.PointD;
import org.meteoinfo.geometry.legend.ColorBreak;
import org.meteoinfo.geometry.legend.ColorBreakCollection;
import org.meteoinfo.geometry.legend.LegendScheme;
import org.meteoinfo.geometry.legend.PolylineBreak;
import org.meteoinfo.geometry.shape.PolylineShape;
import org.meteoinfo.ndarray.Array;
import org.meteoinfo.ndarray.IndexIterator;
import java.util.ArrayList;
import java.util.List;
public class Line2DGraphic extends Graphic {
private Array xData;
private Array yData;
private Array cData;
private boolean curve = false;
/**
* Constructor
*
* @param polylineShape Polyline shape
* @param polylineBreak Polyline break
*/
public Line2DGraphic(PolylineShape polylineShape, PolylineBreak polylineBreak) {
this.shape = polylineShape;
this.legend = polylineBreak;
}
/**
* Constructor
* @param xData X data
* @param yData Y data
* @param polylineBreak Polyline break
*/
public Line2DGraphic(Array xData, Array yData, PolylineBreak polylineBreak) {
this.xData = xData;
this.yData = yData;
updateShape();
if (polylineBreak == null) {
polylineBreak = new PolylineBreak();
}
this.legend = polylineBreak;
}
/**
* Constructor
* @param xData X data
* @param yData Y data
*/
public Line2DGraphic(Array xData, Array yData) {
this(xData, yData, new PolylineBreak());
}
/**
* Constructor
* @param xData X data
* @param yData Y data
* @param cData Color data
* @param legendScheme Legend scheme
*/
public Line2DGraphic(Array xData, Array yData, Array cData, LegendScheme legendScheme) {
this.xData = xData;
this.yData = yData;
this.cData = cData;
updateShapeLegend(legendScheme);
}
protected void updateShape() {
List<PointD> points = new ArrayList<>();
IndexIterator xIter = this.xData.getIndexIterator();
IndexIterator yIter = this.yData.getIndexIterator();
while (xIter.hasNext()) {
points.add(new PointD(xIter.getDoubleNext(), yIter.getDoubleNext()));
}
if (this.shape == null) {
this.shape = new PolylineShape();
}
this.shape.setPoints(points);
}
protected void updateShapeLegend(LegendScheme legendScheme) {
List<PointD> points = new ArrayList<>();
IndexIterator xIter = this.xData.getIndexIterator();
IndexIterator yIter = this.yData.getIndexIterator();
IndexIterator cIter = this.cData.getIndexIterator();
ColorBreakCollection cbc = new ColorBreakCollection();
ColorBreak cb;
double c;
while (xIter.hasNext()) {
points.add(new PointD(xIter.getDoubleNext(), yIter.getDoubleNext()));
c = cIter.getDoubleNext();
cb = legendScheme.findLegendBreak(c);
cbc.add(cb);
}
if (this.shape == null) {
this.shape = new PolylineShape();
}
this.shape.setPoints(points);
this.legend = cbc;
}
/**
* Return plot as curve line or not
* @return Curve line or not
*/
public boolean isCurve() {
return this.curve;
}
/**
* Set plot as curve line or not
* @param value Curve line or not
*/
public void setCurve(boolean value) {
this.curve = value;
}
/**
* Set x data
* @param xData X data
*/
public void setXData(Array xData) {
this.xData = xData;
updateShape();
}
/**
* Set y data
* @param yData Y data
*/
public void setYData(Array yData) {
this.yData = yData;
updateShape();
}
/**
* Set data
* @param xData X data
* @param yData Y data
*/
public void setData(Array xData, Array yData) {
this.xData = xData;
this.yData = yData;
updateShape();
}
}

View File

@ -1,32 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile"> <MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\map\webmap"> <Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\plot">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\hdf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\no_opengl"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\web"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\geoshow"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\FY"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\oco-2"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\boxplot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\funny"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\patch"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\animation"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\subplot"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\satellite\calipso"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\legend"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\webmap"/> <RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\plot"/>
</Path> </Path>
<File> <File>
<OpenedFiles> <OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\chart\subplot\subplot_3.py"/> <OpenedFile File="D:\Working\MIScript\Jython\mis\satellite\calipso\CALIPSO_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\chart\subplot\subplot_2.py"/> <OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_cdata_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\map\add_circle.py"/> <OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_2.py"/>
</OpenedFiles> </OpenedFiles>
<RecentFiles> <RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\chart\subplot\subplot_3.py"/> <RecentFile File="D:\Working\MIScript\Jython\mis\satellite\calipso\CALIPSO_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\chart\subplot\subplot_2.py"/> <RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_cdata_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\map\add_circle.py"/> <RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\plot\plot_2.py"/>
</RecentFiles> </RecentFiles>
</File> </File>
<Font> <Font>
@ -34,5 +34,5 @@
</Font> </Font>
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/> <LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
<Figure DoubleBuffering="true"/> <Figure DoubleBuffering="true"/>
<Startup MainFormLocation="-7,-7" MainFormSize="1293,685"/> <Startup MainFormLocation="-7,0" MainFormSize="1310,788"/>
</MeteoInfo> </MeteoInfo>

View File

@ -6,14 +6,12 @@ from ._axes3d import Axes3D
from ._axes3dgl import Axes3DGL from ._axes3dgl import Axes3DGL
from ._figure import Figure from ._figure import Figure
from ._glfigure import GLFigure from ._glfigure import GLFigure
from .patches import *
from .lines import *
from .colors import * from .colors import *
from .io import * from .io import *
from .graphic import *
__all__ = ['Figure', 'GLFigure', 'Axes', 'PolarAxes', 'MapAxes', 'Axes3D', 'Axes3DGL'] __all__ = ['Figure', 'GLFigure', 'Axes', 'PolarAxes', 'MapAxes', 'Axes3D', 'Axes3DGL']
__all__ += miplot.__all__ __all__ += miplot.__all__
__all__ += patches.__all__
__all__ += lines.__all__
__all__ += colors.__all__ __all__ += colors.__all__
__all__ += io.__all__ __all__ += io.__all__
__all__ += graphic.__all__

View File

@ -35,6 +35,7 @@ from mipylib.geolib.milayer import MILayer, MIXYListData
import plotutil import plotutil
import colors import colors
import mipylib.miutil as miutil import mipylib.miutil as miutil
from .graphic import Line2D
__all__ = ['Axes', 'PolarAxes'] __all__ = ['Axes', 'PolarAxes']
@ -1085,6 +1086,8 @@ class Axes(object):
else: else:
self._axes.addGraphic(zorder, graphic, projection) self._axes.addGraphic(zorder, graphic, projection)
self._axes.setAutoExtent()
def get_graphics(self): def get_graphics(self):
""" """
Get graphics Get graphics
@ -1364,7 +1367,7 @@ class Axes(object):
# Add graphics # Add graphics
zorder = kwargs.pop('zorder', None) zorder = kwargs.pop('zorder', None)
iscurve = kwargs.pop('iscurve', False) iscurve = kwargs.pop('curve', False)
graphics = [] graphics = []
if isxylistdata: if isxylistdata:
graphic = GraphicFactory.createLineString(dataset, lines) graphic = GraphicFactory.createLineString(dataset, lines)
@ -1375,8 +1378,10 @@ class Axes(object):
# Add data series # Add data series
snum = len(xdatalist) snum = len(xdatalist)
if snum == 1: if snum == 1:
xdata = plotutil.getplotdata(xdatalist[0]) #xdata = plotutil.getplotdata(xdatalist[0])
ydata = plotutil.getplotdata(ydatalist[0]) #ydata = plotutil.getplotdata(ydatalist[0])
xdata = np.asarray(xdatalist[0])
ydata = np.asarray(ydatalist[0])
if len(lines) == 1: if len(lines) == 1:
colors = kwargs.pop('colors', None) colors = kwargs.pop('colors', None)
if not colors is None: if not colors is None:
@ -1387,26 +1392,31 @@ class Axes(object):
ncb = cb.clone() ncb = cb.clone()
ncb.setColor(cc) ncb.setColor(cc)
lines.append(ncb) lines.append(ncb)
graphic = GraphicFactory.createLineString(xdata, ydata, lines, iscurve) graphic = GraphicFactory.createLineString(xdata._array, ydata._array, lines, iscurve)
else: else:
graphic = GraphicFactory.createLineString(xdata, ydata, lines[0], iscurve) #graphic = GraphicFactory.createLineString(xdata, ydata, lines[0], iscurve)
graphic = Line2D(xdata, ydata, legend=lines[0], curve=iscurve)
else: # >1 else: # >1
graphic = GraphicFactory.createLineString(xdata, ydata, lines, iscurve) graphic = GraphicFactory.createLineString(xdata._array, ydata._array, lines, iscurve)
self.add_graphic(graphic, zorder=zorder) self.add_graphic(graphic, zorder=zorder)
graphics.append(graphic) graphics.append(graphic)
else: else:
for i in range(0, snum): for i in range(0, snum):
label = kwargs.pop('label', 'S_' + str(i + 1)) label = kwargs.pop('label', 'S_' + str(i + 1))
xdata = plotutil.getplotdata(xdatalist[i]) #xdata = plotutil.getplotdata(xdatalist[i])
ydata = plotutil.getplotdata(ydatalist[i]) #ydata = plotutil.getplotdata(ydatalist[i])
graphic = GraphicFactory.createLineString(xdata, ydata, lines[i], iscurve) xdata = np.asarray(xdatalist[i])
ydata = np.asarray(ydatalist[i])
#graphic = GraphicFactory.createLineString(xdata, ydata, lines[i], iscurve)
graphic = Line2D(xdata, ydata, legend=lines[i], curve=iscurve)
self.add_graphic(graphic) self.add_graphic(graphic)
graphics.append(graphic) graphics.append(graphic)
else: else:
xdata = plotutil.getplotdata(xdatalist[0]) xdata = np.asarray(xdatalist[0])
ydata = plotutil.getplotdata(ydatalist[0]) ydata = np.asarray(ydatalist[0])
zdata = plotutil.getplotdata(cdata) cdata = np.asarray(cdata)
graphic = GraphicFactory.createLineString(xdata, ydata, zdata, ls, iscurve) #graphic = GraphicFactory.createLineString(xdata, ydata, cdata, ls, iscurve)
graphic = Line2D(xdata, ydata, legend=ls, cdata=cdata, curve=iscurve)
self.add_graphic(graphic, zorder=zorder) self.add_graphic(graphic, zorder=zorder)
graphics.append(graphic) graphics.append(graphic)
self._axes.setAutoExtent() self._axes.setAutoExtent()

View File

@ -0,0 +1,5 @@
from .lines import *
from .patches import *
__all__ = lines.__all__
__all__ += patches.__all__

View File

@ -0,0 +1,123 @@
from org.meteoinfo.geometry.graphic import Line2DGraphic
from org.meteoinfo.geometry.legend import PolylineBreak
from .. import plotutil
__all__ = ['Line2D']
class Line2D(Line2DGraphic):
"""
A line - the line can have both a solid linestyle connecting all
the vertices, and a marker at each vertex. Additionally, the
drawing of the solid line is influenced by the drawstyle, e.g., one
can create "stepped" lines in various styles.
"""
#__slots__ = ('set_data')
def __init__(self, xdata, ydata, legend=None, cdata=None, curve=False, **kwargs):
"""
Create a `.Line2D` instance with *x* and *y* data in sequences of
*xdata*, *ydata*.
"""
if legend is None:
legend = plotutil.getlegendbreak('line', **kwargs)[0]
self._x = xdata
self._y = ydata
self._cdata = cdata
if cdata is None:
super(Line2D, self).__init__(xdata._array, ydata._array, legend)
else:
super(Line2D, self).__init__(xdata._array, ydata._array, cdata._array, legend)
if curve:
self.setCurve(curve)
def get_xdata(self):
"""
Return the xdata.
:return: (*array*) xdata.
"""
return self._x
def set_xdata(self, xdata):
"""
Set the xdata.
:param xdata: (*array*) The xdata.
"""
self._x = xdata
self.setXData(xdata._array)
def get_ydata(self):
"""
Return the ydata.
:return: (*array*) ydata.
"""
return self._y
def set_ydata(self, ydata):
"""
Set the ydata.
:param ydata: (*array*) The ydata.
"""
self._y = ydata
self.setYData(ydata._array)
def get_data(self):
"""
Get x, y data.
:return: x, y data.
"""
return (self._x, self._y)
def set_data(self, xdata, ydata):
"""
Set x, y data.
:param xdata: (*array*) X data.
:param ydata: (*array*) Y data.
"""
self._x = xdata
self._y = ydata
self.setData(xdata._array, ydata._array)
def get_color(self):
"""
Return the line color.
:return: (*Color*) The line color.
"""
return self.legend.getColor()
def set_color(self, color):
"""
Set the line color.
:param color: (*color or str*) The line color.
"""
color = plotutil.getcolor(color)
self.legend.setColor(color)
def get_curve(self):
"""
Return curve line or not.
:return: (*bool*) Curve line or not.
"""
return self.isCurve()
def set_curve(self, curve):
"""
Set curve line or not.
:param curve: (*bool*) Curve line or not.
"""
self.setCurve(curve)

View File

@ -2,7 +2,7 @@ from org.meteoinfo.geometry.graphic import Graphic
from org.meteoinfo.geometry.shape import ShapeUtil, CircleShape, EllipseShape, \ from org.meteoinfo.geometry.shape import ShapeUtil, CircleShape, EllipseShape, \
RectangleShape, ArcShape RectangleShape, ArcShape
from . import plotutil from .. import plotutil
import mipylib.numeric as np import mipylib.numeric as np
__all__ = ['Arc','Circle','Ellipse','Rectangle','Polygon','Wedge'] __all__ = ['Arc','Circle','Ellipse','Rectangle','Polygon','Wedge']

View File

@ -1,38 +0,0 @@
from org.meteoinfo.geometry.graphic import Graphic
from org.meteoinfo.geometry.shape import ShapeUtil
from . import plotutil
import mipylib.numeric as np
__all__ = ['Line2D']
class Line2D(Graphic):
"""
A line - the line can have both a solid linestyle connecting all the vertices, and a marker
at each vertex.
"""
def __init__(self, xdata, ydata, **kwargs):
"""
Create a `.Line2D` instance with *x* and *y* data in sequences of
*xdata*, *ydata*.
:param xdata: (*array_like*) X data of the line.
:param ydata: (*array_like*) Y data of the line.
"""
xdata = np.asarray(xdata)
ydata = np.asarray(ydata)
self._xdata = xdata
self._ydata = ydata
shape = ShapeUtil.createPolylineShape(xdata._array, ydata._array)
legend, isunique = plotutil.getlegendbreak('line', **kwargs)
super(Line2D, self).__init__(shape, legend)
@property
def xdata(self):
return self._xdata
@property
def ydata(self):
return self._ydata

View File

@ -379,22 +379,43 @@ def getplotstyle(style, caption, **kwargs):
if not pointStyle is None: if not pointStyle is None:
fill = kwargs.pop('fill', True) fill = kwargs.pop('fill', True)
if lineStyle is None: if lineStyle is None:
pb = PointBreak() # pb = PointBreak()
pb.setCaption(caption) # pb.setCaption(caption)
if '.' in style: # if '.' in style:
pb.setSize(4) # pb.setSize(4)
pb.setDrawOutline(False) # pb.setDrawOutline(False)
else: # else:
pb.setSize(8) # pb.setSize(8)
pb.setStyle(pointStyle) # pb.setStyle(pointStyle)
pb.setDrawFill(fill) # pb.setDrawFill(fill)
# if not c is None:
# pb.setColor(c)
# edgecolor = kwargs.pop('edgecolor', pb.getColor())
# edgecolor = getcolor(edgecolor)
# pb.setOutlineColor(edgecolor)
# setpointlegendbreak(pb, **kwargs)
# return pb
plb = PolylineBreak()
plb.setCaption(caption)
plb.setDrawPolyline(False)
plb.setDrawSymbol(True)
plb.setSymbolStyle(pointStyle)
plb.setFillSymbol(fill)
interval = kwargs.pop('markerinterval', 1)
plb.setSymbolInterval(interval)
if not c is None: if not c is None:
pb.setColor(c) plb.setColor(c)
edgecolor = kwargs.pop('edgecolor', pb.getColor()) markersize = kwargs.pop('markersize', None)
edgecolor = getcolor(edgecolor) if not markersize is None:
pb.setOutlineColor(edgecolor) plb.setSymbolSize(markersize)
setpointlegendbreak(pb, **kwargs) markercolor = kwargs.pop('markeredgecolor', plb.getColor())
return pb markercolor = getcolor(markercolor)
plb.setSymbolColor(markercolor)
markerfillcolor = kwargs.pop('markerfacecolor', markercolor)
markerfillcolor = getcolor(markerfillcolor)
plb.setSymbolFillColor(markerfillcolor)
plb.setFillSymbol(not markerfillcolor is None)
return plb
else: else:
plb = PolylineBreak() plb = PolylineBreak()
plb.setCaption(caption) plb.setCaption(caption)

View File

@ -34,7 +34,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<revision>3.7.9</revision> <revision>3.7.10</revision>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
<maven.compiler.release>8</maven.compiler.release> <maven.compiler.release>8</maven.compiler.release>