Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

Commit

Permalink
Added new SparklineGraph to Utils module and removed old sparklines l…
Browse files Browse the repository at this point in the history
…ibrary.

Moved TimeIntervalGraphics to Utils module.
  • Loading branch information
eduramiba committed Oct 2, 2011
1 parent a591801 commit 937e5d6
Show file tree
Hide file tree
Showing 13 changed files with 658 additions and 76 deletions.
8 changes: 4 additions & 4 deletions DesktopDataLaboratory/nbproject/genfiles.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build.xml.data.CRC32=93720211
build.xml.data.CRC32=febbff0b
build.xml.script.CRC32=e39c7ed0
build.xml.stylesheet.CRC32=a56c6a5b@1.42.2
build.xml.stylesheet.CRC32=a56c6a5b@1.46.2
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=93720211
nbproject/build-impl.xml.data.CRC32=febbff0b
nbproject/build-impl.xml.script.CRC32=91e63bf0
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.42.2
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.46.2
4 changes: 0 additions & 4 deletions DesktopDataLaboratory/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@
</dependency>
</module-dependencies>
<public-packages/>
<class-path-extension>
<runtime-relative-path>ext/spark-1.2.jar</runtime-relative-path>
<binary-origin>release/modules/ext/spark-1.2.jar</binary-origin>
</class-path-extension>
</data>
</configuration>
</project>
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ License, or (at your option) any later version.
*/
package org.gephi.desktop.datalab.utils;

import com.representqueens.spark.LineGraph;
import com.representqueens.spark.SizeParams;
import java.awt.Component;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.gephi.data.attributes.type.DynamicType;
import org.gephi.data.attributes.type.NumberList;
import org.gephi.dynamic.api.DynamicModel.TimeFormat;
import org.gephi.utils.sparklines.SparklineGraph;
import org.gephi.utils.sparklines.SparklineParameters;

/**
* TableCellRenderer for drawing sparklines from cells that have a NumberList or DynamicNumber as their value.
Expand All @@ -58,27 +58,28 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
stringRepresentation = value.toString();
} else if (value instanceof DynamicType) {
numbers = getDynamicNumberNumbers((DynamicType) value);
stringRepresentation=((DynamicType) value).toString(timeFormat==TimeFormat.DOUBLE);
stringRepresentation = ((DynamicType) value).toString(timeFormat == TimeFormat.DOUBLE);
} else {
throw new IllegalArgumentException("Only number lists and dynamic numbers are supported for sparklines rendering");
}

//If there is less than 2 elements, show as a String.
if (numbers.length < 2) {
//If there is less than 3 elements, show as a String.
if (numbers.length < 3) {
return super.getTableCellRendererComponent(table, stringRepresentation, isSelected, hasFocus, row, column);
}

JLabel label = new JLabel();

Color background;
if (isSelected) {
background = SELECTED_BACKGROUND;
} else {
background = UNSELECTED_BACKGROUND;
}

final SizeParams size = new SizeParams(table.getColumnModel().getColumn(column).getWidth(), table.getRowHeight(row) - 1, 1);
final BufferedImage i = LineGraph.createGraph(numbers, size, Color.BLUE, background);
//Note: Can't use interactive SparklineComponent because TableCellEditors don't receive mouse events.

final SparklineParameters sparklineParameters = new SparklineParameters(table.getColumnModel().getColumn(column).getWidth() - 1, table.getRowHeight(row) - 1, Color.BLUE, background, Color.RED, Color.GREEN, null);
final BufferedImage i = SparklineGraph.draw(numbers, sparklineParameters);
label.setIcon(new ImageIcon(i));
label.setToolTipText(stringRepresentation);//String representation as tooltip

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ License, or (at your option) any later version.
*/
package org.gephi.desktop.datalab.utils;

import org.gephi.utils.TimeIntervalGraphics;
import java.awt.Component;
import java.awt.Color;
import java.awt.image.BufferedImage;
Expand Down
16 changes: 8 additions & 8 deletions Utils/build.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="org.gephi.utils" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project org.gephi.utils.</description>
<import file="nbproject/build-impl.xml"/>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="org.gephi.utils" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project org.gephi.utils.</description>
<import file="nbproject/build-impl.xml"/>
</project>
90 changes: 45 additions & 45 deletions Utils/nbproject/build-impl.xml
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*** GENERATED FROM project.xml - DO NOT EDIT ***
*** EDIT ../build.xml INSTEAD ***
-->
<project name="org.gephi.utils-impl" basedir="..">
<fail message="Please build using Ant 1.7.1 or higher.">
<condition>
<not>
<antversion atleast="1.7.1"/>
</not>
</condition>
</fail>
<property file="nbproject/private/suite-private.properties"/>
<property file="nbproject/suite.properties"/>
<fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
<property file="${suite.dir}/nbproject/private/platform-private.properties"/>
<property file="${suite.dir}/nbproject/platform.properties"/>
<macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="${@{value}}"/>
</sequential>
</macrodef>
<macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="property"/>
<attribute name="value"/>
<sequential>
<property name="@{property}" value="@{value}"/>
</sequential>
</macrodef>
<property file="${user.properties.file}"/>
<nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
<condition>
<not>
<contains string="${cluster.path.evaluated}" substring="platform"/>
</not>
</condition>
</fail>
<import file="${harness.dir}/build.xml"/>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!--
*** GENERATED FROM project.xml - DO NOT EDIT ***
*** EDIT ../build.xml INSTEAD ***
-->
<project name="org.gephi.utils-impl" basedir="..">
<fail message="Please build using Ant 1.7.1 or higher.">
<condition>
<not>
<antversion atleast="1.7.1"/>
</not>
</condition>
</fail>
<property file="nbproject/private/suite-private.properties"/>
<property file="nbproject/suite.properties"/>
<fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
<property file="${suite.dir}/nbproject/private/platform-private.properties"/>
<property file="${suite.dir}/nbproject/platform.properties"/>
<macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="${@{value}}"/>
</sequential>
</macrodef>
<macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="property"/>
<attribute name="value"/>
<sequential>
<property name="@{property}" value="@{value}"/>
</sequential>
</macrodef>
<property file="${user.properties.file}"/>
<nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
<condition>
<not>
<contains string="${cluster.path.evaluated}" substring="platform"/>
</not>
</condition>
</fail>
<import file="${harness.dir}/build.xml"/>
</project>
8 changes: 4 additions & 4 deletions Utils/nbproject/genfiles.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build.xml.data.CRC32=25bb282d
build.xml.data.CRC32=8befa235
build.xml.script.CRC32=1ccc572b
build.xml.stylesheet.CRC32=a56c6a5b@1.42.2
build.xml.stylesheet.CRC32=a56c6a5b@1.46.2
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=25bb282d
nbproject/build-impl.xml.data.CRC32=8befa235
nbproject/build-impl.xml.script.CRC32=495599b5
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.42.2
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.46.2
3 changes: 2 additions & 1 deletion Utils/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<specification-version>2.0</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
</module-dependencies>
<test-dependencies>
<test-type>
<name>unit</name>
Expand All @@ -26,6 +26,7 @@
</test-dependencies>
<public-packages>
<package>org.gephi.utils</package>
<package>org.gephi.utils.sparklines</package>
</public-packages>
</data>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ License, or (at your option) any later version.
You should have received a copy of the GNU Affero General Public License
along with Gephi. If not, see <http://www.gnu.org/licenses/>.
*/
package org.gephi.desktop.datalab.utils;
package org.gephi.utils;

import java.awt.Color;
import java.awt.Graphics2D;
Expand Down
99 changes: 99 additions & 0 deletions Utils/src/org/gephi/utils/sparklines/SparklineComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
Copyright 2008-2011 Gephi
Authors : Eduardo Ramos <[email protected]>
Website : http://www.gephi.org
This file is part of Gephi.
Gephi is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Gephi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Gephi. If not, see <http://www.gnu.org/licenses/>.
*/
package org.gephi.utils.sparklines;

import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;

/**
* <p>Simple component that holds a <code>SparklineGraph</code> and auto-repaints it when mouse interaction happens if desired
* (indicate it with <code>updateMouseXPosition</code> parameter in constructors).</p>
* <p>It also takes care to update sparkline width and height to the component width and height when resized</p>
* @author Eduardo Ramos <[email protected]>
*/
public class SparklineComponent extends JComponent {

private Number[] xValues, yValues;
private Number yMinValue, yMaxValue;
private SparklineParameters sparklineParameters;

public SparklineComponent(Number[] yValues, SparklineParameters sparklineParameters, boolean updateMouseXPosition) {
this(null, yValues, null, null, sparklineParameters, updateMouseXPosition);
}

public SparklineComponent(Number[] yValues, Number yMinValue, Number yMaxValue, SparklineParameters sparklineParameters, boolean updateMouseXPosition) {
this(null, yValues, yMinValue, yMaxValue, sparklineParameters, updateMouseXPosition);
}

public SparklineComponent(Number[] xValues, Number[] yValues, SparklineParameters sparklineParameters, boolean updateMouseXPosition) {
this(xValues, yValues, null, null, sparklineParameters, updateMouseXPosition);
}

public SparklineComponent(Number[] xValues, Number[] yValues, Number yMinValue, Number yMaxValue, SparklineParameters sparklineParameters, boolean updateMouseXPosition) {
this.xValues = xValues;
this.yValues = yValues;
this.yMinValue = yMinValue;
this.yMaxValue = yMaxValue;
this.sparklineParameters = sparklineParameters;
if (updateMouseXPosition) {
initEvents();
}
}

private void initEvents() {
MouseEvents listener = new MouseEvents();
addMouseListener(listener);
addMouseMotionListener(listener);
}

@Override
protected void paintComponent(Graphics g) {
sparklineParameters.setWidth(getWidth());
sparklineParameters.setHeight(getHeight());
BufferedImage image = SparklineGraph.draw(xValues, yValues, yMinValue, yMaxValue, sparklineParameters);
g.drawImage(image, 0, 0, this);
}

class MouseEvents extends MouseAdapter implements MouseMotionListener {

@Override
public void mouseEntered(MouseEvent e) {
sparklineParameters.setHiglightedValueXPosition(e.getX());
repaint();
}

@Override
public void mouseExited(MouseEvent e) {
sparklineParameters.setHiglightedValueXPosition(null);
repaint();
}

@Override
public void mouseMoved(MouseEvent e) {
sparklineParameters.setHiglightedValueXPosition(e.getX());
repaint();
}
}
}
Loading

0 comments on commit 937e5d6

Please sign in to comment.