3
* Pure JavaScript plotting plugin using jQuery
5
* Version: 1.0.0b2_r1012
7
* Copyright (c) 2009-2011 Chris Leonello
8
* jqPlot is currently available for use in all personal or commercial projects
9
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
10
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
11
* choose the license that best suits your project and use it accordingly.
13
* Although not required, the author would appreciate an email letting him
14
* know of any substantial use of jqPlot. You can reach the author at:
15
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
17
* If you are feeling kind and generous, consider supporting the project by
18
* making a donation at: http://www.jqplot.com/donate.php .
20
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
24
* http://hexmen.com/blog/2007/03/printf-sprintf/
25
* http://hexmen.com/js/sprintf.js
26
* The author (Ash Searle) has placed this code in the public domain:
27
* "This code is unrestricted: you are free to use it however you like."
32
* Class: $.jqplot.BlockRenderer
33
* Plugin renderer to draw a x-y block chart. A Block chart has data points displayed as
34
* colored squares with a text label inside. Data must be supplied in the form:
36
* > [[x1, y1, "label 1", {css}], [x2, y2, "label 2", {css}], ...]
38
* The label and css object are optional. If the label is ommitted, the
39
* box will collapse unless a css height and/or width is specified.
41
* The css object is an object specifying css properties
44
* > {background:'#4f98a5', border:'3px solid gray', padding:'1px'}
46
* Note that css properties specified with the data point override defaults
47
* specified with the series.
50
$.jqplot.BlockRenderer = function(){
51
$.jqplot.LineRenderer.call(this);
54
$.jqplot.BlockRenderer.prototype = new $.jqplot.LineRenderer();
55
$.jqplot.BlockRenderer.prototype.constructor = $.jqplot.BlockRenderer;
57
// called with scope of a series
58
$.jqplot.BlockRenderer.prototype.init = function(options) {
62
// default css styles that will be applied to all data blocks.
63
// these values will be overridden by css styles supplied with the
64
// individulal data points.
65
this.css = {padding:'2px', border:'1px solid #999', textAlign:'center'};
67
// true to escape html in the box label.
68
this.escapeHtml = false;
70
// true to turn spaces in data block label into html breaks <br />.
71
this.insertBreaks = true;
72
// prop: varyBlockColors
73
// true to vary the color of each block in this series according to
74
// the seriesColors array. False to set each block to the color
75
// specified on this series. This has no effect if a css background color
76
// option is specified in the renderer css options.
77
this.varyBlockColors = false;
78
$.extend(true, this, options);
79
if (this.css.backgroundColor) {
80
this.color = this.css.backgroundColor;
82
else if (this.css.background) {
83
this.color = this.css.background;
85
else if (!this.varyBlockColors) {
86
this.css.background = this.color;
88
this.canvas = new $.jqplot.BlockCanvas();
89
this.shadowCanvas = new $.jqplot.BlockCanvas();
90
this.canvas._plotDimensions = this._plotDimensions;
91
this.shadowCanvas._plotDimensions = this._plotDimensions;
97
// Moves an individual block. More efficient than redrawing
98
// the whole series by calling plot.drawSeries().
100
// idx - the 0 based index of the block or point in this series.
101
// x - the x coordinate in data units (value on x axis) to move the block to.
102
// y - the y coordinate in data units (value on the y axis) to move the block to.
103
// duration - optional parameter to create an animated movement. Can be a
104
// number (higher is slower animation) or 'fast', 'normal' or 'slow'. If not
105
// provided, the element is moved without any animation.
106
this.moveBlock = function (idx, x, y, duration) {
107
// update plotData, stackData, data and gridData
108
// x and y are in data coordinates.
109
var el = this.canvas._elem.children(':eq('+idx+')');
110
this.data[idx][0] = x;
111
this.data[idx][1] = y;
112
this._plotData[idx][0] = x;
113
this._plotData[idx][1] = y;
114
this._stackData[idx][0] = x;
115
this._stackData[idx][1] = y;
116
this.gridData[idx][0] = this._xaxis.series_u2p(x);
117
this.gridData[idx][1] = this._yaxis.series_u2p(y);
118
var w = el.outerWidth();
119
var h = el.outerHeight();
120
var left = this.gridData[idx][0] - w/2 + 'px';
121
var top = this.gridData[idx][1] - h/2 + 'px';
123
if (parseInt(duration, 10)) {
124
duration = parseInt(duration, 10);
126
el.animate({left:left, top:top}, duration);
129
el.css({left:left, top:top});
135
// called with scope of series
136
$.jqplot.BlockRenderer.prototype.draw = function (ctx, gd, options) {
137
if (this.plugins.pointLabels) {
138
this.plugins.pointLabels.show = false;
140
var i, el, d, gd, t, css, w, h, left, top;
141
var opts = (options != undefined) ? options : {};
142
var colorGenerator = new $.jqplot.ColorGenerator(this.seriesColors);
143
this.canvas._elem.empty();
144
for (i=0; i<this.gridData.length; i++) {
146
gd = this.gridData[i];
149
if (typeof d[2] == 'string') {
152
else if (typeof d[2] == 'object') {
155
if (typeof d[3] == 'object') {
158
if (this.insertBreaks){
159
t = t.replace(/ /g, '<br />');
161
css = $.extend(true, {}, this.css, css);
163
el = $('<div style="position:absolute;margin-left:auto;margin-right:auto;"></div>');
164
this.canvas._elem.append(el);
166
this.escapeHtml ? el.text(t) : el.html(t);
168
// remove styles we don't want overridden.
170
delete css.marginRight;
171
delete css.marginLeft;
172
if (!css.background && !css.backgroundColor && !css.backgroundImage){
173
css.background = colorGenerator.next();
177
h = el.outerHeight();
178
left = gd[0] - w/2 + 'px';
179
top = gd[1] - h/2 + 'px';
180
el.css({left:left, top:top});
185
$.jqplot.BlockCanvas = function() {
186
$.jqplot.ElemContainer.call(this);
190
$.jqplot.BlockCanvas.prototype = new $.jqplot.ElemContainer();
191
$.jqplot.BlockCanvas.prototype.constructor = $.jqplot.BlockCanvas;
193
$.jqplot.BlockCanvas.prototype.createElement = function(offsets, clss, plotDimensions) {
194
this._offsets = offsets;
195
var klass = 'jqplot-blockCanvas';
196
if (clss != undefined) {
200
// if this canvas already has a dom element, don't make a new one.
202
elem = this._elem.get(0);
205
elem = document.createElement('div');
207
// if new plotDimensions supplied, use them.
208
if (plotDimensions != undefined) {
209
this._plotDimensions = plotDimensions;
212
var w = this._plotDimensions.width - this._offsets.left - this._offsets.right + 'px';
213
var h = this._plotDimensions.height - this._offsets.top - this._offsets.bottom + 'px';
214
this._elem = $(elem);
215
this._elem.css({ position: 'absolute', width:w, height:h, left: this._offsets.left, top: this._offsets.top });
217
this._elem.addClass(klass);
221
$.jqplot.BlockCanvas.prototype.setContext = function() {
227
clearRect:function(){return null;}
b'\\ No newline at end of file'