private String xValueFormatter(long xValue) { String ret; if (xAxisRenderer != null) { xAxisRenderer.setValue(xValue); ret = xAxisRenderer.getText(); } else if (dateFormatter != null) { ret = dateFormatter.format(xValue); } else { ret = "" + xValue; } return ret; }
private int getYLabelsMaxWidth(FontMetrics fm) { int ret = 0; for (int i = 0; i <= gridLinesCount; i++) { yAxisLabelRenderer.setValue((minYVal * gridLinesCount + i * (maxYVal - minYVal)) / gridLinesCount); int current = fm.stringWidth(yAxisLabelRenderer.getText()); if (current > ret) { ret = current; } } return ret; }
private String xValueFormatter(long xValue) { String ret; if (xAxisRenderer != null) { xAxisRenderer.setValue(xValue); ret = xAxisRenderer.getText(); } else if (dateFormatter != null) { ret = dateFormatter.format(xValue); } else { ret = "" + xValue; } return ret; }
private int getYLabelsMaxWidth(FontMetrics fm) { int ret = 0; for (int i = 0; i <= gridLinesCount; i++) { yAxisLabelRenderer.setValue((minYVal * gridLinesCount + i * (maxYVal - minYVal)) / gridLinesCount); int current = fm.stringWidth(yAxisLabelRenderer.getText()); if (current > ret) { ret = current; } } return ret; }
private void drawLabels(Graphics2D g2d, AbstractGraphRow row, double yValue) { Color oldColor = g2d.getColor(); g2d.setColor(Color.DARK_GRAY); Font oldFont = g2d.getFont(); g2d.setFont(g2d.getFont().deriveFont(Font.BOLD)); FontMetrics fm = g2d.getFontMetrics(g2d.getFont()); labelRenderer.setValue(yValue); int labelSize = g2d.getFontMetrics(g2d.getFont()).stringWidth(labelRenderer.getText()); //if close to end if (x + row.getMarkerSize() + labelSpacing + labelSize > chartRect.x + chartRect.width) { g2d.drawString(labelRenderer.getText(), x - row.getMarkerSize() - labelSpacing - labelSize, y + fm.getAscent() / 2); } else { g2d.drawString(labelRenderer.getText(), x + row.getMarkerSize() + labelSpacing, y + fm.getAscent() / 2); } g2d.setFont(oldFont); g2d.setColor(oldColor); }
private void drawLabels(Graphics2D g2d, AbstractGraphRow row, double yValue) { Color oldColor = g2d.getColor(); g2d.setColor(Color.DARK_GRAY); Font oldFont = g2d.getFont(); g2d.setFont(g2d.getFont().deriveFont(Font.BOLD)); FontMetrics fm = g2d.getFontMetrics(g2d.getFont()); labelRenderer.setValue(yValue); int labelSize = g2d.getFontMetrics(g2d.getFont()).stringWidth(labelRenderer.getText()); //if close to end if (x + row.getMarkerSize() + labelSpacing + labelSize > chartRect.x + chartRect.width) { g2d.drawString(labelRenderer.getText(), x - row.getMarkerSize() - labelSpacing - labelSize, y + fm.getAscent() / 2); } else { g2d.drawString(labelRenderer.getText(), x + row.getMarkerSize() + labelSpacing, y + fm.getAscent() / 2); } g2d.setFont(oldFont); g2d.setColor(oldColor); }
yAxisLabelRenderer.setValue((minYVal * gridLinesCount + n * (maxYVal - minYVal)) / gridLinesCount); valueLabel = yAxisLabelRenderer.getText(); labelXPos = yAxisRect.x + yAxisRect.width - fm.stringWidth(valueLabel) - spacing - spacing / 2;
yAxisLabelRenderer.setValue((minYVal * gridLinesCount + n * (maxYVal - minYVal)) / gridLinesCount); valueLabel = yAxisLabelRenderer.getText(); labelXPos = yAxisRect.x + yAxisRect.width - fm.stringWidth(valueLabel) - spacing - spacing / 2;
private void calculateXAxisDimensions(Graphics g) { FontMetrics fm = g.getFontMetrics(g.getFont()); // we need to handle this and make Y axis wider int axisHeight; if (!isPreview) { axisHeight = 2 * fm.getHeight() + spacing;//labels plus name } else { axisHeight = spacing; } xAxisLabelRenderer.setValue(maxXVal); int axisEndSpace = fm.stringWidth(xAxisLabelRenderer.getText()) / 2; xAxisRect.setBounds(chartRect.x, chartRect.y + chartRect.height - axisHeight, chartRect.width, axisHeight); if (!isPreview) { chartRect.setBounds(chartRect.x, chartRect.y, chartRect.width - axisEndSpace, chartRect.height - axisHeight); } else { chartRect.setBounds(chartRect.x, chartRect.y, chartRect.width - 2 * previewInset, chartRect.height - (previewInset + 1)); //+1 because layout take one pixel } yAxisRect.setBounds(yAxisRect.x, yAxisRect.y, yAxisRect.width, chartRect.height); }
private void calculateXAxisDimensions(Graphics g) { FontMetrics fm = g.getFontMetrics(g.getFont()); // we need to handle this and make Y axis wider int axisHeight; if (!isPreview) { axisHeight = 2 * fm.getHeight() + spacing;//labels plus name } else { axisHeight = spacing; } xAxisLabelRenderer.setValue(maxXVal); int axisEndSpace = fm.stringWidth(xAxisLabelRenderer.getText()) / 2; xAxisRect.setBounds(chartRect.x, chartRect.y + chartRect.height - axisHeight, chartRect.width, axisHeight); if (!isPreview) { chartRect.setBounds(chartRect.x, chartRect.y, chartRect.width - axisEndSpace, chartRect.height - axisHeight); } else { chartRect.setBounds(chartRect.x, chartRect.y, chartRect.width - 2 * previewInset, chartRect.height - (previewInset + 1)); //+1 because layout take one pixel } yAxisRect.setBounds(yAxisRect.x, yAxisRect.y, yAxisRect.width, chartRect.height); }
private synchronized void showHoverInfo() { if (isPreview || chartRect.width == 0 || chartRect.height == 0 || xHoverInfo == -1 || yHoverInfo == -1) { return; } long realX = minXVal + (maxXVal - minXVal) * (xHoverInfo - chartRect.x) / chartRect.width; double realY = minYVal + (maxYVal - minYVal) * (chartRect.height - yHoverInfo + chartRect.y) / chartRect.height; xAxisLabelRenderer.setValue(realX); yAxisLabelRenderer.setValue(realY); String hoverInfo = "(" + xAxisLabelRenderer.getText() + " ; " + yAxisLabelRenderer.getText() + ")"; hoverLabel.setText(hoverInfo); int labelWidth = hoverLabel.getPreferredSize().width + 5; int labelHeight = hoverLabel.getPreferredSize().height; if (hoverWindow.getWidth() < labelWidth || hoverWindow.getHeight() < labelHeight) { hoverWindow.setSize(labelWidth, labelHeight); } Point mousePos = MouseInfo.getPointerInfo().getLocation(); int hoverWindowX = mousePos.x + hoverGap; int hoverWindowY = mousePos.y + hoverGap; //we move window only if far from pointer to limit cpu double deltaX = Math.abs(hoverWindow.getLocation().getX() - hoverWindowX); double deltaY = Math.abs(hoverWindow.getLocation().getY() - hoverWindowY); if (forceHoverPosition || deltaX >= hoverGap || deltaY >= hoverGap) { //prevent out of screen int correctedX = Math.min(hoverWindowX, Toolkit.getDefaultToolkit().getScreenSize().width - hoverWindow.getSize().width); hoverWindow.setLocation(correctedX, hoverWindowY); forceHoverPosition = false; } }
private synchronized void showHoverInfo() { if (isPreview || chartRect.width == 0 || chartRect.height == 0 || xHoverInfo == -1 || yHoverInfo == -1) { return; } long realX = minXVal + (maxXVal - minXVal) * (xHoverInfo - chartRect.x) / chartRect.width; double realY = minYVal + (maxYVal - minYVal) * (chartRect.height - yHoverInfo + chartRect.y) / chartRect.height; xAxisLabelRenderer.setValue(realX); yAxisLabelRenderer.setValue(realY); String hoverInfo = "(" + xAxisLabelRenderer.getText() + " ; " + yAxisLabelRenderer.getText() + ")"; hoverLabel.setText(hoverInfo); int labelWidth = hoverLabel.getPreferredSize().width + 5; int labelHeight = hoverLabel.getPreferredSize().height; if (hoverWindow.getWidth() < labelWidth || hoverWindow.getHeight() < labelHeight) { hoverWindow.setSize(labelWidth, labelHeight); } Point mousePos = MouseInfo.getPointerInfo().getLocation(); int hoverWindowX = mousePos.x + hoverGap; int hoverWindowY = mousePos.y + hoverGap; //we move window only if far from pointer to limit cpu double deltaX = Math.abs(hoverWindow.getLocation().getX() - hoverWindowX); double deltaY = Math.abs(hoverWindow.getLocation().getY() - hoverWindowY); if (forceHoverPosition || deltaX >= hoverGap || deltaY >= hoverGap) { //prevent out of screen int correctedX = Math.min(hoverWindowX, Toolkit.getDefaultToolkit().getScreenSize().width - hoverWindow.getSize().width); hoverWindow.setLocation(correctedX, hoverWindowY); forceHoverPosition = false; } }