phcthemes_admin_panel_pack 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/smarty/core.js +28154 -0
- data/app/assets/javascripts/smarty/core.min.js +2 -0
- data/app/assets/javascripts/smarty/core.sow_builder.js +84 -0
- data/app/assets/javascripts/smarty/core.sow_builder.min.js +1 -0
- data/app/assets/javascripts/smarty/phcthemes_admin_panel_pack_smarty.js +3 -0
- data/app/assets/javascripts/smarty/vendor.chartjs.js +20776 -0
- data/app/assets/javascripts/smarty/vendor.chartjs.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.cocoen.js +1 -0
- data/app/assets/javascripts/smarty/vendor.cocoen.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.colorpicker.js +3 -0
- data/app/assets/javascripts/smarty/vendor.colorpicker.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.datatables.js +42928 -0
- data/app/assets/javascripts/smarty/vendor.datatables.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.datepicker.js +2039 -0
- data/app/assets/javascripts/smarty/vendor.datepicker.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.daterangepicker.js +1578 -0
- data/app/assets/javascripts/smarty/vendor.daterangepicker.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.easypie.js +364 -0
- data/app/assets/javascripts/smarty/vendor.easypie.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.fancybox.js +5632 -0
- data/app/assets/javascripts/smarty/vendor.fancybox.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.flickity.js +4597 -0
- data/app/assets/javascripts/smarty/vendor.flickity.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.flot.js +11921 -0
- data/app/assets/javascripts/smarty/vendor.flot.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.fullcalendar.js +14597 -0
- data/app/assets/javascripts/smarty/vendor.fullcalendar.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.leaflet.js +6 -0
- data/app/assets/javascripts/smarty/vendor.leaflet.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.markdowneditor.js +7 -0
- data/app/assets/javascripts/smarty/vendor.markdowneditor.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.mediumeditor.js +7893 -0
- data/app/assets/javascripts/smarty/vendor.mediumeditor.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.pdfmake.js +79493 -0
- data/app/assets/javascripts/smarty/vendor.pdfmake.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.photoswipe.js +4595 -0
- data/app/assets/javascripts/smarty/vendor.photoswipe.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.prismjs.js +7219 -0
- data/app/assets/javascripts/smarty/vendor.prismjs.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.quilleditor.js +11562 -0
- data/app/assets/javascripts/smarty/vendor.quilleditor.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.sparkline.js +3068 -0
- data/app/assets/javascripts/smarty/vendor.sparkline.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.summernoteeditor.js +10235 -0
- data/app/assets/javascripts/smarty/vendor.summernoteeditor.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor.swiper.js +9899 -0
- data/app/assets/javascripts/smarty/vendor.swiper.min.js +1 -0
- data/app/assets/javascripts/smarty/vendor_bundle.js +30514 -0
- data/app/assets/javascripts/smarty/vendor_bundle.min.js +2 -0
- data/app/assets/stylesheets/smarty/default/phcthemes_admin_panel_pack_smarty.scss +7 -0
- data/app/assets/stylesheets/smarty/theme/css/core.css +20170 -0
- data/app/assets/stylesheets/smarty/theme/css/core.min.css +2 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.chartjs.css +55 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.chartjs.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.cocoen.css +59 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.cocoen.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.colorpicker.css +1196 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.colorpicker.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.datatables.css +1258 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.datatables.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.datepicker.css +173 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.datepicker.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.daterangepicker.css +545 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.daterangepicker.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.fancybox.css +927 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.fancybox.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.flickity.css +263 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.flickity.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.flot.css +17 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.flot.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.fullcalendar.css +1685 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.fullcalendar.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.leaflet.css +653 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.leaflet.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.markdowneditor.css +7 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.markdowneditor.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.mediumeditor.css +308 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.mediumeditor.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.photoswipe.css +436 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.photoswipe.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.prismjs.css +364 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.prismjs.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.quilleditor.css +953 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.quilleditor.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.summernoteeditor.css +710 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.summernoteeditor.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.swiper.css +762 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor.swiper.min.css +1 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor_bundle.css +168 -0
- data/app/assets/stylesheets/smarty/theme/css/vendor_bundle.min.css +2 -0
- data/app/assets/stylesheets/smarty/theme/fonts/flaticon/Flaticon.eot +0 -0
- data/app/assets/stylesheets/smarty/theme/fonts/flaticon/Flaticon.svg +250 -0
- data/app/assets/stylesheets/smarty/theme/fonts/flaticon/Flaticon.ttf +0 -0
- data/app/assets/stylesheets/smarty/theme/fonts/flaticon/Flaticon.woff +0 -0
- data/app/assets/stylesheets/smarty/theme/fonts/flaticon/Flaticon.woff2 +0 -0
- data/app/assets/stylesheets/smarty/theme/fonts/summernote.eot +0 -0
- data/app/assets/stylesheets/smarty/theme/fonts/summernote.hash +1 -0
- data/app/assets/stylesheets/smarty/theme/fonts/summernote.ttf +0 -0
- data/app/assets/stylesheets/smarty/theme/fonts/summernote.woff +0 -0
- data/app/assets/stylesheets/smarty/theme/fonts/summernote.woff2 +0 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/2co.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/amazon.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/amazon_pay_logo.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/american_express.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/apple_pay.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/bitcoin.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/dinners_club.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/discover.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/ebay.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/jcb.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/mastercard.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/paypal.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/paypal_logo.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/shopify.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/skrill.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/switch.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/visa.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/credit_card/western_union.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/flags.png +0 -0
- data/app/assets/stylesheets/smarty/theme/images/logo/logo_dark.svg +2 -0
- data/app/assets/stylesheets/smarty/theme/images/logo/logo_light.svg +2 -0
- data/app/assets/stylesheets/smarty/theme/images/logo/logo_sm.svg +1 -0
- data/app/assets/stylesheets/smarty/theme/images/manifest/icon_192x192.png +0 -0
- data/app/assets/stylesheets/smarty/theme/images/manifest/icon_512x512.png +0 -0
- data/app/assets/stylesheets/smarty/theme/images/manifest/manifest.json +20 -0
- data/app/assets/stylesheets/smarty/theme/images/masks/shape-line-lense.svg +1 -0
- data/lib/phcthemes_admin_panel_pack/version.rb +1 -1
- metadata +128 -2
@@ -0,0 +1,3068 @@
|
|
1
|
+
/**
|
2
|
+
*
|
3
|
+
* jquery.sparkline.js
|
4
|
+
*
|
5
|
+
* v2.4.1
|
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
|
+
|
223
|
+
/**
|
224
|
+
* Default configuration settings
|
225
|
+
*/
|
226
|
+
getDefaults = function () {
|
227
|
+
return {
|
228
|
+
// Settings common to most/all chart types
|
229
|
+
common: {
|
230
|
+
type: 'line',
|
231
|
+
lineColor: '#00f',
|
232
|
+
fillColor: '#cdf',
|
233
|
+
defaultPixelsPerValue: 3,
|
234
|
+
width: 'auto',
|
235
|
+
height: 'auto',
|
236
|
+
composite: false,
|
237
|
+
tagValuesAttribute: 'values',
|
238
|
+
tagOptionsPrefix: 'spark',
|
239
|
+
enableTagOptions: false,
|
240
|
+
enableHighlight: true,
|
241
|
+
highlightLighten: 1.4,
|
242
|
+
tooltipSkipNull: true,
|
243
|
+
tooltipPrefix: '',
|
244
|
+
tooltipSuffix: '',
|
245
|
+
disableHiddenCheck: false,
|
246
|
+
numberFormatter: false,
|
247
|
+
numberDigitGroupCount: 3,
|
248
|
+
numberDigitGroupSep: ',',
|
249
|
+
numberDecimalMark: '.',
|
250
|
+
disableTooltips: false,
|
251
|
+
disableInteraction: false
|
252
|
+
},
|
253
|
+
// Defaults for line charts
|
254
|
+
line: {
|
255
|
+
spotColor: '#f80',
|
256
|
+
highlightSpotColor: '#5f5',
|
257
|
+
highlightLineColor: '#f22',
|
258
|
+
spotRadius: 1.5,
|
259
|
+
minSpotColor: '#f80',
|
260
|
+
maxSpotColor: '#f80',
|
261
|
+
lineWidth: 1,
|
262
|
+
normalRangeMin: undefined,
|
263
|
+
normalRangeMax: undefined,
|
264
|
+
normalRangeColor: '#ccc',
|
265
|
+
drawNormalOnTop: false,
|
266
|
+
chartRangeMin: undefined,
|
267
|
+
chartRangeMax: undefined,
|
268
|
+
chartRangeMinX: undefined,
|
269
|
+
chartRangeMaxX: undefined,
|
270
|
+
tooltipFormat: new SPFormat('<span style="color: {{color}}">●</span> {{prefix}}{{y}}{{suffix}}')
|
271
|
+
},
|
272
|
+
// Defaults for bar charts
|
273
|
+
bar: {
|
274
|
+
barColor: '#3366cc',
|
275
|
+
negBarColor: '#f44',
|
276
|
+
stackedBarColor: ['#3366cc', '#dc3912', '#ff9900', '#109618', '#66aa00',
|
277
|
+
'#dd4477', '#0099c6', '#990099'],
|
278
|
+
zeroColor: undefined,
|
279
|
+
nullColor: undefined,
|
280
|
+
zeroAxis: true,
|
281
|
+
barWidth: 4,
|
282
|
+
barSpacing: 1,
|
283
|
+
chartRangeMax: undefined,
|
284
|
+
chartRangeMin: undefined,
|
285
|
+
chartRangeClip: false,
|
286
|
+
colorMap: undefined,
|
287
|
+
tooltipFormat: new SPFormat('<span style="color: {{color}}">●</span> {{prefix}}{{value}}{{suffix}}')
|
288
|
+
},
|
289
|
+
// Defaults for tristate charts
|
290
|
+
tristate: {
|
291
|
+
barWidth: 4,
|
292
|
+
barSpacing: 1,
|
293
|
+
posBarColor: '#6f6',
|
294
|
+
negBarColor: '#f44',
|
295
|
+
zeroBarColor: '#999',
|
296
|
+
colorMap: {},
|
297
|
+
tooltipFormat: new SPFormat('<span style="color: {{color}}">●</span> {{value:map}}'),
|
298
|
+
tooltipValueLookups: { map: { '-1': 'Loss', '0': 'Draw', '1': 'Win' } }
|
299
|
+
},
|
300
|
+
// Defaults for discrete charts
|
301
|
+
discrete: {
|
302
|
+
lineHeight: 'auto',
|
303
|
+
thresholdColor: undefined,
|
304
|
+
thresholdValue: 0,
|
305
|
+
chartRangeMax: undefined,
|
306
|
+
chartRangeMin: undefined,
|
307
|
+
chartRangeClip: false,
|
308
|
+
tooltipFormat: new SPFormat('{{prefix}}{{value}}{{suffix}}')
|
309
|
+
},
|
310
|
+
// Defaults for bullet charts
|
311
|
+
bullet: {
|
312
|
+
targetColor: '#f33',
|
313
|
+
targetWidth: 3, // width of the target bar in pixels
|
314
|
+
performanceColor: '#33f',
|
315
|
+
rangeColors: ['#d3dafe', '#a8b6ff', '#7f94ff'],
|
316
|
+
base: undefined, // set this to a number to change the base start number
|
317
|
+
tooltipFormat: new SPFormat('{{fieldkey:fields}} - {{value}}'),
|
318
|
+
tooltipValueLookups: { fields: {r: 'Range', p: 'Performance', t: 'Target'} }
|
319
|
+
},
|
320
|
+
// Defaults for pie charts
|
321
|
+
pie: {
|
322
|
+
offset: 0,
|
323
|
+
sliceColors: ['#3366cc', '#dc3912', '#ff9900', '#109618', '#66aa00',
|
324
|
+
'#dd4477', '#0099c6', '#990099'],
|
325
|
+
borderWidth: 0,
|
326
|
+
borderColor: '#000',
|
327
|
+
tooltipFormat: new SPFormat('<span style="color: {{color}}">●</span> {{value}} ({{percent.1}}%)')
|
328
|
+
},
|
329
|
+
// Defaults for box plots
|
330
|
+
box: {
|
331
|
+
raw: false,
|
332
|
+
boxLineColor: '#000',
|
333
|
+
boxFillColor: '#cdf',
|
334
|
+
whiskerColor: '#000',
|
335
|
+
outlierLineColor: '#333',
|
336
|
+
outlierFillColor: '#fff',
|
337
|
+
medianColor: '#f00',
|
338
|
+
showOutliers: true,
|
339
|
+
outlierIQR: 1.5,
|
340
|
+
spotRadius: 1.5,
|
341
|
+
target: undefined,
|
342
|
+
targetColor: '#4a2',
|
343
|
+
chartRangeMax: undefined,
|
344
|
+
chartRangeMin: undefined,
|
345
|
+
tooltipFormat: new SPFormat('{{field:fields}}: {{value}}'),
|
346
|
+
tooltipFormatFieldlistKey: 'field',
|
347
|
+
tooltipValueLookups: { fields: { lq: 'Lower Quartile', med: 'Median',
|
348
|
+
uq: 'Upper Quartile', lo: 'Left Outlier', ro: 'Right Outlier',
|
349
|
+
lw: 'Left Whisker', rw: 'Right Whisker'} }
|
350
|
+
}
|
351
|
+
};
|
352
|
+
};
|
353
|
+
|
354
|
+
// You can have tooltips use a css class other than jqstooltip by specifying tooltipClassname
|
355
|
+
defaultStyles = '.jqstooltip { ' +
|
356
|
+
'position: absolute;' +
|
357
|
+
'left: 0px;' +
|
358
|
+
'top: 0px;' +
|
359
|
+
'visibility: hidden;' +
|
360
|
+
'background: rgb(0, 0, 0) transparent;' +
|
361
|
+
'background-color: rgba(0,0,0,0.6);' +
|
362
|
+
'filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);' +
|
363
|
+
'-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000)";' +
|
364
|
+
'color: white;' +
|
365
|
+
'font: 10px arial, san serif;' +
|
366
|
+
'text-align: left;' +
|
367
|
+
'white-space: nowrap;' +
|
368
|
+
'padding: 5px;' +
|
369
|
+
'border: 1px solid white;' +
|
370
|
+
'box-sizing: content-box;' +
|
371
|
+
'z-index: 10000;' +
|
372
|
+
'}' +
|
373
|
+
'.jqsfield { ' +
|
374
|
+
'color: white;' +
|
375
|
+
'font: 10px arial, san serif;' +
|
376
|
+
'text-align: left;' +
|
377
|
+
'}';
|
378
|
+
|
379
|
+
/**
|
380
|
+
* Utilities
|
381
|
+
*/
|
382
|
+
|
383
|
+
createClass = function (/* [baseclass, [mixin, ...]], definition */) {
|
384
|
+
var Class, args;
|
385
|
+
Class = function () {
|
386
|
+
this.init.apply(this, arguments);
|
387
|
+
};
|
388
|
+
if (arguments.length > 1) {
|
389
|
+
if (arguments[0]) {
|
390
|
+
Class.prototype = $.extend(new arguments[0](), arguments[arguments.length - 1]);
|
391
|
+
Class._super = arguments[0].prototype;
|
392
|
+
} else {
|
393
|
+
Class.prototype = arguments[arguments.length - 1];
|
394
|
+
}
|
395
|
+
if (arguments.length > 2) {
|
396
|
+
args = Array.prototype.slice.call(arguments, 1, -1);
|
397
|
+
args.unshift(Class.prototype);
|
398
|
+
$.extend.apply($, args);
|
399
|
+
}
|
400
|
+
} else {
|
401
|
+
Class.prototype = arguments[0];
|
402
|
+
}
|
403
|
+
Class.prototype.cls = Class;
|
404
|
+
return Class;
|
405
|
+
};
|
406
|
+
|
407
|
+
/**
|
408
|
+
* Wraps a format string for tooltips
|
409
|
+
* {{x}}
|
410
|
+
* {{x.2}
|
411
|
+
* {{x:months}}
|
412
|
+
*/
|
413
|
+
$.SPFormatClass = SPFormat = createClass({
|
414
|
+
fre: /\{\{([\w.]+?)(:(.+?))?\}\}/g,
|
415
|
+
precre: /(\w+)\.(\d+)/,
|
416
|
+
|
417
|
+
init: function (format, fclass) {
|
418
|
+
this.format = format;
|
419
|
+
this.fclass = fclass;
|
420
|
+
},
|
421
|
+
|
422
|
+
render: function (fieldset, lookups, options) {
|
423
|
+
var self = this,
|
424
|
+
fields = fieldset,
|
425
|
+
match, token, lookupkey, fieldvalue, prec;
|
426
|
+
return this.format.replace(this.fre, function () {
|
427
|
+
var lookup;
|
428
|
+
token = arguments[1];
|
429
|
+
lookupkey = arguments[3];
|
430
|
+
match = self.precre.exec(token);
|
431
|
+
if (match) {
|
432
|
+
prec = match[2];
|
433
|
+
token = match[1];
|
434
|
+
} else {
|
435
|
+
prec = false;
|
436
|
+
}
|
437
|
+
fieldvalue = fields[token];
|
438
|
+
if (fieldvalue === undefined) {
|
439
|
+
return '';
|
440
|
+
}
|
441
|
+
if (lookupkey && lookups && lookups[lookupkey]) {
|
442
|
+
lookup = lookups[lookupkey];
|
443
|
+
if (lookup.get) { // RangeMap
|
444
|
+
return lookups[lookupkey].get(fieldvalue) || fieldvalue;
|
445
|
+
} else {
|
446
|
+
return lookups[lookupkey][fieldvalue] || fieldvalue;
|
447
|
+
}
|
448
|
+
}
|
449
|
+
if (isNumber(fieldvalue)) {
|
450
|
+
if (options.get('numberFormatter')) {
|
451
|
+
fieldvalue = options.get('numberFormatter')(fieldvalue);
|
452
|
+
} else {
|
453
|
+
fieldvalue = formatNumber(fieldvalue, prec,
|
454
|
+
options.get('numberDigitGroupCount'),
|
455
|
+
options.get('numberDigitGroupSep'),
|
456
|
+
options.get('numberDecimalMark'));
|
457
|
+
}
|
458
|
+
}
|
459
|
+
return fieldvalue;
|
460
|
+
});
|
461
|
+
}
|
462
|
+
});
|
463
|
+
|
464
|
+
// convience method to avoid needing the new operator
|
465
|
+
$.spformat = function(format, fclass) {
|
466
|
+
return new SPFormat(format, fclass);
|
467
|
+
};
|
468
|
+
|
469
|
+
clipval = function (val, min, max) {
|
470
|
+
if (val < min) {
|
471
|
+
return min;
|
472
|
+
}
|
473
|
+
if (val > max) {
|
474
|
+
return max;
|
475
|
+
}
|
476
|
+
return val;
|
477
|
+
};
|
478
|
+
|
479
|
+
quartile = function (values, q) {
|
480
|
+
var vl;
|
481
|
+
if (q === 2) {
|
482
|
+
vl = Math.floor(values.length / 2);
|
483
|
+
return values.length % 2 ? values[vl] : (values[vl-1] + values[vl]) / 2;
|
484
|
+
} else {
|
485
|
+
if (values.length % 2 ) { // odd
|
486
|
+
vl = (values.length * q + q) / 4;
|
487
|
+
return vl % 1 ? (values[Math.floor(vl)] + values[Math.floor(vl) - 1]) / 2 : values[vl-1];
|
488
|
+
} else { //even
|
489
|
+
vl = (values.length * q + 2) / 4;
|
490
|
+
return vl % 1 ? (values[Math.floor(vl)] + values[Math.floor(vl) - 1]) / 2 : values[vl-1];
|
491
|
+
|
492
|
+
}
|
493
|
+
}
|
494
|
+
};
|
495
|
+
|
496
|
+
normalizeValue = function (val) {
|
497
|
+
var nf;
|
498
|
+
switch (val) {
|
499
|
+
case 'undefined':
|
500
|
+
val = undefined;
|
501
|
+
break;
|
502
|
+
case 'null':
|
503
|
+
val = null;
|
504
|
+
break;
|
505
|
+
case 'true':
|
506
|
+
val = true;
|
507
|
+
break;
|
508
|
+
case 'false':
|
509
|
+
val = false;
|
510
|
+
break;
|
511
|
+
default:
|
512
|
+
nf = parseFloat(val);
|
513
|
+
if (val == nf) {
|
514
|
+
val = nf;
|
515
|
+
}
|
516
|
+
}
|
517
|
+
return val;
|
518
|
+
};
|
519
|
+
|
520
|
+
normalizeValues = function (vals) {
|
521
|
+
var i, result = [];
|
522
|
+
for (i = vals.length; i--;) {
|
523
|
+
result[i] = normalizeValue(vals[i]);
|
524
|
+
}
|
525
|
+
return result;
|
526
|
+
};
|
527
|
+
|
528
|
+
remove = function (vals, filter) {
|
529
|
+
var i, vl, result = [];
|
530
|
+
for (i = 0, vl = vals.length; i < vl; i++) {
|
531
|
+
if (vals[i] !== filter) {
|
532
|
+
result.push(vals[i]);
|
533
|
+
}
|
534
|
+
}
|
535
|
+
return result;
|
536
|
+
};
|
537
|
+
|
538
|
+
isNumber = function (num) {
|
539
|
+
return !isNaN(parseFloat(num)) && isFinite(num);
|
540
|
+
};
|
541
|
+
|
542
|
+
formatNumber = function (num, prec, groupsize, groupsep, decsep) {
|
543
|
+
var p, i;
|
544
|
+
num = (prec === false ? parseFloat(num).toString() : num.toFixed(prec)).split('');
|
545
|
+
p = (p = $.inArray('.', num)) < 0 ? num.length : p;
|
546
|
+
if (p < num.length) {
|
547
|
+
num[p] = decsep;
|
548
|
+
}
|
549
|
+
for (i = p - groupsize; i > 0; i -= groupsize) {
|
550
|
+
num.splice(i, 0, groupsep);
|
551
|
+
}
|
552
|
+
return num.join('');
|
553
|
+
};
|
554
|
+
|
555
|
+
// determine if all values of an array match a value
|
556
|
+
// returns true if the array is empty
|
557
|
+
all = function (val, arr, ignoreNull) {
|
558
|
+
var i;
|
559
|
+
for (i = arr.length; i--; ) {
|
560
|
+
if (ignoreNull && arr[i] === null) continue;
|
561
|
+
if (arr[i] !== val) {
|
562
|
+
return false;
|
563
|
+
}
|
564
|
+
}
|
565
|
+
return true;
|
566
|
+
};
|
567
|
+
|
568
|
+
// sums the numeric values in an array, ignoring other values
|
569
|
+
sum = function (vals) {
|
570
|
+
var total = 0, i;
|
571
|
+
for (i = vals.length; i--;) {
|
572
|
+
total += typeof vals[i] === 'number' ? vals[i] : 0;
|
573
|
+
}
|
574
|
+
return total;
|
575
|
+
};
|
576
|
+
|
577
|
+
ensureArray = function (val) {
|
578
|
+
return $.isArray(val) ? val : [val];
|
579
|
+
};
|
580
|
+
|
581
|
+
// http://paulirish.com/2008/bookmarklet-inject-new-css-rules/
|
582
|
+
addCSS = function(css) {
|
583
|
+
var tag, iefail;
|
584
|
+
if (document.createStyleSheet) {
|
585
|
+
try {
|
586
|
+
document.createStyleSheet().cssText = css;
|
587
|
+
return;
|
588
|
+
} catch (e) {
|
589
|
+
// IE <= 9 maxes out at 31 stylesheets; inject into page instead.
|
590
|
+
iefail = true;
|
591
|
+
}
|
592
|
+
}
|
593
|
+
tag = document.createElement('style');
|
594
|
+
tag.type = 'text/css';
|
595
|
+
document.getElementsByTagName('head')[0].appendChild(tag);
|
596
|
+
if (iefail) {
|
597
|
+
document.styleSheets[document.styleSheets.length - 1].cssText = css;
|
598
|
+
} else {
|
599
|
+
tag[(typeof document.body.style.WebkitAppearance == 'string') /* webkit only */ ? 'innerText' : 'innerHTML'] = css;
|
600
|
+
}
|
601
|
+
};
|
602
|
+
|
603
|
+
// Provide a cross-browser interface to a few simple drawing primitives
|
604
|
+
$.fn.simpledraw = function (width, height, useExisting, interact) {
|
605
|
+
var target, mhandler;
|
606
|
+
if (useExisting && (target = this.data('_jqs_vcanvas'))) {
|
607
|
+
return target;
|
608
|
+
}
|
609
|
+
|
610
|
+
if ($.fn.sparkline.canvas === false) {
|
611
|
+
// We've already determined that neither Canvas nor VML are available
|
612
|
+
return false;
|
613
|
+
|
614
|
+
} else if ($.fn.sparkline.canvas === undefined) {
|
615
|
+
// No function defined yet -- need to see if we support Canvas or VML
|
616
|
+
var el = document.createElement('canvas');
|
617
|
+
if (!!(el.getContext && el.getContext('2d'))) {
|
618
|
+
// Canvas is available
|
619
|
+
$.fn.sparkline.canvas = function(width, height, target, interact) {
|
620
|
+
return new VCanvas_canvas(width, height, target, interact);
|
621
|
+
};
|
622
|
+
} else if (document.namespaces && !document.namespaces.v) {
|
623
|
+
// VML is available
|
624
|
+
document.namespaces.add('v', 'urn:schemas-microsoft-com:vml', '#default#VML');
|
625
|
+
$.fn.sparkline.canvas = function(width, height, target, interact) {
|
626
|
+
return new VCanvas_vml(width, height, target);
|
627
|
+
};
|
628
|
+
} else {
|
629
|
+
// Neither Canvas nor VML are available
|
630
|
+
$.fn.sparkline.canvas = false;
|
631
|
+
return false;
|
632
|
+
}
|
633
|
+
}
|
634
|
+
|
635
|
+
if (width === undefined) {
|
636
|
+
width = $(this).innerWidth();
|
637
|
+
}
|
638
|
+
if (height === undefined) {
|
639
|
+
height = $(this).innerHeight();
|
640
|
+
}
|
641
|
+
|
642
|
+
target = $.fn.sparkline.canvas(width, height, this, interact);
|
643
|
+
|
644
|
+
mhandler = $(this).data('_jqs_mhandler');
|
645
|
+
if (mhandler) {
|
646
|
+
mhandler.registerCanvas(target);
|
647
|
+
}
|
648
|
+
return target;
|
649
|
+
};
|
650
|
+
|
651
|
+
$.fn.cleardraw = function () {
|
652
|
+
var target = this.data('_jqs_vcanvas');
|
653
|
+
if (target) {
|
654
|
+
target.reset();
|
655
|
+
}
|
656
|
+
};
|
657
|
+
|
658
|
+
$.RangeMapClass = RangeMap = createClass({
|
659
|
+
init: function (map) {
|
660
|
+
var key, range, rangelist = [];
|
661
|
+
for (key in map) {
|
662
|
+
if (map.hasOwnProperty(key) && typeof key === 'string' && key.indexOf(':') > -1) {
|
663
|
+
range = key.split(':');
|
664
|
+
range[0] = range[0].length === 0 ? -Infinity : parseFloat(range[0]);
|
665
|
+
range[1] = range[1].length === 0 ? Infinity : parseFloat(range[1]);
|
666
|
+
range[2] = map[key];
|
667
|
+
rangelist.push(range);
|
668
|
+
}
|
669
|
+
}
|
670
|
+
this.map = map;
|
671
|
+
this.rangelist = rangelist || false;
|
672
|
+
},
|
673
|
+
|
674
|
+
get: function (value) {
|
675
|
+
var rangelist = this.rangelist,
|
676
|
+
i, range, result;
|
677
|
+
if ((result = this.map[value]) !== undefined) {
|
678
|
+
return result;
|
679
|
+
}
|
680
|
+
if (rangelist) {
|
681
|
+
for (i = rangelist.length; i--;) {
|
682
|
+
range = rangelist[i];
|
683
|
+
if (range[0] <= value && range[1] >= value) {
|
684
|
+
return range[2];
|
685
|
+
}
|
686
|
+
}
|
687
|
+
}
|
688
|
+
return undefined;
|
689
|
+
}
|
690
|
+
});
|
691
|
+
|
692
|
+
// Convenience function
|
693
|
+
$.range_map = function(map) {
|
694
|
+
return new RangeMap(map);
|
695
|
+
};
|
696
|
+
|
697
|
+
MouseHandler = createClass({
|
698
|
+
init: function (el, options) {
|
699
|
+
var $el = $(el);
|
700
|
+
this.$el = $el;
|
701
|
+
this.options = options;
|
702
|
+
this.currentPageX = 0;
|
703
|
+
this.currentPageY = 0;
|
704
|
+
this.el = el;
|
705
|
+
this.splist = [];
|
706
|
+
this.tooltip = null;
|
707
|
+
this.over = false;
|
708
|
+
this.displayTooltips = !options.get('disableTooltips');
|
709
|
+
this.highlightEnabled = !options.get('disableHighlight');
|
710
|
+
},
|
711
|
+
|
712
|
+
registerSparkline: function (sp) {
|
713
|
+
this.splist.push(sp);
|
714
|
+
if (this.over) {
|
715
|
+
this.updateDisplay();
|
716
|
+
}
|
717
|
+
},
|
718
|
+
|
719
|
+
registerCanvas: function (canvas) {
|
720
|
+
var $canvas = $(canvas.canvas);
|
721
|
+
this.canvas = canvas;
|
722
|
+
this.$canvas = $canvas;
|
723
|
+
$canvas.mouseenter($.proxy(this.mouseenter, this));
|
724
|
+
$canvas.mouseleave($.proxy(this.mouseleave, this));
|
725
|
+
$canvas.click($.proxy(this.mouseclick, this));
|
726
|
+
},
|
727
|
+
|
728
|
+
reset: function (removeTooltip) {
|
729
|
+
this.splist = [];
|
730
|
+
if (this.tooltip && removeTooltip) {
|
731
|
+
this.tooltip.remove();
|
732
|
+
this.tooltip = undefined;
|
733
|
+
}
|
734
|
+
},
|
735
|
+
|
736
|
+
mouseclick: function (e) {
|
737
|
+
var clickEvent = $.Event('sparklineClick');
|
738
|
+
clickEvent.originalEvent = e;
|
739
|
+
clickEvent.sparklines = this.splist;
|
740
|
+
this.$el.trigger(clickEvent);
|
741
|
+
},
|
742
|
+
|
743
|
+
mouseenter: function (e) {
|
744
|
+
$(document.body).unbind('mousemove.jqs');
|
745
|
+
$(document.body).bind('mousemove.jqs', $.proxy(this.mousemove, this));
|
746
|
+
this.over = true;
|
747
|
+
this.currentPageX = e.pageX;
|
748
|
+
this.currentPageY = e.pageY;
|
749
|
+
this.currentEl = e.target;
|
750
|
+
if (!this.tooltip && this.displayTooltips) {
|
751
|
+
this.tooltip = new Tooltip(this.options);
|
752
|
+
this.tooltip.updatePosition(e.pageX, e.pageY);
|
753
|
+
}
|
754
|
+
this.updateDisplay();
|
755
|
+
},
|
756
|
+
|
757
|
+
mouseleave: function () {
|
758
|
+
$(document.body).unbind('mousemove.jqs');
|
759
|
+
var splist = this.splist,
|
760
|
+
spcount = splist.length,
|
761
|
+
needsRefresh = false,
|
762
|
+
sp, i;
|
763
|
+
this.over = false;
|
764
|
+
this.currentEl = null;
|
765
|
+
|
766
|
+
if (this.tooltip) {
|
767
|
+
this.tooltip.remove();
|
768
|
+
this.tooltip = null;
|
769
|
+
}
|
770
|
+
|
771
|
+
for (i = 0; i < spcount; i++) {
|
772
|
+
sp = splist[i];
|
773
|
+
if (sp.clearRegionHighlight()) {
|
774
|
+
needsRefresh = true;
|
775
|
+
}
|
776
|
+
}
|
777
|
+
|
778
|
+
if (needsRefresh) {
|
779
|
+
this.canvas.render();
|
780
|
+
}
|
781
|
+
},
|
782
|
+
|
783
|
+
mousemove: function (e) {
|
784
|
+
this.currentPageX = e.pageX;
|
785
|
+
this.currentPageY = e.pageY;
|
786
|
+
this.currentEl = e.target;
|
787
|
+
if (this.tooltip) {
|
788
|
+
this.tooltip.updatePosition(e.pageX, e.pageY);
|
789
|
+
}
|
790
|
+
this.updateDisplay();
|
791
|
+
},
|
792
|
+
|
793
|
+
updateDisplay: function () {
|
794
|
+
var splist = this.splist,
|
795
|
+
spcount = splist.length,
|
796
|
+
needsRefresh = false,
|
797
|
+
offset = this.$canvas.offset(),
|
798
|
+
localX = this.currentPageX - offset.left,
|
799
|
+
localY = this.currentPageY - offset.top,
|
800
|
+
tooltiphtml, sp, i, result, changeEvent;
|
801
|
+
if (!this.over) {
|
802
|
+
return;
|
803
|
+
}
|
804
|
+
for (i = 0; i < spcount; i++) {
|
805
|
+
sp = splist[i];
|
806
|
+
result = sp.setRegionHighlight(this.currentEl, localX, localY);
|
807
|
+
if (result) {
|
808
|
+
needsRefresh = true;
|
809
|
+
}
|
810
|
+
}
|
811
|
+
if (needsRefresh) {
|
812
|
+
changeEvent = $.Event('sparklineRegionChange');
|
813
|
+
changeEvent.sparklines = this.splist;
|
814
|
+
this.$el.trigger(changeEvent);
|
815
|
+
if (this.tooltip) {
|
816
|
+
tooltiphtml = '';
|
817
|
+
for (i = 0; i < spcount; i++) {
|
818
|
+
sp = splist[i];
|
819
|
+
tooltiphtml += sp.getCurrentRegionTooltip();
|
820
|
+
}
|
821
|
+
this.tooltip.setContent(tooltiphtml);
|
822
|
+
}
|
823
|
+
if (!this.disableHighlight) {
|
824
|
+
this.canvas.render();
|
825
|
+
}
|
826
|
+
}
|
827
|
+
if (result === null) {
|
828
|
+
this.mouseleave();
|
829
|
+
}
|
830
|
+
}
|
831
|
+
});
|
832
|
+
|
833
|
+
|
834
|
+
Tooltip = createClass({
|
835
|
+
sizeStyle: 'position: static !important;' +
|
836
|
+
'display: block !important;' +
|
837
|
+
'visibility: hidden !important;' +
|
838
|
+
'float: left !important;',
|
839
|
+
|
840
|
+
init: function (options) {
|
841
|
+
var tooltipClassname = options.get('tooltipClassname', 'jqstooltip'),
|
842
|
+
sizetipStyle = this.sizeStyle,
|
843
|
+
offset;
|
844
|
+
this.container = options.get('tooltipContainer') || document.body;
|
845
|
+
this.tooltipOffsetX = options.get('tooltipOffsetX', 10);
|
846
|
+
this.tooltipOffsetY = options.get('tooltipOffsetY', 12);
|
847
|
+
// remove any previous lingering tooltip
|
848
|
+
$('#jqssizetip').remove();
|
849
|
+
$('#jqstooltip').remove();
|
850
|
+
this.sizetip = $('<div/>', {
|
851
|
+
id: 'jqssizetip',
|
852
|
+
style: sizetipStyle,
|
853
|
+
'class': tooltipClassname
|
854
|
+
});
|
855
|
+
this.tooltip = $('<div/>', {
|
856
|
+
id: 'jqstooltip',
|
857
|
+
'class': tooltipClassname
|
858
|
+
}).appendTo(this.container);
|
859
|
+
// account for the container's location
|
860
|
+
offset = this.tooltip.offset();
|
861
|
+
this.offsetLeft = offset.left;
|
862
|
+
this.offsetTop = offset.top;
|
863
|
+
this.hidden = true;
|
864
|
+
$(window).unbind('resize.jqs scroll.jqs');
|
865
|
+
$(window).bind('resize.jqs scroll.jqs', $.proxy(this.updateWindowDims, this));
|
866
|
+
this.updateWindowDims();
|
867
|
+
},
|
868
|
+
|
869
|
+
updateWindowDims: function () {
|
870
|
+
this.scrollTop = $(window).scrollTop();
|
871
|
+
this.scrollLeft = $(window).scrollLeft();
|
872
|
+
this.scrollRight = this.scrollLeft + $(window).width();
|
873
|
+
this.updatePosition();
|
874
|
+
},
|
875
|
+
|
876
|
+
getSize: function (content) {
|
877
|
+
this.sizetip.html(content).appendTo(this.container);
|
878
|
+
this.width = this.sizetip.width() + 1;
|
879
|
+
this.height = this.sizetip.height();
|
880
|
+
this.sizetip.remove();
|
881
|
+
},
|
882
|
+
|
883
|
+
setContent: function (content) {
|
884
|
+
if (!content) {
|
885
|
+
this.tooltip.css('visibility', 'hidden');
|
886
|
+
this.hidden = true;
|
887
|
+
return;
|
888
|
+
}
|
889
|
+
this.getSize(content);
|
890
|
+
this.tooltip.html(content)
|
891
|
+
.css({
|
892
|
+
'width': this.width,
|
893
|
+
'height': this.height,
|
894
|
+
'visibility': 'visible'
|
895
|
+
});
|
896
|
+
if (this.hidden) {
|
897
|
+
this.hidden = false;
|
898
|
+
this.updatePosition();
|
899
|
+
}
|
900
|
+
},
|
901
|
+
|
902
|
+
updatePosition: function (x, y) {
|
903
|
+
if (x === undefined) {
|
904
|
+
if (this.mousex === undefined) {
|
905
|
+
return;
|
906
|
+
}
|
907
|
+
x = this.mousex - this.offsetLeft;
|
908
|
+
y = this.mousey - this.offsetTop;
|
909
|
+
|
910
|
+
} else {
|
911
|
+
this.mousex = x = x - this.offsetLeft;
|
912
|
+
this.mousey = y = y - this.offsetTop;
|
913
|
+
}
|
914
|
+
if (!this.height || !this.width || this.hidden) {
|
915
|
+
return;
|
916
|
+
}
|
917
|
+
|
918
|
+
y -= this.height + this.tooltipOffsetY;
|
919
|
+
x += this.tooltipOffsetX;
|
920
|
+
|
921
|
+
if (y < this.scrollTop) {
|
922
|
+
y = this.scrollTop;
|
923
|
+
}
|
924
|
+
if (x < this.scrollLeft) {
|
925
|
+
x = this.scrollLeft;
|
926
|
+
} else if (x + this.width > this.scrollRight) {
|
927
|
+
x = this.scrollRight - this.width;
|
928
|
+
}
|
929
|
+
|
930
|
+
this.tooltip.css({
|
931
|
+
'left': x,
|
932
|
+
'top': y
|
933
|
+
});
|
934
|
+
},
|
935
|
+
|
936
|
+
remove: function () {
|
937
|
+
this.tooltip.remove();
|
938
|
+
this.sizetip.remove();
|
939
|
+
this.sizetip = this.tooltip = undefined;
|
940
|
+
$(window).unbind('resize.jqs scroll.jqs');
|
941
|
+
}
|
942
|
+
});
|
943
|
+
|
944
|
+
initStyles = function() {
|
945
|
+
addCSS(defaultStyles);
|
946
|
+
};
|
947
|
+
|
948
|
+
$(initStyles);
|
949
|
+
|
950
|
+
pending = [];
|
951
|
+
$.fn.sparkline = function (userValues, userOptions) {
|
952
|
+
return this.each(function () {
|
953
|
+
var options = new $.fn.sparkline.options(this, userOptions),
|
954
|
+
$this = $(this),
|
955
|
+
render, i;
|
956
|
+
render = function () {
|
957
|
+
var values, width, height, tmp, mhandler, sp, vals;
|
958
|
+
if (userValues === 'html' || userValues === undefined) {
|
959
|
+
vals = this.getAttribute(options.get('tagValuesAttribute'));
|
960
|
+
if (vals === undefined || vals === null) {
|
961
|
+
vals = $this.html();
|
962
|
+
}
|
963
|
+
values = vals.replace(/(^\s*<!--)|(-->\s*$)|\s+/g, '').split(',');
|
964
|
+
} else {
|
965
|
+
values = userValues;
|
966
|
+
}
|
967
|
+
|
968
|
+
width = options.get('width') === 'auto' ? values.length * options.get('defaultPixelsPerValue') : options.get('width');
|
969
|
+
if (options.get('height') === 'auto') {
|
970
|
+
if (!options.get('composite') || !$.data(this, '_jqs_vcanvas')) {
|
971
|
+
// must be a better way to get the line height
|
972
|
+
tmp = document.createElement('span');
|
973
|
+
tmp.innerHTML = 'a';
|
974
|
+
$this.html(tmp);
|
975
|
+
height = $(tmp).innerHeight() || $(tmp).height();
|
976
|
+
$(tmp).remove();
|
977
|
+
tmp = null;
|
978
|
+
}
|
979
|
+
} else {
|
980
|
+
height = options.get('height');
|
981
|
+
}
|
982
|
+
|
983
|
+
if (!options.get('disableInteraction')) {
|
984
|
+
mhandler = $.data(this, '_jqs_mhandler');
|
985
|
+
if (!mhandler) {
|
986
|
+
mhandler = new MouseHandler(this, options);
|
987
|
+
$.data(this, '_jqs_mhandler', mhandler);
|
988
|
+
} else if (!options.get('composite')) {
|
989
|
+
mhandler.reset();
|
990
|
+
}
|
991
|
+
} else {
|
992
|
+
mhandler = false;
|
993
|
+
}
|
994
|
+
|
995
|
+
if (options.get('composite') && !$.data(this, '_jqs_vcanvas')) {
|
996
|
+
if (!$.data(this, '_jqs_errnotify')) {
|
997
|
+
alert('Attempted to attach a composite sparkline to an element with no existing sparkline');
|
998
|
+
$.data(this, '_jqs_errnotify', true);
|
999
|
+
}
|
1000
|
+
return;
|
1001
|
+
}
|
1002
|
+
|
1003
|
+
sp = new $.fn.sparkline[options.get('type')](this, values, options, width, height);
|
1004
|
+
|
1005
|
+
sp.render();
|
1006
|
+
|
1007
|
+
if (mhandler) {
|
1008
|
+
mhandler.registerSparkline(sp);
|
1009
|
+
}
|
1010
|
+
};
|
1011
|
+
if (($(this).html() && !options.get('disableHiddenCheck') && $(this).is(':hidden')) || !$(this).parents('body').length) {
|
1012
|
+
if (!options.get('composite') && $.data(this, '_jqs_pending')) {
|
1013
|
+
// remove any existing references to the element
|
1014
|
+
for (i = pending.length; i; i--) {
|
1015
|
+
if (pending[i - 1][0] == this) {
|
1016
|
+
pending.splice(i - 1, 1);
|
1017
|
+
}
|
1018
|
+
}
|
1019
|
+
}
|
1020
|
+
pending.push([this, render]);
|
1021
|
+
$.data(this, '_jqs_pending', true);
|
1022
|
+
} else {
|
1023
|
+
render.call(this);
|
1024
|
+
}
|
1025
|
+
});
|
1026
|
+
};
|
1027
|
+
|
1028
|
+
$.fn.sparkline.defaults = getDefaults();
|
1029
|
+
|
1030
|
+
|
1031
|
+
$.sparkline_display_visible = function () {
|
1032
|
+
var el, i, pl;
|
1033
|
+
var done = [];
|
1034
|
+
for (i = 0, pl = pending.length; i < pl; i++) {
|
1035
|
+
el = pending[i][0];
|
1036
|
+
if ($(el).is(':visible') && !$(el).parents().is(':hidden')) {
|
1037
|
+
pending[i][1].call(el);
|
1038
|
+
$.data(pending[i][0], '_jqs_pending', false);
|
1039
|
+
done.push(i);
|
1040
|
+
} else if (!$(el).closest('html').length && !$.data(el, '_jqs_pending')) {
|
1041
|
+
// element has been inserted and removed from the DOM
|
1042
|
+
// If it was not yet inserted into the dom then the .data request
|
1043
|
+
// will return true.
|
1044
|
+
// removing from the dom causes the data to be removed.
|
1045
|
+
$.data(pending[i][0], '_jqs_pending', false);
|
1046
|
+
done.push(i);
|
1047
|
+
}
|
1048
|
+
}
|
1049
|
+
for (i = done.length; i; i--) {
|
1050
|
+
pending.splice(done[i - 1], 1);
|
1051
|
+
}
|
1052
|
+
};
|
1053
|
+
|
1054
|
+
|
1055
|
+
/**
|
1056
|
+
* User option handler
|
1057
|
+
*/
|
1058
|
+
$.fn.sparkline.options = createClass({
|
1059
|
+
init: function (tag, userOptions) {
|
1060
|
+
var extendedOptions, defaults, base, tagOptionType;
|
1061
|
+
this.userOptions = userOptions = userOptions || {};
|
1062
|
+
this.tag = tag;
|
1063
|
+
this.tagValCache = {};
|
1064
|
+
defaults = $.fn.sparkline.defaults;
|
1065
|
+
base = defaults.common;
|
1066
|
+
this.tagOptionsPrefix = userOptions.enableTagOptions && (userOptions.tagOptionsPrefix || base.tagOptionsPrefix);
|
1067
|
+
|
1068
|
+
tagOptionType = this.getTagSetting('type');
|
1069
|
+
if (tagOptionType === UNSET_OPTION) {
|
1070
|
+
extendedOptions = defaults[userOptions.type || base.type];
|
1071
|
+
} else {
|
1072
|
+
extendedOptions = defaults[tagOptionType];
|
1073
|
+
}
|
1074
|
+
this.mergedOptions = $.extend({}, base, extendedOptions, userOptions);
|
1075
|
+
},
|
1076
|
+
|
1077
|
+
|
1078
|
+
getTagSetting: function (key) {
|
1079
|
+
var prefix = this.tagOptionsPrefix,
|
1080
|
+
val, i, pairs, keyval;
|
1081
|
+
if (prefix === false || prefix === undefined) {
|
1082
|
+
return UNSET_OPTION;
|
1083
|
+
}
|
1084
|
+
if (this.tagValCache.hasOwnProperty(key)) {
|
1085
|
+
val = this.tagValCache.key;
|
1086
|
+
} else {
|
1087
|
+
val = this.tag.getAttribute(prefix + key);
|
1088
|
+
if (val === undefined || val === null) {
|
1089
|
+
val = UNSET_OPTION;
|
1090
|
+
} else if (val.substr(0, 1) === '[') {
|
1091
|
+
val = val.substr(1, val.length - 2).split(',');
|
1092
|
+
for (i = val.length; i--;) {
|
1093
|
+
val[i] = normalizeValue(val[i].replace(/(^\s*)|(\s*$)/g, ''));
|
1094
|
+
}
|
1095
|
+
} else if (val.substr(0, 1) === '{') {
|
1096
|
+
pairs = val.substr(1, val.length - 2).split(',');
|
1097
|
+
val = {};
|
1098
|
+
for (i = pairs.length; i--;) {
|
1099
|
+
keyval = pairs[i].split(':', 2);
|
1100
|
+
val[keyval[0].replace(/(^\s*)|(\s*$)/g, '')] = normalizeValue(keyval[1].replace(/(^\s*)|(\s*$)/g, ''));
|
1101
|
+
}
|
1102
|
+
} else {
|
1103
|
+
val = normalizeValue(val);
|
1104
|
+
}
|
1105
|
+
this.tagValCache.key = val;
|
1106
|
+
}
|
1107
|
+
return val;
|
1108
|
+
},
|
1109
|
+
|
1110
|
+
get: function (key, defaultval) {
|
1111
|
+
var tagOption = this.getTagSetting(key),
|
1112
|
+
result;
|
1113
|
+
if (tagOption !== UNSET_OPTION) {
|
1114
|
+
return tagOption;
|
1115
|
+
}
|
1116
|
+
return (result = this.mergedOptions[key]) === undefined ? defaultval : result;
|
1117
|
+
}
|
1118
|
+
});
|
1119
|
+
|
1120
|
+
|
1121
|
+
$.fn.sparkline._base = createClass({
|
1122
|
+
disabled: false,
|
1123
|
+
|
1124
|
+
init: function (el, values, options, width, height) {
|
1125
|
+
this.el = el;
|
1126
|
+
this.$el = $(el);
|
1127
|
+
this.values = values;
|
1128
|
+
this.options = options;
|
1129
|
+
this.width = width;
|
1130
|
+
this.height = height;
|
1131
|
+
this.currentRegion = undefined;
|
1132
|
+
},
|
1133
|
+
|
1134
|
+
/**
|
1135
|
+
* Setup the canvas
|
1136
|
+
*/
|
1137
|
+
initTarget: function () {
|
1138
|
+
var interactive = !this.options.get('disableInteraction');
|
1139
|
+
if (!(this.target = this.$el.simpledraw(this.width, this.height, this.options.get('composite'), interactive))) {
|
1140
|
+
this.disabled = true;
|
1141
|
+
} else {
|
1142
|
+
this.canvasWidth = this.target.pixelWidth;
|
1143
|
+
this.canvasHeight = this.target.pixelHeight;
|
1144
|
+
}
|
1145
|
+
},
|
1146
|
+
|
1147
|
+
/**
|
1148
|
+
* Actually render the chart to the canvas
|
1149
|
+
*/
|
1150
|
+
render: function () {
|
1151
|
+
if (this.disabled) {
|
1152
|
+
this.el.innerHTML = '';
|
1153
|
+
return false;
|
1154
|
+
}
|
1155
|
+
return true;
|
1156
|
+
},
|
1157
|
+
|
1158
|
+
/**
|
1159
|
+
* Return a region id for a given x/y co-ordinate
|
1160
|
+
*/
|
1161
|
+
getRegion: function (x, y) {
|
1162
|
+
},
|
1163
|
+
|
1164
|
+
/**
|
1165
|
+
* Highlight an item based on the moused-over x,y co-ordinate
|
1166
|
+
*/
|
1167
|
+
setRegionHighlight: function (el, x, y) {
|
1168
|
+
var currentRegion = this.currentRegion,
|
1169
|
+
highlightEnabled = !this.options.get('disableHighlight'),
|
1170
|
+
newRegion;
|
1171
|
+
if (x > this.canvasWidth || y > this.canvasHeight || x < 0 || y < 0) {
|
1172
|
+
return null;
|
1173
|
+
}
|
1174
|
+
newRegion = this.getRegion(el, x, y);
|
1175
|
+
if (currentRegion !== newRegion) {
|
1176
|
+
if (currentRegion !== undefined && highlightEnabled) {
|
1177
|
+
this.removeHighlight();
|
1178
|
+
}
|
1179
|
+
this.currentRegion = newRegion;
|
1180
|
+
if (newRegion !== undefined && highlightEnabled) {
|
1181
|
+
this.renderHighlight();
|
1182
|
+
}
|
1183
|
+
return true;
|
1184
|
+
}
|
1185
|
+
return false;
|
1186
|
+
},
|
1187
|
+
|
1188
|
+
/**
|
1189
|
+
* Reset any currently highlighted item
|
1190
|
+
*/
|
1191
|
+
clearRegionHighlight: function () {
|
1192
|
+
if (this.currentRegion !== undefined) {
|
1193
|
+
this.removeHighlight();
|
1194
|
+
this.currentRegion = undefined;
|
1195
|
+
return true;
|
1196
|
+
}
|
1197
|
+
return false;
|
1198
|
+
},
|
1199
|
+
|
1200
|
+
renderHighlight: function () {
|
1201
|
+
this.changeHighlight(true);
|
1202
|
+
},
|
1203
|
+
|
1204
|
+
removeHighlight: function () {
|
1205
|
+
this.changeHighlight(false);
|
1206
|
+
},
|
1207
|
+
|
1208
|
+
changeHighlight: function (highlight) {},
|
1209
|
+
|
1210
|
+
/**
|
1211
|
+
* Fetch the HTML to display as a tooltip
|
1212
|
+
*/
|
1213
|
+
getCurrentRegionTooltip: function () {
|
1214
|
+
var options = this.options,
|
1215
|
+
header = '',
|
1216
|
+
entries = [],
|
1217
|
+
fields, formats, formatlen, fclass, text, i,
|
1218
|
+
showFields, showFieldsKey, newFields, fv,
|
1219
|
+
formatter, format, fieldlen, j;
|
1220
|
+
if (this.currentRegion === undefined) {
|
1221
|
+
return '';
|
1222
|
+
}
|
1223
|
+
fields = this.getCurrentRegionFields();
|
1224
|
+
formatter = options.get('tooltipFormatter');
|
1225
|
+
if (formatter) {
|
1226
|
+
return formatter(this, options, fields);
|
1227
|
+
}
|
1228
|
+
if (options.get('tooltipChartTitle')) {
|
1229
|
+
header += '<div class="jqs jqstitle">' + options.get('tooltipChartTitle') + '</div>\n';
|
1230
|
+
}
|
1231
|
+
formats = this.options.get('tooltipFormat');
|
1232
|
+
if (!formats) {
|
1233
|
+
return '';
|
1234
|
+
}
|
1235
|
+
if (!$.isArray(formats)) {
|
1236
|
+
formats = [formats];
|
1237
|
+
}
|
1238
|
+
if (!$.isArray(fields)) {
|
1239
|
+
fields = [fields];
|
1240
|
+
}
|
1241
|
+
showFields = this.options.get('tooltipFormatFieldlist');
|
1242
|
+
showFieldsKey = this.options.get('tooltipFormatFieldlistKey');
|
1243
|
+
if (showFields && showFieldsKey) {
|
1244
|
+
// user-selected ordering of fields
|
1245
|
+
newFields = [];
|
1246
|
+
for (i = fields.length; i--;) {
|
1247
|
+
fv = fields[i][showFieldsKey];
|
1248
|
+
if ((j = $.inArray(fv, showFields)) != -1) {
|
1249
|
+
newFields[j] = fields[i];
|
1250
|
+
}
|
1251
|
+
}
|
1252
|
+
fields = newFields;
|
1253
|
+
}
|
1254
|
+
formatlen = formats.length;
|
1255
|
+
fieldlen = fields.length;
|
1256
|
+
for (i = 0; i < formatlen; i++) {
|
1257
|
+
format = formats[i];
|
1258
|
+
if (typeof format === 'string') {
|
1259
|
+
format = new SPFormat(format);
|
1260
|
+
}
|
1261
|
+
fclass = format.fclass || 'jqsfield';
|
1262
|
+
for (j = 0; j < fieldlen; j++) {
|
1263
|
+
if (!fields[j].isNull || !options.get('tooltipSkipNull')) {
|
1264
|
+
$.extend(fields[j], {
|
1265
|
+
prefix: options.get('tooltipPrefix'),
|
1266
|
+
suffix: options.get('tooltipSuffix')
|
1267
|
+
});
|
1268
|
+
text = format.render(fields[j], options.get('tooltipValueLookups'), options);
|
1269
|
+
entries.push('<div class="' + fclass + '">' + text + '</div>');
|
1270
|
+
}
|
1271
|
+
}
|
1272
|
+
}
|
1273
|
+
if (entries.length) {
|
1274
|
+
return header + entries.join('\n');
|
1275
|
+
}
|
1276
|
+
return '';
|
1277
|
+
},
|
1278
|
+
|
1279
|
+
getCurrentRegionFields: function () {},
|
1280
|
+
|
1281
|
+
calcHighlightColor: function (color, options) {
|
1282
|
+
var highlightColor = options.get('highlightColor'),
|
1283
|
+
lighten = options.get('highlightLighten'),
|
1284
|
+
parse, mult, rgbnew, i;
|
1285
|
+
if (highlightColor) {
|
1286
|
+
return highlightColor;
|
1287
|
+
}
|
1288
|
+
if (lighten) {
|
1289
|
+
// extract RGB values
|
1290
|
+
parse = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(color) || /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color);
|
1291
|
+
if (parse) {
|
1292
|
+
rgbnew = [];
|
1293
|
+
mult = color.length === 4 ? 16 : 1;
|
1294
|
+
for (i = 0; i < 3; i++) {
|
1295
|
+
rgbnew[i] = clipval(Math.round(parseInt(parse[i + 1], 16) * mult * lighten), 0, 255);
|
1296
|
+
}
|
1297
|
+
return 'rgb(' + rgbnew.join(',') + ')';
|
1298
|
+
}
|
1299
|
+
|
1300
|
+
}
|
1301
|
+
return color;
|
1302
|
+
}
|
1303
|
+
|
1304
|
+
});
|
1305
|
+
|
1306
|
+
barHighlightMixin = {
|
1307
|
+
changeHighlight: function (highlight) {
|
1308
|
+
var currentRegion = this.currentRegion,
|
1309
|
+
target = this.target,
|
1310
|
+
shapeids = this.regionShapes[currentRegion],
|
1311
|
+
newShapes;
|
1312
|
+
// will be null if the region value was null
|
1313
|
+
if (shapeids) {
|
1314
|
+
newShapes = this.renderRegion(currentRegion, highlight);
|
1315
|
+
if ($.isArray(newShapes) || $.isArray(shapeids)) {
|
1316
|
+
target.replaceWithShapes(shapeids, newShapes);
|
1317
|
+
this.regionShapes[currentRegion] = $.map(newShapes, function (newShape) {
|
1318
|
+
return newShape.id;
|
1319
|
+
});
|
1320
|
+
} else {
|
1321
|
+
target.replaceWithShape(shapeids, newShapes);
|
1322
|
+
this.regionShapes[currentRegion] = newShapes.id;
|
1323
|
+
}
|
1324
|
+
}
|
1325
|
+
},
|
1326
|
+
|
1327
|
+
render: function () {
|
1328
|
+
var values = this.values,
|
1329
|
+
target = this.target,
|
1330
|
+
regionShapes = this.regionShapes,
|
1331
|
+
shapes, ids, i, j;
|
1332
|
+
|
1333
|
+
if (!this.cls._super.render.call(this)) {
|
1334
|
+
return;
|
1335
|
+
}
|
1336
|
+
for (i = values.length; i--;) {
|
1337
|
+
shapes = this.renderRegion(i);
|
1338
|
+
if (shapes) {
|
1339
|
+
if ($.isArray(shapes)) {
|
1340
|
+
ids = [];
|
1341
|
+
for (j = shapes.length; j--;) {
|
1342
|
+
shapes[j].append();
|
1343
|
+
ids.push(shapes[j].id);
|
1344
|
+
}
|
1345
|
+
regionShapes[i] = ids;
|
1346
|
+
} else {
|
1347
|
+
shapes.append();
|
1348
|
+
regionShapes[i] = shapes.id; // store just the shapeid
|
1349
|
+
}
|
1350
|
+
} else {
|
1351
|
+
// null value
|
1352
|
+
regionShapes[i] = null;
|
1353
|
+
}
|
1354
|
+
}
|
1355
|
+
target.render();
|
1356
|
+
}
|
1357
|
+
};
|
1358
|
+
|
1359
|
+
/**
|
1360
|
+
* Line charts
|
1361
|
+
*/
|
1362
|
+
$.fn.sparkline.line = line = createClass($.fn.sparkline._base, {
|
1363
|
+
type: 'line',
|
1364
|
+
|
1365
|
+
init: function (el, values, options, width, height) {
|
1366
|
+
line._super.init.call(this, el, values, options, width, height);
|
1367
|
+
this.vertices = [];
|
1368
|
+
this.regionMap = [];
|
1369
|
+
this.xvalues = [];
|
1370
|
+
this.yvalues = [];
|
1371
|
+
this.yminmax = [];
|
1372
|
+
this.hightlightSpotId = null;
|
1373
|
+
this.lastShapeId = null;
|
1374
|
+
this.initTarget();
|
1375
|
+
},
|
1376
|
+
|
1377
|
+
getRegion: function (el, x, y) {
|
1378
|
+
var i,
|
1379
|
+
regionMap = this.regionMap; // maps regions to value positions
|
1380
|
+
for (i = regionMap.length; i--;) {
|
1381
|
+
if (regionMap[i] !== null && x >= regionMap[i][0] && x <= regionMap[i][1]) {
|
1382
|
+
return regionMap[i][2];
|
1383
|
+
}
|
1384
|
+
}
|
1385
|
+
return undefined;
|
1386
|
+
},
|
1387
|
+
|
1388
|
+
getCurrentRegionFields: function () {
|
1389
|
+
var currentRegion = this.currentRegion;
|
1390
|
+
return {
|
1391
|
+
isNull: this.yvalues[currentRegion] === null,
|
1392
|
+
x: this.xvalues[currentRegion],
|
1393
|
+
y: this.yvalues[currentRegion],
|
1394
|
+
color: this.options.get('lineColor'),
|
1395
|
+
fillColor: this.options.get('fillColor'),
|
1396
|
+
offset: currentRegion
|
1397
|
+
};
|
1398
|
+
},
|
1399
|
+
|
1400
|
+
renderHighlight: function () {
|
1401
|
+
var currentRegion = this.currentRegion,
|
1402
|
+
target = this.target,
|
1403
|
+
vertex = this.vertices[currentRegion],
|
1404
|
+
options = this.options,
|
1405
|
+
spotRadius = options.get('spotRadius'),
|
1406
|
+
highlightSpotColor = options.get('highlightSpotColor'),
|
1407
|
+
highlightLineColor = options.get('highlightLineColor'),
|
1408
|
+
highlightSpot, highlightLine;
|
1409
|
+
|
1410
|
+
if (!vertex) {
|
1411
|
+
return;
|
1412
|
+
}
|
1413
|
+
if (spotRadius && highlightSpotColor) {
|
1414
|
+
highlightSpot = target.drawCircle(vertex[0], vertex[1],
|
1415
|
+
spotRadius, undefined, highlightSpotColor);
|
1416
|
+
this.highlightSpotId = highlightSpot.id;
|
1417
|
+
target.insertAfterShape(this.lastShapeId, highlightSpot);
|
1418
|
+
}
|
1419
|
+
if (highlightLineColor) {
|
1420
|
+
highlightLine = target.drawLine(vertex[0], this.canvasTop, vertex[0],
|
1421
|
+
this.canvasTop + this.canvasHeight, highlightLineColor);
|
1422
|
+
this.highlightLineId = highlightLine.id;
|
1423
|
+
target.insertAfterShape(this.lastShapeId, highlightLine);
|
1424
|
+
}
|
1425
|
+
},
|
1426
|
+
|
1427
|
+
removeHighlight: function () {
|
1428
|
+
var target = this.target;
|
1429
|
+
if (this.highlightSpotId) {
|
1430
|
+
target.removeShapeId(this.highlightSpotId);
|
1431
|
+
this.highlightSpotId = null;
|
1432
|
+
}
|
1433
|
+
if (this.highlightLineId) {
|
1434
|
+
target.removeShapeId(this.highlightLineId);
|
1435
|
+
this.highlightLineId = null;
|
1436
|
+
}
|
1437
|
+
},
|
1438
|
+
|
1439
|
+
scanValues: function () {
|
1440
|
+
var values = this.values,
|
1441
|
+
valcount = values.length,
|
1442
|
+
xvalues = this.xvalues,
|
1443
|
+
yvalues = this.yvalues,
|
1444
|
+
yminmax = this.yminmax,
|
1445
|
+
i, val, isStr, isArray, sp;
|
1446
|
+
for (i = 0; i < valcount; i++) {
|
1447
|
+
val = values[i];
|
1448
|
+
isStr = typeof(values[i]) === 'string';
|
1449
|
+
isArray = typeof(values[i]) === 'object' && values[i] instanceof Array;
|
1450
|
+
sp = isStr && values[i].split(':');
|
1451
|
+
if (isStr && sp.length === 2) { // x:y
|
1452
|
+
xvalues.push(Number(sp[0]));
|
1453
|
+
yvalues.push(Number(sp[1]));
|
1454
|
+
yminmax.push(Number(sp[1]));
|
1455
|
+
} else if (isArray) {
|
1456
|
+
xvalues.push(val[0]);
|
1457
|
+
yvalues.push(val[1]);
|
1458
|
+
yminmax.push(val[1]);
|
1459
|
+
} else {
|
1460
|
+
xvalues.push(i);
|
1461
|
+
if (values[i] === null || values[i] === 'null') {
|
1462
|
+
yvalues.push(null);
|
1463
|
+
} else {
|
1464
|
+
yvalues.push(Number(val));
|
1465
|
+
yminmax.push(Number(val));
|
1466
|
+
}
|
1467
|
+
}
|
1468
|
+
}
|
1469
|
+
if (this.options.get('xvalues')) {
|
1470
|
+
xvalues = this.options.get('xvalues');
|
1471
|
+
}
|
1472
|
+
|
1473
|
+
this.maxy = this.maxyorg = Math.max.apply(Math, yminmax);
|
1474
|
+
this.miny = this.minyorg = Math.min.apply(Math, yminmax);
|
1475
|
+
|
1476
|
+
this.maxx = Math.max.apply(Math, xvalues);
|
1477
|
+
this.minx = Math.min.apply(Math, xvalues);
|
1478
|
+
|
1479
|
+
this.xvalues = xvalues;
|
1480
|
+
this.yvalues = yvalues;
|
1481
|
+
this.yminmax = yminmax;
|
1482
|
+
|
1483
|
+
},
|
1484
|
+
|
1485
|
+
processRangeOptions: function () {
|
1486
|
+
var options = this.options,
|
1487
|
+
normalRangeMin = options.get('normalRangeMin'),
|
1488
|
+
normalRangeMax = options.get('normalRangeMax');
|
1489
|
+
|
1490
|
+
if (normalRangeMin !== undefined) {
|
1491
|
+
if (normalRangeMin < this.miny) {
|
1492
|
+
this.miny = normalRangeMin;
|
1493
|
+
}
|
1494
|
+
if (normalRangeMax > this.maxy) {
|
1495
|
+
this.maxy = normalRangeMax;
|
1496
|
+
}
|
1497
|
+
}
|
1498
|
+
if (options.get('chartRangeMin') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMin') < this.miny)) {
|
1499
|
+
this.miny = options.get('chartRangeMin');
|
1500
|
+
}
|
1501
|
+
if (options.get('chartRangeMax') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMax') > this.maxy)) {
|
1502
|
+
this.maxy = options.get('chartRangeMax');
|
1503
|
+
}
|
1504
|
+
if (options.get('chartRangeMinX') !== undefined && (options.get('chartRangeClipX') || options.get('chartRangeMinX') < this.minx)) {
|
1505
|
+
this.minx = options.get('chartRangeMinX');
|
1506
|
+
}
|
1507
|
+
if (options.get('chartRangeMaxX') !== undefined && (options.get('chartRangeClipX') || options.get('chartRangeMaxX') > this.maxx)) {
|
1508
|
+
this.maxx = options.get('chartRangeMaxX');
|
1509
|
+
}
|
1510
|
+
|
1511
|
+
},
|
1512
|
+
|
1513
|
+
drawNormalRange: function (canvasLeft, canvasTop, canvasHeight, canvasWidth, rangey) {
|
1514
|
+
var normalRangeMin = this.options.get('normalRangeMin'),
|
1515
|
+
normalRangeMax = this.options.get('normalRangeMax'),
|
1516
|
+
ytop = canvasTop + Math.round(canvasHeight - (canvasHeight * ((normalRangeMax - this.miny) / rangey))),
|
1517
|
+
height = Math.round((canvasHeight * (normalRangeMax - normalRangeMin)) / rangey);
|
1518
|
+
this.target.drawRect(canvasLeft, ytop, canvasWidth, height, undefined, this.options.get('normalRangeColor')).append();
|
1519
|
+
},
|
1520
|
+
|
1521
|
+
render: function () {
|
1522
|
+
var options = this.options,
|
1523
|
+
target = this.target,
|
1524
|
+
canvasWidth = this.canvasWidth,
|
1525
|
+
canvasHeight = this.canvasHeight,
|
1526
|
+
vertices = this.vertices,
|
1527
|
+
spotRadius = options.get('spotRadius'),
|
1528
|
+
regionMap = this.regionMap,
|
1529
|
+
rangex, rangey, yvallast,
|
1530
|
+
canvasTop, canvasLeft,
|
1531
|
+
vertex, path, paths, x, y, xnext, xpos, xposnext,
|
1532
|
+
last, next, yvalcount, lineShapes, fillShapes, plen,
|
1533
|
+
valueSpots, hlSpotsEnabled, color, xvalues, yvalues, i;
|
1534
|
+
|
1535
|
+
if (!line._super.render.call(this)) {
|
1536
|
+
return;
|
1537
|
+
}
|
1538
|
+
|
1539
|
+
this.scanValues();
|
1540
|
+
this.processRangeOptions();
|
1541
|
+
|
1542
|
+
xvalues = this.xvalues;
|
1543
|
+
yvalues = this.yvalues;
|
1544
|
+
|
1545
|
+
if (!this.yminmax.length || this.yvalues.length < 2) {
|
1546
|
+
// empty or all null valuess
|
1547
|
+
return;
|
1548
|
+
}
|
1549
|
+
|
1550
|
+
canvasTop = canvasLeft = 0;
|
1551
|
+
|
1552
|
+
rangex = this.maxx - this.minx === 0 ? 1 : this.maxx - this.minx;
|
1553
|
+
rangey = this.maxy - this.miny === 0 ? 1 : this.maxy - this.miny;
|
1554
|
+
yvallast = this.yvalues.length - 1;
|
1555
|
+
|
1556
|
+
if (spotRadius && (canvasWidth < (spotRadius * 4) || canvasHeight < (spotRadius * 4))) {
|
1557
|
+
spotRadius = 0;
|
1558
|
+
}
|
1559
|
+
if (spotRadius) {
|
1560
|
+
// adjust the canvas size as required so that spots will fit
|
1561
|
+
hlSpotsEnabled = options.get('highlightSpotColor') && !options.get('disableInteraction');
|
1562
|
+
if (hlSpotsEnabled || options.get('minSpotColor') || (options.get('spotColor') && yvalues[yvallast] === this.miny)) {
|
1563
|
+
canvasHeight -= Math.ceil(spotRadius);
|
1564
|
+
}
|
1565
|
+
if (hlSpotsEnabled || options.get('maxSpotColor') || (options.get('spotColor') && yvalues[yvallast] === this.maxy)) {
|
1566
|
+
canvasHeight -= Math.ceil(spotRadius);
|
1567
|
+
canvasTop += Math.ceil(spotRadius);
|
1568
|
+
}
|
1569
|
+
if (hlSpotsEnabled ||
|
1570
|
+
((options.get('minSpotColor') || options.get('maxSpotColor')) && (yvalues[0] === this.miny || yvalues[0] === this.maxy))) {
|
1571
|
+
canvasLeft += Math.ceil(spotRadius);
|
1572
|
+
canvasWidth -= Math.ceil(spotRadius);
|
1573
|
+
}
|
1574
|
+
if (hlSpotsEnabled || options.get('spotColor') ||
|
1575
|
+
(options.get('minSpotColor') || options.get('maxSpotColor') &&
|
1576
|
+
(yvalues[yvallast] === this.miny || yvalues[yvallast] === this.maxy))) {
|
1577
|
+
canvasWidth -= Math.ceil(spotRadius);
|
1578
|
+
}
|
1579
|
+
}
|
1580
|
+
|
1581
|
+
|
1582
|
+
canvasHeight--;
|
1583
|
+
|
1584
|
+
if (options.get('normalRangeMin') !== undefined && !options.get('drawNormalOnTop')) {
|
1585
|
+
this.drawNormalRange(canvasLeft, canvasTop, canvasHeight, canvasWidth, rangey);
|
1586
|
+
}
|
1587
|
+
|
1588
|
+
path = [];
|
1589
|
+
paths = [path];
|
1590
|
+
last = next = null;
|
1591
|
+
yvalcount = yvalues.length;
|
1592
|
+
for (i = 0; i < yvalcount; i++) {
|
1593
|
+
x = xvalues[i];
|
1594
|
+
xnext = xvalues[i + 1];
|
1595
|
+
y = yvalues[i];
|
1596
|
+
xpos = canvasLeft + Math.round((x - this.minx) * (canvasWidth / rangex));
|
1597
|
+
xposnext = i < yvalcount - 1 ? canvasLeft + Math.round((xnext - this.minx) * (canvasWidth / rangex)) : canvasWidth;
|
1598
|
+
next = xpos + ((xposnext - xpos) / 2);
|
1599
|
+
regionMap[i] = [last || 0, next, i];
|
1600
|
+
last = next;
|
1601
|
+
if (y === null) {
|
1602
|
+
if (i) {
|
1603
|
+
if (yvalues[i - 1] !== null) {
|
1604
|
+
path = [];
|
1605
|
+
paths.push(path);
|
1606
|
+
}
|
1607
|
+
vertices.push(null);
|
1608
|
+
}
|
1609
|
+
} else {
|
1610
|
+
if (y < this.miny) {
|
1611
|
+
y = this.miny;
|
1612
|
+
}
|
1613
|
+
if (y > this.maxy) {
|
1614
|
+
y = this.maxy;
|
1615
|
+
}
|
1616
|
+
if (!path.length) {
|
1617
|
+
// previous value was null
|
1618
|
+
path.push([xpos, canvasTop + canvasHeight]);
|
1619
|
+
}
|
1620
|
+
vertex = [xpos, canvasTop + Math.round(canvasHeight - (canvasHeight * ((y - this.miny) / rangey)))];
|
1621
|
+
path.push(vertex);
|
1622
|
+
vertices.push(vertex);
|
1623
|
+
}
|
1624
|
+
}
|
1625
|
+
|
1626
|
+
lineShapes = [];
|
1627
|
+
fillShapes = [];
|
1628
|
+
plen = paths.length;
|
1629
|
+
for (i = 0; i < plen; i++) {
|
1630
|
+
path = paths[i];
|
1631
|
+
if (path.length) {
|
1632
|
+
if (options.get('fillColor')) {
|
1633
|
+
path.push([path[path.length - 1][0], (canvasTop + canvasHeight)]);
|
1634
|
+
fillShapes.push(path.slice(0));
|
1635
|
+
path.pop();
|
1636
|
+
}
|
1637
|
+
// if there's only a single point in this path, then we want to display it
|
1638
|
+
// as a vertical line which means we keep path[0] as is
|
1639
|
+
if (path.length > 2) {
|
1640
|
+
// else we want the first value
|
1641
|
+
path[0] = [path[0][0], path[1][1]];
|
1642
|
+
}
|
1643
|
+
lineShapes.push(path);
|
1644
|
+
}
|
1645
|
+
}
|
1646
|
+
|
1647
|
+
// draw the fill first, then optionally the normal range, then the line on top of that
|
1648
|
+
plen = fillShapes.length;
|
1649
|
+
for (i = 0; i < plen; i++) {
|
1650
|
+
target.drawShape(fillShapes[i],
|
1651
|
+
options.get('fillColor'), options.get('fillColor')).append();
|
1652
|
+
}
|
1653
|
+
|
1654
|
+
if (options.get('normalRangeMin') !== undefined && options.get('drawNormalOnTop')) {
|
1655
|
+
this.drawNormalRange(canvasLeft, canvasTop, canvasHeight, canvasWidth, rangey);
|
1656
|
+
}
|
1657
|
+
|
1658
|
+
plen = lineShapes.length;
|
1659
|
+
for (i = 0; i < plen; i++) {
|
1660
|
+
target.drawShape(lineShapes[i], options.get('lineColor'), undefined,
|
1661
|
+
options.get('lineWidth')).append();
|
1662
|
+
}
|
1663
|
+
|
1664
|
+
if (spotRadius && options.get('valueSpots')) {
|
1665
|
+
valueSpots = options.get('valueSpots');
|
1666
|
+
if (valueSpots.get === undefined) {
|
1667
|
+
valueSpots = new RangeMap(valueSpots);
|
1668
|
+
}
|
1669
|
+
for (i = 0; i < yvalcount; i++) {
|
1670
|
+
color = valueSpots.get(yvalues[i]);
|
1671
|
+
if (color) {
|
1672
|
+
target.drawCircle(canvasLeft + Math.round((xvalues[i] - this.minx) * (canvasWidth / rangex)),
|
1673
|
+
canvasTop + Math.round(canvasHeight - (canvasHeight * ((yvalues[i] - this.miny) / rangey))),
|
1674
|
+
spotRadius, undefined,
|
1675
|
+
color).append();
|
1676
|
+
}
|
1677
|
+
}
|
1678
|
+
|
1679
|
+
}
|
1680
|
+
if (spotRadius && options.get('spotColor') && yvalues[yvallast] !== null) {
|
1681
|
+
target.drawCircle(canvasLeft + Math.round((xvalues[xvalues.length - 1] - this.minx) * (canvasWidth / rangex)),
|
1682
|
+
canvasTop + Math.round(canvasHeight - (canvasHeight * ((yvalues[yvallast] - this.miny) / rangey))),
|
1683
|
+
spotRadius, undefined,
|
1684
|
+
options.get('spotColor')).append();
|
1685
|
+
}
|
1686
|
+
if (this.maxy !== this.minyorg) {
|
1687
|
+
if (spotRadius && options.get('minSpotColor')) {
|
1688
|
+
x = xvalues[$.inArray(this.minyorg, yvalues)];
|
1689
|
+
target.drawCircle(canvasLeft + Math.round((x - this.minx) * (canvasWidth / rangex)),
|
1690
|
+
canvasTop + Math.round(canvasHeight - (canvasHeight * ((this.minyorg - this.miny) / rangey))),
|
1691
|
+
spotRadius, undefined,
|
1692
|
+
options.get('minSpotColor')).append();
|
1693
|
+
}
|
1694
|
+
if (spotRadius && options.get('maxSpotColor')) {
|
1695
|
+
x = xvalues[$.inArray(this.maxyorg, yvalues)];
|
1696
|
+
target.drawCircle(canvasLeft + Math.round((x - this.minx) * (canvasWidth / rangex)),
|
1697
|
+
canvasTop + Math.round(canvasHeight - (canvasHeight * ((this.maxyorg - this.miny) / rangey))),
|
1698
|
+
spotRadius, undefined,
|
1699
|
+
options.get('maxSpotColor')).append();
|
1700
|
+
}
|
1701
|
+
}
|
1702
|
+
|
1703
|
+
this.lastShapeId = target.getLastShapeId();
|
1704
|
+
this.canvasTop = canvasTop;
|
1705
|
+
target.render();
|
1706
|
+
}
|
1707
|
+
});
|
1708
|
+
|
1709
|
+
/**
|
1710
|
+
* Bar charts
|
1711
|
+
*/
|
1712
|
+
$.fn.sparkline.bar = bar = createClass($.fn.sparkline._base, barHighlightMixin, {
|
1713
|
+
type: 'bar',
|
1714
|
+
|
1715
|
+
init: function (el, values, options, width, height) {
|
1716
|
+
var barWidth = parseInt(options.get('barWidth'), 10),
|
1717
|
+
barSpacing = parseInt(options.get('barSpacing'), 10),
|
1718
|
+
chartRangeMin = options.get('chartRangeMin'),
|
1719
|
+
chartRangeMax = options.get('chartRangeMax'),
|
1720
|
+
chartRangeClip = options.get('chartRangeClip'),
|
1721
|
+
stackMin = Infinity,
|
1722
|
+
stackMax = -Infinity,
|
1723
|
+
isStackString, groupMin, groupMax, stackRanges,
|
1724
|
+
numValues, i, vlen, range, zeroAxis, xaxisOffset, min, max, clipMin, clipMax,
|
1725
|
+
stacked, vlist, j, slen, svals, val, yoffset, yMaxCalc, canvasHeightEf;
|
1726
|
+
bar._super.init.call(this, el, values, options, width, height);
|
1727
|
+
|
1728
|
+
// scan values to determine whether to stack bars
|
1729
|
+
for (i = 0, vlen = values.length; i < vlen; i++) {
|
1730
|
+
val = values[i];
|
1731
|
+
isStackString = typeof(val) === 'string' && val.indexOf(':') > -1;
|
1732
|
+
if (isStackString || $.isArray(val)) {
|
1733
|
+
stacked = true;
|
1734
|
+
if (isStackString) {
|
1735
|
+
val = values[i] = normalizeValues(val.split(':'));
|
1736
|
+
}
|
1737
|
+
val = remove(val, null); // min/max will treat null as zero
|
1738
|
+
groupMin = Math.min.apply(Math, val);
|
1739
|
+
groupMax = Math.max.apply(Math, val);
|
1740
|
+
if (groupMin < stackMin) {
|
1741
|
+
stackMin = groupMin;
|
1742
|
+
}
|
1743
|
+
if (groupMax > stackMax) {
|
1744
|
+
stackMax = groupMax;
|
1745
|
+
}
|
1746
|
+
}
|
1747
|
+
}
|
1748
|
+
|
1749
|
+
this.stacked = stacked;
|
1750
|
+
this.regionShapes = {};
|
1751
|
+
this.barWidth = barWidth;
|
1752
|
+
this.barSpacing = barSpacing;
|
1753
|
+
this.totalBarWidth = barWidth + barSpacing;
|
1754
|
+
this.width = width = (values.length * barWidth) + ((values.length - 1) * barSpacing);
|
1755
|
+
|
1756
|
+
this.initTarget();
|
1757
|
+
|
1758
|
+
if (chartRangeClip) {
|
1759
|
+
clipMin = chartRangeMin === undefined ? -Infinity : chartRangeMin;
|
1760
|
+
clipMax = chartRangeMax === undefined ? Infinity : chartRangeMax;
|
1761
|
+
}
|
1762
|
+
|
1763
|
+
numValues = [];
|
1764
|
+
stackRanges = stacked ? [] : numValues;
|
1765
|
+
var stackTotals = [];
|
1766
|
+
var stackRangesNeg = [];
|
1767
|
+
for (i = 0, vlen = values.length; i < vlen; i++) {
|
1768
|
+
if (stacked) {
|
1769
|
+
vlist = values[i];
|
1770
|
+
values[i] = svals = [];
|
1771
|
+
stackTotals[i] = 0;
|
1772
|
+
stackRanges[i] = stackRangesNeg[i] = 0;
|
1773
|
+
for (j = 0, slen = vlist.length; j < slen; j++) {
|
1774
|
+
val = svals[j] = chartRangeClip ? clipval(vlist[j], clipMin, clipMax) : vlist[j];
|
1775
|
+
if (val !== null) {
|
1776
|
+
if (val > 0) {
|
1777
|
+
stackTotals[i] += val;
|
1778
|
+
}
|
1779
|
+
if (stackMin < 0 && stackMax > 0) {
|
1780
|
+
if (val < 0) {
|
1781
|
+
stackRangesNeg[i] += Math.abs(val);
|
1782
|
+
} else {
|
1783
|
+
stackRanges[i] += val;
|
1784
|
+
}
|
1785
|
+
} else {
|
1786
|
+
stackRanges[i] += Math.abs(val - (val < 0 ? stackMax : stackMin));
|
1787
|
+
}
|
1788
|
+
numValues.push(val);
|
1789
|
+
}
|
1790
|
+
}
|
1791
|
+
} else {
|
1792
|
+
val = chartRangeClip ? clipval(values[i], clipMin, clipMax) : values[i];
|
1793
|
+
val = values[i] = normalizeValue(val);
|
1794
|
+
if (val !== null) {
|
1795
|
+
numValues.push(val);
|
1796
|
+
}
|
1797
|
+
}
|
1798
|
+
}
|
1799
|
+
this.max = max = Math.max.apply(Math, numValues);
|
1800
|
+
this.min = min = Math.min.apply(Math, numValues);
|
1801
|
+
this.stackMax = stackMax = stacked ? Math.max.apply(Math, stackTotals) : max;
|
1802
|
+
this.stackMin = stackMin = stacked ? Math.min.apply(Math, numValues) : min;
|
1803
|
+
|
1804
|
+
if (options.get('chartRangeMin') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMin') < min)) {
|
1805
|
+
min = options.get('chartRangeMin');
|
1806
|
+
}
|
1807
|
+
if (options.get('chartRangeMax') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMax') > max)) {
|
1808
|
+
max = options.get('chartRangeMax');
|
1809
|
+
}
|
1810
|
+
|
1811
|
+
this.zeroAxis = zeroAxis = options.get('zeroAxis', true);
|
1812
|
+
if (min <= 0 && max >= 0 && zeroAxis) {
|
1813
|
+
xaxisOffset = 0;
|
1814
|
+
} else if (zeroAxis == false) {
|
1815
|
+
xaxisOffset = min;
|
1816
|
+
} else if (min > 0) {
|
1817
|
+
xaxisOffset = min;
|
1818
|
+
} else {
|
1819
|
+
xaxisOffset = max;
|
1820
|
+
}
|
1821
|
+
this.xaxisOffset = xaxisOffset;
|
1822
|
+
|
1823
|
+
range = stacked ? (Math.max.apply(Math, stackRanges) + Math.max.apply(Math, stackRangesNeg)) : max - min;
|
1824
|
+
|
1825
|
+
// as we plot zero/min values a single pixel line, we add a pixel to all other
|
1826
|
+
// values - Reduce the effective canvas size to suit
|
1827
|
+
this.canvasHeightEf = (zeroAxis && min < 0) ? this.canvasHeight - 2 : this.canvasHeight - 1;
|
1828
|
+
|
1829
|
+
if (min < xaxisOffset) {
|
1830
|
+
yMaxCalc = (stacked && max >= 0) ? stackMax : max;
|
1831
|
+
yoffset = (yMaxCalc - xaxisOffset) / range * this.canvasHeight;
|
1832
|
+
if (yoffset !== Math.ceil(yoffset)) {
|
1833
|
+
this.canvasHeightEf -= 2;
|
1834
|
+
yoffset = Math.ceil(yoffset);
|
1835
|
+
}
|
1836
|
+
} else {
|
1837
|
+
yoffset = this.canvasHeight;
|
1838
|
+
}
|
1839
|
+
this.yoffset = yoffset;
|
1840
|
+
|
1841
|
+
if ($.isArray(options.get('colorMap'))) {
|
1842
|
+
this.colorMapByIndex = options.get('colorMap');
|
1843
|
+
this.colorMapByValue = null;
|
1844
|
+
} else {
|
1845
|
+
this.colorMapByIndex = null;
|
1846
|
+
this.colorMapByValue = options.get('colorMap');
|
1847
|
+
if (this.colorMapByValue && this.colorMapByValue.get === undefined) {
|
1848
|
+
this.colorMapByValue = new RangeMap(this.colorMapByValue);
|
1849
|
+
}
|
1850
|
+
}
|
1851
|
+
|
1852
|
+
this.range = range;
|
1853
|
+
},
|
1854
|
+
|
1855
|
+
getRegion: function (el, x, y) {
|
1856
|
+
var result = Math.floor(x / this.totalBarWidth);
|
1857
|
+
return (result < 0 || result >= this.values.length) ? undefined : result;
|
1858
|
+
},
|
1859
|
+
|
1860
|
+
getCurrentRegionFields: function () {
|
1861
|
+
var currentRegion = this.currentRegion,
|
1862
|
+
values = ensureArray(this.values[currentRegion]),
|
1863
|
+
result = [],
|
1864
|
+
value, i;
|
1865
|
+
for (i = values.length; i--;) {
|
1866
|
+
value = values[i];
|
1867
|
+
result.push({
|
1868
|
+
isNull: value === null,
|
1869
|
+
value: value,
|
1870
|
+
color: this.calcColor(i, value, currentRegion),
|
1871
|
+
offset: currentRegion
|
1872
|
+
});
|
1873
|
+
}
|
1874
|
+
return result;
|
1875
|
+
},
|
1876
|
+
|
1877
|
+
calcColor: function (stacknum, value, valuenum) {
|
1878
|
+
var colorMapByIndex = this.colorMapByIndex,
|
1879
|
+
colorMapByValue = this.colorMapByValue,
|
1880
|
+
options = this.options,
|
1881
|
+
color, newColor;
|
1882
|
+
if (this.stacked) {
|
1883
|
+
color = options.get('stackedBarColor');
|
1884
|
+
} else {
|
1885
|
+
color = (value < 0) ? options.get('negBarColor') : options.get('barColor');
|
1886
|
+
}
|
1887
|
+
if (value === 0 && options.get('zeroColor') !== undefined) {
|
1888
|
+
color = options.get('zeroColor');
|
1889
|
+
}
|
1890
|
+
if (colorMapByValue && (newColor = colorMapByValue.get(value))) {
|
1891
|
+
color = newColor;
|
1892
|
+
} else if (colorMapByIndex && colorMapByIndex.length > valuenum) {
|
1893
|
+
color = colorMapByIndex[valuenum];
|
1894
|
+
}
|
1895
|
+
return $.isArray(color) ? color[stacknum % color.length] : color;
|
1896
|
+
},
|
1897
|
+
|
1898
|
+
/**
|
1899
|
+
* Render bar(s) for a region
|
1900
|
+
*/
|
1901
|
+
renderRegion: function (valuenum, highlight) {
|
1902
|
+
var vals = this.values[valuenum],
|
1903
|
+
options = this.options,
|
1904
|
+
xaxisOffset = this.xaxisOffset,
|
1905
|
+
result = [],
|
1906
|
+
range = this.range,
|
1907
|
+
stacked = this.stacked,
|
1908
|
+
target = this.target,
|
1909
|
+
x = valuenum * this.totalBarWidth,
|
1910
|
+
canvasHeightEf = this.canvasHeightEf,
|
1911
|
+
yoffset = this.yoffset,
|
1912
|
+
y, height, color, isNull, yoffsetNeg, i, valcount, val, minPlotted, allMin;
|
1913
|
+
|
1914
|
+
vals = $.isArray(vals) ? vals : [vals];
|
1915
|
+
valcount = vals.length;
|
1916
|
+
val = vals[0];
|
1917
|
+
isNull = all(null, vals);
|
1918
|
+
allMin = all(xaxisOffset, vals, true);
|
1919
|
+
|
1920
|
+
if (isNull) {
|
1921
|
+
if (options.get('nullColor')) {
|
1922
|
+
color = highlight ? options.get('nullColor') : this.calcHighlightColor(options.get('nullColor'), options);
|
1923
|
+
y = (yoffset > 0) ? yoffset - 1 : yoffset;
|
1924
|
+
return target.drawRect(x, y, this.barWidth - 1, 0, color, color);
|
1925
|
+
} else {
|
1926
|
+
return undefined;
|
1927
|
+
}
|
1928
|
+
}
|
1929
|
+
yoffsetNeg = yoffset;
|
1930
|
+
for (i = 0; i < valcount; i++) {
|
1931
|
+
val = vals[i];
|
1932
|
+
|
1933
|
+
if (stacked && val === xaxisOffset) {
|
1934
|
+
if (!allMin || minPlotted) {
|
1935
|
+
continue;
|
1936
|
+
}
|
1937
|
+
minPlotted = true;
|
1938
|
+
}
|
1939
|
+
|
1940
|
+
if (range > 0) {
|
1941
|
+
height = Math.floor(canvasHeightEf * ((Math.abs(val - xaxisOffset) / range))) + 1;
|
1942
|
+
} else {
|
1943
|
+
height = 1;
|
1944
|
+
}
|
1945
|
+
if (val < xaxisOffset || (val === xaxisOffset && yoffset === 0)) {
|
1946
|
+
y = yoffsetNeg;
|
1947
|
+
yoffsetNeg += height;
|
1948
|
+
} else {
|
1949
|
+
y = yoffset - height;
|
1950
|
+
yoffset -= height;
|
1951
|
+
}
|
1952
|
+
color = this.calcColor(i, val, valuenum);
|
1953
|
+
if (highlight) {
|
1954
|
+
color = this.calcHighlightColor(color, options);
|
1955
|
+
}
|
1956
|
+
result.push(target.drawRect(x, y, this.barWidth - 1, height - 1, color, color));
|
1957
|
+
}
|
1958
|
+
if (result.length === 1) {
|
1959
|
+
return result[0];
|
1960
|
+
}
|
1961
|
+
return result;
|
1962
|
+
}
|
1963
|
+
});
|
1964
|
+
|
1965
|
+
/**
|
1966
|
+
* Tristate charts
|
1967
|
+
*/
|
1968
|
+
$.fn.sparkline.tristate = tristate = createClass($.fn.sparkline._base, barHighlightMixin, {
|
1969
|
+
type: 'tristate',
|
1970
|
+
|
1971
|
+
init: function (el, values, options, width, height) {
|
1972
|
+
var barWidth = parseInt(options.get('barWidth'), 10),
|
1973
|
+
barSpacing = parseInt(options.get('barSpacing'), 10);
|
1974
|
+
tristate._super.init.call(this, el, values, options, width, height);
|
1975
|
+
|
1976
|
+
this.regionShapes = {};
|
1977
|
+
this.barWidth = barWidth;
|
1978
|
+
this.barSpacing = barSpacing;
|
1979
|
+
this.totalBarWidth = barWidth + barSpacing;
|
1980
|
+
this.values = $.map(values, Number);
|
1981
|
+
this.width = width = (values.length * barWidth) + ((values.length - 1) * barSpacing);
|
1982
|
+
|
1983
|
+
if ($.isArray(options.get('colorMap'))) {
|
1984
|
+
this.colorMapByIndex = options.get('colorMap');
|
1985
|
+
this.colorMapByValue = null;
|
1986
|
+
} else {
|
1987
|
+
this.colorMapByIndex = null;
|
1988
|
+
this.colorMapByValue = options.get('colorMap');
|
1989
|
+
if (this.colorMapByValue && this.colorMapByValue.get === undefined) {
|
1990
|
+
this.colorMapByValue = new RangeMap(this.colorMapByValue);
|
1991
|
+
}
|
1992
|
+
}
|
1993
|
+
this.initTarget();
|
1994
|
+
},
|
1995
|
+
|
1996
|
+
getRegion: function (el, x, y) {
|
1997
|
+
return Math.floor(x / this.totalBarWidth);
|
1998
|
+
},
|
1999
|
+
|
2000
|
+
getCurrentRegionFields: function () {
|
2001
|
+
var currentRegion = this.currentRegion;
|
2002
|
+
return {
|
2003
|
+
isNull: this.values[currentRegion] === undefined,
|
2004
|
+
value: this.values[currentRegion],
|
2005
|
+
color: this.calcColor(this.values[currentRegion], currentRegion),
|
2006
|
+
offset: currentRegion
|
2007
|
+
};
|
2008
|
+
},
|
2009
|
+
|
2010
|
+
calcColor: function (value, valuenum) {
|
2011
|
+
var values = this.values,
|
2012
|
+
options = this.options,
|
2013
|
+
colorMapByIndex = this.colorMapByIndex,
|
2014
|
+
colorMapByValue = this.colorMapByValue,
|
2015
|
+
color, newColor;
|
2016
|
+
|
2017
|
+
if (colorMapByValue && (newColor = colorMapByValue.get(value))) {
|
2018
|
+
color = newColor;
|
2019
|
+
} else if (colorMapByIndex && colorMapByIndex.length > valuenum) {
|
2020
|
+
color = colorMapByIndex[valuenum];
|
2021
|
+
} else if (values[valuenum] < 0) {
|
2022
|
+
color = options.get('negBarColor');
|
2023
|
+
} else if (values[valuenum] > 0) {
|
2024
|
+
color = options.get('posBarColor');
|
2025
|
+
} else {
|
2026
|
+
color = options.get('zeroBarColor');
|
2027
|
+
}
|
2028
|
+
return color;
|
2029
|
+
},
|
2030
|
+
|
2031
|
+
renderRegion: function (valuenum, highlight) {
|
2032
|
+
var values = this.values,
|
2033
|
+
options = this.options,
|
2034
|
+
target = this.target,
|
2035
|
+
canvasHeight, height, halfHeight,
|
2036
|
+
x, y, color;
|
2037
|
+
|
2038
|
+
canvasHeight = target.pixelHeight;
|
2039
|
+
halfHeight = Math.round(canvasHeight / 2);
|
2040
|
+
|
2041
|
+
x = valuenum * this.totalBarWidth;
|
2042
|
+
if (values[valuenum] < 0) {
|
2043
|
+
y = halfHeight;
|
2044
|
+
height = halfHeight - 1;
|
2045
|
+
} else if (values[valuenum] > 0) {
|
2046
|
+
y = 0;
|
2047
|
+
height = halfHeight - 1;
|
2048
|
+
} else {
|
2049
|
+
y = halfHeight - 1;
|
2050
|
+
height = 2;
|
2051
|
+
}
|
2052
|
+
color = this.calcColor(values[valuenum], valuenum);
|
2053
|
+
if (color === null) {
|
2054
|
+
return;
|
2055
|
+
}
|
2056
|
+
if (highlight) {
|
2057
|
+
color = this.calcHighlightColor(color, options);
|
2058
|
+
}
|
2059
|
+
return target.drawRect(x, y, this.barWidth - 1, height - 1, color, color);
|
2060
|
+
}
|
2061
|
+
});
|
2062
|
+
|
2063
|
+
/**
|
2064
|
+
* Discrete charts
|
2065
|
+
*/
|
2066
|
+
$.fn.sparkline.discrete = discrete = createClass($.fn.sparkline._base, barHighlightMixin, {
|
2067
|
+
type: 'discrete',
|
2068
|
+
|
2069
|
+
init: function (el, values, options, width, height) {
|
2070
|
+
discrete._super.init.call(this, el, values, options, width, height);
|
2071
|
+
|
2072
|
+
this.regionShapes = {};
|
2073
|
+
this.values = values = $.map(values, Number);
|
2074
|
+
this.min = Math.min.apply(Math, values);
|
2075
|
+
this.max = Math.max.apply(Math, values);
|
2076
|
+
this.range = this.max - this.min;
|
2077
|
+
this.width = width = options.get('width') === 'auto' ? values.length * 2 : this.width;
|
2078
|
+
this.interval = Math.floor(width / values.length);
|
2079
|
+
this.itemWidth = width / values.length;
|
2080
|
+
if (options.get('chartRangeMin') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMin') < this.min)) {
|
2081
|
+
this.min = options.get('chartRangeMin');
|
2082
|
+
}
|
2083
|
+
if (options.get('chartRangeMax') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMax') > this.max)) {
|
2084
|
+
this.max = options.get('chartRangeMax');
|
2085
|
+
}
|
2086
|
+
this.initTarget();
|
2087
|
+
if (this.target) {
|
2088
|
+
this.lineHeight = options.get('lineHeight') === 'auto' ? Math.round(this.canvasHeight * 0.3) : options.get('lineHeight');
|
2089
|
+
}
|
2090
|
+
},
|
2091
|
+
|
2092
|
+
getRegion: function (el, x, y) {
|
2093
|
+
return Math.floor(x / this.itemWidth);
|
2094
|
+
},
|
2095
|
+
|
2096
|
+
getCurrentRegionFields: function () {
|
2097
|
+
var currentRegion = this.currentRegion;
|
2098
|
+
return {
|
2099
|
+
isNull: this.values[currentRegion] === undefined,
|
2100
|
+
value: this.values[currentRegion],
|
2101
|
+
offset: currentRegion
|
2102
|
+
};
|
2103
|
+
},
|
2104
|
+
|
2105
|
+
renderRegion: function (valuenum, highlight) {
|
2106
|
+
var values = this.values,
|
2107
|
+
options = this.options,
|
2108
|
+
min = this.min,
|
2109
|
+
max = this.max,
|
2110
|
+
range = this.range,
|
2111
|
+
interval = this.interval,
|
2112
|
+
target = this.target,
|
2113
|
+
canvasHeight = this.canvasHeight,
|
2114
|
+
lineHeight = this.lineHeight,
|
2115
|
+
pheight = canvasHeight - lineHeight,
|
2116
|
+
ytop, val, color, x;
|
2117
|
+
|
2118
|
+
val = clipval(values[valuenum], min, max);
|
2119
|
+
x = valuenum * interval;
|
2120
|
+
ytop = Math.round(pheight - pheight * ((val - min) / range));
|
2121
|
+
color = (options.get('thresholdColor') && val < options.get('thresholdValue')) ? options.get('thresholdColor') : options.get('lineColor');
|
2122
|
+
if (highlight) {
|
2123
|
+
color = this.calcHighlightColor(color, options);
|
2124
|
+
}
|
2125
|
+
return target.drawLine(x, ytop, x, ytop + lineHeight, color);
|
2126
|
+
}
|
2127
|
+
});
|
2128
|
+
|
2129
|
+
/**
|
2130
|
+
* Bullet charts
|
2131
|
+
*/
|
2132
|
+
$.fn.sparkline.bullet = bullet = createClass($.fn.sparkline._base, {
|
2133
|
+
type: 'bullet',
|
2134
|
+
|
2135
|
+
init: function (el, values, options, width, height) {
|
2136
|
+
var min, max, vals;
|
2137
|
+
bullet._super.init.call(this, el, values, options, width, height);
|
2138
|
+
|
2139
|
+
// values: target, performance, range1, range2, range3
|
2140
|
+
this.values = values = normalizeValues(values);
|
2141
|
+
// target or performance could be null
|
2142
|
+
vals = values.slice();
|
2143
|
+
vals[0] = vals[0] === null ? vals[2] : vals[0];
|
2144
|
+
vals[1] = values[1] === null ? vals[2] : vals[1];
|
2145
|
+
min = Math.min.apply(Math, values);
|
2146
|
+
max = Math.max.apply(Math, values);
|
2147
|
+
if (options.get('base') === undefined) {
|
2148
|
+
min = min < 0 ? min : 0;
|
2149
|
+
} else {
|
2150
|
+
min = options.get('base');
|
2151
|
+
}
|
2152
|
+
this.min = min;
|
2153
|
+
this.max = max;
|
2154
|
+
this.range = max - min;
|
2155
|
+
this.shapes = {};
|
2156
|
+
this.valueShapes = {};
|
2157
|
+
this.regiondata = {};
|
2158
|
+
this.width = width = options.get('width') === 'auto' ? '4.0em' : width;
|
2159
|
+
this.target = this.$el.simpledraw(width, height, options.get('composite'));
|
2160
|
+
if (!values.length) {
|
2161
|
+
this.disabled = true;
|
2162
|
+
}
|
2163
|
+
this.initTarget();
|
2164
|
+
},
|
2165
|
+
|
2166
|
+
getRegion: function (el, x, y) {
|
2167
|
+
var shapeid = this.target.getShapeAt(el, x, y);
|
2168
|
+
return (shapeid !== undefined && this.shapes[shapeid] !== undefined) ? this.shapes[shapeid] : undefined;
|
2169
|
+
},
|
2170
|
+
|
2171
|
+
getCurrentRegionFields: function () {
|
2172
|
+
var currentRegion = this.currentRegion;
|
2173
|
+
return {
|
2174
|
+
fieldkey: currentRegion.substr(0, 1),
|
2175
|
+
value: this.values[currentRegion.substr(1)],
|
2176
|
+
region: currentRegion
|
2177
|
+
};
|
2178
|
+
},
|
2179
|
+
|
2180
|
+
changeHighlight: function (highlight) {
|
2181
|
+
var currentRegion = this.currentRegion,
|
2182
|
+
shapeid = this.valueShapes[currentRegion],
|
2183
|
+
shape;
|
2184
|
+
delete this.shapes[shapeid];
|
2185
|
+
switch (currentRegion.substr(0, 1)) {
|
2186
|
+
case 'r':
|
2187
|
+
shape = this.renderRange(currentRegion.substr(1), highlight);
|
2188
|
+
break;
|
2189
|
+
case 'p':
|
2190
|
+
shape = this.renderPerformance(highlight);
|
2191
|
+
break;
|
2192
|
+
case 't':
|
2193
|
+
shape = this.renderTarget(highlight);
|
2194
|
+
break;
|
2195
|
+
}
|
2196
|
+
this.valueShapes[currentRegion] = shape.id;
|
2197
|
+
this.shapes[shape.id] = currentRegion;
|
2198
|
+
this.target.replaceWithShape(shapeid, shape);
|
2199
|
+
},
|
2200
|
+
|
2201
|
+
renderRange: function (rn, highlight) {
|
2202
|
+
var rangeval = this.values[rn],
|
2203
|
+
rangewidth = Math.round(this.canvasWidth * ((rangeval - this.min) / this.range)),
|
2204
|
+
color = this.options.get('rangeColors')[rn - 2];
|
2205
|
+
if (highlight) {
|
2206
|
+
color = this.calcHighlightColor(color, this.options);
|
2207
|
+
}
|
2208
|
+
return this.target.drawRect(0, 0, rangewidth - 1, this.canvasHeight - 1, color, color);
|
2209
|
+
},
|
2210
|
+
|
2211
|
+
renderPerformance: function (highlight) {
|
2212
|
+
var perfval = this.values[1],
|
2213
|
+
perfwidth = Math.round(this.canvasWidth * ((perfval - this.min) / this.range)),
|
2214
|
+
color = this.options.get('performanceColor');
|
2215
|
+
if (highlight) {
|
2216
|
+
color = this.calcHighlightColor(color, this.options);
|
2217
|
+
}
|
2218
|
+
return this.target.drawRect(0, Math.round(this.canvasHeight * 0.3), perfwidth - 1,
|
2219
|
+
Math.round(this.canvasHeight * 0.4) - 1, color, color);
|
2220
|
+
},
|
2221
|
+
|
2222
|
+
renderTarget: function (highlight) {
|
2223
|
+
var targetval = this.values[0],
|
2224
|
+
x = Math.round(this.canvasWidth * ((targetval - this.min) / this.range) - (this.options.get('targetWidth') / 2)),
|
2225
|
+
targettop = Math.round(this.canvasHeight * 0.10),
|
2226
|
+
targetheight = this.canvasHeight - (targettop * 2),
|
2227
|
+
color = this.options.get('targetColor');
|
2228
|
+
if (highlight) {
|
2229
|
+
color = this.calcHighlightColor(color, this.options);
|
2230
|
+
}
|
2231
|
+
return this.target.drawRect(x, targettop, this.options.get('targetWidth') - 1, targetheight - 1, color, color);
|
2232
|
+
},
|
2233
|
+
|
2234
|
+
render: function () {
|
2235
|
+
var vlen = this.values.length,
|
2236
|
+
target = this.target,
|
2237
|
+
i, shape;
|
2238
|
+
if (!bullet._super.render.call(this)) {
|
2239
|
+
return;
|
2240
|
+
}
|
2241
|
+
for (i = 2; i < vlen; i++) {
|
2242
|
+
shape = this.renderRange(i).append();
|
2243
|
+
this.shapes[shape.id] = 'r' + i;
|
2244
|
+
this.valueShapes['r' + i] = shape.id;
|
2245
|
+
}
|
2246
|
+
if (this.values[1] !== null) {
|
2247
|
+
shape = this.renderPerformance().append();
|
2248
|
+
this.shapes[shape.id] = 'p1';
|
2249
|
+
this.valueShapes.p1 = shape.id;
|
2250
|
+
}
|
2251
|
+
if (this.values[0] !== null) {
|
2252
|
+
shape = this.renderTarget().append();
|
2253
|
+
this.shapes[shape.id] = 't0';
|
2254
|
+
this.valueShapes.t0 = shape.id;
|
2255
|
+
}
|
2256
|
+
target.render();
|
2257
|
+
}
|
2258
|
+
});
|
2259
|
+
|
2260
|
+
/**
|
2261
|
+
* Pie charts
|
2262
|
+
*/
|
2263
|
+
$.fn.sparkline.pie = pie = createClass($.fn.sparkline._base, {
|
2264
|
+
type: 'pie',
|
2265
|
+
|
2266
|
+
init: function (el, values, options, width, height) {
|
2267
|
+
var total = 0, i;
|
2268
|
+
|
2269
|
+
pie._super.init.call(this, el, values, options, width, height);
|
2270
|
+
|
2271
|
+
this.shapes = {}; // map shape ids to value offsets
|
2272
|
+
this.valueShapes = {}; // maps value offsets to shape ids
|
2273
|
+
this.values = values = $.map(values, Number);
|
2274
|
+
|
2275
|
+
if (options.get('width') === 'auto') {
|
2276
|
+
this.width = this.height;
|
2277
|
+
}
|
2278
|
+
|
2279
|
+
if (values.length > 0) {
|
2280
|
+
for (i = values.length; i--;) {
|
2281
|
+
total += values[i];
|
2282
|
+
}
|
2283
|
+
}
|
2284
|
+
this.total = total;
|
2285
|
+
this.initTarget();
|
2286
|
+
this.radius = Math.floor(Math.min(this.canvasWidth, this.canvasHeight) / 2);
|
2287
|
+
},
|
2288
|
+
|
2289
|
+
getRegion: function (el, x, y) {
|
2290
|
+
var shapeid = this.target.getShapeAt(el, x, y);
|
2291
|
+
return (shapeid !== undefined && this.shapes[shapeid] !== undefined) ? this.shapes[shapeid] : undefined;
|
2292
|
+
},
|
2293
|
+
|
2294
|
+
getCurrentRegionFields: function () {
|
2295
|
+
var currentRegion = this.currentRegion;
|
2296
|
+
return {
|
2297
|
+
isNull: this.values[currentRegion] === undefined,
|
2298
|
+
value: this.values[currentRegion],
|
2299
|
+
percent: this.values[currentRegion] / this.total * 100,
|
2300
|
+
color: this.options.get('sliceColors')[currentRegion % this.options.get('sliceColors').length],
|
2301
|
+
offset: currentRegion
|
2302
|
+
};
|
2303
|
+
},
|
2304
|
+
|
2305
|
+
changeHighlight: function (highlight) {
|
2306
|
+
var currentRegion = this.currentRegion,
|
2307
|
+
newslice = this.renderSlice(currentRegion, highlight),
|
2308
|
+
shapeid = this.valueShapes[currentRegion];
|
2309
|
+
delete this.shapes[shapeid];
|
2310
|
+
this.target.replaceWithShape(shapeid, newslice);
|
2311
|
+
this.valueShapes[currentRegion] = newslice.id;
|
2312
|
+
this.shapes[newslice.id] = currentRegion;
|
2313
|
+
},
|
2314
|
+
|
2315
|
+
renderSlice: function (valuenum, highlight) {
|
2316
|
+
var target = this.target,
|
2317
|
+
options = this.options,
|
2318
|
+
radius = this.radius,
|
2319
|
+
borderWidth = options.get('borderWidth'),
|
2320
|
+
offset = options.get('offset'),
|
2321
|
+
circle = 2 * Math.PI,
|
2322
|
+
values = this.values,
|
2323
|
+
total = this.total,
|
2324
|
+
next = offset ? (2*Math.PI)*(offset/360) : 0,
|
2325
|
+
start, end, i, vlen, color;
|
2326
|
+
|
2327
|
+
vlen = values.length;
|
2328
|
+
for (i = 0; i < vlen; i++) {
|
2329
|
+
start = next;
|
2330
|
+
end = next;
|
2331
|
+
if (total > 0) { // avoid divide by zero
|
2332
|
+
end = next + (circle * (values[i] / total));
|
2333
|
+
}
|
2334
|
+
if (valuenum === i) {
|
2335
|
+
color = options.get('sliceColors')[i % options.get('sliceColors').length];
|
2336
|
+
if (highlight) {
|
2337
|
+
color = this.calcHighlightColor(color, options);
|
2338
|
+
}
|
2339
|
+
|
2340
|
+
return target.drawPieSlice(radius, radius, radius - borderWidth, start, end, undefined, color);
|
2341
|
+
}
|
2342
|
+
next = end;
|
2343
|
+
}
|
2344
|
+
},
|
2345
|
+
|
2346
|
+
render: function () {
|
2347
|
+
var target = this.target,
|
2348
|
+
values = this.values,
|
2349
|
+
options = this.options,
|
2350
|
+
radius = this.radius,
|
2351
|
+
borderWidth = options.get('borderWidth'),
|
2352
|
+
donutWidth = options.get('donutWidth'),
|
2353
|
+
shape, i;
|
2354
|
+
|
2355
|
+
if (!pie._super.render.call(this)) {
|
2356
|
+
return;
|
2357
|
+
}
|
2358
|
+
if (borderWidth) {
|
2359
|
+
target.drawCircle(radius, radius, Math.floor(radius - (borderWidth / 2)),
|
2360
|
+
options.get('borderColor'), undefined, borderWidth).append();
|
2361
|
+
}
|
2362
|
+
for (i = values.length; i--;) {
|
2363
|
+
if (values[i]) { // don't render zero values
|
2364
|
+
shape = this.renderSlice(i).append();
|
2365
|
+
this.valueShapes[i] = shape.id; // store just the shapeid
|
2366
|
+
this.shapes[shape.id] = i;
|
2367
|
+
}
|
2368
|
+
}
|
2369
|
+
if (donutWidth) {
|
2370
|
+
target.drawCircle(radius, radius, radius - donutWidth, options.get('donutColor'),
|
2371
|
+
options.get('donutColor'), 0).append();
|
2372
|
+
}
|
2373
|
+
target.render();
|
2374
|
+
}
|
2375
|
+
});
|
2376
|
+
|
2377
|
+
/**
|
2378
|
+
* Box plots
|
2379
|
+
*/
|
2380
|
+
$.fn.sparkline.box = box = createClass($.fn.sparkline._base, {
|
2381
|
+
type: 'box',
|
2382
|
+
|
2383
|
+
init: function (el, values, options, width, height) {
|
2384
|
+
box._super.init.call(this, el, values, options, width, height);
|
2385
|
+
this.values = $.map(values, Number);
|
2386
|
+
this.width = options.get('width') === 'auto' ? '4.0em' : width;
|
2387
|
+
this.initTarget();
|
2388
|
+
if (!this.values.length) {
|
2389
|
+
this.disabled = 1;
|
2390
|
+
}
|
2391
|
+
},
|
2392
|
+
|
2393
|
+
/**
|
2394
|
+
* Simulate a single region
|
2395
|
+
*/
|
2396
|
+
getRegion: function () {
|
2397
|
+
return 1;
|
2398
|
+
},
|
2399
|
+
|
2400
|
+
getCurrentRegionFields: function () {
|
2401
|
+
var result = [
|
2402
|
+
{ field: 'lq', value: this.quartiles[0] },
|
2403
|
+
{ field: 'med', value: this.quartiles[1] },
|
2404
|
+
{ field: 'uq', value: this.quartiles[2] }
|
2405
|
+
];
|
2406
|
+
if (this.loutlier !== undefined) {
|
2407
|
+
result.push({ field: 'lo', value: this.loutlier});
|
2408
|
+
}
|
2409
|
+
if (this.routlier !== undefined) {
|
2410
|
+
result.push({ field: 'ro', value: this.routlier});
|
2411
|
+
}
|
2412
|
+
if (this.lwhisker !== undefined) {
|
2413
|
+
result.push({ field: 'lw', value: this.lwhisker});
|
2414
|
+
}
|
2415
|
+
if (this.rwhisker !== undefined) {
|
2416
|
+
result.push({ field: 'rw', value: this.rwhisker});
|
2417
|
+
}
|
2418
|
+
return result;
|
2419
|
+
},
|
2420
|
+
|
2421
|
+
render: function () {
|
2422
|
+
var target = this.target,
|
2423
|
+
values = this.values,
|
2424
|
+
vlen = values.length,
|
2425
|
+
options = this.options,
|
2426
|
+
canvasWidth = this.canvasWidth,
|
2427
|
+
canvasHeight = this.canvasHeight,
|
2428
|
+
minValue = options.get('chartRangeMin') === undefined ? Math.min.apply(Math, values) : options.get('chartRangeMin'),
|
2429
|
+
maxValue = options.get('chartRangeMax') === undefined ? Math.max.apply(Math, values) : options.get('chartRangeMax'),
|
2430
|
+
canvasLeft = 0,
|
2431
|
+
lwhisker, loutlier, iqr, q1, q2, q3, rwhisker, routlier, i,
|
2432
|
+
size, unitSize;
|
2433
|
+
|
2434
|
+
if (!box._super.render.call(this)) {
|
2435
|
+
return;
|
2436
|
+
}
|
2437
|
+
|
2438
|
+
if (options.get('raw')) {
|
2439
|
+
if (options.get('showOutliers') && values.length > 5) {
|
2440
|
+
loutlier = values[0];
|
2441
|
+
lwhisker = values[1];
|
2442
|
+
q1 = values[2];
|
2443
|
+
q2 = values[3];
|
2444
|
+
q3 = values[4];
|
2445
|
+
rwhisker = values[5];
|
2446
|
+
routlier = values[6];
|
2447
|
+
} else {
|
2448
|
+
lwhisker = values[0];
|
2449
|
+
q1 = values[1];
|
2450
|
+
q2 = values[2];
|
2451
|
+
q3 = values[3];
|
2452
|
+
rwhisker = values[4];
|
2453
|
+
}
|
2454
|
+
} else {
|
2455
|
+
values.sort(function (a, b) { return a - b; });
|
2456
|
+
q1 = quartile(values, 1);
|
2457
|
+
q2 = quartile(values, 2);
|
2458
|
+
q3 = quartile(values, 3);
|
2459
|
+
iqr = q3 - q1;
|
2460
|
+
if (options.get('showOutliers')) {
|
2461
|
+
lwhisker = rwhisker = undefined;
|
2462
|
+
for (i = 0; i < vlen; i++) {
|
2463
|
+
if (lwhisker === undefined && values[i] > q1 - (iqr * options.get('outlierIQR'))) {
|
2464
|
+
lwhisker = values[i];
|
2465
|
+
}
|
2466
|
+
if (values[i] < q3 + (iqr * options.get('outlierIQR'))) {
|
2467
|
+
rwhisker = values[i];
|
2468
|
+
}
|
2469
|
+
}
|
2470
|
+
loutlier = values[0];
|
2471
|
+
routlier = values[vlen - 1];
|
2472
|
+
} else {
|
2473
|
+
lwhisker = values[0];
|
2474
|
+
rwhisker = values[vlen - 1];
|
2475
|
+
}
|
2476
|
+
}
|
2477
|
+
this.quartiles = [q1, q2, q3];
|
2478
|
+
this.lwhisker = lwhisker;
|
2479
|
+
this.rwhisker = rwhisker;
|
2480
|
+
this.loutlier = loutlier;
|
2481
|
+
this.routlier = routlier;
|
2482
|
+
|
2483
|
+
unitSize = canvasWidth / (maxValue - minValue + 1);
|
2484
|
+
if (options.get('showOutliers')) {
|
2485
|
+
canvasLeft = Math.ceil(options.get('spotRadius'));
|
2486
|
+
canvasWidth -= 2 * Math.ceil(options.get('spotRadius'));
|
2487
|
+
unitSize = canvasWidth / (maxValue - minValue + 1);
|
2488
|
+
if (loutlier < lwhisker) {
|
2489
|
+
target.drawCircle((loutlier - minValue) * unitSize + canvasLeft,
|
2490
|
+
canvasHeight / 2,
|
2491
|
+
options.get('spotRadius'),
|
2492
|
+
options.get('outlierLineColor'),
|
2493
|
+
options.get('outlierFillColor')).append();
|
2494
|
+
}
|
2495
|
+
if (routlier > rwhisker) {
|
2496
|
+
target.drawCircle((routlier - minValue) * unitSize + canvasLeft,
|
2497
|
+
canvasHeight / 2,
|
2498
|
+
options.get('spotRadius'),
|
2499
|
+
options.get('outlierLineColor'),
|
2500
|
+
options.get('outlierFillColor')).append();
|
2501
|
+
}
|
2502
|
+
}
|
2503
|
+
|
2504
|
+
// box
|
2505
|
+
target.drawRect(
|
2506
|
+
Math.round((q1 - minValue) * unitSize + canvasLeft),
|
2507
|
+
Math.round(canvasHeight * 0.1),
|
2508
|
+
Math.round((q3 - q1) * unitSize),
|
2509
|
+
Math.round(canvasHeight * 0.8),
|
2510
|
+
options.get('boxLineColor'),
|
2511
|
+
options.get('boxFillColor')).append();
|
2512
|
+
// left whisker
|
2513
|
+
target.drawLine(
|
2514
|
+
Math.round((lwhisker - minValue) * unitSize + canvasLeft),
|
2515
|
+
Math.round(canvasHeight / 2),
|
2516
|
+
Math.round((q1 - minValue) * unitSize + canvasLeft),
|
2517
|
+
Math.round(canvasHeight / 2),
|
2518
|
+
options.get('lineColor')).append();
|
2519
|
+
target.drawLine(
|
2520
|
+
Math.round((lwhisker - minValue) * unitSize + canvasLeft),
|
2521
|
+
Math.round(canvasHeight / 4),
|
2522
|
+
Math.round((lwhisker - minValue) * unitSize + canvasLeft),
|
2523
|
+
Math.round(canvasHeight - canvasHeight / 4),
|
2524
|
+
options.get('whiskerColor')).append();
|
2525
|
+
// right whisker
|
2526
|
+
target.drawLine(Math.round((rwhisker - minValue) * unitSize + canvasLeft),
|
2527
|
+
Math.round(canvasHeight / 2),
|
2528
|
+
Math.round((q3 - minValue) * unitSize + canvasLeft),
|
2529
|
+
Math.round(canvasHeight / 2),
|
2530
|
+
options.get('lineColor')).append();
|
2531
|
+
target.drawLine(
|
2532
|
+
Math.round((rwhisker - minValue) * unitSize + canvasLeft),
|
2533
|
+
Math.round(canvasHeight / 4),
|
2534
|
+
Math.round((rwhisker - minValue) * unitSize + canvasLeft),
|
2535
|
+
Math.round(canvasHeight - canvasHeight / 4),
|
2536
|
+
options.get('whiskerColor')).append();
|
2537
|
+
// median line
|
2538
|
+
target.drawLine(
|
2539
|
+
Math.round((q2 - minValue) * unitSize + canvasLeft),
|
2540
|
+
Math.round(canvasHeight * 0.1),
|
2541
|
+
Math.round((q2 - minValue) * unitSize + canvasLeft),
|
2542
|
+
Math.round(canvasHeight * 0.9),
|
2543
|
+
options.get('medianColor')).append();
|
2544
|
+
if (options.get('target')) {
|
2545
|
+
size = Math.ceil(options.get('spotRadius'));
|
2546
|
+
target.drawLine(
|
2547
|
+
Math.round((options.get('target') - minValue) * unitSize + canvasLeft),
|
2548
|
+
Math.round((canvasHeight / 2) - size),
|
2549
|
+
Math.round((options.get('target') - minValue) * unitSize + canvasLeft),
|
2550
|
+
Math.round((canvasHeight / 2) + size),
|
2551
|
+
options.get('targetColor')).append();
|
2552
|
+
target.drawLine(
|
2553
|
+
Math.round((options.get('target') - minValue) * unitSize + canvasLeft - size),
|
2554
|
+
Math.round(canvasHeight / 2),
|
2555
|
+
Math.round((options.get('target') - minValue) * unitSize + canvasLeft + size),
|
2556
|
+
Math.round(canvasHeight / 2),
|
2557
|
+
options.get('targetColor')).append();
|
2558
|
+
}
|
2559
|
+
target.render();
|
2560
|
+
}
|
2561
|
+
});
|
2562
|
+
|
2563
|
+
// Setup a very simple "virtual canvas" to make drawing the few shapes we need easier
|
2564
|
+
// This is accessible as $(foo).simpledraw()
|
2565
|
+
|
2566
|
+
VShape = createClass({
|
2567
|
+
init: function (target, id, type, args) {
|
2568
|
+
this.target = target;
|
2569
|
+
this.id = id;
|
2570
|
+
this.type = type;
|
2571
|
+
this.args = args;
|
2572
|
+
},
|
2573
|
+
append: function () {
|
2574
|
+
this.target.appendShape(this);
|
2575
|
+
return this;
|
2576
|
+
}
|
2577
|
+
});
|
2578
|
+
|
2579
|
+
VCanvas_base = createClass({
|
2580
|
+
_pxregex: /(\d+)(px)?\s*$/i,
|
2581
|
+
|
2582
|
+
init: function (width, height, target) {
|
2583
|
+
if (!width) {
|
2584
|
+
return;
|
2585
|
+
}
|
2586
|
+
this.width = width;
|
2587
|
+
this.height = height;
|
2588
|
+
this.target = target;
|
2589
|
+
this.lastShapeId = null;
|
2590
|
+
if (target[0]) {
|
2591
|
+
target = target[0];
|
2592
|
+
}
|
2593
|
+
$.data(target, '_jqs_vcanvas', this);
|
2594
|
+
},
|
2595
|
+
|
2596
|
+
drawLine: function (x1, y1, x2, y2, lineColor, lineWidth) {
|
2597
|
+
return this.drawShape([[x1, y1], [x2, y2]], lineColor, lineWidth);
|
2598
|
+
},
|
2599
|
+
|
2600
|
+
drawShape: function (path, lineColor, fillColor, lineWidth) {
|
2601
|
+
return this._genShape('Shape', [path, lineColor, fillColor, lineWidth]);
|
2602
|
+
},
|
2603
|
+
|
2604
|
+
drawCircle: function (x, y, radius, lineColor, fillColor, lineWidth) {
|
2605
|
+
return this._genShape('Circle', [x, y, radius, lineColor, fillColor, lineWidth]);
|
2606
|
+
},
|
2607
|
+
|
2608
|
+
drawPieSlice: function (x, y, radius, startAngle, endAngle, lineColor, fillColor) {
|
2609
|
+
return this._genShape('PieSlice', [x, y, radius, startAngle, endAngle, lineColor, fillColor]);
|
2610
|
+
},
|
2611
|
+
|
2612
|
+
drawRect: function (x, y, width, height, lineColor, fillColor) {
|
2613
|
+
return this._genShape('Rect', [x, y, width, height, lineColor, fillColor]);
|
2614
|
+
},
|
2615
|
+
|
2616
|
+
getElement: function () {
|
2617
|
+
return this.canvas;
|
2618
|
+
},
|
2619
|
+
|
2620
|
+
/**
|
2621
|
+
* Return the most recently inserted shape id
|
2622
|
+
*/
|
2623
|
+
getLastShapeId: function () {
|
2624
|
+
return this.lastShapeId;
|
2625
|
+
},
|
2626
|
+
|
2627
|
+
/**
|
2628
|
+
* Clear and reset the canvas
|
2629
|
+
*/
|
2630
|
+
reset: function () {
|
2631
|
+
alert('reset not implemented');
|
2632
|
+
},
|
2633
|
+
|
2634
|
+
_insert: function (el, target) {
|
2635
|
+
$(target).html(el);
|
2636
|
+
},
|
2637
|
+
|
2638
|
+
/**
|
2639
|
+
* Calculate the pixel dimensions of the canvas
|
2640
|
+
*/
|
2641
|
+
_calculatePixelDims: function (width, height, canvas) {
|
2642
|
+
// XXX This should probably be a configurable option
|
2643
|
+
var match;
|
2644
|
+
match = this._pxregex.exec(height);
|
2645
|
+
if (match) {
|
2646
|
+
this.pixelHeight = match[1];
|
2647
|
+
} else {
|
2648
|
+
this.pixelHeight = $(canvas).height();
|
2649
|
+
}
|
2650
|
+
match = this._pxregex.exec(width);
|
2651
|
+
if (match) {
|
2652
|
+
this.pixelWidth = match[1];
|
2653
|
+
} else {
|
2654
|
+
this.pixelWidth = $(canvas).width();
|
2655
|
+
}
|
2656
|
+
},
|
2657
|
+
|
2658
|
+
/**
|
2659
|
+
* Generate a shape object and id for later rendering
|
2660
|
+
*/
|
2661
|
+
_genShape: function (shapetype, shapeargs) {
|
2662
|
+
var id = shapeCount++;
|
2663
|
+
shapeargs.unshift(id);
|
2664
|
+
return new VShape(this, id, shapetype, shapeargs);
|
2665
|
+
},
|
2666
|
+
|
2667
|
+
/**
|
2668
|
+
* Add a shape to the end of the render queue
|
2669
|
+
*/
|
2670
|
+
appendShape: function (shape) {
|
2671
|
+
alert('appendShape not implemented');
|
2672
|
+
},
|
2673
|
+
|
2674
|
+
/**
|
2675
|
+
* Replace one shape with another
|
2676
|
+
*/
|
2677
|
+
replaceWithShape: function (shapeid, shape) {
|
2678
|
+
alert('replaceWithShape not implemented');
|
2679
|
+
},
|
2680
|
+
|
2681
|
+
/**
|
2682
|
+
* Insert one shape after another in the render queue
|
2683
|
+
*/
|
2684
|
+
insertAfterShape: function (shapeid, shape) {
|
2685
|
+
alert('insertAfterShape not implemented');
|
2686
|
+
},
|
2687
|
+
|
2688
|
+
/**
|
2689
|
+
* Remove a shape from the queue
|
2690
|
+
*/
|
2691
|
+
removeShapeId: function (shapeid) {
|
2692
|
+
alert('removeShapeId not implemented');
|
2693
|
+
},
|
2694
|
+
|
2695
|
+
/**
|
2696
|
+
* Find a shape at the specified x/y co-ordinates
|
2697
|
+
*/
|
2698
|
+
getShapeAt: function (el, x, y) {
|
2699
|
+
alert('getShapeAt not implemented');
|
2700
|
+
},
|
2701
|
+
|
2702
|
+
/**
|
2703
|
+
* Render all queued shapes onto the canvas
|
2704
|
+
*/
|
2705
|
+
render: function () {
|
2706
|
+
alert('render not implemented');
|
2707
|
+
}
|
2708
|
+
});
|
2709
|
+
|
2710
|
+
VCanvas_canvas = createClass(VCanvas_base, {
|
2711
|
+
init: function (width, height, target, interact) {
|
2712
|
+
VCanvas_canvas._super.init.call(this, width, height, target);
|
2713
|
+
this.canvas = document.createElement('canvas');
|
2714
|
+
if (target[0]) {
|
2715
|
+
target = target[0];
|
2716
|
+
}
|
2717
|
+
$.data(target, '_jqs_vcanvas', this);
|
2718
|
+
$(this.canvas).css({ display: 'inline-block', width: width, height: height, verticalAlign: 'top' });
|
2719
|
+
this._insert(this.canvas, target);
|
2720
|
+
this._calculatePixelDims(width, height, this.canvas);
|
2721
|
+
this.canvas.width = this.pixelWidth;
|
2722
|
+
this.canvas.height = this.pixelHeight;
|
2723
|
+
this.interact = interact;
|
2724
|
+
this.shapes = {};
|
2725
|
+
this.shapeseq = [];
|
2726
|
+
this.currentTargetShapeId = undefined;
|
2727
|
+
$(this.canvas).css({width: this.pixelWidth, height: this.pixelHeight});
|
2728
|
+
},
|
2729
|
+
|
2730
|
+
_getContext: function (lineColor, fillColor, lineWidth) {
|
2731
|
+
var context = this.canvas.getContext('2d');
|
2732
|
+
if (lineColor !== undefined) {
|
2733
|
+
context.strokeStyle = lineColor;
|
2734
|
+
}
|
2735
|
+
context.lineWidth = lineWidth === undefined ? 1 : lineWidth;
|
2736
|
+
if (fillColor !== undefined) {
|
2737
|
+
context.fillStyle = fillColor;
|
2738
|
+
}
|
2739
|
+
return context;
|
2740
|
+
},
|
2741
|
+
|
2742
|
+
reset: function () {
|
2743
|
+
var context = this._getContext();
|
2744
|
+
context.clearRect(0, 0, this.pixelWidth, this.pixelHeight);
|
2745
|
+
this.shapes = {};
|
2746
|
+
this.shapeseq = [];
|
2747
|
+
this.currentTargetShapeId = undefined;
|
2748
|
+
},
|
2749
|
+
|
2750
|
+
_drawShape: function (shapeid, path, lineColor, fillColor, lineWidth) {
|
2751
|
+
var context = this._getContext(lineColor, fillColor, lineWidth),
|
2752
|
+
i, plen;
|
2753
|
+
context.beginPath();
|
2754
|
+
context.moveTo(path[0][0] + 0.5, path[0][1] + 0.5);
|
2755
|
+
for (i = 1, plen = path.length; i < plen; i++) {
|
2756
|
+
context.lineTo(path[i][0] + 0.5, path[i][1] + 0.5); // the 0.5 offset gives us crisp pixel-width lines
|
2757
|
+
}
|
2758
|
+
if (lineColor !== undefined) {
|
2759
|
+
context.stroke();
|
2760
|
+
}
|
2761
|
+
if (fillColor !== undefined) {
|
2762
|
+
context.fill();
|
2763
|
+
}
|
2764
|
+
if (this.targetX !== undefined && this.targetY !== undefined &&
|
2765
|
+
context.isPointInPath(this.targetX, this.targetY)) {
|
2766
|
+
this.currentTargetShapeId = shapeid;
|
2767
|
+
}
|
2768
|
+
},
|
2769
|
+
|
2770
|
+
_drawCircle: function (shapeid, x, y, radius, lineColor, fillColor, lineWidth) {
|
2771
|
+
var context = this._getContext(lineColor, fillColor, lineWidth);
|
2772
|
+
context.beginPath();
|
2773
|
+
context.arc(x, y, radius, 0, 2 * Math.PI, false);
|
2774
|
+
if (this.targetX !== undefined && this.targetY !== undefined &&
|
2775
|
+
context.isPointInPath(this.targetX, this.targetY)) {
|
2776
|
+
this.currentTargetShapeId = shapeid;
|
2777
|
+
}
|
2778
|
+
if (lineColor !== undefined) {
|
2779
|
+
context.stroke();
|
2780
|
+
}
|
2781
|
+
if (fillColor !== undefined) {
|
2782
|
+
context.fill();
|
2783
|
+
}
|
2784
|
+
},
|
2785
|
+
|
2786
|
+
_drawPieSlice: function (shapeid, x, y, radius, startAngle, endAngle, lineColor, fillColor) {
|
2787
|
+
var context = this._getContext(lineColor, fillColor);
|
2788
|
+
context.beginPath();
|
2789
|
+
context.moveTo(x, y);
|
2790
|
+
context.arc(x, y, radius, startAngle, endAngle, false);
|
2791
|
+
context.lineTo(x, y);
|
2792
|
+
context.closePath();
|
2793
|
+
if (lineColor !== undefined) {
|
2794
|
+
context.stroke();
|
2795
|
+
}
|
2796
|
+
if (fillColor) {
|
2797
|
+
context.fill();
|
2798
|
+
}
|
2799
|
+
if (this.targetX !== undefined && this.targetY !== undefined &&
|
2800
|
+
context.isPointInPath(this.targetX, this.targetY)) {
|
2801
|
+
this.currentTargetShapeId = shapeid;
|
2802
|
+
}
|
2803
|
+
},
|
2804
|
+
|
2805
|
+
_drawRect: function (shapeid, x, y, width, height, lineColor, fillColor) {
|
2806
|
+
return this._drawShape(shapeid, [[x, y], [x + width, y], [x + width, y + height], [x, y + height], [x, y]], lineColor, fillColor);
|
2807
|
+
},
|
2808
|
+
|
2809
|
+
appendShape: function (shape) {
|
2810
|
+
this.shapes[shape.id] = shape;
|
2811
|
+
this.shapeseq.push(shape.id);
|
2812
|
+
this.lastShapeId = shape.id;
|
2813
|
+
return shape.id;
|
2814
|
+
},
|
2815
|
+
|
2816
|
+
replaceWithShape: function (shapeid, shape) {
|
2817
|
+
var shapeseq = this.shapeseq,
|
2818
|
+
i;
|
2819
|
+
this.shapes[shape.id] = shape;
|
2820
|
+
for (i = shapeseq.length; i--;) {
|
2821
|
+
if (shapeseq[i] == shapeid) {
|
2822
|
+
shapeseq[i] = shape.id;
|
2823
|
+
}
|
2824
|
+
}
|
2825
|
+
delete this.shapes[shapeid];
|
2826
|
+
},
|
2827
|
+
|
2828
|
+
replaceWithShapes: function (shapeids, shapes) {
|
2829
|
+
var shapeseq = this.shapeseq,
|
2830
|
+
shapemap = {},
|
2831
|
+
sid, i, first;
|
2832
|
+
|
2833
|
+
for (i = shapeids.length; i--;) {
|
2834
|
+
shapemap[shapeids[i]] = true;
|
2835
|
+
}
|
2836
|
+
for (i = shapeseq.length; i--;) {
|
2837
|
+
sid = shapeseq[i];
|
2838
|
+
if (shapemap[sid]) {
|
2839
|
+
shapeseq.splice(i, 1);
|
2840
|
+
delete this.shapes[sid];
|
2841
|
+
first = i;
|
2842
|
+
}
|
2843
|
+
}
|
2844
|
+
for (i = shapes.length; i--;) {
|
2845
|
+
shapeseq.splice(first, 0, shapes[i].id);
|
2846
|
+
this.shapes[shapes[i].id] = shapes[i];
|
2847
|
+
}
|
2848
|
+
|
2849
|
+
},
|
2850
|
+
|
2851
|
+
insertAfterShape: function (shapeid, shape) {
|
2852
|
+
var shapeseq = this.shapeseq,
|
2853
|
+
i;
|
2854
|
+
for (i = shapeseq.length; i--;) {
|
2855
|
+
if (shapeseq[i] === shapeid) {
|
2856
|
+
shapeseq.splice(i + 1, 0, shape.id);
|
2857
|
+
this.shapes[shape.id] = shape;
|
2858
|
+
return;
|
2859
|
+
}
|
2860
|
+
}
|
2861
|
+
},
|
2862
|
+
|
2863
|
+
removeShapeId: function (shapeid) {
|
2864
|
+
var shapeseq = this.shapeseq,
|
2865
|
+
i;
|
2866
|
+
for (i = shapeseq.length; i--;) {
|
2867
|
+
if (shapeseq[i] === shapeid) {
|
2868
|
+
shapeseq.splice(i, 1);
|
2869
|
+
break;
|
2870
|
+
}
|
2871
|
+
}
|
2872
|
+
delete this.shapes[shapeid];
|
2873
|
+
},
|
2874
|
+
|
2875
|
+
getShapeAt: function (el, x, y) {
|
2876
|
+
this.targetX = x;
|
2877
|
+
this.targetY = y;
|
2878
|
+
this.render();
|
2879
|
+
return this.currentTargetShapeId;
|
2880
|
+
},
|
2881
|
+
|
2882
|
+
render: function () {
|
2883
|
+
var shapeseq = this.shapeseq,
|
2884
|
+
shapes = this.shapes,
|
2885
|
+
shapeCount = shapeseq.length,
|
2886
|
+
context = this._getContext(),
|
2887
|
+
shapeid, shape, i;
|
2888
|
+
context.clearRect(0, 0, this.pixelWidth, this.pixelHeight);
|
2889
|
+
for (i = 0; i < shapeCount; i++) {
|
2890
|
+
shapeid = shapeseq[i];
|
2891
|
+
shape = shapes[shapeid];
|
2892
|
+
this['_draw' + shape.type].apply(this, shape.args);
|
2893
|
+
}
|
2894
|
+
if (!this.interact) {
|
2895
|
+
// not interactive so no need to keep the shapes array
|
2896
|
+
this.shapes = {};
|
2897
|
+
this.shapeseq = [];
|
2898
|
+
}
|
2899
|
+
}
|
2900
|
+
|
2901
|
+
});
|
2902
|
+
|
2903
|
+
VCanvas_vml = createClass(VCanvas_base, {
|
2904
|
+
init: function (width, height, target) {
|
2905
|
+
var groupel;
|
2906
|
+
VCanvas_vml._super.init.call(this, width, height, target);
|
2907
|
+
if (target[0]) {
|
2908
|
+
target = target[0];
|
2909
|
+
}
|
2910
|
+
$.data(target, '_jqs_vcanvas', this);
|
2911
|
+
this.canvas = document.createElement('span');
|
2912
|
+
$(this.canvas).css({ display: 'inline-block', position: 'relative', overflow: 'hidden', width: width, height: height, margin: '0px', padding: '0px', verticalAlign: 'top'});
|
2913
|
+
this._insert(this.canvas, target);
|
2914
|
+
this._calculatePixelDims(width, height, this.canvas);
|
2915
|
+
this.canvas.width = this.pixelWidth;
|
2916
|
+
this.canvas.height = this.pixelHeight;
|
2917
|
+
groupel = '<v:group coordorigin="0 0" coordsize="' + this.pixelWidth + ' ' + this.pixelHeight + '"' +
|
2918
|
+
' style="position:absolute;top:0;left:0;width:' + this.pixelWidth + 'px;height=' + this.pixelHeight + 'px;"></v:group>';
|
2919
|
+
this.canvas.insertAdjacentHTML('beforeEnd', groupel);
|
2920
|
+
this.group = $(this.canvas).children()[0];
|
2921
|
+
this.rendered = false;
|
2922
|
+
this.prerender = '';
|
2923
|
+
},
|
2924
|
+
|
2925
|
+
_drawShape: function (shapeid, path, lineColor, fillColor, lineWidth) {
|
2926
|
+
var vpath = [],
|
2927
|
+
initial, stroke, fill, closed, vel, plen, i;
|
2928
|
+
for (i = 0, plen = path.length; i < plen; i++) {
|
2929
|
+
vpath[i] = '' + (path[i][0]) + ',' + (path[i][1]);
|
2930
|
+
}
|
2931
|
+
initial = vpath.splice(0, 1);
|
2932
|
+
lineWidth = lineWidth === undefined ? 1 : lineWidth;
|
2933
|
+
stroke = lineColor === undefined ? ' stroked="false" ' : ' strokeWeight="' + lineWidth + 'px" strokeColor="' + lineColor + '" ';
|
2934
|
+
fill = fillColor === undefined ? ' filled="false"' : ' fillColor="' + fillColor + '" filled="true" ';
|
2935
|
+
closed = vpath[0] === vpath[vpath.length - 1] ? 'x ' : '';
|
2936
|
+
vel = '<v:shape coordorigin="0 0" coordsize="' + this.pixelWidth + ' ' + this.pixelHeight + '" ' +
|
2937
|
+
' id="jqsshape' + shapeid + '" ' +
|
2938
|
+
stroke +
|
2939
|
+
fill +
|
2940
|
+
' style="position:absolute;left:0px;top:0px;height:' + this.pixelHeight + 'px;width:' + this.pixelWidth + 'px;padding:0px;margin:0px;" ' +
|
2941
|
+
' path="m ' + initial + ' l ' + vpath.join(', ') + ' ' + closed + 'e">' +
|
2942
|
+
' </v:shape>';
|
2943
|
+
return vel;
|
2944
|
+
},
|
2945
|
+
|
2946
|
+
_drawCircle: function (shapeid, x, y, radius, lineColor, fillColor, lineWidth) {
|
2947
|
+
var stroke, fill, vel;
|
2948
|
+
x -= radius;
|
2949
|
+
y -= radius;
|
2950
|
+
stroke = lineColor === undefined ? ' stroked="false" ' : ' strokeWeight="' + lineWidth + 'px" strokeColor="' + lineColor + '" ';
|
2951
|
+
fill = fillColor === undefined ? ' filled="false"' : ' fillColor="' + fillColor + '" filled="true" ';
|
2952
|
+
vel = '<v:oval ' +
|
2953
|
+
' id="jqsshape' + shapeid + '" ' +
|
2954
|
+
stroke +
|
2955
|
+
fill +
|
2956
|
+
' style="position:absolute;top:' + y + 'px; left:' + x + 'px; width:' + (radius * 2) + 'px; height:' + (radius * 2) + 'px"></v:oval>';
|
2957
|
+
return vel;
|
2958
|
+
|
2959
|
+
},
|
2960
|
+
|
2961
|
+
_drawPieSlice: function (shapeid, x, y, radius, startAngle, endAngle, lineColor, fillColor) {
|
2962
|
+
var vpath, startx, starty, endx, endy, stroke, fill, vel;
|
2963
|
+
if (startAngle === endAngle) {
|
2964
|
+
return ''; // VML seems to have problem when start angle equals end angle.
|
2965
|
+
}
|
2966
|
+
if ((endAngle - startAngle) === (2 * Math.PI)) {
|
2967
|
+
startAngle = 0.0; // VML seems to have a problem when drawing a full circle that doesn't start 0
|
2968
|
+
endAngle = (2 * Math.PI);
|
2969
|
+
}
|
2970
|
+
|
2971
|
+
startx = x + Math.round(Math.cos(startAngle) * radius);
|
2972
|
+
starty = y + Math.round(Math.sin(startAngle) * radius);
|
2973
|
+
endx = x + Math.round(Math.cos(endAngle) * radius);
|
2974
|
+
endy = y + Math.round(Math.sin(endAngle) * radius);
|
2975
|
+
|
2976
|
+
if (startx === endx && starty === endy) {
|
2977
|
+
if ((endAngle - startAngle) < Math.PI) {
|
2978
|
+
// Prevent very small slices from being mistaken as a whole pie
|
2979
|
+
return '';
|
2980
|
+
}
|
2981
|
+
// essentially going to be the entire circle, so ignore startAngle
|
2982
|
+
startx = endx = x + radius;
|
2983
|
+
starty = endy = y;
|
2984
|
+
}
|
2985
|
+
|
2986
|
+
if (startx === endx && starty === endy && (endAngle - startAngle) < Math.PI) {
|
2987
|
+
return '';
|
2988
|
+
}
|
2989
|
+
|
2990
|
+
vpath = [x - radius, y - radius, x + radius, y + radius, startx, starty, endx, endy];
|
2991
|
+
stroke = lineColor === undefined ? ' stroked="false" ' : ' strokeWeight="1px" strokeColor="' + lineColor + '" ';
|
2992
|
+
fill = fillColor === undefined ? ' filled="false"' : ' fillColor="' + fillColor + '" filled="true" ';
|
2993
|
+
vel = '<v:shape coordorigin="0 0" coordsize="' + this.pixelWidth + ' ' + this.pixelHeight + '" ' +
|
2994
|
+
' id="jqsshape' + shapeid + '" ' +
|
2995
|
+
stroke +
|
2996
|
+
fill +
|
2997
|
+
' style="position:absolute;left:0px;top:0px;height:' + this.pixelHeight + 'px;width:' + this.pixelWidth + 'px;padding:0px;margin:0px;" ' +
|
2998
|
+
' path="m ' + x + ',' + y + ' wa ' + vpath.join(', ') + ' x e">' +
|
2999
|
+
' </v:shape>';
|
3000
|
+
return vel;
|
3001
|
+
},
|
3002
|
+
|
3003
|
+
_drawRect: function (shapeid, x, y, width, height, lineColor, fillColor) {
|
3004
|
+
return this._drawShape(shapeid, [[x, y], [x, y + height], [x + width, y + height], [x + width, y], [x, y]], lineColor, fillColor);
|
3005
|
+
},
|
3006
|
+
|
3007
|
+
reset: function () {
|
3008
|
+
this.group.innerHTML = '';
|
3009
|
+
},
|
3010
|
+
|
3011
|
+
appendShape: function (shape) {
|
3012
|
+
var vel = this['_draw' + shape.type].apply(this, shape.args);
|
3013
|
+
if (this.rendered) {
|
3014
|
+
this.group.insertAdjacentHTML('beforeEnd', vel);
|
3015
|
+
} else {
|
3016
|
+
this.prerender += vel;
|
3017
|
+
}
|
3018
|
+
this.lastShapeId = shape.id;
|
3019
|
+
return shape.id;
|
3020
|
+
},
|
3021
|
+
|
3022
|
+
replaceWithShape: function (shapeid, shape) {
|
3023
|
+
var existing = $('#jqsshape' + shapeid),
|
3024
|
+
vel = this['_draw' + shape.type].apply(this, shape.args);
|
3025
|
+
existing[0].outerHTML = vel;
|
3026
|
+
},
|
3027
|
+
|
3028
|
+
replaceWithShapes: function (shapeids, shapes) {
|
3029
|
+
// replace the first shapeid with all the new shapes then toast the remaining old shapes
|
3030
|
+
var existing = $('#jqsshape' + shapeids[0]),
|
3031
|
+
replace = '',
|
3032
|
+
slen = shapes.length,
|
3033
|
+
i;
|
3034
|
+
for (i = 0; i < slen; i++) {
|
3035
|
+
replace += this['_draw' + shapes[i].type].apply(this, shapes[i].args);
|
3036
|
+
}
|
3037
|
+
existing[0].outerHTML = replace;
|
3038
|
+
for (i = 1; i < shapeids.length; i++) {
|
3039
|
+
$('#jqsshape' + shapeids[i]).remove();
|
3040
|
+
}
|
3041
|
+
},
|
3042
|
+
|
3043
|
+
insertAfterShape: function (shapeid, shape) {
|
3044
|
+
var existing = $('#jqsshape' + shapeid),
|
3045
|
+
vel = this['_draw' + shape.type].apply(this, shape.args);
|
3046
|
+
existing[0].insertAdjacentHTML('afterEnd', vel);
|
3047
|
+
},
|
3048
|
+
|
3049
|
+
removeShapeId: function (shapeid) {
|
3050
|
+
var existing = $('#jqsshape' + shapeid);
|
3051
|
+
this.group.removeChild(existing[0]);
|
3052
|
+
},
|
3053
|
+
|
3054
|
+
getShapeAt: function (el, x, y) {
|
3055
|
+
var shapeid = el.id.substr(8);
|
3056
|
+
return shapeid;
|
3057
|
+
},
|
3058
|
+
|
3059
|
+
render: function () {
|
3060
|
+
if (!this.rendered) {
|
3061
|
+
// batch the intial render into a single repaint
|
3062
|
+
this.group.innerHTML = this.prerender;
|
3063
|
+
this.rendered = true;
|
3064
|
+
}
|
3065
|
+
}
|
3066
|
+
});
|
3067
|
+
|
3068
|
+
}))}(document, Math));
|