OSDN Git Service

now can ploa a point
authorokimoto <okimoto@good-day.co.jp>
Mon, 22 Feb 2010 10:04:22 +0000 (19:04 +0900)
committerokimoto <okimoto@good-day.co.jp>
Mon, 22 Feb 2010 10:04:22 +0000 (19:04 +0900)
public/javascripts/jquery.svgplot.js

index 36eed31..b80f74f 100644 (file)
@@ -22,6 +22,7 @@ function SVGPlot(wrapper) {
        this._gridlines = []; // The formatting of the x- and y-gridlines\r
        this._equalXY = true; // True for equal-sized x- and y-units, false to fill available space\r
        this._functions = []; // The functions to be plotted, each is an object\r
+       this._points = []; // The points to be plotted, each is an object\r
        this._onstatus = null; // The callback function for status updates\r
        this._uuid = new Date().getTime();\r
        this._plotCont = this._wrapper.svg(0, 0, 0, 0, {class_: 'svg-plot'}); // The main container for the plot\r
@@ -173,6 +174,14 @@ $.extend(SVGPlot.prototype, {
                return this;\r
        },\r
 \r
+    addPoint: function(name, x, y, r, color, showLabel){\r
+        this._points.push(new SVGPlotPoint(\r
+            this, name, x, y, r, color, showLabel\r
+        ));\r
+        this._drawPlot();\r
+        return this;\r
+    },\r
+\r
        /* Retrieve the function wrappers.\r
           @param  i  (number) the function index (optional)\r
           @return  (SVGPlotFunction) the specified function or\r
@@ -249,6 +258,9 @@ $.extend(SVGPlot.prototype, {
                for (var i = 0; i < this._functions.length; i++) {\r
                        this._plotFunction(this._functions[i], i);\r
                }\r
+        for (i = 0; i < this._points.length; i++) {\r
+            this._plotPoint(this._points[i], i);\r
+        }\r
                this._drawTitle();\r
                this._drawLegend();\r
        },\r
@@ -409,6 +421,17 @@ $.extend(SVGPlot.prototype, {
                this._showStatus(p, fn._name);\r
        },\r
 \r
+       _plotPoint: function(pt, cur) {\r
+               var dims = this._getDims();\r
+               var scales = this._getScales();\r
+               var px = (pt._x - this.xAxis._scale.min) * scales[0] + dims[this.X];\r
+               var py = dims[this.H] - ((pt._y - this.yAxis._scale.min) * scales[1]) + dims[this.Y];\r
+               this._wrapper.circle(this._plot, px, py, pt._r, { fill: pt._color });\r
+               if (pt._showLabel){\r
+                       this._wrapper.text(this._plot, px+5, py+5, pt._name);\r
+               }\r
+       },\r
+\r
        /* Draw the plot title - centred. */\r
        _drawTitle: function() {\r
                this._wrapper.text(this._plotCont, this._getValue(this._plotCont, 'width') / 2,\r
@@ -590,6 +613,21 @@ $.extend(SVGPlotFunction.prototype, {
        }\r
 });\r
 \r
+function SVGPlotPoint(plot, name, x, y, r, color, showLabel){\r
+       this._plot = plot; // The owning plot\r
+       this._name = name; // Display name\r
+       this._x = x;\r
+       this._y = y;\r
+       this._r = r || 2;\r
+       this._color = color || "red";\r
+       this._showLabel = showLabel || true;\r
+}\r
+\r
+$.extend(SVGPlotPoint.prototype, {\r
+\r
+});\r
+\r
+\r
 /* Default function to plot.\r
    @param  x  (number) the input value\r
    @return  (number) the same value */\r