List of usage examples for org.jfree.data.statistics HistogramType FREQUENCY
HistogramType FREQUENCY
To view the source code for org.jfree.data.statistics HistogramType FREQUENCY.
Click Source Link
From source file:ucar.unidata.idv.control.chart.HistogramWrapper.java
/** * Plot the displayed {@link DataChoice}. * // w w w .j av a 2 s. c om * @param histoWrapper Cannot be {@code null}. */ public static void plotHistogram(HistogramWrapper histoWrapper) { XYPlot p = histoWrapper.plot; List<DataChoiceWrapper> dcWrappers = histoWrapper.getDataChoiceWrappers(); try { for (int dataSetIdx = 0; dataSetIdx < p.getDatasetCount(); dataSetIdx++) { MyHistogramDataset dataset = (MyHistogramDataset) p.getDataset(dataSetIdx); dataset.removeAllSeries(); } Hashtable props = new Hashtable(); props.put(TrackDataSource.PROP_TRACKTYPE, TrackDataSource.ID_TIMETRACE); for (int paramIdx = 0; paramIdx < dcWrappers.size(); paramIdx++) { DataChoiceWrapper wrapper = dcWrappers.get(paramIdx); DataChoice dataChoice = wrapper.getDataChoice(); FlatField data = histoWrapper.getFlatField((FieldImpl) dataChoice.getData(null, props)); Unit unit = ucar.visad.Util.getDefaultRangeUnits((FlatField) data)[0]; double[][] samples = data.getValues(false); double[] actualValues = histoWrapper.filterData(samples[0], histoWrapper.getTimeValues(samples, data))[0]; NumberAxis domainAxis = new NumberAxis(wrapper.getLabel(unit)); XYItemRenderer renderer; if (histoWrapper.stacked) { renderer = new StackedXYBarRenderer(); } else { renderer = new XYBarRenderer(); } p.setRenderer(paramIdx, renderer); Color c = wrapper.getColor(paramIdx); domainAxis.setLabelPaint(c); renderer.setSeriesPaint(0, c); MyHistogramDataset dataset = new MyHistogramDataset(); dataset.setType(HistogramType.FREQUENCY); dataset.addSeries(dataChoice.getName() + " [" + unit + "]", actualValues, histoWrapper.bins); p.setDomainAxis(paramIdx, domainAxis, false); p.mapDatasetToDomainAxis(paramIdx, paramIdx); p.setDataset(paramIdx, dataset); } } catch (VisADException | RemoteException e) { LogUtil.logException("Error creating data set", e); } }
From source file:org.utgenome.core.cui.DrawHistogram.java
public void execute() throws Exception { InputStream in = null;// w w w . j a va2 s . c o m if ("-".equals(input)) { _logger.info("reading from STDIN"); in = new StandardInputStream(); } else { _logger.info("reading from " + input); in = new FileInputStream(input); } List<Double> data = new ArrayList<Double>(); BufferedReader dataSetInput = new BufferedReader(new InputStreamReader(in)); int lineCount = 1; try { // read data set boolean cutOffTail = !Double.isNaN(xMax); boolean cutOffHead = !Double.isNaN(xMin); for (String line; (line = dataSetInput.readLine()) != null; lineCount++) { if (lineCount % 100000 == 0) _logger.info(String.format("read %,d data points", lineCount)); if (line.startsWith("#")) continue; double v = Double.parseDouble(line); if (cutOffTail && v > xMax) continue; if (cutOffHead && v < xMin) continue; data.add(v); } double[] value = new double[data.size()]; for (int i = 0; i < data.size(); ++i) { value[i] = data.get(i); } // draw histogram HistogramDataset dataSet = new HistogramDataset(); dataSet.setType(HistogramType.FREQUENCY); dataSet.addSeries("data", value, numBins); JFreeChart chart = ChartFactory.createHistogram(null, null, "Frequency", dataSet, PlotOrientation.VERTICAL, false, false, false); if (title != null) { chart.setTitle(title); } ValueAxis domainAxis = chart.getXYPlot().getDomainAxis(); if (cutOffHead) { domainAxis.setLowerBound(xMin); } if (cutOffTail) { domainAxis.setUpperBound(xMax); } if (xLabel != null) { domainAxis.setLabel(xLabel); } if (yLog) { LogarithmicAxis logAxis = new LogarithmicAxis("Frequency"); logAxis.setAllowNegativesFlag(true); logAxis.setAutoRangeIncludesZero(true); chart.getXYPlot().setRangeAxis(logAxis); } if (!Double.isNaN(yMin)) { chart.getXYPlot().getRangeAxis().setLowerBound(yMin); } if (!Double.isNaN(yMax)) { chart.getXYPlot().getRangeAxis().setUpperBound(yMax); } File outputFile = new File(output); _logger.info("output to " + outputFile); ChartUtilities.saveChartAsPNG(outputFile, chart, width, height); } catch (Exception e) { throw new Exception(String.format("error at line %d: %s", lineCount, e)); } }
From source file:presenter.MainPresenter.java
@Override public void createHistogram() { HistogramDataset histData = new HistogramDataset(); histData.setType(HistogramType.FREQUENCY); double[] values = this.emissionsequenceModel.getEmissionsAsArray(); histData.addSeries("H1", values, EmissionsequenceModel.EMISSIONCOUNT); JFreeChart chart;/*from ww w. ja va2s .c om*/ if (this.model != null) { chart = ChartFactory.createHistogram(this.model.getName(), "EmissionID", "Frequency", histData, PlotOrientation.VERTICAL, false, false, false); } else { chart = ChartFactory.createHistogram("unknown Model", "EmissionID", "Frequency", histData, PlotOrientation.VERTICAL, false, false, false); } new HistogramView(new ChartPanel(chart)); }
From source file:ucar.unidata.idv.control.McVHistogramWrapper.java
/** * Assumes that {@code data} has been validated and is okay to actually try * loading./*from w ww.j a va 2 s . c o m*/ * * @param data Data to use in histogram. Cannot be {@code null} or all NaNs. * * @throws VisADException * @throws RemoteException */ private void reallyLoadData(FlatField data) throws VisADException, RemoteException { createChart(); List dataChoiceWrappers = getDataChoiceWrappers(); try { clearHistogram(); ErrorEstimate[] errOut = new ErrorEstimate[1]; for (int paramIdx = 0; paramIdx < dataChoiceWrappers.size(); paramIdx++) { DataChoiceWrapper wrapper = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx); DataChoice dataChoice = wrapper.getDataChoice(); Unit defaultUnit = ucar.visad.Util.getDefaultRangeUnits((FlatField) data)[0]; Unit unit = ((DisplayControlImpl) imageControl).getDisplayUnit(); double[][] samples = data.getValues(false); double[] actualValues = filterData(samples[0], getTimeValues(samples, data))[0]; if ((defaultUnit != null) && !defaultUnit.equals(unit)) { actualValues = Unit.transformUnits(unit, errOut, defaultUnit, null, actualValues); } final NumberAxis domainAxis = new NumberAxis(wrapper.getLabel(unit)); domainAxis.setAutoRangeIncludesZero(false); XYItemRenderer renderer; if (getStacked()) { renderer = new StackedXYBarRenderer(); } else { renderer = new XYBarRenderer(); } if ((plot == null) && (chartPanel != null)) { plot = chartPanel.getChart().getXYPlot(); } plot.setRenderer(paramIdx, renderer); Color c = wrapper.getColor(paramIdx); domainAxis.setLabelPaint(c); renderer.setSeriesPaint(0, c); MyHistogramDataset dataset = new MyHistogramDataset(); dataset.setType(HistogramType.FREQUENCY); dataset.addSeries(dataChoice.getName() + " [" + unit + ']', actualValues, getBins()); samples = null; actualValues = null; plot.setDomainAxis(paramIdx, domainAxis, false); plot.mapDatasetToDomainAxis(paramIdx, paramIdx); plot.setDataset(paramIdx, dataset); domainAxis.addChangeListener(new AxisChangeListener() { public void axisChanged(AxisChangeEvent ae) { if (!imageControl.isInitDone()) { return; } Range range = domainAxis.getRange(); double newLow = Math.floor(range.getLowerBound() + 0.5); double newHigh = Math.floor(range.getUpperBound() + 0.5); double prevLow = getLow(); double prevHigh = getHigh(); try { ucar.unidata.util.Range newRange; if (prevLow > prevHigh) { newRange = new ucar.unidata.util.Range(newHigh, newLow); } else { newRange = new ucar.unidata.util.Range(newLow, newHigh); } ((DisplayControlImpl) imageControl).setRange(newRange); } catch (Exception e) { logger.error("Cannot change range", e); } } }); Range range = domainAxis.getRange(); low = range.getLowerBound(); high = range.getUpperBound(); } } catch (Exception exc) { System.out.println("Exception exc=" + exc); LogUtil.logException("Error creating data set", exc); } }
From source file:edu.wisc.ssec.mcidasv.control.McIDASVHistogramWrapper.java
/** * Assumes that {@code data} has been validated and is okay to actually try * loading.//w ww .j av a2 s . c o m * * @param data Data to use in histogram. Cannot be {@code null} or all NaNs. * * @throws VisADException * @throws RemoteException */ private void reallyLoadData(FlatField data) throws VisADException, RemoteException { createChart(); List dataChoiceWrappers = getDataChoiceWrappers(); try { clearHistogram(); Hashtable props = new Hashtable(); ErrorEstimate[] errOut = new ErrorEstimate[1]; for (int paramIdx = 0; paramIdx < dataChoiceWrappers.size(); paramIdx++) { DataChoiceWrapper wrapper = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx); DataChoice dataChoice = wrapper.getDataChoice(); props = dataChoice.getProperties(); Unit defaultUnit = ucar.visad.Util.getDefaultRangeUnits((FlatField) data)[0]; Unit unit = ((DisplayControlImpl) imageControl).getDisplayUnit(); double[][] samples = data.getValues(false); double[] actualValues = filterData(samples[0], getTimeValues(samples, data))[0]; if ((defaultUnit != null) && !defaultUnit.equals(unit)) { actualValues = Unit.transformUnits(unit, errOut, defaultUnit, null, actualValues); } final NumberAxis domainAxis = new NumberAxis(wrapper.getLabel(unit)); domainAxis.setAutoRangeIncludesZero(false); XYItemRenderer renderer; if (getStacked()) { renderer = new StackedXYBarRenderer(); } else { renderer = new XYBarRenderer(); } if ((plot == null) && (chartPanel != null)) { plot = chartPanel.getChart().getXYPlot(); } plot.setRenderer(paramIdx, renderer); Color c = wrapper.getColor(paramIdx); domainAxis.setLabelPaint(c); renderer.setSeriesPaint(0, c); MyHistogramDataset dataset = new MyHistogramDataset(); dataset.setType(HistogramType.FREQUENCY); dataset.addSeries(dataChoice.getName() + " [" + unit + ']', actualValues, getBins()); samples = null; actualValues = null; plot.setDomainAxis(paramIdx, domainAxis, false); plot.mapDatasetToDomainAxis(paramIdx, paramIdx); plot.setDataset(paramIdx, dataset); domainAxis.addChangeListener(new AxisChangeListener() { public void axisChanged(AxisChangeEvent ae) { if (!imageControl.isInitDone()) { return; } Range range = domainAxis.getRange(); double newLow = Math.floor(range.getLowerBound() + 0.5); double newHigh = Math.floor(range.getUpperBound() + 0.5); double prevLow = getLow(); double prevHigh = getHigh(); try { ucar.unidata.util.Range newRange; if (prevLow > prevHigh) { newRange = new ucar.unidata.util.Range(newHigh, newLow); } else { newRange = new ucar.unidata.util.Range(newLow, newHigh); } ((DisplayControlImpl) imageControl).setRange(newRange); } catch (Exception e) { logger.error("Cannot change range", e); } } }); Range range = domainAxis.getRange(); low = range.getLowerBound(); high = range.getUpperBound(); } } catch (Exception exc) { System.out.println("Exception exc=" + exc); LogUtil.logException("Error creating data set", exc); } }
From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java
private void createInputTab(final CTabFolder parentTabFolder) { inputTab = new CTabItem(parentTabFolder, SWT.NONE); inputTab.setText(Messages.ProcessExecutionDialog_tabparameters); ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL); scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Composite container = new Composite(scroller, SWT.NONE); container.setLayout(new GridLayout(2, false)); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); // local moran's i Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$ uiBuilder.createLabel(container, Messages.HistogramDialog_InputLayer, EMPTY, image, 2); cboLayer = uiBuilder.createCombo(container, 2, true); fillLayers(map, cboLayer, VectorLayerType.ALL); uiBuilder.createLabel(container, Messages.HistogramDialog_InputField, EMPTY, image, 2); cboField = uiBuilder.createCombo(container, 2, true); uiBuilder.createLabel(container, Messages.HistogramDialog_BinCount, EMPTY, image, 2); spinner = uiBuilder.createSpinner(container, 10, 1, 50, 0, 1, 5, 2); // yXais Type uiBuilder.createLabel(container, Messages.HistogramDialog_YAxisType, EMPTY, image, 1); GridLayout layout = new GridLayout(2, false); layout.marginWidth = 0;//from w ww .ja v a 2 s.c om Composite subCon = new Composite(container, SWT.NONE); subCon.setLayout(layout); subCon.setLayoutData(new GridData(SWT.LEFT_TO_RIGHT, SWT.CENTER, false, false, 1, 1)); final Button chkRatio = uiBuilder.createRadioButton(subCon, Messages.HistogramDialog_Ratio, null, 1); final Button chkFrequency = uiBuilder.createRadioButton(subCon, Messages.HistogramDialog_Frequency, null, 1); chkFrequency.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { if (chkFrequency.getSelection()) { histogramType = HistogramType.FREQUENCY; } } }); chkRatio.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { if (chkRatio.getSelection()) { histogramType = HistogramType.RELATIVE_FREQUENCY; } } }); chkRatio.setSelection(true); uiBuilder.createLabel(container, null, null, 2); chkStatistics = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_BasicStatistics, null, 2); // register events cboLayer.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { inputLayer = MapUtils.getLayer(map, cboLayer.getText()); if (inputLayer != null) { fillFields(cboField, inputLayer.getSchema(), FieldType.Number); } } }); // finally scroller.setContent(container); inputTab.setControl(scroller); scroller.setMinSize(450, container.getSize().y - 2); scroller.setExpandVertical(true); scroller.setExpandHorizontal(true); scroller.pack(); container.pack(); }
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Build new histogram from the given numbers array using a default title and xLabel. * String dataName will be used for yLabel. * @param numbers Numbers for the histogram * @param dataName Name of the numbers data * @param divisions Divisions for the histogram * @return Prepared histogram/*w w w.j ava2 s. c o m*/ */ public static JFreeChart buildHistogram(final Number[] numbers, final String dataName, final int divisions) { if (numbers == null || numbers.length == 0) { return null; } HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.FREQUENCY); double[] doubleNumbers = new double[numbers.length]; for (int i = 0; i < doubleNumbers.length; i++) { doubleNumbers[i] = numbers[i].doubleValue(); } dataset.addSeries(dataName, doubleNumbers, divisions > 0 ? divisions : 10);//Use 10 divisions if divisions number is invalid. JFreeChart histogram = ChartFactory.createHistogram(getMessage("ChartsUtils.report.histogram.title"), dataName, getMessage("ChartsUtils.report.histogram.yLabel"), dataset, PlotOrientation.VERTICAL, true, true, false); return histogram; }
From source file:net.bioclipse.chembl.moss.ui.wizard.ChemblMossWizardPage2.java
@Override public void createControl(Composite parent) { final Composite container = new Composite(parent, SWT.NONE); final GridLayout layout = new GridLayout(4, false); layout.marginRight = 2;/*from www . ja v a 2 s . c o m*/ layout.marginLeft = 2; layout.marginBottom = -2; layout.marginTop = 10; layout.marginWidth = 2; layout.marginHeight = 2; layout.verticalSpacing = 5; layout.horizontalSpacing = 5; container.setLayout(layout); PlatformUI.getWorkbench().getHelpSystem().setHelp(container, "net.bioclipse.moss.business.helpmessage"); setControl(container); setMessage("Select the first protein family to compare with substructure mining."); setPageComplete(true); label = new Label(container, SWT.NONE); gridData = new GridData(GridData.FILL); gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 2; label.setLayoutData(gridData); label.setText("Choose Kinase Protein Familes"); cbox = new Combo(container, SWT.READ_ONLY); cbox.setToolTipText("Kinase family"); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 2; gridData.widthHint = 100; cbox.setLayoutData(gridData); String[] items = { "TK", "TKL", "STE", "CK1", "CMGC", "AGC", "CAMK" }; cbox.setItems(items); cbox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { final String selected = cbox.getItem(cbox.getSelectionIndex()); try { table.clearAll(); table.removeAll(); setErrorMessage(null); List<String> list = chembl.mossAvailableActivities(selected); if (list.size() > 0) { String[] item = new String[list.size()]; for (int i = 0; i < list.size(); i++) { item[i] = list.get(i); } if (cboxAct.isEnabled()) { if (cboxAct.getSelection().x == cboxAct.getSelection().y) { cboxAct.setItems(item); } else { //Solves the problem involving changing the protein family... //Brings the current activities to an array String oldItems[] = cboxAct.getItems(); // Takes that array and makes it a list for (int i = 0; i < list.size(); i++) { cboxAct.add(item[i]); } //Remove the old items in the combobox int oldlistsize = cboxAct.getItemCount() - list.size(); index = cboxAct.getText();//cboxAct.getItem(cboxAct.getSelectionIndex()); cboxAct.remove(0, oldlistsize - 1); //Adds new items to the comboboxlist List<String> oldItemsList = new ArrayList<String>(); for (int i = 0; i < oldItems.length; i++) { oldItemsList.add(oldItems[i]); } //New query with the given settings //if(oldItemsList.contains((index))==true){ if (list.contains((index)) == true) { spinn.setSelection(50); IStringMatrix matrix, matrix2; try { matrix = chembl.mossGetCompoundsFromProteinFamilyWithActivity(selected, index, spinn.getSelection()); matrix2 = chembl.mossGetCompoundsFromProteinFamily(selected, index); cboxAct.setText(index); info.setText("Distinct compunds: " + matrix2.getRowCount()); addToTable(matrix); } catch (BioclipseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else { setErrorMessage("The activity " + index + " does not exist for the protein family " + selected + "."); info.setText("Total compund hit:"); setPageComplete(false); } } } else { cboxAct.setItems(item); cboxAct.setEnabled(true); } } } catch (BioclipseException e1) { e1.printStackTrace(); } } }); /*Returns the available compunds for the family*/ label = new Label(container, SWT.NONE); gridData = new GridData(GridData.FILL); gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 2; label.setLayoutData(gridData); label.setText("Choose one available activity"); cboxAct = new Combo(container, SWT.READ_ONLY); gridData = new GridData(GridData.FILL); gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 2; gridData.widthHint = 100; String[] item = { "No available activity" }; cboxAct.setItems(item); cboxAct.setLayoutData(gridData); cboxAct.setEnabled(false); cboxAct.setToolTipText("These activities are only accurate for chosen protein"); //Listener for available activities(IC50, Ki etc) cboxAct.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String selected = cboxAct.getItem(cboxAct.getSelectionIndex()); try { setErrorMessage(null); table.clearAll(); table.removeAll(); spinn.setSelection(50); check.setSelection(false); spinnLow.setEnabled(false); spinnHigh.setEnabled(false); spinnLow.setSelection(0); spinnHigh.setSelection(1000); //SPARQL queries for fetching compounds and activities IStringMatrix matrix = chembl.mossGetCompoundsFromProteinFamilyWithActivity( cbox.getItem(cbox.getSelectionIndex()), selected, spinn.getSelection()); addToTable(matrix); //Count the amount of compounds there is for one hit, i.e. same query without limit. IStringMatrix matrix2 = chembl.mossGetCompoundsFromProteinFamily( cbox.getItem(cbox.getSelectionIndex()), cboxAct.getItem(cboxAct.getSelectionIndex())); info.setText("Distinct compounds: " + matrix2.getRowCount()); //Query for activities. Adds them to the plot series. matrixAct = chembl.mossGetCompoundsFromProteinFamilyWithActivity( cbox.getItem(cbox.getSelectionIndex()), selected); //IStringMatrix matrix = chembl.MossProtFamilyCompounds(cbox.getItem(cbox.getSelectionIndex()), selected,50); //IStringMatrix matrix = chembl.MossProtFamilyCompounds(cbox.getItem(cbox.getSelectionIndex()), selected, spinn.getSelection()); //Adds activity to histogram series series = new XYSeries("Activity for compounds"); histogramSeries = new HistogramDataset(); histogramSeries.setType(HistogramType.FREQUENCY); ArrayList<Double> activites = new ArrayList<Double>(); double value; int cnt = 1; double[] histact = new double[matrixAct.getRowCount() + 1]; for (int i = 1; i < matrixAct.getRowCount() + 1; i++) { if (matrixAct.get(i, "actval").equals("")) { value = 0; } else { value = Double.parseDouble(matrixAct.get(i, "actval")); } activites.add(value); } //Sort list to increasing order of activities and adds them to histogram Collections.sort(activites); for (int i = 0; i < activites.size(); i++) { double d = activites.get(i); histact[i] = d; int t = activites.size() - 1; if (i == t) { series.add(d, cnt); } else { double dd = activites.get(i + 1); if (d == dd) { cnt++; } else { histact[i] = d; series.add(d, cnt); cnt = 1; } } } histogramSeries.addSeries("Histogram", histact, matrixAct.getRowCount()); button.setEnabled(true); spinn.setEnabled(true); check.setEnabled(true); //cboxAct.setEnabled(true); //buttonH.setEnabled(true); } catch (BioclipseException e1) { e1.printStackTrace(); } setPageComplete(true); } }); label = new Label(container, SWT.NONE); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalSpan = 2; label.setLayoutData(gridData); label.setText("Limit"); spinn = new Spinner(container, SWT.BORDER); gridData = new GridData(); spinn.setLayoutData(gridData); spinn.setSelection(50); spinn.setMaximum(10000000); spinn.setIncrement(50); spinn.setEnabled(false); gridData.widthHint = 100; gridData.horizontalSpan = 1; spinn.setToolTipText("Limits the search, increases by 50"); spinn.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int selected = spinn.getSelection(); try { table.clearAll(); table.removeAll(); IStringMatrix matrix = chembl.mossGetCompounds(cbox.getItem(cbox.getSelectionIndex()), cboxAct.getItem(cboxAct.getSelectionIndex()), selected); table.setVisible(true); addToTable(matrix); } catch (BioclipseException e1) { e1.printStackTrace(); } } }); //Button that adds all hits to the limit button = new Button(container, SWT.PUSH); button.setToolTipText("Add all compounds to the table"); button.setText("Display all"); button.setEnabled(false); button.setLayoutData(gridData); gridData = new GridData(); gridData.horizontalSpan = 1; button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { //try { table.removeAll(); // ProgressMonitorDialog dialog = new ProgressMonitorDialog(container.getShell()); // // try { // dialog.run(true, true, new IRunnableWithProgress(){ // public void run(IProgressMonitor monitor) { // monitor.beginTask("Searching for compounds", IProgressMonitor.UNKNOWN); try { IStringMatrix matrix = chembl.mossGetCompoundsFromProteinFamilyWithActivity( cbox.getItem(cbox.getSelectionIndex()), cboxAct.getItem(cboxAct.getSelectionIndex())); // final IStringMatrix matrix = chembl.MossProtFamilyCompoundsAct("TK", "Ki"); addToTable(matrix); info.setText("Total hit(not always distinct compounds): " + matrix.getRowCount()); spinn.setSelection(matrix.getRowCount()); } catch (BioclipseException eb) { // TODO Auto-generated catch block eb.printStackTrace(); } // // monitor.done(); // } // }); // } catch (InvocationTargetException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } catch (InterruptedException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } // } catch (BioclipseException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } } }); label = new Label(container, SWT.NONE); label.setText("Optional: Modify activity values."); Font font1 = new Font(container.getDisplay(), "Helvetica", 13, SWT.NONE); label.setFont(font1); gridData = new GridData(); gridData.horizontalSpan = 4; gridData.verticalSpan = 5; label.setLayoutData(gridData); check = new Button(container, SWT.CHECK); check.setText("Modify activities"); check.setToolTipText("Modify data by specifying upper and lower activity limit"); check.setEnabled(false); gridData = new GridData(GridData.BEGINNING); gridData.horizontalSpan = 2; check.setLayoutData(gridData); check.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { boolean selected = check.getSelection(); if (selected == true) { spinnLow.setEnabled(true); spinnHigh.setEnabled(true); buttonUpdate.setEnabled(true); labelHigh.setEnabled(true); labelLow.setEnabled(true); buttonH.setEnabled(true); } else if (selected == false) { spinnLow.setEnabled(false); spinnHigh.setEnabled(false); buttonUpdate.setEnabled(false); labelHigh.setEnabled(false); labelLow.setEnabled(false); buttonH.setEnabled(false); } } }); label = new Label(container, SWT.NONE); label.setText("Look at activity span: "); gridData = new GridData(); gridData.horizontalSpan = 1; label.setLayoutData(gridData); buttonH = new Button(container, SWT.PUSH); buttonH.setText("Graph"); buttonH.setToolTipText("Shows activity in a graph(for all compounds)"); buttonH.setEnabled(false); gridData = new GridData(); gridData.horizontalSpan = 1; buttonH.setLayoutData(gridData); buttonH.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { JFreeChart jfreechart = ChartFactory.createXYLineChart("Histogram Demo", "Activity values", "Number of compounds", histogramSeries, PlotOrientation.VERTICAL, true, false, false); // final XYSeriesCollection dataset = new XYSeriesCollection(series); // JFreeChart chart = ChartFactory.createXYBarChart( // "Activity chart", // "Activity value", // false, // "Number of Compounds", // dataset, // PlotOrientation.VERTICAL, // true, // true, // false // ); ChartFrame frame = new ChartFrame("Activities", jfreechart); frame.pack(); frame.setVisible(true); } }); // Lower activity bound for updating table labelLow = new Label(container, SWT.NONE); labelLow.setText("Lower activity limit"); labelLow.setEnabled(false); gridData = new GridData(); gridData.horizontalSpan = 1; labelLow.setLayoutData(gridData); spinnLow = new Spinner(container, SWT.NONE); spinnLow.setSelection(0); spinnLow.setMaximum(10000000); spinnLow.setIncrement(50); spinnLow.setEnabled(false); spinnLow.setToolTipText("Specify lower activity limit"); gridData = new GridData(); gridData.widthHint = 100; gridData.horizontalSpan = 1; spinnLow.setLayoutData(gridData); buttonUpdate = new Button(container, SWT.PUSH); buttonUpdate.setText("Update table"); buttonUpdate.setToolTipText("Update the table with the specified activity limits"); buttonUpdate.setEnabled(false); gridData = new GridData(); gridData.horizontalSpan = 2; buttonUpdate.setLayoutData(gridData); buttonUpdate.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { table.clearAll(); table.removeAll(); try { IStringMatrix matrix = chembl.mossSetActivityBound(matrixAct, spinnLow.getSelection(), spinnHigh.getSelection()); addToTable(matrix); spinn.setSelection(matrix.getRowCount()); info.setText("Total compound hit: " + matrix.getRowCount()); } catch (BioclipseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); //Upper activity bound for updating table labelHigh = new Label(container, SWT.NONE); labelHigh.setText("Upper activity limit"); labelHigh.setEnabled(false); gridData = new GridData(); gridData.horizontalSpan = 1; labelHigh.setLayoutData(gridData); spinnHigh = new Spinner(container, SWT.BORDER); spinnHigh.setSelection(1000); spinnHigh.setMaximum(1000000000); spinnHigh.setIncrement(50); spinnHigh.setEnabled(false); spinnHigh.setToolTipText("Specify upper activity limit"); gridData = new GridData(); gridData.widthHint = 100; gridData.horizontalSpan = 3; spinnHigh.setLayoutData(gridData); //Label for displaying compound hits info = new Label(container, SWT.NONE); gridData = new GridData(); info.setLayoutData(gridData); gridData.horizontalSpan = 4; gridData.verticalSpan = 6; gridData.widthHint = 350; info.setText("Total compound hit:"); //Table displaying contents table = new Table(container, SWT.BORDER); table.setHeaderVisible(true); table.setLinesVisible(true); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.widthHint = 300; gridData.heightHint = 300; gridData.horizontalSpan = 4; table.setLayoutData(gridData); column1 = new TableColumn(table, SWT.NONE); column1.setText("Index"); column2 = new TableColumn(table, SWT.NONE); column2.setText("Activity value"); column3 = new TableColumn(table, SWT.NONE); column3.setText("Compounds (SMILES)"); }
From source file:org.jfree.data.statistics.HistogramDataset.java
/** * Returns the y-value for a bin (calculated to take into account the * histogram type).//from w w w . j a v a 2 s. c o m * * @param series the series index (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * @param item the item index (zero based). * * @return The y-value. * * @throws IndexOutOfBoundsException if <code>series</code> is outside the * specified range. */ @Override public Number getY(int series, int item) { List bins = getBins(series); HistogramBin bin = (HistogramBin) bins.get(item); double total = getTotal(series); double binWidth = getBinWidth(series); if (this.type == HistogramType.FREQUENCY) { return new Double(bin.getCount()); } else if (this.type == HistogramType.RELATIVE_FREQUENCY) { return new Double(bin.getCount() / total); } else if (this.type == HistogramType.SCALE_AREA_TO_1) { return new Double(bin.getCount() / (binWidth * total)); } else { // pretty sure this shouldn't ever happen throw new IllegalStateException(); } }
From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java
private void updateChart(SimpleFeatureCollection features, String field) { int bin = spinner.getSelection(); double[] values = getValues(features, field); HistogramDataset dataset = new HistogramDataset(); dataset.addSeries(field, values, bin, minMaxVisitor.getMinX(), minMaxVisitor.getMaxX()); dataset.setType(histogramType);/*from w w w .j a v a 2 s . co m*/ JFreeChart chart = ChartFactory.createHistogram(EMPTY, null, null, dataset, PlotOrientation.VERTICAL, false, false, false); // 1. Create a single plot containing both the scatter and line chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(0.85F); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY); plot.setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY); int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis valueAxis = new NumberAxis(cboField.getText()); valueAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); valueAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); valueAxis.setAutoRange(false); valueAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX()); String rangeAxisLabel = histogramType == HistogramType.FREQUENCY ? "Frequency" : "Ratio"; //$NON-NLS-1$ //$NON-NLS-2$ NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel); rangeAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); rangeAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); if (histogramType == HistogramType.FREQUENCY) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setShadowVisible(false); CustomXYBarPainter.selectedColumn = -1; // init renderer.setBarPainter(new CustomXYBarPainter()); renderer.setAutoPopulateSeriesFillPaint(true); renderer.setAutoPopulateSeriesPaint(true); renderer.setShadowXOffset(3); renderer.setMargin(0.01); renderer.setBaseItemLabelsVisible(true); ItemLabelPosition pos = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_CENTER); renderer.setBasePositiveItemLabelPosition(pos); XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator(); renderer.setBaseToolTipGenerator(plotToolTip); // color GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, java.awt.Color.GRAY, 0.0f, 0.0f, java.awt.Color.LIGHT_GRAY); renderer.setSeriesPaint(0, gp0); plot.setDomainAxis(0, valueAxis); plot.setRangeAxis(0, rangeAxis); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.RED); lineRenderer.setSeriesStroke(0, new BasicStroke(2f)); // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); xLineAxis.setAutoRange(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); yLineAxis.setAutoRange(false); double maxYValue = Double.MIN_VALUE; for (int i = 0; i < dataset.getItemCount(0); i++) { maxYValue = Math.max(maxYValue, dataset.getYValue(0, i)); } XYSeriesCollection lineDatset = new XYSeriesCollection(); // Vertical Average XYSeries vertical = new XYSeries("Average"); //$NON-NLS-1$ vertical.add(minMaxVisitor.getAverageX(), 0); vertical.add(minMaxVisitor.getAverageX(), maxYValue); lineDatset.addSeries(vertical); plot.setDataset(1, lineDatset); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); chartComposite.setChart(chart); chartComposite.forceRedraw(); }