<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Closure Library on the Server</title>
	<atom:link href="http://www.scottlogic.co.uk/2010/09/closure-library-on-the-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scottlogic.co.uk/2010/09/closure-library-on-the-server/</link>
	<description>Financial Software Development</description>
	<lastBuildDate>Mon, 14 May 2012 11:55:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Steven Hall</title>
		<link>http://www.scottlogic.co.uk/2010/09/closure-library-on-the-server/#comment-2877</link>
		<dc:creator>Steven Hall</dc:creator>
		<pubDate>Tue, 15 Feb 2011 07:57:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/?p=69113#comment-2877</guid>
		<description>Thanks!

I&#039;ve actually no experience using the flot library for jQuery. However, I took a quick look at the project and noticed that it uses the Canvas element too. If I link you to here in the source (http://code.google.com/p/flot/source/browse/trunk/jquery.flot.js#741) you can see where flot gets the Canvas element from.

If you imagine this &quot;Canvas&quot; object as an interface, rather than a specific implementation. The interface defines such methods as drawText, clearRect etc. The actual implementation of these methods is hidden to you, by the browser. To generate the graphic on the server, you&#039;d simply need to change the implementation of the interface to draw to the Graphics2D object in Java. Because we know it&#039;s an interface, we can simply implement the methods we need (so clearRect, drawText) in Java, and expose them to the context object. The only change that you&#039;d have to make to the flot library is where the &#039;ctx&#039; variable is initialized from (this is explained in the blog post, where I expose the &#039;adapter&#039; global variable which has access to the Java canvas implementation). So rather than having &lt;pre lang=&quot;javascript&quot;&gt;var ctx = canvas.getContext(&quot;2d&quot;);&lt;/pre&gt; as we do now, we&#039;d replace that line with something like:
&lt;pre lang=&quot;javascript&quot;&gt;
var ctx;
if(requiresServerRendering()) {
  ctx = adapter; // adapter is put on the global scope by Rhino
} else {
  ctx = canvas.getContext(&quot;2d&quot;);
}
&lt;/pre&gt;

When any calls are made on ctx, they&#039;re &quot;redirected&quot; to the server, which draws to a Java graphics object. You&#039;d then expose another method to the global scope such as getImage() which returns the generated image of the Chart.

However, provided you don&#039;t have an external commitment to use the flot library, I&#039;d suggest taking a look at Closure Charts here: http://code.google.com/p/closure-charts/

We handle a lot of browser-specific issues that may come up with using a Canvas-dependent solution such as flot (for example, Closure Charts will work in all modern browsers -- mobile included -- without any change required by the user). It may be worth your while taking a quick look at the source.

Steven</description>
		<content:encoded><![CDATA[<p>Thanks!</p>
<p>I&#8217;ve actually no experience using the flot library for jQuery. However, I took a quick look at the project and noticed that it uses the Canvas element too. If I link you to here in the source (<a href="http://code.google.com/p/flot/source/browse/trunk/jquery.flot.js#741" rel="nofollow">http://code.google.com/p/flot/source/browse/trunk/jquery.flot.js#741</a>) you can see where flot gets the Canvas element from.</p>
<p>If you imagine this &#8220;Canvas&#8221; object as an interface, rather than a specific implementation. The interface defines such methods as drawText, clearRect etc. The actual implementation of these methods is hidden to you, by the browser. To generate the graphic on the server, you&#8217;d simply need to change the implementation of the interface to draw to the Graphics2D object in Java. Because we know it&#8217;s an interface, we can simply implement the methods we need (so clearRect, drawText) in Java, and expose them to the context object. The only change that you&#8217;d have to make to the flot library is where the &#8216;ctx&#8217; variable is initialized from (this is explained in the blog post, where I expose the &#8216;adapter&#8217; global variable which has access to the Java canvas implementation). So rather than having</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> ctx <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p> as we do now, we&#8217;d replace that line with something like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> ctx<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>requiresServerRendering<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  ctx <span style="color: #339933;">=</span> adapter<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// adapter is put on the global scope by Rhino</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
  ctx <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>When any calls are made on ctx, they&#8217;re &#8220;redirected&#8221; to the server, which draws to a Java graphics object. You&#8217;d then expose another method to the global scope such as getImage() which returns the generated image of the Chart.</p>
<p>However, provided you don&#8217;t have an external commitment to use the flot library, I&#8217;d suggest taking a look at Closure Charts here: <a href="http://code.google.com/p/closure-charts/" rel="nofollow">http://code.google.com/p/closure-charts/</a></p>
<p>We handle a lot of browser-specific issues that may come up with using a Canvas-dependent solution such as flot (for example, Closure Charts will work in all modern browsers &#8212; mobile included &#8212; without any change required by the user). It may be worth your while taking a quick look at the source.</p>
<p>Steven</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Germán Viera</title>
		<link>http://www.scottlogic.co.uk/2010/09/closure-library-on-the-server/#comment-2876</link>
		<dc:creator>Germán Viera</dc:creator>
		<pubDate>Tue, 08 Feb 2011 17:26:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.scottlogic.co.uk/?p=69113#comment-2876</guid>
		<description>Hi Steve,

Excellent post. Is there any way that you can share this code with me. I&#039;m facing a problema that could be solved with this kind of solution. I&#039;m using jquery flot library for charts, and I&#039;m having trouble to export the chart images. I would like to know if with this approach I would be able to plot in the server and generate chart images.

Appreciate your help,

Regards,

GV.</description>
		<content:encoded><![CDATA[<p>Hi Steve,</p>
<p>Excellent post. Is there any way that you can share this code with me. I&#8217;m facing a problema that could be solved with this kind of solution. I&#8217;m using jquery flot library for charts, and I&#8217;m having trouble to export the chart images. I would like to know if with this approach I would be able to plot in the server and generate chart images.</p>
<p>Appreciate your help,</p>
<p>Regards,</p>
<p>GV.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

