r102487 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102486‎ | r102487 | r102488 >
Date:03:19, 9 November 2011
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
aply modified patch of James Hong Kong
Modified paths:
  • /trunk/extensions/SemanticResultFormats/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/SemanticResultFormats/SRF_Messages.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/jqPlot/SRF_jqPlotBar.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/jqPlot/jqplot.pointLabels.min.js (added) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/RELEASE-NOTES
@@ -9,6 +9,7 @@
1010 * Added warning icon with tooltip to jqplotpie shown when there are no results instead of a non-working chart.
1111 * Added value distribution support to jqplotpie and jqplotbar.
1212 * Added min parameter to jqplotbar to set the minimun value for the Y-axis.
 13+* Added pointlabel parameter to jqplotbar, based on a patch by James Hong Kong.
1314
1415 New formats in this version are:
1516 * valuerank (written by DaSch)
Index: trunk/extensions/SemanticResultFormats/SRF_Messages.php
@@ -78,6 +78,7 @@
7979 'srf_paramdesc_bardirection'=> 'The direction of the bar chart',
8080 'srf_paramdesc_barnumbersaxislabel' => 'The label for the numbers axis',
8181 'srf-paramdesc-minvalue' => 'The minimum value to show on the Y-axis',
 82+ 'srf-paramdesc-pointlabels' => 'Display of individual data points',
8283
8384 // "gallery" format
8485 'srf_printername_gallery' => 'Gallery',
Index: trunk/extensions/SemanticResultFormats/jqPlot/jqplot.pointLabels.min.js
@@ -0,0 +1,57 @@
 2+/**
 3+ * jqPlot
 4+ * Pure JavaScript plotting plugin using jQuery
 5+ *
 6+ * Version: 1.0.0b2_r947
 7+ *
 8+ * Copyright (c) 2009-2011 Chris Leonello
 9+ * jqPlot is currently available for use in all personal or commercial projects
 10+ * under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
 11+ * version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
 12+ * choose the license that best suits your project and use it accordingly.
 13+ *
 14+ * Although not required, the author would appreciate an email letting him
 15+ * know of any substantial use of jqPlot. You can reach the author at:
 16+ * chris at jqplot dot com or see http://www.jqplot.com/info.php .
 17+ *
 18+ * If you are feeling kind and generous, consider supporting the project by
 19+ * making a donation at: http://www.jqplot.com/donate.php .
 20+ *
 21+ * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
 22+ *
 23+ * version 2007.04.27
 24+ * author Ash Searle
 25+ * http://hexmen.com/blog/2007/03/printf-sprintf/
 26+ * http://hexmen.com/js/sprintf.js
 27+ * The author (Ash Searle) has placed this code in the public domain:
 28+ * "This code is unrestricted: you are free to use it however you like."
 29+ *
 30+ * included jsDate library by Chris Leonello:
 31+ *
 32+ * Copyright (c) 2010-2011 Chris Leonello
 33+ *
 34+ * jsDate is currently available for use in all personal or commercial projects
 35+ * under both the MIT and GPL version 2.0 licenses. This means that you can
 36+ * choose the license that best suits your project and use it accordingly.
 37+ *
 38+ * jsDate borrows many concepts and ideas from the Date Instance
 39+ * Methods by Ken Snyder along with some parts of Ken's actual code.
 40+ *
 41+ * Ken's origianl Date Instance Methods and copyright notice:
 42+ *
 43+ * Ken Snyder (ken d snyder at gmail dot com)
 44+ * 2008-09-10
 45+ * version 2.0.2 (http://kendsnyder.com/sandbox/date/)
 46+ * Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
 47+ *
 48+ * jqplotToImage function based on Larry Siden's export-jqplot-to-png.js.
 49+ * Larry has generously given permission to adapt his code for inclusion
 50+ * into jqPlot.
 51+ *
 52+ * Larry's original code can be found here:
 53+ *
 54+ * https://github.com/lsiden/export-jqplot-to-png
 55+ *
 56+ *
 57+ */
 58+(function(c){c.jqplot.PointLabels=function(e){this.show=c.jqplot.config.enablePlugins;this.location="n";this.labelsFromSeries=false;this.seriesLabelIndex=null;this.labels=[];this._labels=[];this.stackedValue=false;this.ypadding=6;this.xpadding=6;this.escapeHTML=true;this.edgeTolerance=-5;this.formatter=c.jqplot.DefaultTickFormatter;this.formatString="";this.hideZeros=false;this._elems=[];c.extend(true,this,e)};var a=["nw","n","ne","e","se","s","sw","w"];var d={nw:0,n:1,ne:2,e:3,se:4,s:5,sw:6,w:7};var b=["se","s","sw","w","nw","n","ne","e"];c.jqplot.PointLabels.init=function(i,h,f,g){var e=c.extend(true,{},f,g);e.pointLabels=e.pointLabels||{};if(this.renderer.constructor===c.jqplot.BarRenderer&&this.barDirection==="horizontal"&&!e.pointLabels.location){e.pointLabels.location="e"}this.plugins.pointLabels=new c.jqplot.PointLabels(e.pointLabels);this.plugins.pointLabels.setLabels.call(this)};c.jqplot.PointLabels.prototype.setLabels=function(){var f=this.plugins.pointLabels;var h;if(f.seriesLabelIndex!=null){h=f.seriesLabelIndex}else{if(this.renderer.constructor===c.jqplot.BarRenderer&&this.barDirection==="horizontal"){h=0}else{h=(this._plotData.length===0)?0:this._plotData[0].length-1}}f._labels=[];if(f.labels.length===0||f.labelsFromSeries){if(f.stackedValue){if(this._plotData.length&&this._plotData[0].length){for(var e=0;e<this._plotData.length;e++){f._labels.push(this._plotData[e][h])}}}else{var g=this._plotData;if(this.renderer.constructor===c.jqplot.BarRenderer&&this.waterfall){g=this._data}if(g.length&&g[0].length){for(var e=0;e<g.length;e++){f._labels.push(g[e][h])}}g=null}}else{if(f.labels.length){f._labels=f.labels}}};c.jqplot.PointLabels.prototype.xOffset=function(f,e,g){e=e||this.location;g=g||this.xpadding;var h;switch(e){case"nw":h=-f.outerWidth(true)-this.xpadding;break;case"n":h=-f.outerWidth(true)/2;break;case"ne":h=this.xpadding;break;case"e":h=this.xpadding;break;case"se":h=this.xpadding;break;case"s":h=-f.outerWidth(true)/2;break;case"sw":h=-f.outerWidth(true)-this.xpadding;break;case"w":h=-f.outerWidth(true)-this.xpadding;break;default:h=-f.outerWidth(true)-this.xpadding;break}return h};c.jqplot.PointLabels.prototype.yOffset=function(f,e,g){e=e||this.location;g=g||this.xpadding;var h;switch(e){case"nw":h=-f.outerHeight(true)-this.ypadding;break;case"n":h=-f.outerHeight(true)-this.ypadding;break;case"ne":h=-f.outerHeight(true)-this.ypadding;break;case"e":h=-f.outerHeight(true)/2;break;case"se":h=this.ypadding;break;case"s":h=this.ypadding;break;case"sw":h=this.ypadding;break;case"w":h=-f.outerHeight(true)/2;break;default:h=-f.outerHeight(true)-this.ypadding;break}return h};c.jqplot.PointLabels.draw=function(w,j){var t=this.plugins.pointLabels;t.setLabels.call(this);for(var v=0;v<t._elems.length;v++){t._elems[v].emptyForce()}t._elems.splice(0,t._elems.length);if(t.show){var r="_"+this._stackAxis+"axis";if(!t.formatString){t.formatString=this[r]._ticks[0].formatString;t.formatter=this[r]._ticks[0].formatter}var C=this._plotData;var z=this._xaxis;var q=this._yaxis;var y,f;for(var v=0,u=t._labels.length;v<u;v++){var o=t._labels[v];if(t.hideZeros&&parseInt(t._labels[v],10)==0){o=""}if(o!=null){o=t.formatter(t.formatString,o)}f=document.createElement("div");t._elems[v]=c(f);y=t._elems[v];y.addClass("jqplot-point-label jqplot-series-"+this.index+" jqplot-point-"+v);y.css("position","absolute");y.insertAfter(w.canvas);if(t.escapeHTML){y.text(o)}else{y.html(o)}var g=t.location;if((this.fillToZero&&C[v][1]<0)||(this.fillToZero&&this._type==="bar"&&this.barDirection==="horizontal"&&C[v][0]<0)||(this.waterfall&&parseInt(o,10))<0){g=b[d[g]]}var n=z.u2p(C[v][0])+t.xOffset(y,g);var h=q.u2p(C[v][1])+t.yOffset(y,g);if(this.renderer.constructor==c.jqplot.BarRenderer){if(this.barDirection=="vertical"){n+=this._barNudge}else{h-=this._barNudge}}y.css("left",n);y.css("top",h);var k=n+y.width();var s=h+y.height();var B=t.edgeTolerance;var e=c(w.canvas).position().left;var x=c(w.canvas).position().top;var A=w.canvas.width+e;var m=w.canvas.height+x;if(n-B<e||h-B<x||k+B>A||s+B>m){y.remove()}y=null;f=null}}};c.jqplot.postSeriesInitHooks.push(c.jqplot.PointLabels.init);c.jqplot.postDrawSeriesHooks.push(c.jqplot.PointLabels.draw)})(jQuery);
\ No newline at end of file
Property changes on: trunk/extensions/SemanticResultFormats/jqPlot/jqplot.pointLabels.min.js
___________________________________________________________________
Added: svn:eol-style
159 + native
Index: trunk/extensions/SemanticResultFormats/jqPlot/SRF_jqPlotBar.php
@@ -51,9 +51,8 @@
5252 'styles' => array(
5353 'jquery.jqplot.css',
5454 ),
55 - 'dependencies' => array(
56 - ),
5755 );
 56+
5857 $wgResourceModules['ext.srf.jqplotbar'] = $resourceTemplate + array(
5958 'scripts' => array(
6059 'jqplot.categoryAxisRenderer.js',
@@ -61,19 +60,30 @@
6261 'jqplot.canvasAxisTickRenderer.js',
6362 'jqplot.canvasTextRenderer.js',
6463 'excanvas.js',
 64+ 'jqplot.pointLabels.js',
6565 ),
66 - 'styles' => array(
67 - ),
6866 'dependencies' => array(
6967 'ext.srf.jqplot',
7068 ),
7169 );
 70+
 71+ $wgResourceModules['ext.srf.jqplotpointlabels'] = $resourceTemplate + array(
 72+ 'scripts' => array(
 73+ 'jqplot.pointLabels.min.js',
 74+ ),
 75+ 'dependencies' => array(
 76+ 'ext.srf.jqplotbar',
 77+ ),
 78+ );
7279 }
7380
74 - protected static function loadJavascriptAndCSS() {
 81+ protected function loadJavascriptAndCSS() {
7582 global $wgOut;
76 - $wgOut->addModules( 'ext.srf.jqplot' );
7783 $wgOut->addModules( 'ext.srf.jqplotbar' );
 84+
 85+ if ( $this->params['pointlabels'] ) {
 86+ $wgOut->addModules( 'ext.srf.jqplotpointlabels' );
 87+ }
7888 }
7989
8090 /**
@@ -88,7 +98,7 @@
8999
90100 // MW 1.17 +
91101 if ( class_exists( 'ResourceLoader' ) ) {
92 - self::loadJavascriptAndCSS();
 102+ $this->loadJavascriptAndCSS();
93103 return;
94104 }
95105
@@ -109,6 +119,10 @@
110120 $scripts[] = "$srfgScriptPath/jqPlot/jqplot.canvasAxisTickRenderer.js";
111121 $scripts[] = "$srfgScriptPath/jqPlot/jqplot.canvasTextRenderer.js";
112122
 123+ if ( $this->params['pointlabels'] ) {
 124+ $scripts[] = "$srfgScriptPath/jqPlot/jqplot.pointLabels.js";
 125+ }
 126+
113127 foreach ( $scripts as $script ) {
114128 $wgOut->addScriptFile( $script );
115129 }
@@ -205,6 +219,8 @@
206220 $numbers_ticks .= ($i * $biggerMultipleOf10) . ', ';
207221 }
208222
 223+ $pointlabels = FormatJson::encode( $this->params['pointlabels'] );
 224+
209225 $js_bar =<<<END
210226 <script type="text/javascript">
211227 jQuery(document).ready(function(){
@@ -220,7 +236,8 @@
221237 barDirection: '{$this->m_bardirection}',
222238 barPadding: 6,
223239 barMargin: $barmargin
224 - }
 240+ },
 241+ pointLabels: {show: $pointlabels}
225242 }],
226243 axes: {
227244 $labels_axis: {
@@ -284,6 +301,9 @@
285302 $params['min']->setMessage( 'srf-paramdesc-minvalue' );
286303 $params['min']->setDefault( false, false );
287304
 305+ $params['pointlabels'] = new Parameter( 'pointlabels', Parameter::TYPE_BOOLEAN, false );
 306+ $params['pointlabels']->setMessage( 'srf-paramdesc-pointlabels' );
 307+
288308 return $params;
289309 }
290310

Follow-up revisions

RevisionCommit summaryAuthorDate
r105083follow up to r102882 r102487 r103330jeroendedauw21:25, 3 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   08:37, 9 November 2011

There isn't much point of adding preminified JS if you are using resource loader, which will minify it anyway.

#Comment by Siebrand (talk | contribs)   16:54, 25 November 2011

Please add message documentation for the newly added messages. Thanks.

Status & tagging log