Skip to content

Commit a028b4b

Browse files
committed
Built files for 0.1 release
1 parent 2a7ece1 commit a028b4b

File tree

2 files changed

+134
-46
lines changed

2 files changed

+134
-46
lines changed

Chart.Annotation.js

Lines changed: 133 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,84 @@
1010
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
1111

1212
},{}],2:[function(require,module,exports){
13+
// Box Annotation implementation
14+
module.exports = function(Chart) {
15+
var BoxAnnotation = Chart.Element.extend({
16+
draw: function(ctx) {
17+
var view = this._view;
18+
19+
// Canvas setup
20+
ctx.lineWidth = view.borderWidth;
21+
ctx.strokeStyle = view.borderColor;
22+
ctx.fillStyle = view.backgroundColor;
23+
24+
// Draw
25+
var width = view.right - view.left,
26+
height = view.bottom - view.top;
27+
ctx.fillRect(view.left, view.top, width, height);
28+
ctx.strokeRect(view.left, view.top, width, height)
29+
}
30+
});
31+
32+
function isValid(num) {
33+
return !isNaN(num) && isFinite(num);
34+
}
35+
36+
// Function that updates a box annotation
37+
function boxUpdate(obj, options, chartInstance) {
38+
var model = obj._model = obj._model || {};
39+
40+
var xScale = chartInstance.scales[options.xScaleID];
41+
var yScale = chartInstance.scales[options.yScaleID];
42+
var chartArea = chartInstance.chartArea;
43+
44+
var left = chartArea.left,
45+
top = chartArea.top,
46+
right = chartArea.right,
47+
bottom = chartArea.bottom;
48+
49+
var min,max;
50+
51+
if (xScale) {
52+
min = isValid(options.xMin) ? xScale.getPixelForValue(options.xMin) : chartArea.left;
53+
max = isValid(options.xMax) ? xScale.getPixelForValue(options.xMax) : chartArea.right;
54+
left = Math.min(min, max);
55+
right = Math.max(min, max);
56+
}
57+
58+
if (yScale) {
59+
min = isValid(options.yMin) ? yScale.getPixelForValue(options.yMin) : chartArea.bottom;
60+
max = isValid(options.yMax) ? yScale.getPixelForValue(options.yMax) : chartArea.top;
61+
top = Math.min(min, max);
62+
bottom = Math.max(min, max);
63+
}
64+
65+
// Ensure model has rect coordinates
66+
model.left = left;
67+
model.top = top;
68+
model.right = right;
69+
model.bottom = bottom;
70+
71+
// Stylistic options
72+
model.borderColor = options.borderColor;
73+
model.borderWidth = options.borderWidth;
74+
model.backgroundColor = options.backgroundColor;
75+
}
76+
77+
78+
return {
79+
Constructor: BoxAnnotation,
80+
update: boxUpdate
81+
};
82+
}
83+
84+
},{}],3:[function(require,module,exports){
1385
// Get the chart variable
1486
var Chart = require('chart.js');
1587
Chart = typeof(Chart) === 'function' ? Chart : window.Chart;
1688
var helpers = Chart.helpers;
1789
var isArray = helpers.isArray;
1890

19-
var horizontalKeyword = 'horizontal';
20-
var verticalKeyword= 'vertica';
21-
2291
// Take the zoom namespace of Chart
2392
Chart.Annotation = Chart.Annotation || {};
2493

@@ -27,54 +96,19 @@ var defaultOptions = Chart.Annotation.defaults = {
2796
annotations: [] // default to no annotations
2897
};
2998

30-
var LineAnnotation = Chart.Element.extend({
31-
32-
draw: function(ctx) {
33-
var view = this._view;
34-
35-
// Canvas setup
36-
ctx.lineWidth = view.borderWidth;
37-
ctx.strokeStyle = view.borderColor;
38-
39-
// Draw
40-
ctx.beginPath();
41-
ctx.moveTo(view.x1, view.y1);
42-
ctx.lineTo(view.x2, view.y2);
43-
ctx.stroke();
44-
}
45-
});
46-
47-
function lineUpdate(obj, options, chartInstance) {
48-
var model = obj._model = obj._model || {};
49-
50-
var scale = chartInstance.scales[options.scaleID];
51-
var pixel = scale ? scale.getPixelForValue(options.value) : NaN;
52-
var chartArea = chartInstance.chartArea;
53-
54-
if (!isNaN(pixel)) {
55-
if (options.mode == horizontalKeyword) {
56-
model.x1 = chartArea.left;
57-
model.x2 = chartArea.right;
58-
model.y1 = model.y2 = pixel;
59-
} else {
60-
model.y1 = chartArea.top;
61-
model.y2 = chartArea.bottom;
62-
model.x1 = model.x2 = pixel;
63-
}
64-
}
65-
66-
model.borderColor = options.borderColor;
67-
model.borderWidth = options.borderWidth;
68-
}
99+
var lineAnnotation = require('./line.js')(Chart);
100+
var boxAnnotation = require('./box.js')(Chart);
69101

70102
// Map of all types
71103
var annotationTypes = Chart.Annotation.annotationTypes = {
72-
line: LineAnnotation
104+
line: lineAnnotation.Constructor,
105+
box: boxAnnotation.Constructor
73106
};
74107

75108
// Map of all update functions
76109
var updateFunctions = Chart.Annotation.updateFunctions = {
77-
line: lineUpdate,
110+
line: lineAnnotation.update,
111+
box: boxAnnotation.update
78112
};
79113

80114
// Chartjs Zoom Plugin
@@ -127,6 +161,60 @@ var AnnotationPlugin = Chart.PluginBase.extend({
127161
}
128162
});
129163

164+
module.exports = AnnotationPlugin;
130165
Chart.pluginService.register(new AnnotationPlugin());
131166

132-
},{"chart.js":1}]},{},[2]);
167+
},{"./box.js":2,"./line.js":4,"chart.js":1}],4:[function(require,module,exports){
168+
// Line Annotation implementation
169+
module.exports = function(Chart) {
170+
var horizontalKeyword = 'horizontal';
171+
var verticalKeyword = 'vertical';
172+
173+
var LineAnnotation = Chart.Element.extend({
174+
175+
draw: function(ctx) {
176+
var view = this._view;
177+
178+
// Canvas setup
179+
ctx.lineWidth = view.borderWidth;
180+
ctx.strokeStyle = view.borderColor;
181+
182+
// Draw
183+
ctx.beginPath();
184+
ctx.moveTo(view.x1, view.y1);
185+
ctx.lineTo(view.x2, view.y2);
186+
ctx.stroke();
187+
}
188+
});
189+
190+
function lineUpdate(obj, options, chartInstance) {
191+
var model = obj._model = obj._model || {};
192+
193+
var scale = chartInstance.scales[options.scaleID];
194+
var pixel = scale ? scale.getPixelForValue(options.value) : NaN;
195+
var chartArea = chartInstance.chartArea;
196+
197+
if (!isNaN(pixel)) {
198+
if (options.mode == horizontalKeyword) {
199+
model.x1 = chartArea.left;
200+
model.x2 = chartArea.right;
201+
model.y1 = model.y2 = pixel;
202+
} else {
203+
model.y1 = chartArea.top;
204+
model.y2 = chartArea.bottom;
205+
model.x1 = model.x2 = pixel;
206+
}
207+
}
208+
209+
model.borderColor = options.borderColor;
210+
model.borderWidth = options.borderWidth;
211+
}
212+
213+
214+
return {
215+
Constructor: LineAnnotation,
216+
update: lineUpdate
217+
};
218+
};
219+
220+
},{}]},{},[3]);

Chart.Annotation.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)