[PATCH] visualizationsforvaadin and datetime

Hi,

The Annotated Timeline in the visualizations plugin is hardcoded not to show more than one datapoint per day by hardcoding addColumn(“date”,“Date”) in the constructor.

This patch removes that restriction and adds support for addColumn(datetime). Hopefully this can be applied to the plugin, it is quite a big assumption to make that only one datapoint exists per day. The datatime format is hardcoded to yyyy-MM-dd HH:mm:ss, i did not look into making this configurable (would be nice perhaps).

Thanks
Jorg Heymans


Index: src/org/vaadin/vaadinvisualizations/AnnotatedTimeLine.java
===================================================================
--- src/org/vaadin/vaadinvisualizations/AnnotatedTimeLine.java  (revision 22096)
+++ src/org/vaadin/vaadinvisualizations/AnnotatedTimeLine.java  (working copy)
@@ -22,9 +22,6 @@
        private static final long serialVersionUID = -1535700363714366672L;

        public AnnotatedTimeLine() {
-               addColumn("date", "Date");
-
-
        }

        public void addLineLabel(String lineLabel) {
Index: src/org/vaadin/vaadinvisualizations/widgetset/client/ui/VVisualizationWidget.java
===================================================================
--- src/org/vaadin/vaadinvisualizations/widgetset/client/ui/VVisualizationWidget.java   (revision 22096)
+++ src/org/vaadin/vaadinvisualizations/widgetset/client/ui/VVisualizationWidget.java   (working copy)
@@ -294,7 +294,11 @@
                                        DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd");
                                        nd.setValue(row, col, dtf.parse(table[row]
[col]
));
                                        //nd.setValue(row, col, new Date(table[row]
[col]
));
-                               } else if (nd.getColumnType(col) == AbstractDataTable.ColumnType.BOOLEAN){
+                } else if (nd.getColumnType(col) == ColumnType.DATETIME){
+                    DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
+                    nd.setValue(row, col, dtf.parse(table[row]
[col]
));
+                }
+                else if (nd.getColumnType(col) == AbstractDataTable.ColumnType.BOOLEAN){
                                        nd.setValue(row, col, Boolean.parseBoolean(table[row]
[col]
));
                                } else {
                                nd.setValue(row, col, table[row]
[col]
);

Also, the width and height are hardcoded in VannotatedTimeLine. Below patch makes it honor the width and height set on the AnnotatedTimeLine class.


Index: VAnnotatedTimeLine.java
===================================================================
--- VAnnotatedTimeLine.java     (revision 22096)
+++ VAnnotatedTimeLine.java     (working copy)
@@ -8,6 +8,7 @@

 import com.google.gwt.visualization.client.visualizations.AnnotatedTimeLine;
 import com.google.gwt.visualization.client.visualizations.AnnotatedTimeLine.Options;
+import com.vaadin.terminal.gwt.client.UIDL;


 public class VAnnotatedTimeLine extends VCommonVisualizationWidget {
@@ -27,7 +28,12 @@
        /** */
        AnnotatedTimeLine chart;

-       /**
+    // timeline canvas width and height
+    String width;
+
+    String height;
+
+    /**
         * The constructor should first call super() to initialize the component and
         * then handle any initialization relevant to Vaadin.
         */
@@ -45,6 +51,14 @@
                setStyleName(CLASSNAME);
        }

+    @Override
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+        this.width = uidl.getStringAttribute("width");
+        this.height  = uidl.getStringAttribute("height");
+        super.updateFromUIDL(uidl,client);
+    }
+
+
        protected void drawChart(AbstractDataTable data, AbstractDrawOptions options) {
                ApplicationConnection.getConsole().log(
                                "VAnnotatedTimeLine draw " + data.getNumberOfRows()
@@ -53,7 +67,7 @@
                        remove(chart);
                }

-               chart = new AnnotatedTimeLine(data, (Options) options, "700px", "240px" );
+               chart = new AnnotatedTimeLine(data, (Options) options, this.width, this.height );
                //chart.addSelectHandler(new VisualizationSelectHandler(chart));

                VAnnotatedTimeLine.this.add(chart);

Hi there Jorg,

I am searching for AnnotatedTimeline to work with datetime instead of date, and I found this thread.
I patched the AnnotatedTimeline and made necessary changes to work with datetime as you have mentioned but it’s not working for me, it is not rendering just blank screen.
Can you help me on resolving this issue ?

Thank you

Hi,
I tried to use the date patch and it would render blank as well(data conversion error).
I got it to work with the following changes:


  Index: src/org/vaadin/vaadinvisualizations/AnnotatedTimeLine.java
===================================================================
--- src/org/vaadin/vaadinvisualizations/AnnotatedTimeLine.java	(revision 24880)
+++ src/org/vaadin/vaadinvisualizations/AnnotatedTimeLine.java	(working copy)
@@ -22,7 +22,7 @@
 	private static final long serialVersionUID = -1535700363714366672L;
 
 	public AnnotatedTimeLine() {
-		addColumn("date", "Date");
+		addColumn("datetime", "Date");
 		
 		
 	}
@@ -44,7 +44,7 @@
 	public void add(Calendar date, ArrayList<AnnotatedTimeLineEntry> timeLineEntries) {
 		
 		String[] stringLineValues = new String[(timeLineEntries.size() * 3) +1]
;
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 		
 		stringLineValues[0]
 =  sdf.format(date.getTime());

Index: src/org/vaadin/vaadinvisualizations/widgetset/client/ui/VVisualizationWidget.java
===================================================================
--- src/org/vaadin/vaadinvisualizations/widgetset/client/ui/VVisualizationWidget.java   (revision 22096)
+++ src/org/vaadin/vaadinvisualizations/widgetset/client/ui/VVisualizationWidget.java   (working copy)
@@ -294,7 +294,11 @@
                                        DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd");
                                        nd.setValue(row, col, dtf.parse(table[row]
[col]
));
                                        //nd.setValue(row, col, new Date(table[row]
[col]
));
-                               } else if (nd.getColumnType(col) == AbstractDataTable.ColumnType.BOOLEAN){
+                } else if (nd.getColumnType(col) == ColumnType.DATETIME){
+                    DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
+                    nd.setValue(row, col, dtf.parse(table[row]
[col]
));
+                }
+                else if (nd.getColumnType(col) == AbstractDataTable.ColumnType.BOOLEAN){
                                        nd.setValue(row, col, Boolean.parseBoolean(table[row]
[col]
));
                                } else {
                                nd.setValue(row, col, table[row]
[col]
);