Class GraphicsUtils
- java.lang.Object
-
- uk.ac.rdg.resc.edal.graphics.utils.GraphicsUtils
-
- All Implemented Interfaces:
Serializable
public class GraphicsUtils extends Object implements Serializable
Class containing static utility methods for dealing with graphics- Author:
- Guy Griffiths
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GraphicsUtils.ColorAdapter
-
Constructor Summary
Constructors Constructor Description GraphicsUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
colourToHtmlString(Color colour)
static String
colourToString(Color colour)
static BufferedImage
drawCategoricalLegend(Map<Integer,Parameter.Category> categories)
Renders a legend for categorical datastatic Extent<Float>
estimateValueRange(Dataset dataset, String varId)
Estimate the range of values in this layer by reading a sample of data from the default time and elevation.static Collection<? extends DiscreteFeature<?,?>>
extractGeneralMapFeatures(Dataset dataset, String varId, PlottingDomainParams params)
Convenience method to extract map features for a single variable in a generic dataset.static Color[]
generateColourSet(Color[] palette, int numColorBands)
Gets a version of this palette with the given number of color bands, either by subsampling or interpolating the existing palettestatic Map<Integer,Color>
getColourMapForCategories(Map<Integer,Parameter.Category> categories)
static Collection<String>
getNamedColours()
static Color
parseColour(String colourString)
Parses a string to obtain aColor
.static BufferedImage
plotDefaultImage(Dataset dataset, String varId, int width, int height)
Draws a raster image from the supplied dataset and variablestatic double
roundToSignificantFigures(double num, int n)
Rounds a double to a number of significant figures Taken from: http://stackoverflow.com/questions/202302/rounding-to-an-arbitrary -number-of-significant-digits
-
-
-
Method Detail
-
extractGeneralMapFeatures
public static Collection<? extends DiscreteFeature<?,?>> extractGeneralMapFeatures(Dataset dataset, String varId, PlottingDomainParams params)
Convenience method to extract map features for a single variable in a generic dataset.- Parameters:
dataset
- The Dataset to extract features fromvarId
- The variable ID to extractparams
- ThePlottingDomainParams
representing the domain to extract onto- Returns:
- A
Collection
ofDiscreteFeature
s
-
parseColour
public static Color parseColour(String colourString) throws EdalParseException
Parses a string to obtain aColor
.- Parameters:
colourString
- A string of one of the forms:- 0xRRGGBB
- 0xAARRGGBB
- #RRGGBB
- #AARRGGBB
- "transparent"
- "extend"
- A named colour. See
getNamedColours()
for a full list- Returns:
- A
Color
representing the string, ornull
if "extend" was supplied - Throws:
EdalParseException
- If the format of the string does not fall into one of the above categories
-
getNamedColours
public static Collection<String> getNamedColours()
- Returns:
- The available named colours
-
estimateValueRange
public static Extent<Float> estimateValueRange(Dataset dataset, String varId)
Estimate the range of values in this layer by reading a sample of data from the default time and elevation. If the given variable is not found, a default range of 0-100 is returned- Parameters:
dataset
- The dataset containing the variable to estimatevarId
- The ID of the variable to estimate- Returns:
- An approximate value range
-
roundToSignificantFigures
public static double roundToSignificantFigures(double num, int n)
Rounds a double to a number of significant figures Taken from: http://stackoverflow.com/questions/202302/rounding-to-an-arbitrary -number-of-significant-digits- Parameters:
num
- The number to roundn
- The number of significant figures- Returns:
- The rounded number
-
generateColourSet
public static Color[] generateColourSet(Color[] palette, int numColorBands)
Gets a version of this palette with the given number of color bands, either by subsampling or interpolating the existing palette- Parameters:
numColorBands
- The number of bands of colour to be used in the new palette- Returns:
- An array of Colors, with length numColorBands
-
getColourMapForCategories
public static Map<Integer,Color> getColourMapForCategories(Map<Integer,Parameter.Category> categories)
-
drawCategoricalLegend
public static BufferedImage drawCategoricalLegend(Map<Integer,Parameter.Category> categories)
Renders a legend for categorical data- Parameters:
categories
- The categories to draw a legend for- Returns:
- The resulting BufferedImage
-
plotDefaultImage
public static BufferedImage plotDefaultImage(Dataset dataset, String varId, int width, int height)
Draws a raster image from the supplied dataset and variable- Parameters:
dataset
- The dataset containing the datavarId
- The ID of the variable to plotwidth
- The desired width of the output imageheight
- The desired height of the output image- Returns:
- A
BufferedImage
containing the plot
-
-