@Override public void doWork() throws OperatorException { DataTable table = null; if (isParameterSet(PARAMETER_LOG_NAME)) { String dataTableName = getParameterAsString(PARAMETER_LOG_NAME); table = getProcess().getDataTable(dataTableName); } else { if (getProcess().getDataTables().size() > 0) { table = getProcess().getDataTables().iterator().next(); logNote("No log name was specified, using first data table found..."); } } // check if (table == null) { throw new UserError(this, 939); } // create attributes List<Attribute> attributes = new ArrayList<Attribute>(); for (int i = 0; i < table.getNumberOfColumns(); i++) { String name = table.getColumnName(i); if (table.isDate(i)) { attributes.add(AttributeFactory.createAttribute(name, Ontology.DATE)); } else if (table.isDateTime(i)) { attributes.add(AttributeFactory.createAttribute(name, Ontology.DATE_TIME)); } else if (table.isNumerical(i)) { attributes.add(AttributeFactory.createAttribute(name, Ontology.REAL)); } else { attributes.add(AttributeFactory.createAttribute(name, Ontology.NOMINAL)); } } // create table MemoryExampleTable exampleTable = new MemoryExampleTable(attributes); for (int r = 0; r < table.getNumberOfRows(); r++) { DataTableRow row = table.getRow(r); double[] data = new double[attributes.size()]; for (int i = 0; i < table.getNumberOfColumns(); i++) { if (table.isDate(i)) { data[i] = row.getValue(i); } else if (table.isDateTime(i)) { data[i] = row.getValue(i); } else if (table.isNumerical(i)) { data[i] = row.getValue(i); } else { Attribute attribute = attributes.get(i); String value = table.getValueAsString(row, i); data[i] = attribute.getMapping().mapString(value); } } exampleTable.addDataRow(new DoubleArrayDataRow(data)); } // create and return example set exampleSetOutput.deliver(exampleTable.createExampleSet()); dummyPorts.passDataThrough(); }
@Override public void update() { if (getAxis(0) != -1 && getAxis(1) != -1) { getPlotPanel().removeAllPlots(); int totalNumberOfColumns = countColumns(); for (int currentVariable = 0; currentVariable < totalNumberOfColumns; currentVariable++) { if (getPlotColumn(currentVariable)) { DataTable table = getDataTable(); synchronized (table) { Iterator iterator = table.iterator(); int i = 0; double[][] data = new double[getDataTable().getNumberOfRows()][2]; double[][] deviation = new double[getDataTable().getNumberOfRows()][2]; while (iterator.hasNext()) { DataTableRow row = (DataTableRow) iterator.next(); data[i][0] = row.getValue(getAxis(0)); if (Double.isNaN(data[i][0])) { data[i][0] = 0.0d; } data[i][1] = row.getValue(getAxis(1)); if (Double.isNaN(data[i][1])) { data[i][1] = 0.0d; } deviation[i][0] = deviation[i][1] = row.getValue(currentVariable); if (Double.isNaN(deviation[i][0])) { deviation[i][0] = deviation[i][1] = 0.0d; } i++; } // PlotPanel construction Color color = getColorProvider() .getPointColor((double) (currentVariable + 1) / (double) totalNumberOfColumns); ((Plot2DPanel) getPlotPanel()) .addBoxPlot(getDataTable().getColumnName(currentVariable), color, data, deviation); } } } } else { getPlotPanel().removeAllPlots(); } }
private JFreeChart createChart() { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart( null, // chart title null, // x axis label null, // y axis label null, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customization... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis)); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); chart.getXYPlot().setDomainAxis(domainAxis); } } else { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false); ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false); } ValueAxis xAxis = plot.getDomainAxis(); if (indexAxis > -1) xAxis.setLabel(getDataTable().getColumnName(indexAxis)); else xAxis.setLabel(SERIESINDEX_LABEL); xAxis.setAutoRange(true); xAxis.setLabelFont(LABEL_FONT_BOLD); xAxis.setTickLabelFont(LABEL_FONT); xAxis.setVerticalTickLabels(isLabelRotating()); if (indexAxis > 0) { if (getRangeForDimension(indexAxis) != null) { xAxis.setRange(getRangeForDimension(indexAxis)); } } else { if (getRangeForName(SERIESINDEX_LABEL) != null) { xAxis.setRange(getRangeForName(SERIESINDEX_LABEL)); } } // renderer and range axis synchronized (dataTable) { int numberOfSelectedColumns = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { numberOfSelectedColumns++; } } } int columnCount = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { // YIntervalSeries series = new YIntervalSeries(this.dataTable.getColumnName(c)); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries(dataTable.getColumnName(c)); Iterator<DataTableRow> i = dataTable.iterator(); int index = 1; while (i.hasNext()) { DataTableRow row = i.next(); double value = row.getValue(c); if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { double indexValue = row.getValue(indexAxis); series.add(indexValue, value); } else { series.add(index++, value); } } dataset.addSeries(series); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Color color = getColorProvider().getPointColor(1.0d); if (numberOfSelectedColumns > 1) { color = getColorProvider() .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1)); } renderer.setSeriesPaint(0, color); renderer.setSeriesStroke( 0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); renderer.setSeriesShapesVisible(0, false); NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c)); if (getRangeForDimension(c) != null) { yAxis.setRange(getRangeForDimension(c)); } else { yAxis.setAutoRange(true); yAxis.setAutoRangeStickyZero(false); yAxis.setAutoRangeIncludesZero(false); } yAxis.setLabelFont(LABEL_FONT_BOLD); yAxis.setTickLabelFont(LABEL_FONT); if (numberOfSelectedColumns > 1) { yAxis.setAxisLinePaint(color); yAxis.setTickMarkPaint(color); yAxis.setLabelPaint(color); yAxis.setTickLabelPaint(color); } plot.setRangeAxis(columnCount, yAxis); plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT); plot.setDataset(columnCount, dataset); plot.setRenderer(columnCount, renderer); plot.mapDatasetToRangeAxis(columnCount, columnCount); columnCount++; } } } } chart.setBackgroundPaint(Color.white); return chart; }