Skip to content

Update to Wicket 7, Jackson 2 and jQPlot 1.0.8r1250 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@
<groupId>nl.topicus</groupId>
<artifactId>wqplot</artifactId>
<packaging>jar</packaging>
<version>1.6-SNAPSHOT</version>
<version>7.0.0-SNAPSHOT</version>
<name>WQPlot</name>
<description>Wicket/WiQuery-JqPlot binding</description>

<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<wicket.version>6.6.0</wicket.version>
<wiquery.version>6.6.0</wiquery.version>
<slf4j.version>[1.6,1.6.10]</slf4j.version>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<wicket.version>7.1.0</wicket.version>
<wiquery.version>7.0</wiquery.version>
<slf4j.version>1.7.12</slf4j.version>
<junit.version>4.11</junit.version>
<jetty.version>6.1.26</jetty.version>
<jetty.version>8.1.16.v20140903</jetty.version>

<maven-buildnumber-plugin.version>1.0</maven-buildnumber-plugin.version>
<maven-bundle-plugin.version>2.3.5</maven-bundle-plugin.version>
Expand All @@ -31,11 +36,11 @@
<maven-source-plugin.version>2.1.2</maven-source-plugin.version>
</properties>

<url>https://github.com/hielkehoeve/wiquery-jqplot/wiki</url>
<url>https://github.com/wicketstuff/wiquery-jqplot/</url>
<scm>
<url>[email protected]:hielkehoeve/wiquery-jqplot.git</url>
<connection>scm:git:[email protected]:hielkehoeve/wiquery-jqplot.git</connection>
<developerConnection>scm:git:[email protected]:hielkehoeve/wiquery-jqplot.git</developerConnection>
<url>[email protected]:wicketstuff/wiquery-jqplot.git</url>
<connection>scm:git:[email protected]:wicketstuff/wiquery-jqplot.git</connection>
<developerConnection>scm:git:[email protected]:wicketstuff/wiquery-jqplot.git</developerConnection>
</scm>

<developers>
Expand Down Expand Up @@ -88,7 +93,7 @@
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.odlabs.wiquery</groupId>
<groupId>org.wicketstuff.wiquery</groupId>
<artifactId>wiquery-jquery-ui</artifactId>
<version>${wiquery.version}</version>
</dependency>
Expand All @@ -106,20 +111,14 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
<groupId>org.eclipse.jetty</groupId>
<artifactId>test-jetty-servlet</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-management</artifactId>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all-server</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -165,8 +164,8 @@
<version>${maven-compiler-plugin.version}</version>
<inherited>true</inherited>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>UTF-8</encoding>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
Expand Down
121 changes: 62 additions & 59 deletions src/main/java/nl/topicus/wqplot/components/JQPlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@
import java.util.List;
import java.util.Map;

import nl.topicus.wqplot.components.plugins.DefaultPlugins;
import nl.topicus.wqplot.components.plugins.IPlugin;
import nl.topicus.wqplot.components.plugins.IPluginResolver;
import nl.topicus.wqplot.components.plugins.JQPlotCanvasTextRendererResourceReference;
import nl.topicus.wqplot.data.Series;
import nl.topicus.wqplot.options.PlotOptions;
import nl.topicus.wqplot.options.PluginReferenceSerializer;

import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.protocol.http.WebSession;
import org.apache.wicket.protocol.http.request.WebClientInfo;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
import org.odlabs.wiquery.core.javascript.JsStatement;
import org.wicketstuff.wiquery.core.javascript.JsStatement;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import nl.topicus.wqplot.components.plugins.DefaultPlugins;
import nl.topicus.wqplot.components.plugins.IPlugin;
import nl.topicus.wqplot.components.plugins.IPluginResolver;
import nl.topicus.wqplot.components.plugins.JQPlotCanvasTextRendererResourceReference;
import nl.topicus.wqplot.data.Series;
import nl.topicus.wqplot.options.PlotOptions;
import nl.topicus.wqplot.options.PluginReferenceSerializer;

public class JQPlot extends WebMarkupContainer implements IPluginResolver
{
Expand Down Expand Up @@ -92,17 +94,19 @@ public void renderHead(org.apache.wicket.markup.head.IHeaderResponse response)
&& info.getProperties().getBrowserVersionMajor() < 9)
{
// wiQueryResourceManager.addJavaScriptResource(JQPlotExcanvasJavaScriptResourceReference.get());
response.render(JavaScriptHeaderItem
.forReference(JQPlotExcanvasJavaScriptResourceReference.get()));
response.render(
JavaScriptHeaderItem.forReference(JQPlotExcanvasJavaScriptResourceReference.get()));
}

// wiQueryResourceManager.addJavaScriptResource(JQPlotJavaScriptResourceReference.get());
// wiQueryResourceManager.addCssResource(JQPlotStyleSheetResourceReference.get());
// wiQueryResourceManager.addJavaScriptResource(JQPlotCanvasTextRendererResourceReference.get());
response.render(JavaScriptHeaderItem.forReference(JQPlotJavaScriptResourceReference.get()));
response.render(CssHeaderItem.forReference(JQPlotStyleSheetResourceReference.get()));
response.render(JavaScriptHeaderItem.forReference(JQPlotCanvasTextRendererResourceReference
.get()));
response.render(
JavaScriptHeaderItem.forReference(JQPlotCanvasTextRendererResourceReference.get()));

response.render(OnDomReadyHeaderItem.forScript(statement().render()));

try
{
Expand All @@ -112,41 +116,6 @@ public void renderHead(org.apache.wicket.markup.head.IHeaderResponse response)
{
throw new RuntimeException(e);
}

ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationConfig(mapper.getSerializationConfig().withSerializationInclusion(
Inclusion.NON_NULL));
String optionsStr = "{}";
String plotDataStr = "[]";
try
{
optionsStr = mapper.writeValueAsString(options);
plotDataStr = mapper.writeValueAsString(getModelObject());
}
catch (JsonGenerationException e)
{
e.printStackTrace();
}
catch (JsonMappingException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}

JsStatement jsStatement =
new JsStatement().append("$.jqplot.config.catchErrors = " + isCatchErrors() + ";\n");
jsStatement.append("var " + getMarkupId() + " = $.jqplot('" + getMarkupId() + "', "
+ plotDataStr + ", " + optionsStr + ");\n");

for (String statement : afterRenderStatements)
jsStatement.append(statement);

response.render(JavaScriptHeaderItem.forScript(
String.format("%s function() {\n\t%s\n});", getJQueryBinding(), jsStatement.render()),
String.format("plot-%s", getMarkupId())));
}

private void addPlugins(IHeaderResponse headerResponse) throws IllegalAccessException
Expand Down Expand Up @@ -193,8 +162,8 @@ private void addPlugin(IHeaderResponse headerResponse, String plugin)
if (plugins.containsKey(plugin))
{
// wiQueryResourceManager.addJavaScriptResource(getPlugin(plugin).getJavaScriptResourceReference());
headerResponse.render(JavaScriptHeaderItem.forReference(getPlugin(plugin)
.getJavaScriptResourceReference()));
headerResponse.render(JavaScriptHeaderItem
.forReference(getPlugin(plugin).getJavaScriptResourceReference()));
return;
}

Expand All @@ -204,8 +173,8 @@ private void addPlugin(IHeaderResponse headerResponse, String plugin)
if (iPlugin != null)
{
// wiQueryResourceManager.addJavaScriptResource(iPlugin.getJavaScriptResourceReference());
headerResponse.render(JavaScriptHeaderItem.forReference(iPlugin
.getJavaScriptResourceReference()));
headerResponse.render(
JavaScriptHeaderItem.forReference(iPlugin.getJavaScriptResourceReference()));
return;
}
}
Expand All @@ -214,7 +183,7 @@ private void addPlugin(IHeaderResponse headerResponse, String plugin)

/**
* Allows to register a new plugin.
*
*
* @param iPlugin
*/
public void registerPlugin(IPlugin iPlugin)
Expand All @@ -226,7 +195,7 @@ public void registerPlugin(IPlugin iPlugin)

/**
* Allows to register a new resolver.
*
*
* @param resolver
*/
public void registerPluginResolver(IPluginResolver resolver)
Expand All @@ -246,4 +215,38 @@ public IPlugin getPlugin(String name)
{
return plugins.get(name);
}

public JsStatement statement()
{
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);
String optionsStr = "{}";
String plotDataStr = "[]";
try
{
optionsStr = mapper.writeValueAsString(options);
plotDataStr = mapper.writeValueAsString(getModelObject());
}
catch (JsonGenerationException e)
{
e.printStackTrace();
}
catch (JsonMappingException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
JsStatement jsStatement =
new JsStatement().append("$.jqplot.config.catchErrors = " + isCatchErrors() + ";\n");
jsStatement.append("var " + getMarkupId() + " = $.jqplot('" + getMarkupId() + "', "
+ plotDataStr + ", " + optionsStr + ");\n");

for (String statement : afterRenderStatements)
jsStatement.append(statement);

return jsStatement;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nl.topicus.wqplot.components;

import org.odlabs.wiquery.core.events.EventLabel;
import org.wicketstuff.wiquery.core.events.EventLabel;

public enum JQPlotEvent implements EventLabel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package nl.topicus.wqplot.components;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.Application;
import org.apache.wicket.markup.head.HeaderItem;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.request.resource.JavaScriptResourceReference;

public class JQPlotJavaScriptResourceReference extends JavaScriptResourceReference
Expand All @@ -18,4 +24,17 @@ public static JQPlotJavaScriptResourceReference get()
{
return INSTANCE;
}

@Override
public List<HeaderItem> getDependencies()
{
List<HeaderItem> dependencies = new ArrayList<HeaderItem>();
for (HeaderItem headerItem : super.getDependencies())
{
dependencies.add(headerItem);
}
dependencies.add(JavaScriptHeaderItem
.forReference(Application.get().getJavaScriptLibrarySettings().getJQueryReference()));
return dependencies;
}
}
30 changes: 26 additions & 4 deletions src/main/java/nl/topicus/wqplot/components/excanvas.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Memory Leaks patch from http://explorercanvas.googlecode.com/svn/trunk/
// svn : r73
// ------------------------------------------------------------------
// Copyright 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -171,6 +174,21 @@ if (!document.createElement('canvas').getContext) {
//el.getContext().setCoordsize_()
}
return el;
},

// Memory Leaks patch : see http://code.google.com/p/explorercanvas/issues/detail?id=82
uninitElement: function(el){
if (el.getContext) {
var ctx = el.getContext();
delete ctx.element_;
delete ctx.canvas;
el.innerHTML = "";
//el.outerHTML = "";
el.context_ = null;
el.getContext = null;
el.detachEvent("onpropertychange", onPropertyChange);
el.detachEvent("onresize", onResize);
}
}
};

Expand Down Expand Up @@ -543,6 +561,9 @@ if (!document.createElement('canvas').getContext) {
// trial and error to get the same size as non VML text.
computedStyle.size *= 0.981;

// Fix for VML handling of bare font family names. Add a '' around font family names.
computedStyle.family = "'" + computedStyle.family.replace(/(\'|\")/g,'').replace(/\s*,\s*/g, "', '") + "'";

return computedStyle;
}

Expand Down Expand Up @@ -1210,8 +1231,7 @@ if (!document.createElement('canvas').getContext) {
offset = {x: 0, y: 0},
lineStr = [];

var fontStyle = getComputedStyle(processFontStyle(this.font),
this.element_);
var fontStyle = getComputedStyle(processFontStyle(this.font), this.element_);

var fontStyleString = buildStyle(fontStyle);

Expand Down Expand Up @@ -1277,7 +1297,8 @@ if (!document.createElement('canvas').getContext) {
var skewM = m[0][0].toFixed(3) + ',' + m[1][0].toFixed(3) + ',' +
m[0][1].toFixed(3) + ',' + m[1][1].toFixed(3) + ',0,0';

var skewOffset = mr(d.x / Z) + ',' + mr(d.y / Z);
var skewOffset = mr(d.x / Z + 1 - m[0][0]) + ',' + mr(d.y / Z - 2 * m[1][0]);


lineStr.push('<g_vml_:skew on="t" matrix="', skewM ,'" ',
' offset="', skewOffset, '" origin="', left ,' 0" />',
Expand Down Expand Up @@ -1354,7 +1375,7 @@ if (!document.createElement('canvas').getContext) {
case null:
case '':
this.repetition_ = 'repeat';
break
break;
case 'repeat-x':
case 'repeat-y':
case 'no-repeat':
Expand Down Expand Up @@ -1411,6 +1432,7 @@ if (!document.createElement('canvas').getContext) {
CanvasGradient = CanvasGradient_;
CanvasPattern = CanvasPattern_;
DOMException = DOMException_;
G_vmlCanvasManager._version = 888;
})();

} // if
Loading