本文整理汇总了Java中de.erichseifert.gral.data.DataSource类的典型用法代码示例。如果您正苦于以下问题:Java DataSource类的具体用法?Java DataSource怎么用?Java DataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataSource类属于de.erichseifert.gral.data包,在下文中一共展示了DataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReader
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testReader() throws IOException, ParseException {
DataReader reader = DataReaderFactory.getInstance().get("image/png");
DataSource data = reader.read(imageData);
assertEquals(3, data.getColumnCount());
assertEquals(4, data.getRowCount());
double[] expected = new double[] {
255.0, 0.0, 0.0,
0.0, 255.0, 0.0,
0.0, 0.0, 255.0,
127.0, 127.0, 127.0
};
for (int i = 0; i < expected.length; i++) {
int col = i % 3;
int row = i / 3;
double value = ((Number) data.get(col, row)).doubleValue();
assertEquals(expected[i], value, DELTA);
}
}
示例2: Histogram2D
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
/**
* Initializes a new histogram with the specified data source and
* subdivisions at the specified positions.
* @param data Data source to be analyzed.
* @param orientation Orientation in which the data should be sampled.
* @param breaks Values of where a subdivision should occur.
*/
public Histogram2D(DataSource data, Orientation orientation,
Number[]... breaks) {
this(data, orientation);
int count = getData().getColumnCount();
if (orientation == Orientation.HORIZONTAL) {
count = getData().getRowCount();
}
if (breaks.length != count) {
throw new IllegalArgumentException(MessageFormat.format(
"Invalid number of breaks: got {0,number,integer}, expected {1,number,integer}.", //$NON-NLS-1$
breaks.length, count));
}
Collections.addAll(this.breaks, breaks);
dataUpdated(getData());
}
示例3: XYPlot
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
/**
* Initializes a new instance object with the specified data sources and
* reasonable default settings.
* @param data Data to be displayed.
*/
public XYPlot(DataSource... data) {
super();
pointRenderersByDataSource = new HashMap<>(data.length);
lineRenderersByDataSource = new HashMap<>(data.length);
areaRenderersByDataSource = new HashMap<>(data.length);
setPlotArea(new XYPlotArea2D(this));
setLegend(new XYLegend(this));
// Handle data sources after the renderer lists are initialized
for (DataSource source : data) {
add(source);
}
createDefaultAxes();
autoscaleAxes();
createDefaultAxisRenderers();
// Listen for changes of the axis range
for (String axisName : getAxesNames()) {
getAxis(axisName).addAxisListener(this);
}
}
示例4: setPointRenderers
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
/**
* Sets the {@code PointRenderer}s for a certain data source to the specified value.
* @param s Data source.
* @param pointRendererFirst First PointRenderer.
* @param pointRenderers Remaining PointRenderers to be set.
*/
public void setPointRenderers(DataSource s, PointRenderer pointRendererFirst, PointRenderer... pointRenderers) {
List<PointRenderer> pointRendererList = null;
if (pointRendererFirst == null) {
setPointRenderers(s, pointRendererList);
return;
}
pointRendererList = new ArrayList<>(pointRenderers.length + 1);
pointRendererList.add(pointRendererFirst);
for (PointRenderer pointRenderer : pointRenderers) {
if (pointRenderer == null) {
throw new IllegalArgumentException("A PointRenderer for a DataSource cannot be null.");
}
pointRendererList.add(pointRenderer);
}
setPointRenderers(s, pointRendererList);
}
示例5: setLineRenderers
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
/**
* Sets the {@code LineRenderer}s for a certain data source to the specified
* value.
* @param s Data source.
* @param lineRendererFirst First {@code LineRenderer} to be set.
* @param lineRenderers Remaining {@code LineRenderer}s to be set.
*/
public void setLineRenderers(DataSource s, LineRenderer lineRendererFirst, LineRenderer... lineRenderers) {
List<LineRenderer> lineRendererList = null;
if (lineRendererFirst == null) {
setLineRenderers(s, lineRendererList);
return;
}
lineRendererList = new ArrayList<>(lineRenderers.length + 1);
lineRendererList.add(lineRendererFirst);
for (LineRenderer lineRenderer : lineRenderers) {
if (lineRenderer == null) {
throw new IllegalArgumentException("A LineRenderer for a DataSource cannot be null.");
}
lineRendererList.add(lineRenderer);
}
setLineRenderers(s, lineRendererList);
}
示例6: PiePlot
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
/**
* Initializes a new pie plot with the specified data source.
* @param data Data to be displayed.
*/
public PiePlot(DataSource data) {
super();
center = new Point2D.Double(0.5, 0.5);
radius = 1.0;
start = 0.0;
clockwise = true;
pointRenderers = new HashMap<>();
setPlotArea(new PiePlotArea2D(this));
setLegend(new PiePlotLegend(this));
add(data);
createDefaultAxes();
createDefaultAxisRenderers();
dataUpdated(data);
}
示例7: RasterPlot
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
/**
* Initializes a new box-and-whisker plot with the specified data source.
* @param data Data to be displayed.
*/
public RasterPlot(DataSource data) {
offset = new Point2D.Double();
distance = new de.erichseifert.gral.graphics.Dimension2D.Double(1.0, 1.0);
colors = new Grayscale();
((XYPlotArea2D) getPlotArea()).setMajorGridX(false);
((XYPlotArea2D) getPlotArea()).setMajorGridY(false);
//getAxisRenderer(AXIS_X).setSetting(AxisRenderer.TICKS, false);
//getAxisRenderer(AXIS_Y).setSetting(AxisRenderer.TICKS, false);
getAxisRenderer(AXIS_X).setIntersection(-Double.MAX_VALUE);
getAxisRenderer(AXIS_Y).setIntersection(-Double.MAX_VALUE);
// Store data
add(data);
// Adjust axes to the data series
autoscaleAxes();
}
示例8: setLegend
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
/**
* Sets the legend to the specified value.
* @param legend Legend to be set.
*/
protected void setLegend(Legend legend) {
if (this.legend != null) {
legendContainer.remove(this.legend);
this.legend.clear();
this.legend.setBaseFont(null);
}
this.legend = legend;
if (this.legend != null) {
this.legend.setBaseFont(font);
Location constraints = getLegendLocation();
legendContainer.add(legend, constraints);
for (DataSource source : getVisibleData()) {
legend.add(source);
}
}
}
示例9: remove
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
@Override
public void remove(DataSource source) {
super.remove(source);
Set<Row> rows = new HashSet<>(components.keySet());
for (Row row : rows) {
if (row.getSource() != source) {
continue;
}
Drawable item = components.remove(row);
if (item != null) {
remove(item);
}
}
refresh();
source.removeDataListener(this);
}
示例10: testDataVisibility
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
@Test
public void testDataVisibility() {
// get
assertTrue(plot.isVisible(series1));
assertTrue(plot.isVisible(series2));
// set
plot.setVisible(series1, false);
assertFalse(plot.isVisible(series1));
plot.setVisible(series1, true);
assertTrue(plot.isVisible(series1));
// get all
List<DataSource> all = plot.getData();
List<DataSource> visible = plot.getVisibleData();
assertEquals(all.size(), visible.size());
for (int i = 0; i < all.size(); i++) {
assertEquals(all.get(i), visible.get(i));
}
plot.setVisible(series1, false);
assertEquals(visible.size() - 1, plot.getVisibleData().size());
assertEquals(all.get(1), plot.getVisibleData().get(0));
}
示例11: testSeparator
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testSeparator() throws IOException {
InputStream input = new ByteArrayInputStream((
"0;10.0;20\r\n" +
"1;11.0;21\r\n" +
"2;12.0;22\r\n"
).getBytes());
DataReader reader = DataReaderFactory.getInstance().get("text/csv");
reader.setSetting(CSVReader.SEPARATOR_CHAR, ';');
DataSource data = reader.read(input, Integer.class, Double.class, Double.class);
assertEquals( 0, data.get(0, 0));
assertEquals( 1, data.get(0, 1));
assertEquals( 2, data.get(0, 2));
assertEquals(10.0, data.get(1, 0));
assertEquals(11.0, data.get(1, 1));
assertEquals(12.0, data.get(1, 2));
assertEquals(20.0, data.get(2, 0));
assertEquals(21.0, data.get(2, 1));
assertEquals(22.0, data.get(2, 2));
}
示例12: testEmptyValues
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testEmptyValues() throws IOException, ParseException {
InputStream input = new ByteArrayInputStream((
"0,10.0,\r\n" +
"1,,21\r\n" +
",,3\r\n"
).getBytes());
DataReader reader = DataReaderFactory.getInstance().get("text/csv");
DataSource data = reader.read(input, Integer.class, Double.class, Double.class);
assertEquals( 0, data.get(0, 0));
assertEquals(10.0, data.get(1, 0));
assertNull( data.get(2, 0));
assertEquals( 1, data.get(0, 1));
assertNull( data.get(1, 1));
assertEquals(21.0, data.get(2, 1));
assertNull( data.get(0, 2));
assertNull( data.get(1, 2));
assertEquals( 3.0, data.get(2, 2));
}
示例13: testSerialization
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
@Test
public void testSerialization() throws IOException, ClassNotFoundException {
BoxPlot original = plot;
BoxPlot deserialized = TestUtils.serializeAndDeserialize(original);
assertEquals(original.getBackground(), deserialized.getBackground());
assertEquals(original.getBorderStroke(), deserialized.getBorderStroke());
assertEquals(original.getBorderColor(), deserialized.getBorderColor());
assertEquals(original.isLegendVisible(), deserialized.isLegendVisible());
assertEquals(original.getLegendLocation(), deserialized.getLegendLocation());
assertEquals(original.getLegendDistance(), deserialized.getLegendDistance(), DELTA);
List<DataSource> dataSourcesOriginal = original.getData();
List<DataSource> dataSourcesDeserialized = deserialized.getData();
assertEquals(dataSourcesOriginal.size(), dataSourcesDeserialized.size());
for (int index = 0; index < dataSourcesOriginal.size(); index++) {
List<PointRenderer> pointRenderersOriginal = original.getPointRenderers(
dataSourcesOriginal.get(index));
List<PointRenderer> pointRenderersDeserialized = deserialized.getPointRenderers(
dataSourcesDeserialized.get(index));
testPointRendererSerialization(pointRenderersOriginal, pointRenderersDeserialized);
}
}
示例14: formatFilledArea
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
private static void formatFilledArea(XYPlot plot, DataSource data, Color color) {
PointRenderer point = new DefaultPointRenderer2D();
point.setColor(color);
plot.setPointRenderer(data, point);
LineRenderer line = new DefaultLineRenderer2D();
line.setColor(color);
line.setGap(3.0);
line.setGapRounded(true);
plot.setLineRenderer(data, line);
AreaRenderer area = new DefaultAreaRenderer2D();
area.setColor(GraphicsUtils.deriveWithAlpha(color, 64));
plot.setAreaRenderer(data, area);
}
示例15: formatLineArea
import de.erichseifert.gral.data.DataSource; //导入依赖的package包/类
private static void formatLineArea(XYPlot plot, DataSource data, Color color) {
PointRenderer point = new DefaultPointRenderer2D();
point.setColor(color);
plot.setPointRenderer(data, point);
plot.setLineRenderer(data, null);
AreaRenderer area = new LineAreaRenderer2D();
area.setGap(3.0);
area.setColor(color);
plot.setAreaRenderer(data, area);
}