PageRenderTime 20ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/application/static/libs/adminlte/bower_components/jquery-sparkline/src/header.js

https://bitbucket.org/tin_gimranoff/docstar
JavaScript | 222 lines | 16 code | 4 blank | 202 comment | 5 complexity | 993d3107e8e293190c8f66ef57e987a5 MD5 | raw file
  1/**
  2*
  3* jquery.sparkline.js
  4*
  5* v@VERSION@
  6* (c) Splunk, Inc
  7* Contact: Gareth Watts (gareth@splunk.com)
  8* http://omnipotent.net/jquery.sparkline/
  9*
 10* Generates inline sparkline charts from data supplied either to the method
 11* or inline in HTML
 12*
 13* Compatible with Internet Explorer 6.0+ and modern browsers equipped with the canvas tag
 14* (Firefox 2.0+, Safari, Opera, etc)
 15*
 16* License: New BSD License
 17*
 18* Copyright (c) 2012, Splunk Inc.
 19* All rights reserved.
 20*
 21* Redistribution and use in source and binary forms, with or without modification,
 22* are permitted provided that the following conditions are met:
 23*
 24*     * Redistributions of source code must retain the above copyright notice,
 25*       this list of conditions and the following disclaimer.
 26*     * Redistributions in binary form must reproduce the above copyright notice,
 27*       this list of conditions and the following disclaimer in the documentation
 28*       and/or other materials provided with the distribution.
 29*     * Neither the name of Splunk Inc nor the names of its contributors may
 30*       be used to endorse or promote products derived from this software without
 31*       specific prior written permission.
 32*
 33* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 34* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 35* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 36* SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 37* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 38* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 39* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 40* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 41* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 42*
 43*
 44* Usage:
 45*  $(selector).sparkline(values, options)
 46*
 47* If values is undefined or set to 'html' then the data values are read from the specified tag:
 48*   <p>Sparkline: <span class="sparkline">1,4,6,6,8,5,3,5</span></p>
 49*   $('.sparkline').sparkline();
 50* There must be no spaces in the enclosed data set
 51*
 52* Otherwise values must be an array of numbers or null values
 53*    <p>Sparkline: <span id="sparkline1">This text replaced if the browser is compatible</span></p>
 54*    $('#sparkline1').sparkline([1,4,6,6,8,5,3,5])
 55*    $('#sparkline2').sparkline([1,4,6,null,null,5,3,5])
 56*
 57* Values can also be specified in an HTML comment, or as a values attribute:
 58*    <p>Sparkline: <span class="sparkline"><!--1,4,6,6,8,5,3,5 --></span></p>
 59*    <p>Sparkline: <span class="sparkline" values="1,4,6,6,8,5,3,5"></span></p>
 60*    $('.sparkline').sparkline();
 61*
 62* For line charts, x values can also be specified:
 63*   <p>Sparkline: <span class="sparkline">1:1,2.7:4,3.4:6,5:6,6:8,8.7:5,9:3,10:5</span></p>
 64*    $('#sparkline1').sparkline([ [1,1], [2.7,4], [3.4,6], [5,6], [6,8], [8.7,5], [9,3], [10,5] ])
 65*
 66* By default, options should be passed in as the second argument to the sparkline function:
 67*   $('.sparkline').sparkline([1,2,3,4], {type: 'bar'})
 68*
 69* Options can also be set by passing them on the tag itself.  This feature is disabled by default though
 70* as there's a slight performance overhead:
 71*   $('.sparkline').sparkline([1,2,3,4], {enableTagOptions: true})
 72*   <p>Sparkline: <span class="sparkline" sparkType="bar" sparkBarColor="red">loading</span></p>
 73* Prefix all options supplied as tag attribute with "spark" (configurable by setting tagOptionsPrefix)
 74*
 75* Supported options:
 76*   lineColor - Color of the line used for the chart
 77*   fillColor - Color used to fill in the chart - Set to '' or false for a transparent chart
 78*   width - Width of the chart - Defaults to 3 times the number of values in pixels
 79*   height - Height of the chart - Defaults to the height of the containing element
 80*   chartRangeMin - Specify the minimum value to use for the Y range of the chart - Defaults to the minimum value supplied
 81*   chartRangeMax - Specify the maximum value to use for the Y range of the chart - Defaults to the maximum value supplied
 82*   chartRangeClip - Clip out of range values to the max/min specified by chartRangeMin and chartRangeMax
 83*   chartRangeMinX - Specify the minimum value to use for the X range of the chart - Defaults to the minimum value supplied
 84*   chartRangeMaxX - Specify the maximum value to use for the X range of the chart - Defaults to the maximum value supplied
 85*   composite - If true then don't erase any existing chart attached to the tag, but draw
 86*           another chart over the top - Note that width and height are ignored if an
 87*           existing chart is detected.
 88*   tagValuesAttribute - Name of tag attribute to check for data values - Defaults to 'values'
 89*   enableTagOptions - Whether to check tags for sparkline options
 90*   tagOptionsPrefix - Prefix used for options supplied as tag attributes - Defaults to 'spark'
 91*   disableHiddenCheck - If set to true, then the plugin will assume that charts will never be drawn into a
 92*           hidden dom element, avoding a browser reflow
 93*   disableInteraction - If set to true then all mouseover/click interaction behaviour will be disabled,
 94*       making the plugin perform much like it did in 1.x
 95*   disableTooltips - If set to true then tooltips will be disabled - Defaults to false (tooltips enabled)
 96*   disableHighlight - If set to true then highlighting of selected chart elements on mouseover will be disabled
 97*       defaults to false (highlights enabled)
 98*   highlightLighten - Factor to lighten/darken highlighted chart values by - Defaults to 1.4 for a 40% increase
 99*   tooltipContainer - Specify which DOM element the tooltip should be rendered into - defaults to document.body
100*   tooltipClassname - Optional CSS classname to apply to tooltips - If not specified then a default style will be applied
101*   tooltipOffsetX - How many pixels away from the mouse pointer to render the tooltip on the X axis
102*   tooltipOffsetY - How many pixels away from the mouse pointer to render the tooltip on the r axis
103*   tooltipFormatter  - Optional callback that allows you to override the HTML displayed in the tooltip
104*       callback is given arguments of (sparkline, options, fields)
105*   tooltipChartTitle - If specified then the tooltip uses the string specified by this setting as a title
106*   tooltipFormat - A format string or SPFormat object  (or an array thereof for multiple entries)
107*       to control the format of the tooltip
108*   tooltipPrefix - A string to prepend to each field displayed in a tooltip
109*   tooltipSuffix - A string to append to each field displayed in a tooltip
110*   tooltipSkipNull - If true then null values will not have a tooltip displayed (defaults to true)
111*   tooltipValueLookups - An object or range map to map field values to tooltip strings
112*       (eg. to map -1 to "Lost", 0 to "Draw", and 1 to "Win")
113*   numberFormatter - Optional callback for formatting numbers in tooltips
114*   numberDigitGroupSep - Character to use for group separator in numbers "1,234" - Defaults to ","
115*   numberDecimalMark - Character to use for the decimal point when formatting numbers - Defaults to "."
116*   numberDigitGroupCount - Number of digits between group separator - Defaults to 3
117*
118* There are 7 types of sparkline, selected by supplying a "type" option of 'line' (default),
119* 'bar', 'tristate', 'bullet', 'discrete', 'pie' or 'box'
120*    line - Line chart.  Options:
121*       spotColor - Set to '' to not end each line in a circular spot
122*       minSpotColor - If set, color of spot at minimum value
123*       maxSpotColor - If set, color of spot at maximum value
124*       spotRadius - Radius in pixels
125*       lineWidth - Width of line in pixels
126*       normalRangeMin
127*       normalRangeMax - If set draws a filled horizontal bar between these two values marking the "normal"
128*                      or expected range of values
129*       normalRangeColor - Color to use for the above bar
130*       drawNormalOnTop - Draw the normal range above the chart fill color if true
131*       defaultPixelsPerValue - Defaults to 3 pixels of width for each value in the chart
132*       highlightSpotColor - The color to use for drawing a highlight spot on mouseover - Set to null to disable
133*       highlightLineColor - The color to use for drawing a highlight line on mouseover - Set to null to disable
134*       valueSpots - Specify which points to draw spots on, and in which color.  Accepts a range map
135*
136*   bar - Bar chart.  Options:
137*       barColor - Color of bars for postive values
138*       negBarColor - Color of bars for negative values
139*       zeroColor - Color of bars with zero values
140*       nullColor - Color of bars with null values - Defaults to omitting the bar entirely
141*       barWidth - Width of bars in pixels
142*       colorMap - Optional mappnig of values to colors to override the *BarColor values above
143*                  can be an Array of values to control the color of individual bars or a range map
144*                  to specify colors for individual ranges of values
145*       barSpacing - Gap between bars in pixels
146*       zeroAxis - Centers the y-axis around zero if true
147*
148*   tristate - Charts values of win (>0), lose (<0) or draw (=0)
149*       posBarColor - Color of win values
150*       negBarColor - Color of lose values
151*       zeroBarColor - Color of draw values
152*       barWidth - Width of bars in pixels
153*       barSpacing - Gap between bars in pixels
154*       colorMap - Optional mappnig of values to colors to override the *BarColor values above
155*                  can be an Array of values to control the color of individual bars or a range map
156*                  to specify colors for individual ranges of values
157*
158*   discrete - Options:
159*       lineHeight - Height of each line in pixels - Defaults to 30% of the graph height
160*       thesholdValue - Values less than this value will be drawn using thresholdColor instead of lineColor
161*       thresholdColor
162*
163*   bullet - Values for bullet graphs msut be in the order: target, performance, range1, range2, range3, ...
164*       options:
165*       targetColor - The color of the vertical target marker
166*       targetWidth - The width of the target marker in pixels
167*       performanceColor - The color of the performance measure horizontal bar
168*       rangeColors - Colors to use for each qualitative range background color
169*
170*   pie - Pie chart. Options:
171*       sliceColors - An array of colors to use for pie slices
172*       offset - Angle in degrees to offset the first slice - Try -90 or +90
173*       borderWidth - Width of border to draw around the pie chart, in pixels - Defaults to 0 (no border)
174*       borderColor - Color to use for the pie chart border - Defaults to #000
175*
176*   box - Box plot. Options:
177*       raw - Set to true to supply pre-computed plot points as values
178*             values should be: low_outlier, low_whisker, q1, median, q3, high_whisker, high_outlier
179*             When set to false you can supply any number of values and the box plot will
180*             be computed for you.  Default is false.
181*       showOutliers - Set to true (default) to display outliers as circles
182*       outlierIQR - Interquartile range used to determine outliers.  Default 1.5
183*       boxLineColor - Outline color of the box
184*       boxFillColor - Fill color for the box
185*       whiskerColor - Line color used for whiskers
186*       outlierLineColor - Outline color of outlier circles
187*       outlierFillColor - Fill color of the outlier circles
188*       spotRadius - Radius of outlier circles
189*       medianColor - Line color of the median line
190*       target - Draw a target cross hair at the supplied value (default undefined)
191*
192*
193*
194*   Examples:
195*   $('#sparkline1').sparkline(myvalues, { lineColor: '#f00', fillColor: false });
196*   $('.barsparks').sparkline('html', { type:'bar', height:'40px', barWidth:5 });
197*   $('#tristate').sparkline([1,1,-1,1,0,0,-1], { type:'tristate' }):
198*   $('#discrete').sparkline([1,3,4,5,5,3,4,5], { type:'discrete' });
199*   $('#bullet').sparkline([10,12,12,9,7], { type:'bullet' });
200*   $('#pie').sparkline([1,1,2], { type:'pie' });
201*/
202
203/*jslint regexp: true, browser: true, jquery: true, white: true, nomen: false, plusplus: false, maxerr: 500, indent: 4 */
204
205(function(document, Math, undefined) { // performance/minified-size optimization
206(function(factory) {
207    if(typeof define === 'function' && define.amd) {
208        define(['jquery'], factory);
209    } else if (jQuery && !jQuery.fn.sparkline) {
210        factory(jQuery);
211    }
212}
213(function($) {
214    'use strict';
215
216    var UNSET_OPTION = {},
217        getDefaults, createClass, SPFormat, clipval, quartile, normalizeValue, normalizeValues,
218        remove, isNumber, all, sum, addCSS, ensureArray, formatNumber, RangeMap,
219        MouseHandler, Tooltip, barHighlightMixin,
220        line, bar, tristate, discrete, bullet, pie, box, defaultStyles, initStyles,
221        VShape, VCanvas_base, VCanvas_canvas, VCanvas_vml, pending, shapeCount = 0;
222