Skip to content

Commit

Permalink
more map making options
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmilner committed Aug 15, 2023
1 parent c25f08d commit e8f8d3d
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions src/main/java/org/opensha/commons/gui/plot/GeographicMapMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public class GeographicMapMaker {
*/
protected List<Location> scatterLocs;
protected List<Double> scatterScalars;
protected List<PlotCurveCharacterstics> scatterChars;
protected CPT scatterScalarCPT;
protected String scatterScalarLabel;
protected Color scatterColor;
Expand Down Expand Up @@ -170,10 +171,12 @@ public class GeographicMapMaker {
protected List<Location> surfMiddles;

public GeographicMapMaker(Region region) {
this(region, PoliticalBoundariesData.loadDefaultOutlines(region));
}

public GeographicMapMaker(Region region, XY_DataSet[] politicalBoundaries) {
this.region = region;

// political boundary special cases
politicalBoundaries = PoliticalBoundariesData.loadDefaultOutlines(region);
this.politicalBoundaries = politicalBoundaries;
}

public static Region buildBufferedRegion(Collection<? extends FaultSection> sects) {
Expand Down Expand Up @@ -471,6 +474,22 @@ public void plotScatters(List<Location> locs, Color color) {
this.scatterColor = color;
}

public void plotScatters(List<Location> locs, List<PlotCurveCharacterstics> chars, String label) {
clearScatters();
Preconditions.checkState(locs.size() == chars.size());
this.scatterLocs = locs;
this.scatterChars = chars;
this.scatterScalarLabel = label;
}

public void plotScatters(List<Location> locs, List<PlotCurveCharacterstics> chars, PlotSymbol outlineSymbol, String label) {
clearScatters();
Preconditions.checkState(locs.size() == chars.size());
this.scatterLocs = locs;
this.scatterChars = chars;
this.scatterScalarLabel = label;
}

public void plotScatterScalars(List<Location> locs, List<Double> values, CPT cpt, String label) {
clearScatters();
Preconditions.checkState(locs.size() == values.size());
Expand All @@ -484,6 +503,7 @@ public void plotScatterScalars(List<Location> locs, List<Double> values, CPT cpt
public void clearScatters() {
this.scatterLocs = null;
this.scatterScalars = null;
this.scatterChars = null;
this.scatterScalarCPT = null;
this.scatterScalarLabel = null;
this.scatterColor = null;
Expand Down Expand Up @@ -782,7 +802,7 @@ protected void plotSects() {

// we'll plot fault traces if we don't have scalar values
boolean doTraces = sectScalars == null && sectColors == null;
if (!doTraces && skipNaNs &&
if (!doTraces && !skipNaNs &&
(sectScalars != null && Double.isNaN(sectScalars[s]) || sectColors != null && sectColors.get(s) == null))
doTraces = true;

Expand Down Expand Up @@ -1059,8 +1079,8 @@ protected void plotJumps() {
protected void plotScatters() {
if (scatterLocs == null || scatterLocs.isEmpty())
return;
XY_DataSet outlines = scatterOutline == null ? null : new DefaultXY_DataSet();
if (scatterScalars != null) {
XY_DataSet outlines = scatterOutline == null ? null : new DefaultXY_DataSet();
List<ComparablePairing<Double, XY_DataSet>> sortables = new ArrayList<>();
for (int j=0; j<scatterLocs.size(); j++) {
double scalar = scatterScalars.get(j);
Expand Down Expand Up @@ -1100,9 +1120,38 @@ else if (scatterSymbolWidth > 4f)
chars.add(new PlotCurveCharacterstics(scatterOutline, scatterSymbolWidth, scatterOutlineColor));
}

if (scatterScalarLabel != null)
cptLegend.add(buildCPTLegend(scatterScalarCPT, scatterScalarLabel));
} else if (scatterChars != null) {
for (int j=0; j<scatterLocs.size(); j++) {
Location loc = scatterLocs.get(j);
PlotCurveCharacterstics xyChar = scatterChars.get(j);

XY_DataSet xy = new DefaultXY_DataSet();
xy.set(loc.getLongitude(), loc.getLatitude());

funcs.add(xy);
chars.add(xyChar);

if (writeGeoJSON) {
Color color = xyChar.getColor();
FeatureProperties props = new FeatureProperties();
props.set(FeatureProperties.MARKER_COLOR_PROP, color);
float width = xyChar.getSymbolWidth();
if (width > 8f)
props.set(FeatureProperties.MARKER_SIZE_PROP, FeatureProperties.MARKER_SIZE_LARGE);
else if (width > 4f)
props.set(FeatureProperties.MARKER_SIZE_PROP, FeatureProperties.MARKER_SIZE_MEDIUM);
else
props.set(FeatureProperties.MARKER_SIZE_PROP, FeatureProperties.MARKER_SIZE_SMALL);
features.add(new Feature(new Geometry.Point(loc), props));
}
}

if (scatterScalarLabel != null)
cptLegend.add(buildCPTLegend(scatterScalarCPT, scatterScalarLabel));
} else {
XY_DataSet outlines = scatterOutline == null ? null : new DefaultXY_DataSet();
Preconditions.checkNotNull(scatterColor);
XY_DataSet xy = new DefaultXY_DataSet();
LocationList locs = new LocationList();
Expand Down

0 comments on commit e8f8d3d

Please sign in to comment.