Teaching:TUW - UE InfoVis WS 2006/07 - Gruppe 02 - Aufgabe 3 - Prototype: Difference between revisions
Jump to navigation
Jump to search
(→code) |
|||
Line 14: | Line 14: | ||
==code== | ==code== | ||
===class1=== | ===class1=== | ||
<pre> | |||
//@author: simon diesenreiter (sd) | |||
//@year: 2006 | |||
//@class InfoVisMain: main entry class for the project | |||
import java.util.Date; | |||
import java.text.SimpleDateFormat; | |||
import prefuse.data.parser.DateTimeParser; | |||
import prefuse.data.parser.DateParser; | |||
import prefuse.data.parser.TimeParser; | |||
import prefuse.data.parser.DoubleParser; | |||
import prefuse.data.parser.DataParser; | |||
import prefuse.data.parser.ParserFactory; | |||
import prefuse.data.io.CSVTableReader; | |||
import prefuse.data.io.TableReadListener; | |||
import prefuse.data.Table; | |||
import prefuse.data.io.DataIOException; | |||
import prefuse.data.io.DelimitedTextTableReader; | |||
import prefuse.data.Schema; | |||
import prefuse.Visualization; | |||
import prefuse.render.DefaultRendererFactory; | |||
import prefuse.render.ShapeRenderer; | |||
import java.io.FileInputStream; | |||
import java.io.File; | |||
import java.io.FileNotFoundException; | |||
import java.util.Calendar; | |||
//imports for step4: actions | |||
import prefuse.action.layout.AxisLayout; | |||
import prefuse.Constants; | |||
import prefuse.visual.expression.VisiblePredicate; | |||
import prefuse.action.assignment.ColorAction; | |||
import prefuse.visual.VisualItem; | |||
import prefuse.util.ColorLib; | |||
import prefuse.action.assignment.DataShapeAction; | |||
import prefuse.action.ActionList; | |||
import prefuse.action.RepaintAction; | |||
import prefuse.action.assignment.DataColorAction; | |||
import java.awt.Color; | |||
import prefuse.action.layout.AxisLabelLayout; | |||
//imports for step5: display | |||
import prefuse.Display; | |||
import prefuse.controls.ZoomControl; | |||
import prefuse.controls.PanControl; | |||
import javax.swing.BorderFactory; | |||
import prefuse.controls.ToolTipControl; | |||
//imports for step6: launching the Application | |||
import javax.swing.JFrame; | |||
public class InfoVisMain { | |||
private static final String group = "data"; | |||
private static final int tilesize = 10; //tilesize in pixel | |||
private static final int binsize = 5; //number of bins for color-coding | |||
private static boolean logFlag = false; // a flag for setting linear or logarithmic scale | |||
public static void main(String[] args){ | |||
//-------basic output---------- | |||
System.out.println("InfoVisMain.main(): started \n"); | |||
//1: read the data from a file******************************************************************* | |||
/* | |||
* example file-entry: | |||
* column1: 01.01.1977 11:00:00 | |||
* column2: 5,721 | |||
*/ | |||
//set up the Parser: | |||
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); | |||
SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy"); | |||
SimpleDateFormat tf = new SimpleDateFormat("HH:mm:ss"); | |||
DateTimeParser dateTimeParser = new DateTimeParser(); | |||
DateParser dateParser = new DateParser(df); | |||
TimeParser timeParser = new TimeParser(tf); | |||
DoubleParser doubleParser = new DoubleParser(); | |||
DataParser[] dP1 = new DataParser[]{dateParser, timeParser, doubleParser}; | |||
ParserFactory pF1 = new ParserFactory(dP1); | |||
DataParser[] dP2 = new DataParser[]{dateTimeParser, doubleParser}; | |||
ParserFactory pF2 = new ParserFactory(dP2); | |||
File file = new File("D:\\infovis_eclipse_workspace\\resources\\abfluss_mittersill_csv_1jahr.csv"); | |||
DelimitedTextTableReader reader = new DelimitedTextTableReader("[;]", pF2); | |||
Table table = new Table(); | |||
try{ | |||
// System.out.println("InfoVisMain.main()1: reading file: " + file.getName()); | |||
table = reader.readTable(file); | |||
// System.out.println("InfoVisMain.main()2: reading file: " + file.getName()); | |||
} | |||
catch(DataIOException ex){ | |||
System.out.println("InfoVisMain.main(): error reading the file: " + ex.getMessage()); | |||
} | |||
table.addColumn("Tag", int.class); | |||
table.addColumn("Woche", int.class); | |||
table.addColumn("Jahr", int.class); | |||
//output: tableproperties (size, etc..) | |||
System.out.println("Table_properties: " + table.toString()); | |||
// //output: table after reading from file | |||
// System.out.println("table after reading from file"); | |||
// for(int i=0; i<table.getRowCount(); i++){ | |||
// for (int j=0; j<table.getColumnCount(); j++){ | |||
// System.out.print(table.get(i, j).toString() + "\t"); | |||
// } | |||
// System.out.print("\n"); | |||
// } | |||
for (int i=0; i<table.getRowCount(); i++){ | |||
if(table.canGetDate(table.getColumnName(0))){ | |||
Date tmpDate = table.getDate(i, 0); | |||
Calendar myCalendar = Calendar.getInstance(); | |||
myCalendar.setTime(tmpDate); | |||
// System.out.println("Wochentag: " + myCalendar.get(Calendar.DAY_OF_WEEK)); | |||
// System.out.println("Woche: " + myCalendar.get(Calendar.WEEK_OF_YEAR)); | |||
table.setInt(i, "Tag", myCalendar.get(Calendar.DAY_OF_WEEK)); | |||
table.setInt(i, "Woche", myCalendar.get(Calendar.WEEK_OF_YEAR)); | |||
table.setInt(i, "Jahr", myCalendar.get(Calendar.YEAR)); | |||
} | |||
} | |||
//output: table after adding extracolumns for weekday and week | |||
System.out.println("table after adding extracolumns for weekday, week and year"); | |||
for(int i=0; i<table.getRowCount(); i++){ | |||
for (int j=0; j<table.getColumnCount(); j++){ | |||
System.out.print(table.get(i, j).toString() + "\t"); | |||
} | |||
System.out.print("\n"); | |||
} | |||
//2: create a Visualisation... ********************************************************************* | |||
Visualization vis = new Visualization(); | |||
vis.add(group, table); | |||
// -- 3. the renderers and renderer factory --------------------------- | |||
ShapeRenderer myShapeR = new ShapeRenderer(tilesize);//create a default shapeRenderer with size tilesize | |||
DefaultRendererFactory rf = new DefaultRendererFactory(myShapeR); | |||
vis.setRendererFactory(rf); | |||
// -- 4. the processing actions -------------------------------------- | |||
AxisLayout x_axis = new AxisLayout(group, "Woche", Constants.X_AXIS, VisiblePredicate.TRUE); | |||
vis.putAction("x", x_axis); | |||
AxisLayout y_axis = new AxisLayout(group, "Tag", Constants.Y_AXIS, VisiblePredicate.TRUE); | |||
vis.putAction("y", y_axis); | |||
// @todo: dayLabels funkt noch nicht | |||
// AxisLabelLayout dayLabels = new AxisLabelLayout("Tag", y_axis); | |||
// vis.putAction("dayLabel", dayLabels); | |||
int[] palette = ColorLib.getInterpolatedPalette(binsize, | |||
ColorLib.color(Color.BLUE), ColorLib.color(Color.RED)); | |||
DataColorAction dataColor = new DataColorAction(group, "Abfluss", Constants.NUMERICAL, | |||
VisualItem.FILLCOLOR, palette); | |||
if(logFlag)dataColor.setScale(Constants.LOG_SCALE); | |||
vis.putAction("dataColor", dataColor); | |||
ActionList draw = new ActionList(); | |||
draw.add(x_axis); | |||
draw.add(y_axis); | |||
// draw.add(dayLabels); | |||
draw.add(dataColor); | |||
draw.add(new RepaintAction()); | |||
vis.putAction("draw", draw); | |||
// -- 5. the display and interactive controls ------------------------- | |||
Display d = new Display(vis); | |||
d.setBorder(BorderFactory.createEmptyBorder(20,20,20,20)); | |||
d.setSize(tilesize*53, tilesize*7); //size = (tilesize*weeks+offset, tilesize*days+offset) | |||
d.setHighQuality(true); | |||
ToolTipControl ttc = new ToolTipControl(new String[] {"Datum", "Abfluss"}); | |||
d.addControlListener(ttc); | |||
d.addControlListener(new ZoomControl()); | |||
// -- 6. launch the visualization ------------------------------------- | |||
// create a new window to hold the visualization | |||
JFrame frame = new JFrame("T I L E M A P"); | |||
// ensure application exits when window is closed | |||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |||
frame.add(d); | |||
frame.pack(); // layout components in window | |||
frame.setVisible(true); // show the window | |||
vis.run("draw"); | |||
} | |||
} | |||
</pre> | |||
===class2=== | ===class2=== | ||
===class3=== | ===class3=== |
Revision as of 19:46, 18 December 2006
our prototype here
architecture
description
images
code
class1
//@author: simon diesenreiter (sd) //@year: 2006 //@class InfoVisMain: main entry class for the project import java.util.Date; import java.text.SimpleDateFormat; import prefuse.data.parser.DateTimeParser; import prefuse.data.parser.DateParser; import prefuse.data.parser.TimeParser; import prefuse.data.parser.DoubleParser; import prefuse.data.parser.DataParser; import prefuse.data.parser.ParserFactory; import prefuse.data.io.CSVTableReader; import prefuse.data.io.TableReadListener; import prefuse.data.Table; import prefuse.data.io.DataIOException; import prefuse.data.io.DelimitedTextTableReader; import prefuse.data.Schema; import prefuse.Visualization; import prefuse.render.DefaultRendererFactory; import prefuse.render.ShapeRenderer; import java.io.FileInputStream; import java.io.File; import java.io.FileNotFoundException; import java.util.Calendar; //imports for step4: actions import prefuse.action.layout.AxisLayout; import prefuse.Constants; import prefuse.visual.expression.VisiblePredicate; import prefuse.action.assignment.ColorAction; import prefuse.visual.VisualItem; import prefuse.util.ColorLib; import prefuse.action.assignment.DataShapeAction; import prefuse.action.ActionList; import prefuse.action.RepaintAction; import prefuse.action.assignment.DataColorAction; import java.awt.Color; import prefuse.action.layout.AxisLabelLayout; //imports for step5: display import prefuse.Display; import prefuse.controls.ZoomControl; import prefuse.controls.PanControl; import javax.swing.BorderFactory; import prefuse.controls.ToolTipControl; //imports for step6: launching the Application import javax.swing.JFrame; public class InfoVisMain { private static final String group = "data"; private static final int tilesize = 10; //tilesize in pixel private static final int binsize = 5; //number of bins for color-coding private static boolean logFlag = false; // a flag for setting linear or logarithmic scale public static void main(String[] args){ //-------basic output---------- System.out.println("InfoVisMain.main(): started \n"); //1: read the data from a file******************************************************************* /* * example file-entry: * column1: 01.01.1977 11:00:00 * column2: 5,721 */ //set up the Parser: SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy"); SimpleDateFormat tf = new SimpleDateFormat("HH:mm:ss"); DateTimeParser dateTimeParser = new DateTimeParser(); DateParser dateParser = new DateParser(df); TimeParser timeParser = new TimeParser(tf); DoubleParser doubleParser = new DoubleParser(); DataParser[] dP1 = new DataParser[]{dateParser, timeParser, doubleParser}; ParserFactory pF1 = new ParserFactory(dP1); DataParser[] dP2 = new DataParser[]{dateTimeParser, doubleParser}; ParserFactory pF2 = new ParserFactory(dP2); File file = new File("D:\\infovis_eclipse_workspace\\resources\\abfluss_mittersill_csv_1jahr.csv"); DelimitedTextTableReader reader = new DelimitedTextTableReader("[;]", pF2); Table table = new Table(); try{ // System.out.println("InfoVisMain.main()1: reading file: " + file.getName()); table = reader.readTable(file); // System.out.println("InfoVisMain.main()2: reading file: " + file.getName()); } catch(DataIOException ex){ System.out.println("InfoVisMain.main(): error reading the file: " + ex.getMessage()); } table.addColumn("Tag", int.class); table.addColumn("Woche", int.class); table.addColumn("Jahr", int.class); //output: tableproperties (size, etc..) System.out.println("Table_properties: " + table.toString()); // //output: table after reading from file // System.out.println("table after reading from file"); // for(int i=0; i<table.getRowCount(); i++){ // for (int j=0; j<table.getColumnCount(); j++){ // System.out.print(table.get(i, j).toString() + "\t"); // } // System.out.print("\n"); // } for (int i=0; i<table.getRowCount(); i++){ if(table.canGetDate(table.getColumnName(0))){ Date tmpDate = table.getDate(i, 0); Calendar myCalendar = Calendar.getInstance(); myCalendar.setTime(tmpDate); // System.out.println("Wochentag: " + myCalendar.get(Calendar.DAY_OF_WEEK)); // System.out.println("Woche: " + myCalendar.get(Calendar.WEEK_OF_YEAR)); table.setInt(i, "Tag", myCalendar.get(Calendar.DAY_OF_WEEK)); table.setInt(i, "Woche", myCalendar.get(Calendar.WEEK_OF_YEAR)); table.setInt(i, "Jahr", myCalendar.get(Calendar.YEAR)); } } //output: table after adding extracolumns for weekday and week System.out.println("table after adding extracolumns for weekday, week and year"); for(int i=0; i<table.getRowCount(); i++){ for (int j=0; j<table.getColumnCount(); j++){ System.out.print(table.get(i, j).toString() + "\t"); } System.out.print("\n"); } //2: create a Visualisation... ********************************************************************* Visualization vis = new Visualization(); vis.add(group, table); // -- 3. the renderers and renderer factory --------------------------- ShapeRenderer myShapeR = new ShapeRenderer(tilesize);//create a default shapeRenderer with size tilesize DefaultRendererFactory rf = new DefaultRendererFactory(myShapeR); vis.setRendererFactory(rf); // -- 4. the processing actions -------------------------------------- AxisLayout x_axis = new AxisLayout(group, "Woche", Constants.X_AXIS, VisiblePredicate.TRUE); vis.putAction("x", x_axis); AxisLayout y_axis = new AxisLayout(group, "Tag", Constants.Y_AXIS, VisiblePredicate.TRUE); vis.putAction("y", y_axis); // @todo: dayLabels funkt noch nicht // AxisLabelLayout dayLabels = new AxisLabelLayout("Tag", y_axis); // vis.putAction("dayLabel", dayLabels); int[] palette = ColorLib.getInterpolatedPalette(binsize, ColorLib.color(Color.BLUE), ColorLib.color(Color.RED)); DataColorAction dataColor = new DataColorAction(group, "Abfluss", Constants.NUMERICAL, VisualItem.FILLCOLOR, palette); if(logFlag)dataColor.setScale(Constants.LOG_SCALE); vis.putAction("dataColor", dataColor); ActionList draw = new ActionList(); draw.add(x_axis); draw.add(y_axis); // draw.add(dayLabels); draw.add(dataColor); draw.add(new RepaintAction()); vis.putAction("draw", draw); // -- 5. the display and interactive controls ------------------------- Display d = new Display(vis); d.setBorder(BorderFactory.createEmptyBorder(20,20,20,20)); d.setSize(tilesize*53, tilesize*7); //size = (tilesize*weeks+offset, tilesize*days+offset) d.setHighQuality(true); ToolTipControl ttc = new ToolTipControl(new String[] {"Datum", "Abfluss"}); d.addControlListener(ttc); d.addControlListener(new ZoomControl()); // -- 6. launch the visualization ------------------------------------- // create a new window to hold the visualization JFrame frame = new JFrame("T I L E M A P"); // ensure application exits when window is closed frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(d); frame.pack(); // layout components in window frame.setVisible(true); // show the window vis.run("draw"); } }