use of org.gephi.utils.sparklines.SparklineParameters in project gephi by gephi.
the class AbstractSparklinesGraphicsComponentProvider method setImagePainter.
public void setImagePainter(Object value, boolean isSelected) {
if (value == null) {
rendererLabel.setPainter(null);
return;
}
Number[][] values = getSparklinesXAndYNumbers(value);
Number[] xValues = values[0];
Number[] yValues = values[1];
//If there is less than 1 element, don't show anything.
if (yValues.length < 1) {
rendererLabel.setPainter(null);
return;
}
if (yValues.length == 1) {
//SparklineGraph needs at least 2 values, duplicate the only one we have to get a sparkline with a single line showing that the value does not change over time
xValues = null;
yValues = new Number[] { yValues[0], yValues[0] };
}
Color background;
if (isSelected) {
background = SELECTED_BACKGROUND;
} else {
background = UNSELECTED_BACKGROUND;
}
//Note: Can't use interactive SparklineComponent because TableCellEditors don't receive mouse events.
final SparklineParameters sparklineParameters = new SparklineParameters(rendererLabel.getWidth() - 1, rendererLabel.getHeight() - 1, Color.BLUE, background, Color.RED, Color.GREEN, null);
final BufferedImage image = SparklineGraph.draw(xValues, yValues, sparklineParameters);
rendererLabel.setPainter(new ImagePainter(image));
}
use of org.gephi.utils.sparklines.SparklineParameters in project gephi by gephi.
the class Sparkline method getImage.
public BufferedImage getImage(TimelineModel model, int width, int height) {
double newMin = model.getCustomMin();
double newMax = model.getCustomMax();
TimelineChart newChart = model.getChart();
if (chart == null || newMax != max || newMin != min || image.getWidth() != width || image.getHeight() != height || newChart != chart) {
min = newMin;
max = newMax;
chart = newChart;
if (chart != null) {
double minX = chart.getMinX().doubleValue();
double maxX = chart.getMaxX().doubleValue();
int sparklineWidth = (int) (((maxX - minX) / (max - min)) * width);
parameters = new SparklineParameters(sparklineWidth, height);
parameters.setTransparentBackground(true);
parameters.setDrawArea(true);
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
int sparklineX = (int) ((minX - min) / (max - min) * width);
BufferedImage sparklineImage = draw();
Graphics g = image.getGraphics();
g.drawImage(sparklineImage, sparklineX, 0, null);
g.dispose();
} else {
return null;
}
}
return image;
}
use of org.gephi.utils.sparklines.SparklineParameters in project gephi-plugins-bootcamp by gephi.
the class InteractiveSparkline method execute.
@Override
public void execute() {
//Show interactive sparkline window:
//Dimension is automatically updated by SparklineComponent
SparklineParameters parameters = new SparklineParameters(200, 20, SparklineParameters.DEFAULT_LINE_COLOR, new Color(225, 255, 255), Color.RED, Color.GREEN);
parameters.setHighlightTextColor(SparklineParameters.DEFAULT_TEXT_COLOR);
parameters.setHighlightTextBoxColor(SparklineParameters.DEFAULT_TEXT_BOX_COLOR);
//True makes it interactive to mouse
SparklineComponent sparklineUI = new SparklineComponent(xValues, yValues, parameters, true);
//Initial size
sparklineUI.setPreferredSize(new Dimension(200, 20));
//Using Netbeans RCP Dialogs API:
DialogDescriptor dd = new DialogDescriptor(sparklineUI, column.getTitle());
dd.setModal(false);
//No buttons
dd.setOptions(new Object[0]);
DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
}
Aggregations