Skip to content
Browse files

Reworked readme, changed example files to be generic

  • Loading branch information...
1 parent 261165e commit a49c6bd9331f75e1450f46d4b15ad19d2d5e95d5 @ericbarnes committed Jan 7, 2011
Showing with 103 additions and 3,192 deletions.
  1. +7 −7 readme.md
  2. +0 −220 test/css/calendar.css
  3. +0 −64 test/css/colorbox.css
  4. +6 −0 test/css/test1.css
  5. +2 −0 test/css/test2.css
  6. +0 −781 test/js/colorbox.js
  7. +0 −2,120 test/js/flot.js
  8. +42 −0 test/js/test1.js
  9. +46 −0 test/js/test2.js
View
14 readme.md
@@ -1,7 +1,7 @@
# CodeIgniter Minify
The goal of this project is to provide a simple way to minify and combine js and css files inside a CodeIgniter application. Currently other systems
-exists but I wanted to the compression to be part of my build process. So on deployments I compress and minify all the js and css. Then push off to s3
+exists but I wanted the compression to be part of my build process. So on deployments I compress and minify all the js and css. Then push off to s3
but this could also be useful to write them to a single file.
## Installation
@@ -15,37 +15,37 @@ Below is an overview of different usages:
Minify JS file
<pre>
$this->load->driver('minify');
-$file = 'test/js/colorbox.js';
+$file = 'test/js/test1.js';
echo $this->minify->js->min($file);
</pre>
Minify CSS file
<pre>
$this->load->driver('minify');
-$file = 'test/css/colorbox.css';
+$file = 'test/css/test1.css';
echo $this->minify->js->min($file);
</pre>
Minify and combine an array of files. Useful if you need files to be in a certain order.
<pre>
$this->load->driver('minify');
-$this->minify->combine_files(array('test/css/calendar.css', 'test/css/colorbox.css');
+echo $this->minify->combine_files(array('test/css/test2.css', 'test/css/test1.css'));
</pre>
Minify and save a physical file
<pre>
$this->load->driver('minify');
-$file = 'test/css/colorbox.css';
+$file = 'test/css/test1.css';
$contents = $this->minify->js->min($file);
$this->minify->save_file($contents, 'test/css/all.css');
</pre>
Minify an entire directory. The second param is an array of ignored files.
<pre>
$this->load->driver('minify');
-$this->minify->combine_directory('test/css/, array('all.css'));
+echo $this->minify->combine_directory('test/css/, array('all.css'));
</pre>
## Credits
-JS-Min - https://github.com/rgrove/jsmin-php
+JS-Min - (https://github.com/rgrove/jsmin-php)
View
220 test/css/calendar.css
@@ -1,220 +0,0 @@
-#content {
- padding: 0px;
-}
-.options {
- text-align: center;
-}
-.options input {
- margin: 10px 0;
- padding: 5px;
-}
-.options select {
- margin: 10px 0;
- padding: 5px;
-}
-.start label {
- padding: 0 0 0 10px;
-}
-.start input {
- margin: 5px 10px;
-}
-#gh_calendar {
- height:280px;
- width:310px;
- float:left;
-}
-
-#theday {
- -moz-border-radius:5px;
- background-color:#36387B;
- color:#FFFFFF;
- float:left;
- font-size:90px;
- height:80px;
- line-height:50px;
- margin-top:30px;
- padding:60px;
- text-shadow:0 0 5px #DDDDDD;
- width:107px;
-}
-
-#theday span {
- display:block;
- font-size:16px;
- text-align:center;
-}
-
-
-/* the input field */
-
-#calroot {
- /* place on top of other elements. set a higher value if nessessary */
- z-index: 99999;
- margin-top:-22px;
- width:230px;
- margin: 0 0 0 20px;
-}
-
-#calbody {
- clear:both;
- font-family:sans-serif;
- width:225px;
- font-size:13px;
- border:1px solid #BDC8D2;
- border-width:1px 1px 0;
- -moz-box-shadow:0 0 10px 0px #ccc;
- -webkit-box-shadow:0 0 10px 0px #ccc;
-}
-
-#calhead {
- padding:10px 0;
-}
-
-#caltitle {
- font-family:sans-serif;
- text-align:center;
- font-size:14px;
- float:left;
- width:170px;
-}
-
-#calnext, #calprev {
- display:block;
- width:20px;
- height:20px;
- background:transparent url(../images/prev.gif) no-repeat scroll center center;
- float:left;
- cursor:pointer;
-}
-
-#calnext {
- background-image:url(../images/next.gif);
- float:right;
-}
-
-#calprev.caldisabled, #calnext.caldisabled {
- visibility:hidden;
-}
-
-#caldays span {
- display:block;
- float:left;
- width:32px;
- text-align:center;
- font-weight:bold;
- padding:4px 0;
- font-size:11px;
- color:#7e7e7e;
- line-height:18px;
-}
-
-#calweeks {
-
-}
-
-.calweek {
- clear:left;
- height:30px;
- border-bottom:1px solid #BDC8D2;
- border-top:1px solid #fff;
-}
-
-
-.calweek a {
- display:block;
- float:left;
- width:30px;
- height:30px;
- text-decoration:none;
- font-size:15px;
- text-align:center;
- line-height:30px;
- color:#000;
- border-right:1px solid #fff;
- border-left:1px solid #BDC8D2;
- text-shadow:1px 1px 1px #fff;
-}
-
-a.calsunday {
- border-left:1px solid transparent;
- color:#900;
- background-color:#f2f2f2;
-}
-
-.calweek a:hover, .calfocus {
- background:#fff;
-}
-
-.calsun {
- color:red;
-}
-
-a.caloff {
- color:#999;
- background:#eee;
-}
-
-a.caloff.calfocus {
- background-color:#ddd;
-}
-
-.caldisabled {
- background-color:#efefef !important;
- color:#ccc !important;
- cursor:default;
-}
-
-.caloff:hover {
- background-color:rgb(245, 245, 250);
-}
-
-
-#caltitle select {
- font-size:10px;
-}
-
-/* current day */
-#calcurrent {
- background-color:#498CE2;
- color:#fff;
- text-shadow:0 1px 0 #000;
- border:0;
- width:32px;
- background-image:none;
- -moz-box-shadow:inset 0 0 10px 0px #000;
-}
-
-/* today */
-#caltoday {
- background-color:#666;
- color:#fff;
- text-shadow:0 1px 0 #000;
-}
-
-#calendar {
- height:250px;
- width:261px;
- margin: 0 auto;
- padding: 0 10px 20px
-}
-
-#theday {
- -moz-border-radius:5px;
- background-color:#36387B;
- color:#FFFFFF;
- float:left;
- font-size:90px;
- height:80px;
- line-height:50px;
- margin-top:30px;
- padding:60px;
- text-shadow:0 0 5px #DDDDDD;
- width:117px;
- text-align: center;
-}
-
-#theday span {
- display:block;
- font-size:16px;
- text-align:center;
-}
View
64 test/css/colorbox.css
@@ -1,64 +0,0 @@
-#modal { background: #fff; margin:0; padding: 0;}
-#modal form.crud label {width:50%;}
-/*
- ColorBox Core Style
- The following rules are the styles that are consistant between themes.
- Avoid changing this area to maintain compatability with future versions of ColorBox.
-*/
-#colorbox, #cboxOverlay, #cboxWrapper{position:absolute; top:0; left:0; z-index:9999; overflow:hidden;}
-#cboxOverlay{position:fixed; width:100%; height:100%;}
-#cboxMiddleLeft, #cboxBottomLeft{clear:left;}
-#cboxContent{position:relative; overflow:hidden;}
-#cboxLoadedContent{overflow:auto;}
-#cboxLoadedContent iframe{display:block; width:100%; height:100%; border:0;}
-#cboxTitle{margin:0;}
-#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%;}
-#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
-
-/*
- Example user style
- The following rules are ordered and tabbed in a way that represents the
- order/nesting of the generated HTML, so that the structure easier to understand.
-*/
-#cboxOverlay{background:url(../images/overlay.png) 0 0 repeat;}
-#colorbox{}
- #cboxTopLeft{width:21px; height:21px; background:url(../images/controls.png) -100px 0 no-repeat;}
- #cboxTopRight{width:21px; height:21px; background:url(../images/controls.png) -129px 0 no-repeat;}
- #cboxBottomLeft{width:21px; height:21px; background:url(../images/controls.png) -100px -29px no-repeat;}
- #cboxBottomRight{width:21px; height:21px; background:url(../images/controls.png) -129px -29px no-repeat;}
- #cboxMiddleLeft{width:21px; background:url(../images/controls.png) left top repeat-y;}
- #cboxMiddleRight{width:21px; background:url(../images/controls.png) right top repeat-y;}
- #cboxTopCenter{height:21px; background:url(../images/border.png) 0 0 repeat-x;}
- #cboxBottomCenter{height:21px; background:url(../images/border.png) 0 -29px repeat-x;}
- #cboxContent{background:#fff;}
- #cboxLoadedContent{margin-bottom:28px;}
- #cboxTitle{position:absolute; bottom:4px; left:0; text-align:center; width:100%; color:#949494;}
- #cboxCurrent{position:absolute; bottom:4px; left:58px; color:#949494;}
- #cboxSlideshow{position:absolute; bottom:4px; right:30px; color:#0092ef;}
- #cboxPrevious{position:absolute; bottom:0; left:0px; background:url(../images/controls.png) -75px 0px no-repeat; width:25px; height:25px; text-indent:-9999px;}
- #cboxPrevious.hover{background-position:-75px -25px;}
- #cboxNext{position:absolute; bottom:0; left:27px; background:url(../images/controls.png) -50px 0px no-repeat; width:25px; height:25px; text-indent:-9999px;}
- #cboxNext.hover{background-position:-50px -25px;}
- #cboxLoadingOverlay{background:url(../images/loading_background.png) center center no-repeat;}
- #cboxLoadingGraphic{background:url(../images/loading.gif) center center no-repeat;}
- #cboxClose{position:absolute; bottom:0; right:0; background:url(../images/controls.png) -25px 0px no-repeat; width:25px; height:25px; text-indent:-9999px;}
- #cboxClose.hover{background-position:-25px -25px;}
-
-/*
- The following fixes png-transparency for IE6.
- It is also necessary for png-transparency in IE7 & IE8 to avoid 'black halos' with the fade transition
-
- Since this method does not support CSS background-positioning, it is incompatible with CSS sprites.
- Colorbox preloads navigation hover classes to account for this.
-
- !! Important Note: AlphaImageLoader src paths are relative to the HTML document,
- while regular CSS background images are relative to the CSS document.
-*/
-.cboxIE #cboxTopLeft{background:transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=../images/internet_explorer/borderTopLeft.png, sizingMethod='scale');}
-.cboxIE #cboxTopCenter{background:transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=../images/internet_explorer/borderTopCenter.png, sizingMethod='scale');}
-.cboxIE #cboxTopRight{background:transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=../images/internet_explorer/borderTopRight.png, sizingMethod='scale');}
-.cboxIE #cboxBottomLeft{background:transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=../images/internet_explorer/borderBottomLeft.png, sizingMethod='scale');}
-.cboxIE #cboxBottomCenter{background:transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=../images/internet_explorer/borderBottomCenter.png, sizingMethod='scale');}
-.cboxIE #cboxBottomRight{background:transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=../images/internet_explorer/borderBottomRight.png, sizingMethod='scale');}
-.cboxIE #cboxMiddleLeft{background:transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=../images/internet_explorer/borderMiddleLeft.png, sizingMethod='scale');}
-.cboxIE #cboxMiddleRight{background:transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=../images/internet_explorer/borderMiddleRight.png, sizingMethod='scale');}
View
6 test/css/test1.css
@@ -0,0 +1,6 @@
+body {
+ font: 62.5%/100% Arial, Helvetica, Geneva, sans-serif;
+}
+#content {
+ padding: 0px;
+}
View
2 test/css/test2.css
@@ -0,0 +1,2 @@
+#modal { background: #fff; margin:0; padding: 0;}
+#modal form.crud label {width:50%;}
View
781 test/js/colorbox.js
@@ -1,781 +0,0 @@
-/*!
- * ColorBox v1.3.12 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
- * Copyright (c) 2010 Jack Moore - jack@colorpowered.com
- * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
- */
-(function ($, window) {
-
- var
- // ColorBox Default Settings.
- // See http://colorpowered.com/colorbox for details.
- defaults = {
- transition: "elastic",
- speed: 300,
- width: false,
- initialWidth: "600",
- innerWidth: false,
- maxWidth: false,
- height: false,
- initialHeight: "450",
- innerHeight: false,
- maxHeight: false,
- scalePhotos: true,
- scrolling: true,
- inline: false,
- html: false,
- iframe: false,
- photo: false,
- href: false,
- title: false,
- rel: false,
- opacity: 0.9,
- preloading: true,
- current: "image {current} of {total}",
- previous: "previous",
- next: "next",
- close: "close",
- open: false,
- loop: true,
- slideshow: false,
- slideshowAuto: true,
- slideshowSpeed: 2500,
- slideshowStart: "start slideshow",
- slideshowStop: "stop slideshow",
- onOpen: false,
- onLoad: false,
- onComplete: false,
- onCleanup: false,
- onClosed: false,
- overlayClose: true,
- escKey: true,
- arrowKey: true
- },
-
- // Abstracting the HTML and event identifiers for easy rebranding
- colorbox = 'colorbox',
- prefix = 'cbox',
-
- // Events
- event_open = prefix + '_open',
- event_load = prefix + '_load',
- event_complete = prefix + '_complete',
- event_cleanup = prefix + '_cleanup',
- event_closed = prefix + '_closed',
- event_purge = prefix + '_purge',
- event_loaded = prefix + '_loaded',
-
- // Special Handling for IE
- isIE = $.browser.msie && !$.support.opacity, // feature detection alone gave a false positive on at least one phone browser and on some development versions of Chrome.
- isIE6 = isIE && $.browser.version < 7,
- event_ie6 = prefix + '_IE6',
-
- // Cached jQuery Object Variables
- $overlay,
- $box,
- $wrap,
- $content,
- $topBorder,
- $leftBorder,
- $rightBorder,
- $bottomBorder,
- $related,
- $window,
- $loaded,
- $loadingBay,
- $loadingOverlay,
- $title,
- $current,
- $slideshow,
- $next,
- $prev,
- $close,
-
- // Variables for cached values or use across multiple functions
- interfaceHeight,
- interfaceWidth,
- loadedHeight,
- loadedWidth,
- element,
- bookmark,
- index,
- settings,
- open,
- active,
- closing = false,
-
- publicMethod,
- boxElement = prefix + 'Element';
-
- // ****************
- // HELPER FUNCTIONS
- // ****************
-
- // jQuery object generator to reduce code size
- function $div(id, css) {
- id = id ? ' id="' + prefix + id + '"' : '';
- css = css ? ' style="' + css + '"' : '';
- return $('<div' + id + css + '/>');
- }
-
- // Convert % values to pixels
- function setSize(size, dimension) {
- dimension = dimension === 'x' ? $window.width() : $window.height();
- return (typeof size === 'string') ? Math.round((/%/.test(size) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10))) : size;
- }
-
- // Checks an href to see if it is a photo.
- // There is a force photo option (photo: true) for hrefs that cannot be matched by this regex.
- function isImage(url) {
- return settings.photo || /\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(url);
- }
-
- // Assigns function results to their respective settings. This allows functions to be used as values.
- function process(settings) {
- for (var i in settings) {
- if ($.isFunction(settings[i]) && i.substring(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time.
- settings[i] = settings[i].call(element);
- }
- }
- settings.rel = settings.rel || element.rel || 'nofollow';
- settings.href = settings.href || $(element).attr('href');
- settings.title = settings.title || element.title;
- return settings;
- }
-
- function trigger(event, callback) {
- if (callback) {
- callback.call(element);
- }
- $.event.trigger(event);
- }
-
- // Slideshow functionality
- function slideshow() {
- var
- timeOut,
- className = prefix + "Slideshow_",
- click = "click." + prefix,
- start,
- stop,
- clear;
-
- if (settings.slideshow && $related[1]) {
- start = function () {
- $slideshow
- .text(settings.slideshowStop)
- .unbind(click)
- .bind(event_complete, function () {
- if (index < $related.length - 1 || settings.loop) {
- timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
- }
- })
- .bind(event_load, function () {
- clearTimeout(timeOut);
- })
- .one(click, stop);
- $box.removeClass(className + "off").addClass(className + "on");
- timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
- };
-
- stop = function () {
- clearTimeout(timeOut);
- $slideshow
- .text(settings.slideshowStart)
- .unbind(event_complete + ' ' + event_load + ' ' + click)
- .one(click, start);
- $box.removeClass(className + "on").addClass(className + "off");
- };
-
- $slideshow.bind(event_closed, function () {
- clearTimeout(timeOut);
- });
-
- if ($box.hasClass(className + "on") || (settings.slideshowAuto && !$box.hasClass(className + "off"))) {
- start();
- } else {
- stop();
- }
- }
- }
-
- function launch(elem) {
- if (!closing) {
-
- element = elem;
-
- settings = process($.extend({}, $.data(element, colorbox)));
-
- $related = $(element);
-
- index = 0;
-
- if (settings.rel !== 'nofollow') {
- $related = $('.' + boxElement).filter(function () {
- var relRelated = $.data(this, colorbox).rel || this.rel;
- return (relRelated === settings.rel);
- });
- index = $related.index(element);
-
- // Check direct calls to ColorBox.
- if (index === -1) {
- $related = $related.add(element);
- index = $related.length - 1;
- }
- }
-
- if (!open) {
- open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
-
- $box.show();
-
- bookmark = element;
-
- try {
- bookmark.blur(); // Remove the focus from the calling element.
- }catch (e) {}
-
- // +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5'
- $overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show();
-
- // Opens inital empty ColorBox prior to content being loaded.
- settings.w = setSize(settings.initialWidth, 'x');
- settings.h = setSize(settings.initialHeight, 'y');
- publicMethod.position(0);
-
- if (isIE6) {
- $window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
- $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()});
- }).trigger('scroll.' + event_ie6);
- }
-
- trigger(event_open, settings.onOpen);
-
- $current.add($prev).add($next).add($slideshow).add($title).hide();
-
- $close.html(settings.close).show();
- }
-
- publicMethod.load(true);
- }
- }
-
- // ****************
- // PUBLIC FUNCTIONS
- // Usage format: $.fn.colorbox.close();
- // Usage from within an iframe: parent.$.fn.colorbox.close();
- // ****************
-
- publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
- var $this = this, autoOpen;
-
- if (!$this[0] && $this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit.
- return $this;
- }
-
- options = options || {};
-
- if (callback) {
- options.onComplete = callback;
- }
-
- if (!$this[0] || $this.selector === undefined) { // detects $.colorbox() and $.fn.colorbox()
- $this = $('<a/>');
- options.open = true; // assume an immediate open
- }
-
- $this.each(function () {
- $.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options));
- $(this).addClass(boxElement);
- });
-
- autoOpen = options.open;
-
- if ($.isFunction(autoOpen)) {
- autoOpen = autoOpen.call($this);
- }
-
- if (autoOpen) {
- launch($this[0]);
- }
-
- return $this;
- };
-
- // Initialize ColorBox: store common calculations, preload the interface graphics, append the html.
- // This preps colorbox for a speedy open when clicked, and lightens the burdon on the browser by only
- // having to run once, instead of each time colorbox is opened.
- publicMethod.init = function () {
- // Create & Append jQuery Objects
- $window = $(window);
- $box = $div().attr({id: colorbox, 'class': isIE ? prefix + 'IE' : ''});
- $overlay = $div("Overlay", isIE6 ? 'position:absolute' : '').hide();
-
- $wrap = $div("Wrapper");
- $content = $div("Content").append(
- $loaded = $div("LoadedContent", 'width:0; height:0; overflow:hidden'),
- $loadingOverlay = $div("LoadingOverlay").add($div("LoadingGraphic")),
- $title = $div("Title"),
- $current = $div("Current"),
- $next = $div("Next"),
- $prev = $div("Previous"),
- $slideshow = $div("Slideshow").bind(event_open, slideshow),
- $close = $div("Close")
- );
- $wrap.append( // The 3x3 Grid that makes up ColorBox
- $div().append(
- $div("TopLeft"),
- $topBorder = $div("TopCenter"),
- $div("TopRight")
- ),
- $div(false, 'clear:left').append(
- $leftBorder = $div("MiddleLeft"),
- $content,
- $rightBorder = $div("MiddleRight")
- ),
- $div(false, 'clear:left').append(
- $div("BottomLeft"),
- $bottomBorder = $div("BottomCenter"),
- $div("BottomRight")
- )
- ).children().children().css({'float': 'left'});
-
- $loadingBay = $div(false, 'position:absolute; width:9999px; visibility:hidden; display:none');
-
- $('body').prepend($overlay, $box.append($wrap, $loadingBay));
-
- $content.children()
- .hover(function () {
- $(this).addClass('hover');
- }, function () {
- $(this).removeClass('hover');
- }).addClass('hover');
-
- // Cache values needed for size calculations
- interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6
- interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
- loadedHeight = $loaded.outerHeight(true);
- loadedWidth = $loaded.outerWidth(true);
-
- // Setting padding to remove the need to do size conversions during the animation step.
- $box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide();
-
- // Setup button events.
- $next.click(publicMethod.next);
- $prev.click(publicMethod.prev);
- $close.click(publicMethod.close);
-
- // Adding the 'hover' class allowed the browser to load the hover-state
- // background graphics. The class can now can be removed.
- $content.children().removeClass('hover');
-
- $('.' + boxElement).live('click', function (e) {
- // checks to see if it was a non-left mouse-click and for clicks modified with ctrl, shift, or alt.
- if (!((e.button !== 0 && typeof e.button !== 'undefined') || e.ctrlKey || e.shiftKey || e.altKey)) {
- e.preventDefault();
- launch(this);
- }
- });
-
- $overlay.click(function () {
- if (settings.overlayClose) {
- publicMethod.close();
- }
- });
-
- // Set Navigation Key Bindings
- $(document).bind("keydown", function (e) {
- if (open && settings.escKey && e.keyCode === 27) {
- e.preventDefault();
- publicMethod.close();
- }
- if (open && settings.arrowKey && !active && $related[1]) {
- if (e.keyCode === 37 && (index || settings.loop)) {
- e.preventDefault();
- $prev.click();
- } else if (e.keyCode === 39 && (index < $related.length - 1 || settings.loop)) {
- e.preventDefault();
- $next.click();
- }
- }
- });
- };
-
- publicMethod.remove = function () {
- $box.add($overlay).remove();
- $('.' + boxElement).die('click').removeData(colorbox).removeClass(boxElement);
- };
-
- publicMethod.position = function (speed, loadedCallback) {
- var
- animate_speed,
- // keeps the top and left positions within the browser's viewport.
- posTop = Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight, 0) / 2 + $window.scrollTop(),
- posLeft = Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2 + $window.scrollLeft();
-
- // setting the speed to 0 to reduce the delay between same-sized content.
- animate_speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed;
-
- // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
- // but it has to be shrank down around the size of div#colorbox when it's done. If not,
- // it can invoke an obscure IE bug when using iframes.
- $wrap[0].style.width = $wrap[0].style.height = "9999px";
-
- function modalDimensions(that) {
- // loading overlay height has to be explicitly set for IE6.
- $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width;
- $loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
- }
-
- $box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: posTop, left: posLeft}, {
- duration: animate_speed,
- complete: function () {
- modalDimensions(this);
-
- active = false;
-
- // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
- $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
- $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
-
- if (loadedCallback) {
- loadedCallback();
- }
- },
- step: function () {
- modalDimensions(this);
- }
- });
- };
-
- publicMethod.resize = function (options) {
- if (open) {
- options = options || {};
-
- if (options.width) {
- settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
- }
- if (options.innerWidth) {
- settings.w = setSize(options.innerWidth, 'x');
- }
- $loaded.css({width: settings.w});
-
- if (options.height) {
- settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
- }
- if (options.innerHeight) {
- settings.h = setSize(options.innerHeight, 'y');
- }
- if (!options.innerHeight && !options.height) {
- var $child = $loaded.wrapInner("<div style='overflow:auto'></div>").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be.
- settings.h = $child.height();
- $child.replaceWith($child.children()); // ditch the temporary wrapper div used in height calculation
- }
- $loaded.css({height: settings.h});
-
- publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
- }
- };
-
- publicMethod.prep = function (object) {
- if (!open) {
- return;
- }
-
- var photo,
- speed = settings.transition === "none" ? 0 : settings.speed;
-
- $window.unbind('resize.' + prefix);
- $loaded.remove();
- $loaded = $div('LoadedContent').html(object);
-
- function getWidth() {
- settings.w = settings.w || $loaded.width();
- settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
- return settings.w;
- }
- function getHeight() {
- settings.h = settings.h || $loaded.height();
- settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
- return settings.h;
- }
-
- $loaded.hide()
- .appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
- .css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
- .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
- .prependTo($content);
-
- $loadingBay.hide();
-
- // floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width.
- $('#' + prefix + 'Photo').css({cssFloat: 'none', marginLeft: 'auto', marginRight: 'auto'});
-
- // Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay.
- if (isIE6) {
- $('select').not($box.find('select')).filter(function () {
- return this.style.visibility !== 'hidden';
- }).css({'visibility': 'hidden'}).one(event_cleanup, function () {
- this.style.visibility = 'inherit';
- });
- }
-
- function setPosition(s) {
- var prev, prevSrc, next, nextSrc, total = $related.length, loop = settings.loop;
- publicMethod.position(s, function () {
- function defilter() {
- if (isIE) {
- //IE adds a filter when ColorBox fades in and out that can cause problems if the loaded content contains transparent pngs.
- $box[0].style.filter = false;
- }
- }
-
- if (!open) {
- return;
- }
-
- if (isIE) {
- //This fadeIn helps the bicubic resampling to kick-in.
- if (photo) {
- $loaded.fadeIn(100);
- }
- }
-
- $loaded.show();
-
- trigger(event_loaded);
-
- $title.show().html(settings.title);
-
- if (total > 1) { // handle grouping
- if (typeof settings.current == "string") {
- $current.html(settings.current.replace(/\{current\}/, index + 1).replace(/\{total\}/, total)).show();
- }
-
- $next[(loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
- $prev[(loop || index) ? "show" : "hide"]().html(settings.previous);
-
- prev = index ? $related[index - 1] : $related[total - 1];
- next = index < total - 1 ? $related[index + 1] : $related[0];
-
- if (settings.slideshow) {
- $slideshow.show();
- }
-
- // Preloads images within a rel group
- if (settings.preloading) {
- nextSrc = $.data(next, colorbox).href || next.href;
- prevSrc = $.data(prev, colorbox).href || prev.href;
-
- nextSrc = $.isFunction(nextSrc) ? nextSrc.call(next) : nextSrc;
- prevSrc = $.isFunction(prevSrc) ? prevSrc.call(prev) : prevSrc;
-
- if (isImage(nextSrc)) {
- $('<img/>')[0].src = nextSrc;
- }
-
- if (isImage(prevSrc)) {
- $('<img/>')[0].src = prevSrc;
- }
- }
- }
-
- $loadingOverlay.hide();
-
- if (settings.transition === 'fade') {
- $box.fadeTo(speed, 1, function () {
- defilter();
- });
- } else {
- defilter();
- }
-
- $window.bind('resize.' + prefix, function () {
- publicMethod.position(0);
- });
-
- trigger(event_complete, settings.onComplete);
- });
- }
-
- if (settings.transition === 'fade') {
- $box.fadeTo(speed, 0, function () {
- setPosition(0);
- });
- } else {
- setPosition(speed);
- }
- };
-
- publicMethod.load = function (launched) {
- var href, img, setResize, prep = publicMethod.prep;
-
- active = true;
- element = $related[index];
-
- if (!launched) {
- settings = process($.extend({}, $.data(element, colorbox)));
- }
-
- trigger(event_purge);
-
- trigger(event_load, settings.onLoad);
-
- settings.h = settings.height ?
- setSize(settings.height, 'y') - loadedHeight - interfaceHeight :
- settings.innerHeight && setSize(settings.innerHeight, 'y');
-
- settings.w = settings.width ?
- setSize(settings.width, 'x') - loadedWidth - interfaceWidth :
- settings.innerWidth && setSize(settings.innerWidth, 'x');
-
- // Sets the minimum dimensions for use in image scaling
- settings.mw = settings.w;
- settings.mh = settings.h;
-
- // Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
- // If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
- if (settings.maxWidth) {
- settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth;
- settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
- }
- if (settings.maxHeight) {
- settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight;
- settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
- }
-
- href = settings.href;
-
- $loadingOverlay.show();
-
- if (settings.inline) {
- // Inserts an empty placeholder where inline content is being pulled from.
- // An event is bound to put inline content back when ColorBox closes or loads new content.
- $div().hide().insertBefore($(href)[0]).one(event_purge, function () {
- $(this).replaceWith($loaded.children());
- });
- prep($(href));
- } else if (settings.iframe) {
- // IFrame element won't be added to the DOM until it is ready to be displayed,
- // to avoid problems with DOM-ready JS that might be trying to run in that iframe.
- $box.one(event_loaded, function () {
- var $iframe = $("<iframe id='iframe' name='" + new Date().getTime() + "' frameborder=0" + (settings.scrolling ? "" : " scrolling='no'") + (isIE ? " allowtransparency='true'" : '') + " style='width:100%; height:100%; border:0; display:block;'/>");
- $iframe[0].src = settings.href;
- $iframe.appendTo($loaded).one(event_purge, function () {
- $iframe[0].src = 'about:blank';
- });
- });
-
- prep(" ");
- } else if (settings.html) {
- prep(settings.html);
- } else if (isImage(href)) {
- img = new Image();
- img.onload = function () {
- var percent;
- img.onload = null;
- img.id = prefix + 'Photo';
- $(img).css({border: 'none', display: 'block', cssFloat: 'left'});
- if (settings.scalePhotos) {
- setResize = function () {
- img.height -= img.height * percent;
- img.width -= img.width * percent;
- };
- if (settings.mw && img.width > settings.mw) {
- percent = (img.width - settings.mw) / img.width;
- setResize();
- }
- if (settings.mh && img.height > settings.mh) {
- percent = (img.height - settings.mh) / img.height;
- setResize();
- }
- }
-
- if (settings.h) {
- img.style.marginTop = Math.max(settings.h - img.height, 0) / 2 + 'px';
- }
-
- if ($related[1] && (index < $related.length - 1 || settings.loop)) {
- $(img).css({cursor: 'pointer'}).click(publicMethod.next);
- }
-
- if (isIE) {
- img.style.msInterpolationMode = 'bicubic';
- }
-
- setTimeout(function () { // Chrome will sometimes report a 0 by 0 size if there isn't pause in execution
- prep(img);
- }, 1);
- };
-
- setTimeout(function () { // Opera 10.6+ will sometimes load the src before the onload function is set
- img.src = href;
- }, 1);
- } else if (href) {
- $loadingBay.load(href, function (data, status, xhr) {
- prep(status === 'error' ? 'Request unsuccessful: ' + xhr.statusText : $(this).children());
- });
- }
- };
-
- // Navigates to the next page/image in a set.
- publicMethod.next = function () {
- if (!active) {
- index = index < $related.length - 1 ? index + 1 : 0;
- publicMethod.load();
- }
- };
-
- publicMethod.prev = function () {
- if (!active) {
- index = index ? index - 1 : $related.length - 1;
- publicMethod.load();
- }
- };
-
- // Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close();
- publicMethod.close = function () {
- if (open && !closing) {
- closing = true;
-
- open = false;
-
- trigger(event_cleanup, settings.onCleanup);
-
- $window.unbind('.' + prefix + ' .' + event_ie6);
-
- $overlay.fadeTo('fast', 0);
-
- $box.stop().fadeTo('fast', 0, function () {
-
- trigger(event_purge);
-
- $loaded.remove();
-
- $box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
-
- try {
- bookmark.focus();
- } catch (e) {
- // do nothing
- }
-
- setTimeout(function () {
- closing = false;
- trigger(event_closed, settings.onClosed);
- }, 1);
- });
- }
- };
-
- // A method for fetching the current element ColorBox is referencing.
- // returns a jQuery object.
- publicMethod.element = function () {
- return $(element);
- };
-
- publicMethod.settings = defaults;
-
- // Initializes ColorBox when the DOM has loaded
- $(publicMethod.init);
-
-}(jQuery, this));
View
2,120 test/js/flot.js
@@ -1,2120 +0,0 @@
-/*!
- * Javascript plotting library for jQuery, v. 0.6.
- *
- * Released under the MIT license by IOLA, December 2007.
- *
- */
-
-// first an inline dependency, jquery.colorhelpers.js, we inline it here
-// for convenience
-
-/* Plugin for jQuery for working with colors.
- *
- * Version 1.0.
- *
- * Inspiration from jQuery color animation plugin by John Resig.
- *
- * Released under the MIT license by Ole Laursen, October 2009.
- *
- * Examples:
- *
- * $.color.parse("#fff").scale('rgb', 0.25).add('a', -0.5).toString()
- * var c = $.color.extract($("#mydiv"), 'background-color');
- * console.log(c.r, c.g, c.b, c.a);
- * $.color.make(100, 50, 25, 0.4).toString() // returns "rgba(100,50,25,0.4)"
- *
- * Note that .scale() and .add() work in-place instead of returning
- * new objects.
- */
-(function(){jQuery.color={};jQuery.color.make=function(E,D,B,C){var F={};F.r=E||0;F.g=D||0;F.b=B||0;F.a=C!=null?C:1;F.add=function(I,H){for(var G=0;G<I.length;++G){F[I.charAt(G)]+=H}return F.normalize()};F.scale=function(I,H){for(var G=0;G<I.length;++G){F[I.charAt(G)]*=H}return F.normalize()};F.toString=function(){if(F.a>=1){return"rgb("+[F.r,F.g,F.b].join(",")+")"}else{return"rgba("+[F.r,F.g,F.b,F.a].join(",")+")"}};F.normalize=function(){function G(I,J,H){return J<I?I:(J>H?H:J)}F.r=G(0,parseInt(F.r),255);F.g=G(0,parseInt(F.g),255);F.b=G(0,parseInt(F.b),255);F.a=G(0,F.a,1);return F};F.clone=function(){return jQuery.color.make(F.r,F.b,F.g,F.a)};return F.normalize()};jQuery.color.extract=function(C,B){var D;do{D=C.css(B).toLowerCase();if(D!=""&&D!="transparent"){break}C=C.parent()}while(!jQuery.nodeName(C.get(0),"body"));if(D=="rgba(0, 0, 0, 0)"){D="transparent"}return jQuery.color.parse(D)};jQuery.color.parse=function(E){var D,B=jQuery.color.make;if(D=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(E)){return B(parseInt(D[1],10),parseInt(D[2],10),parseInt(D[3],10))}if(D=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(E)){return B(parseInt(D[1],10),parseInt(D[2],10),parseInt(D[3],10),parseFloat(D[4]))}if(D=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(E)){return B(parseFloat(D[1])*2.55,parseFloat(D[2])*2.55,parseFloat(D[3])*2.55)}if(D=/rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(E)){return B(parseFloat(D[1])*2.55,parseFloat(D[2])*2.55,parseFloat(D[3])*2.55,parseFloat(D[4]))}if(D=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(E)){return B(parseInt(D[1],16),parseInt(D[2],16),parseInt(D[3],16))}if(D=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(E)){return B(parseInt(D[1]+D[1],16),parseInt(D[2]+D[2],16),parseInt(D[3]+D[3],16))}var C=jQuery.trim(E).toLowerCase();if(C=="transparent"){return B(255,255,255,0)}else{D=A[C];return B(D[0],D[1],D[2])}};var A={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})();
-
-// the actual Flot code
-(function($) {
- function Plot(placeholder, data_, options_, plugins) {
- // data is on the form:
- // [ series1, series2 ... ]
- // where series is either just the data as [ [x1, y1], [x2, y2], ... ]
- // or { data: [ [x1, y1], [x2, y2], ... ], label: "some label", ... }
-
- var series = [],
- options = {
- // the color theme used for graphs
- colors: ["#edc240", "#afd8f8", "#cb4b4b", "#4da74d", "#9440ed"],
- legend: {
- show: true,
- noColumns: 1, // number of colums in legend table
- labelFormatter: null, // fn: string -> string
- labelBoxBorderColor: "#ccc", // border color for the little label boxes
- container: null, // container (as jQuery object) to put legend in, null means default on top of graph
- position: "ne", // position of default legend container within plot
- margin: 5, // distance from grid edge to default legend container within plot
- backgroundColor: null, // null means auto-detect
- backgroundOpacity: 0.85 // set to 0 to avoid background
- },
- xaxis: {
- mode: null, // null or "time"
- transform: null, // null or f: number -> number to transform axis
- inverseTransform: null, // if transform is set, this should be the inverse function
- min: null, // min. value to show, null means set automatically
- max: null, // max. value to show, null means set automatically
- autoscaleMargin: null, // margin in % to add if auto-setting min/max
- ticks: null, // either [1, 3] or [[1, "a"], 3] or (fn: axis info -> ticks) or app. number of ticks for auto-ticks
- tickFormatter: null, // fn: number -> string
- labelWidth: null, // size of tick labels in pixels
- labelHeight: null,
-
- // mode specific options
- tickDecimals: null, // no. of decimals, null means auto
- tickSize: null, // number or [number, "unit"]
- minTickSize: null, // number or [number, "unit"]
- monthNames: null, // list of names of months
- timeformat: null, // format string to use
- twelveHourClock: false // 12 or 24 time in time mode
- },
- yaxis: {
- autoscaleMargin: 0.02
- },
- x2axis: {
- autoscaleMargin: null
- },
- y2axis: {
- autoscaleMargin: 0.02
- },
- series: {
- points: {
- show: false,
- radius: 3,
- lineWidth: 2, // in pixels
- fill: true,
- fillColor: "#ffffff"
- },
- lines: {
- // we don't put in show: false so we can see
- // whether lines were actively disabled
- lineWidth: 2, // in pixels
- fill: false,
- fillColor: null,
- steps: false
- },
- bars: {
- show: false,
- lineWidth: 2, // in pixels
- barWidth: 1, // in units of the x axis
- fill: true,
- fillColor: null,
- align: "left", // or "center"
- horizontal: false // when horizontal, left is now top
- },
- shadowSize: 3
- },
- grid: {
- show: true,
- aboveData: false,
- color: "#545454", // primary color used for outline and labels
- backgroundColor: null, // null for transparent, else color
- tickColor: "rgba(0,0,0,0.15)", // color used for the ticks
- labelMargin: 5, // in pixels
- borderWidth: 2, // in pixels
- borderColor: null, // set if different from the grid color
- markings: null, // array of ranges or fn: axes -> array of ranges
- markingsColor: "#f4f4f4",
- markingsLineWidth: 2,
- // interactive stuff
- clickable: false,
- hoverable: false,
- autoHighlight: true, // highlight in case mouse is near
- mouseActiveRadius: 10 // how far the mouse can be away to activate an item
- },
- hooks: {}
- },
- canvas = null, // the canvas for the plot itself
- overlay = null, // canvas for interactive stuff on top of plot
- eventHolder = null, // jQuery object that events should be bound to
- ctx = null, octx = null,
- axes = { xaxis: {}, yaxis: {}, x2axis: {}, y2axis: {} },
- plotOffset = { left: 0, right: 0, top: 0, bottom: 0},
- canvasWidth = 0, canvasHeight = 0,
- plotWidth = 0, plotHeight = 0,
- hooks = {
- processOptions: [],
- processRawData: [],
- processDatapoints: [],
- draw: [],
- bindEvents: [],
- drawOverlay: []
- },
- plot = this;
-
- // public functions
- plot.setData = setData;
- plot.setupGrid = setupGrid;
- plot.draw = draw;
- plot.getPlaceholder = function() { return placeholder; };
- plot.getCanvas = function() { return canvas; };
- plot.getPlotOffset = function() { return plotOffset; };
- plot.width = function () { return plotWidth; };
- plot.height = function () { return plotHeight; };
- plot.offset = function () {
- var o = eventHolder.offset();
- o.left += plotOffset.left;
- o.top += plotOffset.top;
- return o;
- };
- plot.getData = function() { return series; };
- plot.getAxes = function() { return axes; };
- plot.getOptions = function() { return options; };
- plot.highlight = highlight;
- plot.unhighlight = unhighlight;
- plot.triggerRedrawOverlay = triggerRedrawOverlay;
- plot.pointOffset = function(point) {
- return { left: parseInt(axisSpecToRealAxis(point, "xaxis").p2c(+point.x) + plotOffset.left),
- top: parseInt(axisSpecToRealAxis(point, "yaxis").p2c(+point.y) + plotOffset.top) };
- };
-
-
- // public attributes
- plot.hooks = hooks;
-
- // initialize
- initPlugins(plot);
- parseOptions(options_);
- constructCanvas();
- setData(data_);
- setupGrid();
- draw();
- bindEvents();
-
-
- function executeHooks(hook, args) {
- args = [plot].concat(args);
- for (var i = 0; i < hook.length; ++i)
- hook[i].apply(this, args);
- }
-
- function initPlugins() {
- for (var i = 0; i < plugins.length; ++i) {
- var p = plugins[i];
- p.init(plot);
- if (p.options)
- $.extend(true, options, p.options);
- }
- }
-
- function parseOptions(opts) {
- $.extend(true, options, opts);
- if (options.grid.borderColor == null)
- options.grid.borderColor = options.grid.color;
- // backwards compatibility, to be removed in future
- if (options.xaxis.noTicks && options.xaxis.ticks == null)
- options.xaxis.ticks = options.xaxis.noTicks;
- if (options.yaxis.noTicks && options.yaxis.ticks == null)
- options.yaxis.ticks = options.yaxis.noTicks;
- if (options.grid.coloredAreas)
- options.grid.markings = options.grid.coloredAreas;
- if (options.grid.coloredAreasColor)
- options.grid.markingsColor = options.grid.coloredAreasColor;
- if (options.lines)
- $.extend(true, options.series.lines, options.lines);
- if (options.points)
- $.extend(true, options.series.points, options.points);
- if (options.bars)
- $.extend(true, options.series.bars, options.bars);
- if (options.shadowSize)
- options.series.shadowSize = options.shadowSize;
-
- for (var n in hooks)
- if (options.hooks[n] && options.hooks[n].length)
- hooks[n] = hooks[n].concat(options.hooks[n]);
-
- executeHooks(hooks.processOptions, [options]);
- }
-
- function setData(d) {
- series = parseData(d);
- fillInSeriesOptions();
- processData();
- }
-
- function parseData(d) {
- var res = [];
- for (var i = 0; i < d.length; ++i) {
- var s = $.extend(true, {}, options.series);
-
- if (d[i].data) {
- s.data = d[i].data; // move the data instead of deep-copy
- delete d[i].data;
-
- $.extend(true, s, d[i]);
-
- d[i].data = s.data;
- }
- else
- s.data = d[i];
- res.push(s);
- }
-
- return res;
- }
-
- function axisSpecToRealAxis(obj, attr) {
- var a = obj[attr];
- if (!a || a == 1)
- return axes[attr];
- if (typeof a == "number")
- return axes[attr.charAt(0) + a + attr.slice(1)];
- return a; // assume it's OK
- }
-
- function fillInSeriesOptions() {
- var i;
-
- // collect what we already got of colors
- var neededColors = series.length,
- usedColors = [],
- assignedColors = [];
- for (i = 0; i < series.length; ++i) {
- var sc = series[i].color;
- if (sc != null) {
- --neededColors;
- if (typeof sc == "number")
- assignedColors.push(sc);
- else
- usedColors.push($.color.parse(series[i].color));
- }
- }
-
- // we might need to generate more colors if higher indices
- // are assigned
- for (i = 0; i < assignedColors.length; ++i) {
- neededColors = Math.max(neededColors, assignedColors[i] + 1);
- }
-
- // produce colors as needed
- var colors = [], variation = 0;
- i = 0;
- while (colors.length < neededColors) {
- var c;
- if (options.colors.length == i) // check degenerate case
- c = $.color.make(100, 100, 100);
- else
- c = $.color.parse(options.colors[i]);
-
- // vary color if needed
- var sign = variation % 2 == 1 ? -1 : 1;
- c.scale('rgb', 1 + sign * Math.ceil(variation / 2) * 0.2)
-
- // FIXME: if we're getting to close to something else,
- // we should probably skip this one
- colors.push(c);
-
- ++i;
- if (i >= options.colors.length) {
- i = 0;
- ++variation;
- }
- }
-
- // fill in the options
- var colori = 0, s;
- for (i = 0; i < series.length; ++i) {
- s = series[i];
-
- // assign colors
- if (s.color == null) {
- s.color = colors[colori].toString();
- ++colori;
- }
- else if (typeof s.color == "number")
- s.color = colors[s.color].toString();
-
- // turn on lines automatically in case nothing is set
- if (s.lines.show == null) {
- var v, show = true;
- for (v in s)
- if (s[v].show) {
- show = false;
- break;
- }
- if (show)
- s.lines.show = true;
- }
-
- // setup axes
- s.xaxis = axisSpecToRealAxis(s, "xaxis");
- s.yaxis = axisSpecToRealAxis(s, "yaxis");
- }
- }
-
- function processData() {
- var topSentry = Number.POSITIVE_INFINITY,
- bottomSentry = Number.NEGATIVE_INFINITY,
- i, j, k, m, length,
- s, points, ps, x, y, axis, val, f, p;
-
- for (axis in axes) {
- axes[axis].datamin = topSentry;
- axes[axis].datamax = bottomSentry;
- axes[axis].used = false;
- }
-
- function updateAxis(axis, min, max) {
- if (min < axis.datamin)
- axis.datamin = min;
- if (max > axis.datamax)
- axis.datamax = max;
- }
-
- for (i = 0; i < series.length; ++i) {
- s = series[i];
- s.datapoints = { points: [] };
-
- executeHooks(hooks.processRawData, [ s, s.data, s.datapoints ]);
- }
-
- // first pass: clean and copy data
- for (i = 0; i < series.length; ++i) {
- s = series[i];
-
- var data = s.data, format = s.datapoints.format;
-
- if (!format) {
- format = [];
- // find out how to copy
- format.push({ x: true, number: true, required: true });
- format.push({ y: true, number: true, required: true });
-
- if (s.bars.show)
- format.push({ y: true, number: true, required: false, defaultValue: 0 });
-
- s.datapoints.format = format;
- }
-
- if (s.datapoints.pointsize != null)
- continue; // already filled in
-
- if (s.datapoints.pointsize == null)
- s.datapoints.pointsize = format.length;
-
- ps = s.datapoints.pointsize;
- points = s.datapoints.points;
-
- insertSteps = s.lines.show && s.lines.steps;
- s.xaxis.used = s.yaxis.used = true;
-
- for (j = k = 0; j < data.length; ++j, k += ps) {
- p = data[j];
-
- var nullify = p == null;
- if (!nullify) {
- for (m = 0; m < ps; ++m) {
- val = p[m];
- f = format[m];
-
- if (f) {
- if (f.number && val != null) {
- val = +val; // convert to number
- if (isNaN(val))
- val = null;
- }
-
- if (val == null) {
- if (f.required)
- nullify = true;
-
- if (f.defaultValue != null)
- val = f.defaultValue;
- }
- }
-
- points[k + m] = val;
- }
- }
-
- if (nullify) {
- for (m = 0; m < ps; ++m) {
- val = points[k + m];
- if (val != null) {
- f = format[m];
- // extract min/max info
- if (f.x)
- updateAxis(s.xaxis, val, val);
- if (f.y)
- updateAxis(s.yaxis, val, val);
- }
- points[k + m] = null;
- }
- }
- else {
- // a little bit of line specific stuff that
- // perhaps shouldn't be here, but lacking
- // better means...
- if (insertSteps && k > 0
- && points[k - ps] != null
- && points[k - ps] != points[k]
- && points[k - ps + 1] != points[k + 1]) {
- // copy the point to make room for a middle point
- for (m = 0; m < ps; ++m)
- points[k + ps + m] = points[k + m];
-
- // middle point has same y
- points[k + 1] = points[k - ps + 1];
-
- // we've added a point, better reflect that
- k += ps;
- }
- }
- }
- }
-
- // give the hooks a chance to run
- for (i = 0; i < series.length; ++i) {
- s = series[i];
-
- executeHooks(hooks.processDatapoints, [ s, s.datapoints]);
- }
-
- // second pass: find datamax/datamin for auto-scaling
- for (i = 0; i < series.length; ++i) {
- s = series[i];
- points = s.datapoints.points,
- ps = s.datapoints.pointsize;
-
- var xmin = topSentry, ymin = topSentry,
- xmax = bottomSentry, ymax = bottomSentry;
-
- for (j = 0; j < points.length; j += ps) {
- if (points[j] == null)
- continue;
-
- for (m = 0; m < ps; ++m) {
- val = points[j + m];
- f = format[m];
- if (!f)
- continue;
-
- if (f.x) {
- if (val < xmin)
- xmin = val;
- if (val > xmax)
- xmax = val;
- }
- if (f.y) {
- if (val < ymin)
- ymin = val;
- if (val > ymax)
- ymax = val;
- }
- }
- }
-
- if (s.bars.show) {
- // make sure we got room for the bar on the dancing floor
- var delta = s.bars.align == "left" ? 0 : -s.bars.barWidth/2;
- if (s.bars.horizontal) {
- ymin += delta;
- ymax += delta + s.bars.barWidth;
- }
- else {
- xmin += delta;
- xmax += delta + s.bars.barWidth;
- }
- }
-
- updateAxis(s.xaxis, xmin, xmax);
- updateAxis(s.yaxis, ymin, ymax);
- }
-
- for (axis in axes) {
- if (axes[axis].datamin == topSentry)
- axes[axis].datamin = null;
- if (axes[axis].datamax == bottomSentry)
- axes[axis].datamax = null;
- }
- }
-
- function constructCanvas() {
- function makeCanvas(width, height) {
- var c = document.createElement('canvas');
- c.width = width;
- c.height = height;
- if ($.browser.msie) // excanvas hack
- c = window.G_vmlCanvasManager.initElement(c);
- return c;
- }
-
- canvasWidth = placeholder.width();
- canvasHeight = placeholder.height();
- placeholder.html(""); // clear placeholder
- if (placeholder.css("position") == 'static')
- placeholder.css("position", "relative"); // for positioning labels and overlay
-
- if (canvasWidth <= 0 || canvasHeight <= 0)
- throw "Invalid dimensions for plot, width = " + canvasWidth + ", height = " + canvasHeight;
-
- if ($.browser.msie) // excanvas hack
- window.G_vmlCanvasManager.init_(document); // make sure everything is setup
-
- // the canvas
- canvas = $(makeCanvas(canvasWidth, canvasHeight)).appendTo(placeholder).get(0);
- ctx = canvas.getContext("2d");
-
- // overlay canvas for interactive features
- overlay = $(makeCanvas(canvasWidth, canvasHeight)).css({ position: 'absolute', left: 0, top: 0 }).appendTo(placeholder).get(0);
- octx = overlay.getContext("2d");
- octx.stroke();
- }
-
- function bindEvents() {
- // we include the canvas in the event holder too, because IE 7
- // sometimes has trouble with the stacking order
- eventHolder = $([overlay, canvas]);
-
- // bind events
- if (options.grid.hoverable)
- eventHolder.mousemove(onMouseMove);
-
- if (options.grid.clickable)
- eventHolder.click(onClick);
-
- executeHooks(hooks.bindEvents, [eventHolder]);
- }
-
- function setupGrid() {
- function setTransformationHelpers(axis, o) {
- function identity(x) { return x; }
-
- var s, m, t = o.transform || identity,
- it = o.inverseTransform;
-
- // add transformation helpers
- if (axis == axes.xaxis || axis == axes.x2axis) {
- // precompute how much the axis is scaling a point
- // in canvas space
- s = axis.scale = plotWidth / (t(axis.max) - t(axis.min));
- m = t(axis.min);
-
- // data point to canvas coordinate
- if (t == identity) // slight optimization
- axis.p2c = function (p) { return (p - m) * s; };
- else
- axis.p2c = function (p) { return (t(p) - m) * s; };
- // canvas coordinate to data point
- if (!it)
- axis.c2p = function (c) { return m + c / s; };
- else
- axis.c2p = function (c) { return it(m + c / s); };
- }
- else {
- s = axis.scale = plotHeight / (t(axis.max) - t(axis.min));
- m = t(axis.max);
-
- if (t == identity)
- axis.p2c = function (p) { return (m - p) * s; };
- else
- axis.p2c = function (p) { return (m - t(p)) * s; };
- if (!it)
- axis.c2p = function (c) { return m - c / s; };
- else
- axis.c2p = function (c) { return it(m - c / s); };
- }
- }
-
- function measureLabels(axis, axisOptions) {
- var i, labels = [], l;
-
- axis.labelWidth = axisOptions.labelWidth;
- axis.labelHeight = axisOptions.labelHeight;
-
- if (axis == axes.xaxis || axis == axes.x2axis) {
- // to avoid measuring the widths of the labels, we
- // construct fixed-size boxes and put the labels inside
- // them, we don't need the exact figures and the
- // fixed-size box content is easy to center
- if (axis.labelWidth == null)
- axis.labelWidth = canvasWidth / (axis.ticks.length > 0 ? axis.ticks.length : 1);
-
- // measure x label heights
- if (axis.labelHeight == null) {
- labels = [];
- for (i = 0; i < axis.ticks.length; ++i) {
- l = axis.ticks[i].label;
- if (l)
- labels.push('<div class="tickLabel" style="float:left;width:' + axis.labelWidth + 'px">' + l + '</div>');
- }
-
- if (labels.length > 0) {
- var dummyDiv = $('<div style="position:absolute;top:-10000px;width:10000px;font-size:smaller">'
- + labels.join("") + '<div style="clear:left"></div></div>').appendTo(placeholder);
- axis.labelHeight = dummyDiv.height();
- dummyDiv.remove();
- }
- }
- }
- else if (axis.labelWidth == null || axis.labelHeight == null) {
- // calculate y label dimensions
- for (i = 0; i < axis.ticks.length; ++i) {
- l = axis.ticks[i].label;
- if (l)
- labels.push('<div class="tickLabel">' + l + '</div>');
- }
-
- if (labels.length > 0) {
- var dummyDiv = $('<div style="position:absolute;top:-10000px;font-size:smaller">'
- + labels.join("") + '</div>').appendTo(placeholder);
- if (axis.labelWidth == null)
- axis.labelWidth = dummyDiv.width();
- if (axis.labelHeight == null)
- axis.labelHeight = dummyDiv.find("div").height();
- dummyDiv.remove();
- }
-
- }
-
- if (axis.labelWidth == null)
- axis.labelWidth = 0;
- if (axis.labelHeight == null)
- axis.labelHeight = 0;
- }
-
- function setGridSpacing() {
- // get the most space needed around the grid for things
- // that may stick out
- var maxOutset = options.grid.borderWidth;
- for (i = 0; i < series.length; ++i)
- maxOutset = Math.max(maxOutset, 2 * (series[i].points.radius + series[i].points.lineWidth/2));
-
- plotOffset.left = plotOffset.right = plotOffset.top = plotOffset.bottom = maxOutset;
-
- var margin = options.grid.labelMargin + options.grid.borderWidth;
-
- if (axes.xaxis.labelHeight > 0)
- plotOffset.bottom = Math.max(maxOutset, axes.xaxis.labelHeight + margin);
- if (axes.yaxis.labelWidth > 0)
- plotOffset.left = Math.max(maxOutset, axes.yaxis.labelWidth + margin);
- if (axes.x2axis.labelHeight > 0)
- plotOffset.top = Math.max(maxOutset, axes.x2axis.labelHeight + margin);
- if (axes.y2axis.labelWidth > 0)
- plotOffset.right = Math.max(maxOutset, axes.y2axis.labelWidth + margin);
-
- plotWidth = canvasWidth - plotOffset.left - plotOffset.right;
- plotHeight = canvasHeight - plotOffset.bottom - plotOffset.top;
- }
-
- var axis;
- for (axis in axes)
- setRange(axes[axis], options[axis]);
-
- if (options.grid.show) {
- for (axis in axes) {
- prepareTickGeneration(axes[axis], options[axis]);
- setTicks(axes[axis], options[axis]);
- measureLabels(axes[axis], options[axis]);
- }
-
- setGridSpacing();
- }
- else {
- plotOffset.left = plotOffset.right = plotOffset.top = plotOffset.bottom = 0;
- plotWidth = canvasWidth;
- plotHeight = canvasHeight;
- }
-
- for (axis in axes)
- setTransformationHelpers(axes[axis], options[axis]);
-
- if (options.grid.show)
- insertLabels();
-
- insertLegend();
- }
-
- function setRange(axis, axisOptions) {
- var min = +(axisOptions.min != null ? axisOptions.min : axis.datamin),
- max = +(axisOptions.max != null ? axisOptions.max : axis.datamax),
- delta = max - min;
-
- if (delta == 0.0) {
- // degenerate case
- var widen = max == 0 ? 1 : 0.01;
-
- if (axisOptions.min == null)
- min -= widen;
- // alway widen max if we couldn't widen min to ensure we
- // don't fall into min == max which doesn't work
- if (axisOptions.max == null || axisOptions.min != null)
- max += widen;
- }
- else {
- // consider autoscaling
- var margin = axisOptions.autoscaleMargin;
- if (margin != null) {
- if (axisOptions.min == null) {
- min -= delta * margin;
- // make sure we don't go below zero if all values
- // are positive
- if (min < 0 && axis.datamin != null && axis.datamin >= 0)
- min = 0;
- }
- if (axisOptions.max == null) {
- max += delta * margin;
- if (max > 0 && axis.datamax != null && axis.datamax <= 0)
- max = 0;
- }
- }
- }
- axis.min = min;
- axis.max = max;
- }
-
- function prepareTickGeneration(axis, axisOptions) {
- // estimate number of ticks
- var noTicks;
- if (typeof axisOptions.ticks == "number" && axisOptions.ticks > 0)
- noTicks = axisOptions.ticks;
- else if (axis == axes.xaxis || axis == axes.x2axis)
- // heuristic based on the model a*sqrt(x) fitted to
- // some reasonable data points
- noTicks = 0.3 * Math.sqrt(canvasWidth);
- else
- noTicks = 0.3 * Math.sqrt(canvasHeight);
-
- var delta = (axis.max - axis.min) / noTicks,
- size, generator, unit, formatter, i, magn, norm;
-
- if (axisOptions.mode == "time") {
- // pretty handling of time
-
- // map of app. size of time units in milliseconds
- var timeUnitSize = {
- "second": 1000,
- "minute": 60 * 1000,
- "hour": 60 * 60 * 1000,
- "day": 24 * 60 * 60 * 1000,
- "month": 30 * 24 * 60 * 60 * 1000,
- "year": 365.2425 * 24 * 60 * 60 * 1000
- };
-
-
- // the allowed tick sizes, after 1 year we use
- // an integer algorithm
- var spec = [
- [1, "second"], [2, "second"], [5, "second"], [10, "second"],
- [30, "second"],
- [1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"],
- [30, "minute"],
- [1, "hour"], [2, "hour"], [4, "hour"],
- [8, "hour"], [12, "hour"],
- [1, "day"], [2, "day"], [3, "day"],
- [0.25, "month"], [0.5, "month"], [1, "month"],
- [2, "month"], [3, "month"], [6, "month"],
- [1, "year"]
- ];
-
- var minSize = 0;
- if (axisOptions.minTickSize != null) {
- if (typeof axisOptions.tickSize == "number")
- minSize = axisOptions.tickSize;
- else
- minSize = axisOptions.minTickSize[0] * timeUnitSize[axisOptions.minTickSize[1]];
- }
-
- for (i = 0; i < spec.length - 1; ++i)
- if (delta < (spec[i][0] * timeUnitSize[spec[i][1]]
- + spec[i + 1][0] * timeUnitSize[spec[i + 1][1]]) / 2
- && spec[i][0] * timeUnitSize[spec[i][1]] >= minSize)
- break;
- size = spec[i][0];
- unit = spec[i][1];
-
- // special-case the possibility of several years
- if (unit == "year") {
- magn = Math.pow(10, Math.floor(Math.log(delta / timeUnitSize.year) / Math.LN10));
- norm = (delta / timeUnitSize.year) / magn;
- if (norm < 1.5)
- size = 1;
- else if (norm < 3)
- size = 2;
- else if (norm < 7.5)
- size = 5;
- else
- size = 10;
-
- size *= magn;
- }
-
- if (axisOptions.tickSize) {
- size = axisOptions.tickSize[0];
- unit = axisOptions.tickSize[1];
- }
-
- generator = function(axis) {
- var ticks = [],
- tickSize = axis.tickSize[0], unit = axis.tickSize[1],
- d = new Date(axis.min);
-
- var step = tickSize * timeUnitSize[unit];
-
- if (unit == "second")
- d.setUTCSeconds(floorInBase(d.getUTCSeconds(), tickSize));
- if (unit == "minute")
- d.setUTCMinutes(floorInBase(d.getUTCMinutes(), tickSize));
- if (unit == "hour")
- d.setUTCHours(floorInBase(d.getUTCHours(), tickSize));
- if (unit == "month")
- d.setUTCMonth(floorInBase(d.getUTCMonth(), tickSize));
- if (unit == "year")
- d.setUTCFullYear(floorInBase(d.getUTCFullYear(), tickSize));
-
- // reset smaller components
- d.setUTCMilliseconds(0);
- if (step >= timeUnitSize.minute)
- d.setUTCSeconds(0);
- if (step >= timeUnitSize.hour)
- d.setUTCMinutes(0);
- if (step >= timeUnitSize.day)
- d.setUTCHours(0);
- if (step >= timeUnitSize.day * 4)
- d.setUTCDate(1);
- if (step >= timeUnitSize.year)
- d.setUTCMonth(0);
-
-
- var carry = 0, v = Number.NaN, prev;
- do {
- prev = v;
- v = d.getTime();
- ticks.push({ v: v, label: axis.tickFormatter(v, axis) });
- if (unit == "month") {
- if (tickSize < 1) {
- // a bit complicated - we'll divide the month
- // up but we need to take care of fractions
- // so we don't end up in the middle of a day
- d.setUTCDate(1);
- var start = d.getTime();
- d.setUTCMonth(d.getUTCMonth() + 1);
- var end = d.getTime();
- d.setTime(v + carry * timeUnitSize.hour + (end - start) * tickSize);
- carry = d.getUTCHours();
- d.setUTCHours(0);
- }
- else
- d.setUTCMonth(d.getUTCMonth() + tickSize);
- }
- else if (unit == "year") {
- d.setUTCFullYear(d.getUTCFullYear() + tickSize);
- }
- else
- d.setTime(v + step);
- } while (v < axis.max && v != prev);
-
- return ticks;
- };
-
- formatter = function (v, axis) {
- var d = new Date(v);
-
- // first check global format
- if (axisOptions.timeformat != null)
- return $.plot.formatDate(d, axisOptions.timeformat, axisOptions.monthNames);
-
- var t = axis.tickSize[0] * timeUnitSize[axis.tickSize[1]];
- var span = axis.max - axis.min;
- var suffix = (axisOptions.twelveHourClock) ? " %p" : "";
-
- if (t < timeUnitSize.minute)
- fmt = "%h:%M:%S" + suffix;
- else if (t < timeUnitSize.day) {
- if (span < 2 * timeUnitSize.day)
- fmt = "%h:%M" + suffix;
- else
- fmt = "%b %d %h:%M" + suffix;
- }
- else if (t < timeUnitSize.month)
- fmt = "%b %d";
- else if (t < timeUnitSize.year) {
- if (span < timeUnitSize.year)
- fmt = "%b";
- else
- fmt = "%b %y";
- }
- else
- fmt = "%y";
-
- return $.plot.formatDate(d, fmt, axisOptions.monthNames);
- };
- }
- else {
- // pretty rounding of base-10 numbers
- var maxDec = axisOptions.tickDecimals;
- var dec = -Math.floor(Math.log(delta) / Math.LN10);
- if (maxDec != null && dec > maxDec)
- dec = maxDec;
-
- magn = Math.pow(10, -dec);
- norm = delta / magn; // norm is between 1.0 and 10.0
-
- if (norm < 1.5)
- size = 1;
- else if (norm < 3) {
- size = 2;
- // special case for 2.5, requires an extra decimal
- if (norm > 2.25 && (maxDec == null || dec + 1 <= maxDec)) {
- size = 2.5;
- ++dec;
- }
- }
- else if (norm < 7.5)
- size = 5;
- else
- size = 10;
-
- size *= magn;
-
- if (axisOptions.minTickSize != null && size < axisOptions.minTickSize)
- size = axisOptions.minTickSize;
-
- if (axisOptions.tickSize != null)
- size = axisOptions.tickSize;
-
- axis.tickDecimals = Math.max(0, (maxDec != null) ? maxDec : dec);
-
- generator = function (axis) {
- var ticks = [];
-
- // spew out all possible ticks
- var start = floorInBase(axis.min, axis.tickSize),
- i = 0, v = Number.NaN, prev;
- do {
- prev = v;
- v = start + i * axis.tickSize;
- ticks.push({ v: v, label: axis.tickFormatter(v, axis) });
- ++i;
- } while (v < axis.max && v != prev);
- return ticks;
- };
-
- formatter = function (v, axis) {
- return v.toFixed(axis.tickDecimals);
- };
- }
-
- axis.tickSize = unit ? [size, unit] : size;
- axis.tickGenerator = generator;
- if ($.isFunction(axisOptions.tickFormatter))
- axis.tickFormatter = function (v, axis) { return "" + axisOptions.tickFormatter(v, axis); };
- else
- axis.tickFormatter = formatter;
- }
-
- function setTicks(axis, axisOptions) {
- axis.ticks = [];
-
- if (!axis.used)
- return;
-
- if (axisOptions.ticks == null)
- axis.ticks = axis.tickGenerator(axis);
- else if (typeof axisOptions.ticks == "number") {
- if (axisOptions.ticks > 0)
- axis.ticks = axis.tickGenerator(axis);
- }
- else if (axisOptions.ticks) {
- var ticks = axisOptions.ticks;
-
- if ($.isFunction(ticks))
- // generate the ticks
- ticks = ticks({ min: axis.min, max: axis.max });
-
- // clean up the user-supplied ticks, copy them over
- var i, v;
- for (i = 0; i < ticks.length; ++i) {
- var label = null;
- var t = ticks[i];
- if (typeof t == "object") {
- v = t[0];
- if (t.length > 1)
- label = t[1];
- }
- else
- v = t;
- if (label == null)
- label = axis.tickFormatter(v, axis);
- axis.ticks[i] = { v: v, label: label };
- }
- }
-
- if (axisOptions.autoscaleMargin != null && axis.ticks.length > 0) {
- // snap to ticks
- if (axisOptions.min == null)
- axis.min = Math.min(axis.min, axis.ticks[0].v);
- if (axisOptions.max == null && axis.ticks.length > 1)
- axis.max = Math.max(axis.max, axis.ticks[axis.ticks.length - 1].v);
- }
- }
-
- function draw() {
- ctx.clearRect(0, 0, canvasWidth, canvasHeight);
-
- var grid = options.grid;
-
- if (grid.show && !grid.aboveData)
- drawGrid();
-
- for (var i = 0; i < series.length; ++i)
- drawSeries(series[i]);
-
- executeHooks(hooks.draw, [ctx]);
-
- if (grid.show && grid.aboveData)
- drawGrid();
- }
-
- function extractRange(ranges, coord) {
- var firstAxis = coord + "axis",
- secondaryAxis = coord + "2axis",
- axis, from, to, reverse;
-
- if (ranges[firstAxis]) {
- axis = axes[firstAxis];
- from = ranges[firstAxis].from;
- to = ranges[firstAxis].to;
- }
- else if (ranges[secondaryAxis]) {
- axis = axes[secondaryAxis];
- from = ranges[secondaryAxis].from;
- to = ranges[secondaryAxis].to;
- }
- else {
- // backwards-compat stuff - to be removed in future
- axis = axes[firstAxis];
- from = ranges[coord + "1"];
- to = ranges[coord + "2"];
- }
-
- // auto-reverse as an added bonus
- if (from != null && to != null && from > to)
- return { from: to, to: from, axis: axis };
-
- return { from: from, to: to, axis: axis };
- }
-
- function drawGrid() {
- var i;
-
- ctx.save();
- ctx.translate(plotOffset.left, plotOffset.top);
-
- // draw background, if any
- if (options.grid.backgroundColor) {
- ctx.fillStyle = getColorOrGradient(options.grid.backgroundColor, plotHeight, 0, "rgba(255, 255, 255, 0)");
- ctx.fillRect(0, 0, plotWidth, plotHeight);
- }
-
- // draw markings
- var markings = options.grid.markings;
- if (markings) {