~openerp-dev/openerp-web/trunk-view_improvement-psi

« back to all changes in this revision

Viewing changes to addons/web_graph/static/lib/flotr2/js/Text.js

  • Committer: Jitendra Prajapati(OpenERP)
  • Date: 2014-01-28 05:37:19 UTC
  • mfrom: (3870.1.48 web)
  • Revision ID: prajapatijitendra7969@gmail.com-20140128053719-keddm9112a4cl8mr
[MERGE]with main branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * Text Utilities
3
 
 */
4
 
(function () {
5
 
 
6
 
var
7
 
  F = Flotr,
8
 
  D = F.DOM,
9
 
  _ = F._,
10
 
 
11
 
Text = function (o) {
12
 
  this.o = o;
13
 
};
14
 
 
15
 
Text.prototype = {
16
 
 
17
 
  dimensions : function (text, canvasStyle, htmlStyle, className) {
18
 
 
19
 
    if (!text) return { width : 0, height : 0 };
20
 
    
21
 
    return (this.o.html) ?
22
 
      this.html(text, this.o.element, htmlStyle, className) : 
23
 
      this.canvas(text, canvasStyle);
24
 
  },
25
 
 
26
 
  canvas : function (text, style) {
27
 
 
28
 
    if (!this.o.textEnabled) return;
29
 
    style = style || {};
30
 
 
31
 
    var
32
 
      metrics = this.measureText(text, style),
33
 
      width = metrics.width,
34
 
      height = style.size || F.defaultOptions.fontSize,
35
 
      angle = style.angle || 0,
36
 
      cosAngle = Math.cos(angle),
37
 
      sinAngle = Math.sin(angle),
38
 
      widthPadding = 2,
39
 
      heightPadding = 6,
40
 
      bounds;
41
 
 
42
 
    bounds = {
43
 
      width: Math.abs(cosAngle * width) + Math.abs(sinAngle * height) + widthPadding,
44
 
      height: Math.abs(sinAngle * width) + Math.abs(cosAngle * height) + heightPadding
45
 
    };
46
 
 
47
 
    return bounds;
48
 
  },
49
 
 
50
 
  html : function (text, element, style, className) {
51
 
 
52
 
    var div = D.create('div');
53
 
 
54
 
    D.setStyles(div, { 'position' : 'absolute', 'top' : '-10000px' });
55
 
    D.insert(div, '<div style="'+style+'" class="'+className+' flotr-dummy-div">' + text + '</div>');
56
 
    D.insert(this.o.element, div);
57
 
 
58
 
    return D.size(div);
59
 
  },
60
 
 
61
 
  measureText : function (text, style) {
62
 
 
63
 
    var
64
 
      context = this.o.ctx,
65
 
      metrics;
66
 
 
67
 
    if (!context.fillText || (F.isIphone && context.measure)) {
68
 
      return { width : context.measure(text, style)};
69
 
    }
70
 
 
71
 
    style = _.extend({
72
 
      size: F.defaultOptions.fontSize,
73
 
      weight: 1,
74
 
      angle: 0
75
 
    }, style);
76
 
 
77
 
    context.save();
78
 
    context.font = (style.weight > 1 ? "bold " : "") + (style.size*1.3) + "px sans-serif";
79
 
    metrics = context.measureText(text);
80
 
    context.restore();
81
 
 
82
 
    return metrics;
83
 
  }
84
 
};
85
 
 
86
 
Flotr.Text = Text;
87
 
 
88
 
})();