List of usage examples for java.lang Comparable toString
public String toString()
From source file:com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.java
public void updatePlotter() { int categoryCount = prepareData(); String maxClassesProperty = ParameterService .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_LEGEND_CLASSLIMIT); int maxClasses = 20; try {/*from ww w. j av a2s .c om*/ if (maxClassesProperty != null) { maxClasses = Integer.parseInt(maxClassesProperty); } } catch (NumberFormatException e) { // LogService.getGlobal().log("Pie Chart plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.", // LogService.WARNING); LogService.getRoot().log(Level.WARNING, "com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.pie_chart_plotter_parsing_error"); } boolean createLegend = categoryCount > 0 && categoryCount < maxClasses; if (categoryCount <= MAX_CATEGORIES) { JFreeChart chart = createChart(pieDataSet, createLegend); // set the background color for the chart... chart.setBackgroundPaint(Color.white); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setSectionOutlinesVisible(true); plot.setShadowPaint(new Color(104, 104, 104, 100)); int size = pieDataSet.getKeys().size(); for (int i = 0; i < size; i++) { Comparable<?> key = pieDataSet.getKey(i); plot.setSectionPaint(key, getColorProvider(true).getPointColor(i / (double) (size - 1))); boolean explode = false; for (String explosionGroup : explodingGroups) { if (key.toString().startsWith(explosionGroup) || explosionGroup.startsWith(key.toString())) { explode = true; break; } } if (explode) { plot.setExplodePercent(key, this.explodingAmount); } } plot.setLabelFont(LABEL_FONT); plot.setNoDataMessage("No data available"); plot.setCircular(false); plot.setLabelGap(0.02); plot.setOutlinePaint(Color.WHITE); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } if (panel instanceof AbstractChartPanel) { panel.setChart(chart); } else { panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN); final ChartPanelShiftController controller = new ChartPanelShiftController(panel); panel.addMouseListener(controller); panel.addMouseMotionListener(controller); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } else { // LogService.getGlobal().logNote("Too many columns (" + categoryCount + // "), this chart is only able to plot up to " + MAX_CATEGORIES + // " different categories."); LogService.getRoot().log(Level.INFO, "com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.too_many_columns", new Object[] { categoryCount, MAX_CATEGORIES }); } }
From source file:com.mycollab.ui.chart.PieChartWrapper.java
@Override protected final ComponentContainer createLegendBox() { final CssLayout mainLayout = new CssLayout(); mainLayout.addStyleName("legendBoxContent"); mainLayout.setSizeUndefined();/*from ww w.jav a2 s.co m*/ final List keys = pieDataSet.getKeys(); for (int i = 0; i < keys.size(); i++) { MHorizontalLayout layout = new MHorizontalLayout().withMargin(new MarginInfo(false, false, false, true)) .withStyleName("inline-block").withWidthUndefined(); layout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); final Comparable key = (Comparable) keys.get(i); int colorIndex = i % CHART_COLOR_STR.size(); final String color = "<div style = \" width:13px;height:13px;background: #" + CHART_COLOR_STR.get(colorIndex) + "\" />"; final ELabel lblCircle = ELabel.html(color); String btnCaption; if (enumKeyCls == null) { if (key instanceof Key) { btnCaption = String.format("%s (%d)", StringUtils.trim(((Key) key).getDisplayName(), 20, true), pieDataSet.getValue(key).intValue()); } else { btnCaption = String.format("%s (%d)", key, pieDataSet.getValue(key).intValue()); } } else { btnCaption = String.format("%s(%d)", UserUIContext.getMessage(enumKeyCls, key.toString()), pieDataSet.getValue(key).intValue()); } MButton btnLink = new MButton(StringUtils.trim(btnCaption, 25, true), clickEvent -> { if (key instanceof Key) { clickLegendItem(((Key) key).getKey()); } else { clickLegendItem(key.toString()); } }).withStyleName(WebThemes.BUTTON_LINK).withDescription(btnCaption); layout.with(lblCircle, btnLink); mainLayout.addComponent(layout); } mainLayout.setWidth("100%"); return mainLayout; }
From source file:com.esofthead.mycollab.ui.chart.PieChartWrapper.java
@Override protected final ComponentContainer createLegendBox() { final CssLayout mainLayout = new CssLayout(); mainLayout.addStyleName("legendBoxContent"); mainLayout.setSizeUndefined();//from w w w. j a va 2 s. c o m final List keys = pieDataSet.getKeys(); for (int i = 0; i < keys.size(); i++) { MHorizontalLayout layout = new MHorizontalLayout() .withMargin(new MarginInfo(false, false, false, true)); layout.addStyleName("inline-block"); layout.setSizeUndefined(); layout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); final Comparable key = (Comparable) keys.get(i); int colorIndex = i % CHART_COLOR_STR.size(); final String color = "<div style = \" width:13px;height:13px;background: #" + CHART_COLOR_STR.get(colorIndex) + "\" />"; final Label lblCircle = new Label(color); lblCircle.setContentMode(ContentMode.HTML); String btnCaption; if (enumKeyCls == null) { if (key instanceof Key) { btnCaption = String.format("%s (%d)", StringUtils.trim(((Key) key).getDisplayName(), 20, true), pieDataSet.getValue(key).intValue()); } else { btnCaption = String.format("%s (%d)", key, pieDataSet.getValue(key).intValue()); } } else { btnCaption = String.format("%s(%d)", AppContext.getMessage(enumKeyCls, key.toString()), pieDataSet.getValue(key).intValue()); } final Button btnLink = new Button(StringUtils.trim(btnCaption, 25, true), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { if (key instanceof Key) { clickLegendItem(((Key) key).getKey()); } else { clickLegendItem(key.toString()); } } }); btnLink.setDescription(btnCaption); btnLink.addStyleName(UIConstants.BUTTON_LINK); layout.with(lblCircle, btnLink); mainLayout.addComponent(layout); } mainLayout.setWidth("100%"); return mainLayout; }
From source file:com.aurel.track.admin.customize.category.report.execute.ReportBeansToXML.java
public Document convertToDOM(List<ReportBean> items, boolean withHistory, Locale locale, String personName, String filterName, String filterExpression, boolean useProjectSpecificID) { boolean budgetActive = ApplicationBean.getInstance().getBudgetActive(); Document dom = null;//from w ww . jav a 2 s .c o m try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); dom = builder.newDocument(); } catch (FactoryConfigurationError e) { LOGGER.error("Creating the DOM document failed with FactoryConfigurationError:" + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); return null; } catch (ParserConfigurationException e) { LOGGER.error("Creating the DOM document failed with ParserConfigurationException: " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); return null; } Element root = dom.createElement("track-report"); appendChild(root, "createdBy", personName, dom); Element filter = dom.createElement("filter"); appendChild(filter, "name", filterName, dom); appendChild(filter, "expression", filterExpression, dom); root.appendChild(filter); Map<Integer, ILinkType> linkTypeIDToLinkTypeMap = LinkTypeBL.getLinkTypeIDToLinkTypeMap(); List<TFieldBean> fields = FieldBL.loadAll(); String issueNoName = null; if (useProjectSpecificID) { for (Iterator<TFieldBean> iterator = fields.iterator(); iterator.hasNext();) { TFieldBean fieldBean = iterator.next(); if (SystemFields.INTEGER_ISSUENO.equals(fieldBean.getObjectID())) { issueNoName = fieldBean.getName(); break; } } } for (Iterator<TFieldBean> iterator = fields.iterator(); iterator.hasNext();) { //only one from INTEGER_ISSUENO and INTEGER_PROJECT_SPECIFIC_ISSUENO should be shown TFieldBean fieldBean = iterator.next(); if (useProjectSpecificID) { if (SystemFields.INTEGER_ISSUENO.equals(fieldBean.getObjectID())) { iterator.remove(); } if (SystemFields.INTEGER_PROJECT_SPECIFIC_ISSUENO.equals(fieldBean.getObjectID())) { fieldBean.setName(issueNoName); } } else { if (SystemFields.INTEGER_PROJECT_SPECIFIC_ISSUENO.equals(fieldBean.getObjectID())) { iterator.remove(); } } } String unavailable = LocalizeUtil.getLocalizedTextFromApplicationResources("itemov.lbl.unavailable", locale); for (ReportBean reportBean : items) { Element item = dom.createElement("item"); TWorkItemBean workItemBean = reportBean.getWorkItemBean(); for (TFieldBean fieldBean : fields) { Integer fieldID = fieldBean.getObjectID(); String fieldName = fieldBean.getName(); Object attributeValue = workItemBean.getAttribute(fieldID); if (attributeValue != null) { IFieldTypeRT fieldTypeRT = FieldTypeManager.getFieldTypeRT(fieldID); if (fieldTypeRT != null) { if (fieldTypeRT.isLong()) { String isoValue = (String) reportBean.getShowISOValue(fieldID); if (isoValue != null && !isoValue.equals(unavailable)) { String plainDescription = (String) workItemBean.getAttribute(fieldID); try { plainDescription = Html2Text.getNewInstance().convert((String) attributeValue); } catch (Exception e) { LOGGER.info("Transforming the HTML to plain text for workItemID " + workItemBean.getObjectID() + " and field " + fieldID + " failed with " + e); } appendChild(item, fieldName + PLAIN_SUFFIX, plainDescription, dom); appendChild(item, fieldName, HTMLSanitiser.stripHTML((String) attributeValue), dom); } } else { String isoValue = (String) reportBean.getShowISOValue(fieldID); appendChild(item, fieldName, isoValue, dom); } if (fieldTypeRT.getValueType() == ValueType.CUSTOMOPTION || fieldTypeRT.isComposite()) { //add custom list sortOrder appendChild(item, fieldBean.getName() + TReportLayoutBean.PSEUDO_COLUMN_NAMES.CUSTOM_OPTION_SYMBOL, (String) reportBean.getShowISOValue(Integer.valueOf(-fieldID)), dom); } if (hasExtraSortField(fieldID)) { Comparable sortOrder = reportBean.getSortOrder(fieldID); if (sortOrder != null) { appendChild(item, fieldBean.getName() + TReportLayoutBean.PSEUDO_COLUMN_NAMES.ORDER, sortOrder.toString(), dom); } } } } } appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.GLOBAL_ITEM_NO, workItemBean.getObjectID().toString(), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.PROJECT_TYPE, reportBean.getProjectType(), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.STATUS_FLAG, reportBean.getStateFlag().toString(), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.COMMITTED_DATE_CONFLICT, new Boolean(reportBean.isCommittedDateConflict()).toString(), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.TARGET_DATE_CONFLICT, new Boolean(reportBean.isTargetDateConflict()).toString(), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.PLANNED_VALUE_CONFLICT, new Boolean(reportBean.isPlannedValueConflict()).toString(), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.BUDGET_CONFLICT, new Boolean(reportBean.isBudgetConflict()).toString(), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.SUMMARY, new Boolean(reportBean.isSummary()).toString(), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.INDENT_LEVEL, String.valueOf(reportBean.getLevel()), dom); String consultants = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.CONSULTANT_LIST); if (consultants != null && !"".equals(consultants)) { appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.CONSULTANT_LIST, consultants, dom); } String informed = (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.INFORMANT_LIST); if (informed != null && !"".equals(informed)) { appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.INFORMANT_LIST, informed, dom); } String linkedItems = (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.LINKED_ITEMS); if (linkedItems != null && !"".equals(linkedItems)) { appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.LINKED_ITEMS, linkedItems, dom); } appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.PRIVATE_SYMBOL, (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.PRIVATE_SYMBOL), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.OVERFLOW_SYMBOL, (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.OVERFLOW_ICONS), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.PRIORITY_SYMBOL, (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.PRIORITY_SYMBOL), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.SEVERITY_SYMBOL, (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.SEVERITY_SYMBOL), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.STATUS_SYMBOL, (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.STATUS_SYMBOL), dom); appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.ISSUETYPE_SYMBOL, (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.ISSUETYPE_SYMBOL), dom); String valueAndMeasurementUnit; valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.TOTAL_EXPENSE_COST); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.TOTAL_EXPENSE_COST, valueAndMeasurementUnit, dom, item); valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.TOTAL_EXPENSE_TIME); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.TOTAL_EXPENSE_TIME, valueAndMeasurementUnit, dom, item); valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.MY_EXPENSE_COST); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.MY_EXPENSE_COST, valueAndMeasurementUnit, dom, item); valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.MY_EXPENSE_TIME); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.MY_EXPENSE_TIME, valueAndMeasurementUnit, dom, item); if (budgetActive) { valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.BUDGET_COST); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.BUDGET_COST, valueAndMeasurementUnit, dom, item); valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.BUDGET_TIME); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.BUDGET_TIME, valueAndMeasurementUnit, dom, item); } valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.TOTAL_PLANNED_COST); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.TOTAL_PLANNED_COST, valueAndMeasurementUnit, dom, item); valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.TOTAL_PLANNED_TIME); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.TOTAL_PLANNED_TIME, valueAndMeasurementUnit, dom, item); valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.REMAINING_PLANNED_COST); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.REMAINING_PLANNED_COST, valueAndMeasurementUnit, dom, item); valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.REMAINING_PLANNED_TIME); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.REMAINING_PLANNED_TIME, valueAndMeasurementUnit, dom, item); valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.BUDGET_COST); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.BUDGET_COST, valueAndMeasurementUnit, dom, item); valueAndMeasurementUnit = (String) reportBean .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.BUDGET_TIME); createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.BUDGET_TIME, valueAndMeasurementUnit, dom, item); Element links = createLinkElement(reportBean.getReportBeanLinksSet(), linkTypeIDToLinkTypeMap, locale, dom); if (links != null) { item.appendChild(links); } if (withHistory) { ReportBeanWithHistory reportBeanWithHistory = (ReportBeanWithHistory) reportBean; Element historyElement = createHistoryElement(reportBeanWithHistory.getHistoryValuesMap(), dom); if (historyElement != null) { item.appendChild(historyElement); } Element commentElement = createCommentElement(reportBeanWithHistory.getComments(), dom); if (commentElement != null) { item.appendChild(commentElement); } Element budgetElement = createBudgetElement(reportBeanWithHistory.getBudgetHistory(), dom, locale); if (budgetElement != null) { item.appendChild(budgetElement); } Element plannedValueElement = createBudgetElement(reportBeanWithHistory.getPlannedValueHistory(), dom, locale); if (plannedValueElement != null) { item.appendChild(plannedValueElement); } if (plannedValueElement != null) { //do not add estimated remaining budget element if no budget exists Element remainingBudgetElement = createRemainingBudgetElement( reportBeanWithHistory.getActualEstimatedBudgetBean(), dom, locale); if (remainingBudgetElement != null) { item.appendChild(remainingBudgetElement); } } Element costElement = createExpenseElement(reportBeanWithHistory.getCosts(), dom, locale); if (costElement != null) { item.appendChild(costElement); } } root.appendChild(item); } dom.appendChild(root); return dom; }
From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java
public JFreeChart makePieChart(ChartModel chartModel, NamedValuesDataModel dataModel, final IChartLinkGenerator linkGenerator) { final DefaultPieDataset dataset = new DefaultPieDataset(); for (NamedValue namedValue : dataModel) { if (namedValue.getName() != null) { dataset.setValue(namedValue.getName(), scaleNumber(namedValue.getValue(), dataModel.getScalingFactor())); }//w w w . ja v a 2 s .c om } boolean showLegend = (chartModel.getLegend() != null) && (chartModel.getLegend().getVisible()); String title = ""; if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null) && (chartModel.getTitle().getText().trim().length() > 0)) { title = chartModel.getTitle().getText(); } final JFreeChart chart = ChartFactory.createPieChart(title, dataset, showLegend, true, false); initChart(chart, chartModel); final PiePlot jFreePiePlot = (PiePlot) chart.getPlot(); if (linkGenerator != null) { jFreePiePlot.setURLGenerator(new PieURLGenerator() { public String generateURL(PieDataset arg0, Comparable arg1, int arg2) { return linkGenerator.generateLink(arg1.toString(), arg1.toString(), arg0.getValue(arg1)); } }); } jFreePiePlot.setNoDataMessage("No data available"); //$NON-NLS-1$ jFreePiePlot.setCircular(true); jFreePiePlot.setLabelGap(0.02); org.pentaho.chart.model.PiePlot chartBeansPiePlot = (org.pentaho.chart.model.PiePlot) chartModel.getPlot(); List<Integer> colors = getPlotColors(chartBeansPiePlot); int index = 0; for (NamedValue namedValue : dataModel) { if (namedValue.getName() != null) { jFreePiePlot.setSectionPaint(namedValue.getName(), new Color(0x00FFFFFF & colors.get(index % colors.size()))); } index++; } if (chartBeansPiePlot.getLabels().getVisible()) { jFreePiePlot.setLabelGenerator(new StandardPieSectionLabelGenerator()); Font font = ChartUtils.getFont(chartBeansPiePlot.getLabels().getFontFamily(), chartBeansPiePlot.getLabels().getFontStyle(), chartBeansPiePlot.getLabels().getFontWeight(), chartBeansPiePlot.getLabels().getFontSize()); if (font != null) { jFreePiePlot.setLabelFont(font); if (chartBeansPiePlot.getLabels().getColor() != null) { jFreePiePlot.setLabelPaint(new Color(0x00FFFFFF & chartBeansPiePlot.getLabels().getColor())); } if (chartBeansPiePlot.getLabels().getBackgroundColor() != null) { jFreePiePlot.setLabelBackgroundPaint( new Color(0x00FFFFFF & chartBeansPiePlot.getLabels().getBackgroundColor())); } } } else { jFreePiePlot.setLabelGenerator(null); } jFreePiePlot.setStartAngle(-chartBeansPiePlot.getStartAngle()); return chart; }
From source file:lucee.runtime.tag.Chart.java
private void setUrl(JFreeChart chart) { if (StringUtil.isEmpty(url)) return;/*ww w. jav a 2s .c om*/ Plot plot = chart.getPlot(); if (plot instanceof PiePlot) { PiePlot pp = (PiePlot) plot; pp.setURLGenerator(new PieURLGenerator() { public String generateURL(PieDataset dataset, Comparable key, int pieIndex) { if (!StringUtil.contains(url, "?")) url += "?series=$SERIESLABEL$&category=$ITEMLABEL$&value=$VALUE$"; String retUrl = StringUtil.replace(url, "$ITEMLABEL$", URLUtilities.encode(key.toString(), "UTF-8"), false, true); retUrl = StringUtil.replace(retUrl, "$SERIESLABEL$", Integer.toString(pieIndex), false, true); retUrl = StringUtil.replace(retUrl, "$VALUE$", URLUtilities.encode(dataset.getValue(key).toString(), "UTF-8"), false, true); return retUrl; } }); } else if (plot instanceof CategoryPlot) { CategoryPlot cp = (CategoryPlot) plot; CategoryItemRenderer renderer = cp.getRenderer(); renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator() { public String generateURL(CategoryDataset dataset, int series, int category) { if (!StringUtil.contains(url, "?")) url += "?series=$SERIESLABEL$&category=$ITEMLABEL$&value=$VALUE$"; String retUrl = StringUtil.replace(url, "$ITEMLABEL$", URLUtilities.encode(dataset.getColumnKey(category).toString(), "UTF-8"), false, true); retUrl = StringUtil.replace(retUrl, "$SERIESLABEL$", URLUtilities.encode(dataset.getRowKey(series).toString(), "UTF-8"), false, true); retUrl = StringUtil.replace(retUrl, "$VALUE$", URLUtilities.encode(dataset.getValue(series, category).toString(), "UTF-8"), false, true); return retUrl; } }); } else if (plot instanceof XYPlot) { XYPlot cp = (XYPlot) plot; XYItemRenderer renderer = cp.getRenderer(); renderer.setURLGenerator(new StandardXYURLGenerator() { public String generateURL(XYDataset dataset, int series, int category) { if (!StringUtil.contains(url, "?")) url += "?series=$SERIESLABEL$&category=$ITEMLABEL$&value=$VALUE$"; String itemLabel = _plotItemLables.get(category + 1) != null ? _plotItemLables.get(category + 1) : dataset.getX(series, category).toString(); String retUrl = StringUtil.replace(url, "$ITEMLABEL$", URLUtilities.encode(itemLabel, "UTF-8"), false, true); retUrl = StringUtil.replace(retUrl, "$SERIESLABEL$", URLUtilities.encode(dataset.getSeriesKey(series).toString(), "UTF-8"), false, true); retUrl = StringUtil.replace(retUrl, "$VALUE$", URLUtilities.encode(dataset.getY(series, category).toString(), "UTF-8"), false, true); return retUrl; } }); } }
From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private AbstractDataset getTimeSeriesCollectionDataset(Report report) { List<Stat> reportData = report.getReportData(); // fill dataset TimeSeriesCollection dataSet = new TimeSeriesCollection(); String dataSource = report.getReportDefinition().getReportParams().getHowChartSource(); String seriesFrom = report.getReportDefinition().getReportParams().getHowChartSeriesSource(); if (StatsManager.T_TOTAL.equals(seriesFrom) || StatsManager.T_NONE.equals(seriesFrom)) { seriesFrom = null;//from w w w.j a v a 2 s .c o m } Class periodGrouping = null; if (StatsManager.CHARTTIMESERIES_DAY .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod()) || StatsManager.CHARTTIMESERIES_WEEKDAY .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) { periodGrouping = org.jfree.data.time.Day.class; } else if (StatsManager.CHARTTIMESERIES_MONTH .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) { periodGrouping = org.jfree.data.time.Month.class; } else if (StatsManager.CHARTTIMESERIES_YEAR .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) { periodGrouping = org.jfree.data.time.Year.class; } boolean visitsTotalsChart = ReportManager.WHAT_VISITS_TOTALS .equals(report.getReportDefinition().getReportParams().getWhat()) || report.getReportDefinition().getReportParams().getHowTotalsBy().contains(StatsManager.T_VISITS) || report.getReportDefinition().getReportParams().getHowTotalsBy() .contains(StatsManager.T_UNIQUEVISITS); Set<RegularTimePeriod> keys = new HashSet<RegularTimePeriod>(); if (!visitsTotalsChart && seriesFrom == null) { // without additional series String name = msgs.getString("th_total"); TimeSeries ts = new TimeSeries(name, periodGrouping); for (Stat s : reportData) { RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping); if (key != null) { Number existing = null; if ((existing = ts.getValue(key)) == null) { ts.add(key, getTotalValue(s, report)); } else { ts.addOrUpdate(key, getTotalValue(existing, s, report)); } keys.add(key); } } dataSet.addSeries(ts); } else if (!visitsTotalsChart && seriesFrom != null) { // with additional series Map<Comparable, TimeSeries> series = new HashMap<Comparable, TimeSeries>(); //TimeSeries ts = new TimeSeries(dataSource, org.jfree.data.time.Day.class); for (Stat s : reportData) { RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping); Comparable serie = (Comparable) getStatValue(s, seriesFrom); if (key != null && serie != null) { // determine appropriate serie TimeSeries ts = null; if (!series.containsKey(serie)) { ts = new TimeSeries(serie.toString(), periodGrouping); series.put(serie, ts); } else { ts = series.get(serie); } Number existing = null; if ((existing = ts.getValue(key)) == null) { ts.add(key, getTotalValue(s, report)); } else { ts.addOrUpdate(key, getTotalValue(existing, s, report)); } keys.add(key); } } // add series for (TimeSeries ts : series.values()) { dataSet.addSeries(ts); } } else if (visitsTotalsChart) { // 2 series: visits & unique visitors TimeSeries tsV = new TimeSeries(msgs.getString("th_visits"), periodGrouping); TimeSeries tsUV = new TimeSeries(msgs.getString("th_uniquevisitors"), periodGrouping); for (Stat _s : reportData) { SiteVisits s = (SiteVisits) _s; RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping); if (key != null) { Number existing = null; if ((existing = tsV.getValue(key)) == null) { tsV.add(key, s.getTotalVisits()); tsUV.add(key, s.getTotalUnique()); } else { tsV.addOrUpdate(key, s.getTotalVisits() + existing.longValue()); tsUV.addOrUpdate(key, s.getTotalVisits() + existing.longValue()); } keys.add(key); } } dataSet.addSeries(tsV); dataSet.addSeries(tsUV); } // fill missing values with zeros /*for(TimeSeries ts : (List<TimeSeries>) dataSet.getSeries()) { for(RegularTimePeriod tp : keys) { if(ts.getValue(tp) == null) { ts.add(tp, 0.0); } } }*/ dataSet.setXPosition(TimePeriodAnchor.MIDDLE); return dataSet; }
From source file:com.smartitengineering.dao.impl.hbase.CommonDao.java
protected void verifyAllEntitiesExists(boolean existenceExpected, Template... states) { List<Future<Boolean>> gets = new ArrayList<Future<Boolean>>(states.length); int i = 0;// ww w . jav a 2 s . com for (Template t : states) { try { final Comparable id = t.getId(); if (logger.isInfoEnabled()) { logger.info(new StringBuilder("Adding ").append(id).append(" to index ").append(i).toString()); } final Get get = new Get(infoProvider.getRowIdFromId((IdType) id)); final int index = i; gets.add(executorService.executeAsynchronously(infoProvider.getMainTableName(), new Callback<Boolean>() { @Override public Boolean call(HTableInterface tableInterface) throws Exception { final boolean exists = tableInterface.exists(get); if (logger.isDebugEnabled()) { logger.debug(new StringBuilder("Id ").append(id.toString()).append(" exists ") .append(index).toString()); } return exists; } })); i++; } catch (Exception ex) { logger.warn("Exception testing row existense...", ex); } } i = 0; for (Future<Boolean> future : gets) { Boolean exists = true; try { if (logger.isInfoEnabled()) { logger.info(new StringBuilder("Checking index ").append(i++).toString()); } exists = future.get(); } catch (Exception ex) { logger.warn("Exception testing row existense...", ex); } if (!existenceExpected && exists) { throw new IllegalArgumentException( "Some of the entities are already saved, so did not procced with any of them"); } if (existenceExpected && !exists) { throw new IllegalArgumentException( "Some of the entities are not saved, so did not procced with any of them"); } } }
From source file:spinworld.gui.RadarPlot.java
/** * Returns a collection of legend items for the spider web chart. * * @return The legend items (never <code>null</code>). *//*from w ww . j a va2 s . c om*/ public LegendItemCollection getLegendItems() { LegendItemCollection result = new LegendItemCollection(); if (getDataset() == null) { return result; } List<?> keys = null; if (this.dataExtractOrder == TableOrder.BY_ROW) { keys = this.dataset.getRowKeys(); } else if (this.dataExtractOrder == TableOrder.BY_COLUMN) { keys = this.dataset.getColumnKeys(); } if (keys == null) { return result; } int series = 0; Iterator<?> iterator = keys.iterator(); Shape shape = getLegendItemShape(); while (iterator.hasNext()) { Comparable<?> key = (Comparable<?>) iterator.next(); String label = key.toString(); String description = label; Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); Stroke stroke = getHeadOutlineStroke(series); LegendItem item = new LegendItem(label, description, null, null, shape, paint, stroke, outlinePaint); item.setDataset(getDataset()); item.setSeriesKey(key); item.setSeriesIndex(series); result.add(item); series++; } return result; }
From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java
protected void drawRadar(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info, int pieIndex, PieDataset data) {//from w w w .j a v a 2s.c om // adjust the plot area by the interior spacing value double gapHorizontal = plotArea.getWidth() * this.interiorGap; double gapVertical = plotArea.getHeight() * this.interiorGap; double radarX = plotArea.getX() + gapHorizontal / 2; double radarY = plotArea.getY() + gapVertical / 2; double radarW = plotArea.getWidth() - gapHorizontal; double radarH = plotArea.getHeight() - gapVertical; // make the radar area a square if the radar chart is to be circular... // NOTE that non-circular radar charts are not currently supported. if (true) { //circular) { double min = Math.min(radarW, radarH) / 2; radarX = (radarX + radarX + radarW) / 2 - min; radarY = (radarY + radarY + radarH) / 2 - min; radarW = 2 * min; radarH = 2 * min; } double radius = radarW / 2; double centerX = radarX + radarW / 2; double centerY = radarY + radarH / 2; Rectangle2D radarArea = new Rectangle2D.Double(radarX, radarY, radarW, radarH); // plot the data (unless the dataset is null)... if ((data != null) && (data.getKeys().size() > 0)) { // get a list of categories... List keys = data.getKeys(); int numAxes = keys.size(); // draw each of the axes on the radar chart, and register // the shape of the radar line. double multiplier = 1.0; GeneralPath lineShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1); GeneralPath gridShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1); int axisNumber = -1; Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable currentKey = (Comparable) iterator.next(); axisNumber++; Number dataValue = data.getValue(currentKey); double value = (dataValue != null ? dataValue.doubleValue() : 0); if (value > 1 || Double.isNaN(value) || Double.isInfinite(value)) value = 1.0; if (value < 0) value = 0.0; multiplier *= value; double angle = 2 * Math.PI * axisNumber / numAxes; double deltaX = Math.sin(angle) * radius; double deltaY = -Math.cos(angle) * radius; // draw the spoke g2.setPaint(axisPaint); g2.setStroke(axisStroke); Line2D line = new Line2D.Double(centerX, centerY, centerX + deltaX, centerY + deltaY); g2.draw(line); // register the grid line and the shape line if (axisNumber == 0) { gridShape.moveTo((float) deltaX, (float) deltaY); lineShape.moveTo((float) (deltaX * value), (float) (deltaY * value)); } else { gridShape.lineTo((float) deltaX, (float) deltaY); lineShape.lineTo((float) (deltaX * value), (float) (deltaY * value)); } if (showAxisLabels) { // draw the label double labelX = centerX + deltaX * (1 + axisLabelGap); double labelY = centerY + deltaY * (1 + axisLabelGap); String label = currentKey.toString(); drawLabel(g2, radarArea, label, axisNumber, labelX, labelY); } } gridShape.closePath(); lineShape.closePath(); // draw five gray concentric gridlines g2.translate(centerX, centerY); g2.setPaint(gridLinePaint); g2.setStroke(gridLineStroke); for (int i = 5; i > 0; i--) { Shape scaledGrid = gridShape .createTransformedShape(AffineTransform.getScaleInstance(i / 5.0, i / 5.0)); g2.draw(scaledGrid); } // get the color for the plot shape. Paint dataPaint = plotLinePaint; if (dataPaint == ADAPTIVE_COLORING) { //multiplier = Math.exp(Math.log(multiplier) * 2 / numAxes); dataPaint = getMultiplierColor((float) multiplier); } // compute a slightly transparent version of the plot color for // the fill. Paint dataFill = null; if (dataPaint instanceof Color && getForegroundAlpha() != 1.0) dataFill = new Color(((Color) dataPaint).getRed() / 255f, ((Color) dataPaint).getGreen() / 255f, ((Color) dataPaint).getBlue() / 255f, getForegroundAlpha()); else dataFill = dataPaint; // draw the plot shape. First fill with a parially // transparent color, then stroke with the opaque color. g2.setPaint(dataFill); g2.fill(lineShape); g2.setPaint(dataPaint); g2.setStroke(plotLineStroke); g2.draw(lineShape); // cleanup the graphics context. g2.translate(-centerX, -centerY); } }