bugfix for flatiter class

This commit is contained in:
wyq 2024-04-10 14:47:58 +08:00
parent 98e0f1f67c
commit 499b195969
12 changed files with 149 additions and 99 deletions

View File

@ -565,8 +565,7 @@ public class GLChart implements GLEventListener {
//double zoom = this.getPositionAreaZoom(g, plotArea);
//Margin tightInset = this.getPlotsTightInset(g, plotArea);
Margin shrink = this.getPlotsShrink(g, plotArea);
for (int i = 0; i < this.plots.size(); i++) {
Plot plot = this.plots.get(i);
for (Plot plot : this.plots) {
plot.setAntiAlias(this.antialias);
plot.setSymbolAntiAlias(this.symbolAntialias);
if (plot.isOuterPosActive()){
@ -713,17 +712,16 @@ public class GLChart implements GLEventListener {
private Margin getPlotsShrink(Graphics2D g, Rectangle2D area) {
Margin pshrink = null, shrink;
for (int i = 0; i < this.plots.size(); i++) {
Plot plot = this.plots.get(i);
for (Plot plot : this.plots) {
plot.setOuterPositionArea(plot.getOuterPositionArea(area));
Rectangle2D positionArea = plot.getPositionArea(area);
plot.setPositionArea(positionArea);
Margin tightInset = plot.getTightInset(g, positionArea);
plot.setTightInset(tightInset);
shrink = plot.getPlotShrink();
if (i == 0) {
if (pshrink == null) {
pshrink = shrink;
} else if (pshrink != null) {
} else {
pshrink = pshrink.extend(shrink);
}
}

View File

@ -1543,9 +1543,10 @@ public class Plot2D extends AbstractPlot2D {
ShapeTypes stype = ShapeTypes.POLYLINE;
ls = new LegendScheme(stype);
for (Graphic g : this.graphics.getGraphics()) {
if (g.getShapeType() == ShapeTypes.POLYLINE) {
ls.getLegendBreaks().add(g.getLegend());
/*if (g.getShapeType() == ShapeTypes.POLYLINE) {
ls.getLegendBreaks().add(g.getLegend());
}
}*/
}
}
return ls;

View File

@ -1501,6 +1501,38 @@ public class LegendManage {
return ls;
}
/**
* Create weather legend scheme
*
* @param wList Weather index list
* @param size Size
* @param color Color
* @return Weather legend scheme
*/
public static LegendScheme createWeatherLegendScheme(List<Integer> wList, int size, Color color) {
LegendScheme aLS = new LegendScheme(ShapeTypes.POINT);
aLS.setLegendType(LegendType.UNIQUE_VALUE);
for (int w : wList) {
PointBreak aPB = new PointBreak();
aPB.setMarkerType(MarkerType.CHARACTER);
aPB.setSize(size);
aPB.setColor(color);
aPB.setFontName("Weather");
aPB.setStartValue(w);
aPB.setEndValue(w);
int charIdx = w + 28;
if (w == 99) {
charIdx = w + 97;
}
aPB.setCharIndex(charIdx);
aPB.setCaption(String.valueOf(w));
aLS.getLegendBreaks().add(aPB);
}
return aLS;
}
/**
* Create random colors
*

View File

@ -167,6 +167,14 @@ package org.meteoinfo.geometry.legend;
return this.fieldName.equals("Geometry_M") || this.fieldName.equals("Geometry_Z");
}
/**
* Return the legend scheme is empty or not
* @return Empty or not
*/
public boolean isEmpty() {
return this.legendBreaks.isEmpty();
}
/**
* Get legend type
*
@ -296,7 +304,11 @@ package org.meteoinfo.geometry.legend;
* @return A legend break
*/
public ColorBreak getLegendBreak(int i) {
return this.legendBreaks.get(i);
if (i >= this.legendBreaks.size()) {
return null;
} else {
return this.legendBreaks.get(i);
}
}
/**

View File

@ -1,34 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\arrow">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\model"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\geotiff"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\hdf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataframe"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\data_process"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\ascii"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataset"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\netcdf"/>
<RecentFolder Folder="D:\Run\emips\run_chengdu"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\wind">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\bar"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\imshow"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\patch"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\pcolor"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\pie"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\plot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\polar"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\scatter"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\step"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\taylor"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\violinplot"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\weather"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\arrow"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\wind"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\map\geoshow\geoshow_2.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\geotiff\geotiff_dem_4.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\arrow\arrow_map.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\arrow\arrow_1.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\wind\windrose_data_func.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\map\geoshow\geoshow_2.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\io\geotiff\geotiff_dem_4.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\arrow\arrow_map.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\arrow\arrow_1.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\wind\windrose_data_func.py"/>
</RecentFiles>
</File>
<Font>

View File

@ -29,10 +29,14 @@ class flatiter(object):
self.size = self.array.size
def __iter__(self):
self._iter = self.array._array.getIndexIterator()
return self
def next(self):
return self.array.next()
if self._iter.hasNext():
return self._iter.getObjectNext()
else:
raise StopIteration()
def __getitem__(self, key):
if isinstance(key, int):

View File

@ -2023,7 +2023,7 @@ class Axes(object):
barswidth = kwargs.pop('barswidth', 0.8)
self._axes.setBarsWidth(barswidth)
return barbreaks
return graphics
def barh(self, *args, **kwargs):
"""
@ -2045,8 +2045,8 @@ class Axes(object):
:param hatchsize: (*int*) Hatch size. Default is None (8).
:param bgcolor: (*Color*) Background color, only valid with hatch.
:param barswidth: (*float*) Bars width (0 - 1), only used for automatic bar with plot
(only one argument widthout ``width`` augument). Defaul is 0.8.
:param morepoints: (*boolean*) More points in bar rectangle. Defaul is False.
(only one argument without ``width`` augment). Default is 0.8.
:param morepoints: (*boolean*) More points in bar rectangle. Default is False.
:returns: Bar legend break.
@ -2150,7 +2150,7 @@ class Axes(object):
barsheight = kwargs.pop('barsheight', 0.8)
self._axes.setBarsWidth(barsheight)
return barbreaks
return graphics
def hist(self, x, bins=10, density=False, cumulative=False,
rwidth=None, orientation='vertical', **kwargs):
@ -3847,7 +3847,7 @@ class Axes(object):
:param labels: (*list of string*) Legend labels (optional).
:param orientation: (*string*) Legend orientation: ``vertical`` or ``horizontal``.
:param loc: (*string*) The location of the legend, including: 'upper right', 'upper left',
'lower left', 'lower right', 'right', 'ceter left', 'center right', lower center',
'lower left', 'lower right', 'right', 'center left', 'center right', lower center',
'upper center', 'center' and 'custom'. Default is 'upper right'.
:param x: (*float*) Location x in normalized (0, 1) units when ``loc=custom`` .
:param y: (*float*) Location y in normalized (0, 1) units when ``loc=custom`` .
@ -4476,9 +4476,9 @@ class PolarAxes(Axes):
rrmax = max(rrmax, wdhist.max())
lab = '%s - %s' % (wsbins[i], wsbins[i + 1])
bb = self.bar(theta, wdhist, width, bottom=hhist, color=colors[i], \
edgecolor='gray', label=lab, morepoints=True)[0]
bb.setStartValue(wsbins[i])
bb.setEndValue(wsbins[i + 1])
edgecolor='gray', label=lab, morepoints=True)
#bb.setStartValue(wsbins[i])
#bb.setEndValue(wsbins[i + 1])
bars.append(bb)
hhist = hhist + wdhist

View File

@ -529,10 +529,8 @@ class MapAxes(Axes):
if antialias is not None:
graphics.setAntiAlias(antialias)
if visible:
graphics = self.add_graphic(graphics, projection=layer.proj, zorder=zorder)
#self._axes.setDrawExtent(graphics.getExtent().clone())
#self._axes.setExtent(graphics.getExtent().clone())
graphics = self.add_graphic(graphics, projection=layer.proj, zorder=zorder)
graphics.setVisible(visible)
return GeoGraphicCollection(graphics)
else:
if isinstance(args[0], Graphic):
@ -588,17 +586,18 @@ class MapAxes(Axes):
if graphic.getNumGraphics() == 1:
graphic = graphic.getGraphicN(0)
if visible:
if graphic.isCollection():
if self.islonlat():
self._axes.addGraphics(graphic)
else:
graphic = self._axes.addGraphics(graphic, migeo.projinfo())
if graphic.isCollection():
if self.islonlat():
self._axes.addGraphics(graphic)
else:
if self.islonlat():
self._axes.addGraphic(graphic)
else:
graphic = self._axes.addGraphic(graphic, migeo.projinfo())
graphic = self._axes.addGraphics(graphic, migeo.projinfo())
else:
if self.islonlat():
self._axes.addGraphic(graphic)
else:
graphic = self._axes.addGraphic(graphic, migeo.projinfo())
graphic.setVisible(visible)
return graphic
@ -848,10 +847,10 @@ class MapAxes(Axes):
graphics.setAntiAlias(antialias)
visible = kwargs.pop('visible', True)
if visible:
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
graphics.setVisible(visible)
return graphics
@ -928,10 +927,10 @@ class MapAxes(Axes):
graphics.setAntiAlias(antialias)
visible = kwargs.pop('visible', True)
if visible:
zorder = kwargs.pop('zorder', None)
contours = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
graphics.setVisible(visible)
return graphics
@ -990,12 +989,12 @@ class MapAxes(Axes):
graphics.setAntiAlias(antialias)
visible = kwargs.pop('visible', True)
if visible:
zorder = kwargs.pop('zorder', None)
if zorder is None:
zorder = 0
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
zorder = kwargs.pop('zorder', None)
if zorder is None:
zorder = 0
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
graphics.setVisible(visible)
return graphics
@ -1126,14 +1125,14 @@ class MapAxes(Axes):
if antialias is not None:
igraphic.setAntiAlias(antialias)
if visible:
zorder = kwargs.pop('zorder', None)
if zorder is None:
zorder = 0
igraphic = self.add_graphic(igraphic, zorder=zorder)
self.set_draw_extent(igraphic.getExtent())
gridline = self._axes.getGridLine()
gridline.setTop(True)
zorder = kwargs.pop('zorder', None)
if zorder is None:
zorder = 0
igraphic = self.add_graphic(igraphic, zorder=zorder)
self.set_draw_extent(igraphic.getExtent())
igraphic.setVisible(visible)
gridline = self._axes.getGridLine()
gridline.setTop(True)
return igraphic
@ -1193,10 +1192,10 @@ class MapAxes(Axes):
graphics.setAntiAlias(antialias)
visible = kwargs.pop('visible', True)
if visible:
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
graphics.setVisible(visible)
return graphics
@ -1247,12 +1246,12 @@ class MapAxes(Axes):
proj = kwargs.pop('proj', migeo.projinfo())
visible = kwargs.pop('visible', True)
if visible:
zorder = kwargs.pop('zorder', None)
if zorder is None:
zorder = 0
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
zorder = kwargs.pop('zorder', None)
if zorder is None:
zorder = 0
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
graphics.setVisible(visible)
return graphics
@ -1347,10 +1346,10 @@ class MapAxes(Axes):
graphics.setAvoidCollision(avoidcoll)
visible = kwargs.pop('visible', True)
if visible:
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
graphics.setVisible(visible)
return graphics
@ -1443,10 +1442,10 @@ class MapAxes(Axes):
proj = kwargs.pop('proj', migeo.projinfo())
visible = kwargs.pop('visible', True)
if visible:
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
graphics.setVisible(visible)
return graphics
@ -1521,10 +1520,10 @@ class MapAxes(Axes):
graphics.setAntiAlias(antialias)
visible = kwargs.pop('visible', True)
if visible:
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
graphics.setVisible(visible)
return graphics
@ -1559,10 +1558,10 @@ class MapAxes(Axes):
graphics.setAvoidCollision(avoidcoll)
visible = kwargs.pop('visible', True)
if visible:
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
zorder = kwargs.pop('zorder', None)
graphics = self.add_graphic(graphics, projection=proj, zorder=zorder)
self.set_draw_extent(graphics.getExtent())
graphics.setVisible(visible)
return graphics

View File

@ -12,6 +12,7 @@ from org.meteoinfo.geometry.legend import LineStyles, HatchStyle, ColorBreak, Po
PolygonBreak, ArrowBreak, ArrowLineBreak, ArrowPolygonBreak, StreamlineBreak, \
PointStyle, MarkerType, LegendScheme, LegendManage, ExtendFraction
from org.meteoinfo.geometry.colors import ExtendType
from org.meteoinfo.geometry.graphic import Graphic
from org.meteoinfo.common.colors import ColorUtil, ColorMap
from org.meteoinfo.geometry.shape import ShapeTypes
from org.meteoinfo.chart import ChartText
@ -1195,6 +1196,11 @@ def makelegend(source, **kwargs):
if isinstance(source, list):
if isinstance(source[0], ColorBreak):
ls = LegendScheme(source)
elif isinstance(source[0], Graphic):
breaks = []
for g in source:
breaks.append(g.getLegend())
ls = LegendScheme(breaks)
else:
colors = getcolors(source)
values = kwargs.pop('values', None)