Added dual licensing WTFPL and MIT, built new version

This commit is contained in:
Gion Kunz 2016-02-21 10:46:31 +01:00
parent 5bfcffb3d5
commit 2d92bf55cb
9 changed files with 750 additions and 111 deletions

7
LICENSE-MIT Normal file
View File

@ -0,0 +1,7 @@
Copyright (c) 2013 Gion Kunz <gion.kunz@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,7 +1,7 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Copyright (c) 2013 Gion Kunz <gion.kunz@gmail.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long

13
dist/LICENSE vendored
View File

@ -1,13 +0,0 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

592
dist/chartist.css vendored Normal file
View File

@ -0,0 +1,592 @@
.ct-label {
fill: rgba(0, 0, 0, 0.4);
color: rgba(0, 0, 0, 0.4);
font-size: 0.75rem;
line-height: 1; }
.ct-chart-line .ct-label, .ct-chart-bar .ct-label {
display: block;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex; }
.ct-label.ct-horizontal.ct-start {
-webkit-box-align: flex-end;
-webkit-align-items: flex-end;
-ms-flex-align: flex-end;
align-items: flex-end;
-webkit-box-pack: flex-start;
-webkit-justify-content: flex-start;
-ms-flex-pack: flex-start;
justify-content: flex-start;
text-align: left;
text-anchor: start; }
.ct-label.ct-horizontal.ct-end {
-webkit-box-align: flex-start;
-webkit-align-items: flex-start;
-ms-flex-align: flex-start;
align-items: flex-start;
-webkit-box-pack: flex-start;
-webkit-justify-content: flex-start;
-ms-flex-pack: flex-start;
justify-content: flex-start;
text-align: left;
text-anchor: start; }
.ct-label.ct-vertical.ct-start {
-webkit-box-align: flex-end;
-webkit-align-items: flex-end;
-ms-flex-align: flex-end;
align-items: flex-end;
-webkit-box-pack: flex-end;
-webkit-justify-content: flex-end;
-ms-flex-pack: flex-end;
justify-content: flex-end;
text-align: right;
text-anchor: end; }
.ct-label.ct-vertical.ct-end {
-webkit-box-align: flex-end;
-webkit-align-items: flex-end;
-ms-flex-align: flex-end;
align-items: flex-end;
-webkit-box-pack: flex-start;
-webkit-justify-content: flex-start;
-ms-flex-pack: flex-start;
justify-content: flex-start;
text-align: left;
text-anchor: start; }
.ct-chart-bar .ct-label.ct-horizontal.ct-start {
-webkit-box-align: flex-end;
-webkit-align-items: flex-end;
-ms-flex-align: flex-end;
align-items: flex-end;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
text-align: center;
text-anchor: start; }
.ct-chart-bar .ct-label.ct-horizontal.ct-end {
-webkit-box-align: flex-start;
-webkit-align-items: flex-start;
-ms-flex-align: flex-start;
align-items: flex-start;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
text-align: center;
text-anchor: start; }
.ct-chart-bar.ct-horizontal-bars .ct-label.ct-horizontal.ct-start {
-webkit-box-align: flex-end;
-webkit-align-items: flex-end;
-ms-flex-align: flex-end;
align-items: flex-end;
-webkit-box-pack: flex-start;
-webkit-justify-content: flex-start;
-ms-flex-pack: flex-start;
justify-content: flex-start;
text-align: left;
text-anchor: start; }
.ct-chart-bar.ct-horizontal-bars .ct-label.ct-horizontal.ct-end {
-webkit-box-align: flex-start;
-webkit-align-items: flex-start;
-ms-flex-align: flex-start;
align-items: flex-start;
-webkit-box-pack: flex-start;
-webkit-justify-content: flex-start;
-ms-flex-pack: flex-start;
justify-content: flex-start;
text-align: left;
text-anchor: start; }
.ct-chart-bar.ct-horizontal-bars .ct-label.ct-vertical.ct-start {
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: flex-end;
-webkit-justify-content: flex-end;
-ms-flex-pack: flex-end;
justify-content: flex-end;
text-align: right;
text-anchor: end; }
.ct-chart-bar.ct-horizontal-bars .ct-label.ct-vertical.ct-end {
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: flex-start;
-webkit-justify-content: flex-start;
-ms-flex-pack: flex-start;
justify-content: flex-start;
text-align: left;
text-anchor: end; }
.ct-grid {
stroke: rgba(0, 0, 0, 0.2);
stroke-width: 1px;
stroke-dasharray: 2px; }
.ct-point {
stroke-width: 10px;
stroke-linecap: round; }
.ct-line {
fill: none;
stroke-width: 4px; }
.ct-area {
stroke: none;
fill-opacity: 0.1; }
.ct-bar {
fill: none;
stroke-width: 10px; }
.ct-slice-donut {
fill: none;
stroke-width: 60px; }
.ct-series-a .ct-point, .ct-series-a .ct-line, .ct-series-a .ct-bar, .ct-series-a .ct-slice-donut {
stroke: #d70206; }
.ct-series-a .ct-slice-pie, .ct-series-a .ct-area {
fill: #d70206; }
.ct-series-b .ct-point, .ct-series-b .ct-line, .ct-series-b .ct-bar, .ct-series-b .ct-slice-donut {
stroke: #f05b4f; }
.ct-series-b .ct-slice-pie, .ct-series-b .ct-area {
fill: #f05b4f; }
.ct-series-c .ct-point, .ct-series-c .ct-line, .ct-series-c .ct-bar, .ct-series-c .ct-slice-donut {
stroke: #f4c63d; }
.ct-series-c .ct-slice-pie, .ct-series-c .ct-area {
fill: #f4c63d; }
.ct-series-d .ct-point, .ct-series-d .ct-line, .ct-series-d .ct-bar, .ct-series-d .ct-slice-donut {
stroke: #d17905; }
.ct-series-d .ct-slice-pie, .ct-series-d .ct-area {
fill: #d17905; }
.ct-series-e .ct-point, .ct-series-e .ct-line, .ct-series-e .ct-bar, .ct-series-e .ct-slice-donut {
stroke: #453d3f; }
.ct-series-e .ct-slice-pie, .ct-series-e .ct-area {
fill: #453d3f; }
.ct-series-f .ct-point, .ct-series-f .ct-line, .ct-series-f .ct-bar, .ct-series-f .ct-slice-donut {
stroke: #59922b; }
.ct-series-f .ct-slice-pie, .ct-series-f .ct-area {
fill: #59922b; }
.ct-series-g .ct-point, .ct-series-g .ct-line, .ct-series-g .ct-bar, .ct-series-g .ct-slice-donut {
stroke: #0544d3; }
.ct-series-g .ct-slice-pie, .ct-series-g .ct-area {
fill: #0544d3; }
.ct-series-h .ct-point, .ct-series-h .ct-line, .ct-series-h .ct-bar, .ct-series-h .ct-slice-donut {
stroke: #6b0392; }
.ct-series-h .ct-slice-pie, .ct-series-h .ct-area {
fill: #6b0392; }
.ct-series-i .ct-point, .ct-series-i .ct-line, .ct-series-i .ct-bar, .ct-series-i .ct-slice-donut {
stroke: #f05b4f; }
.ct-series-i .ct-slice-pie, .ct-series-i .ct-area {
fill: #f05b4f; }
.ct-series-j .ct-point, .ct-series-j .ct-line, .ct-series-j .ct-bar, .ct-series-j .ct-slice-donut {
stroke: #dda458; }
.ct-series-j .ct-slice-pie, .ct-series-j .ct-area {
fill: #dda458; }
.ct-series-k .ct-point, .ct-series-k .ct-line, .ct-series-k .ct-bar, .ct-series-k .ct-slice-donut {
stroke: #eacf7d; }
.ct-series-k .ct-slice-pie, .ct-series-k .ct-area {
fill: #eacf7d; }
.ct-series-l .ct-point, .ct-series-l .ct-line, .ct-series-l .ct-bar, .ct-series-l .ct-slice-donut {
stroke: #86797d; }
.ct-series-l .ct-slice-pie, .ct-series-l .ct-area {
fill: #86797d; }
.ct-series-m .ct-point, .ct-series-m .ct-line, .ct-series-m .ct-bar, .ct-series-m .ct-slice-donut {
stroke: #b2c326; }
.ct-series-m .ct-slice-pie, .ct-series-m .ct-area {
fill: #b2c326; }
.ct-series-n .ct-point, .ct-series-n .ct-line, .ct-series-n .ct-bar, .ct-series-n .ct-slice-donut {
stroke: #6188e2; }
.ct-series-n .ct-slice-pie, .ct-series-n .ct-area {
fill: #6188e2; }
.ct-series-o .ct-point, .ct-series-o .ct-line, .ct-series-o .ct-bar, .ct-series-o .ct-slice-donut {
stroke: #a748ca; }
.ct-series-o .ct-slice-pie, .ct-series-o .ct-area {
fill: #a748ca; }
.ct-square {
display: block;
position: relative;
width: 100%; }
.ct-square:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 100%; }
.ct-square:after {
content: "";
display: table;
clear: both; }
.ct-square > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-minor-second {
display: block;
position: relative;
width: 100%; }
.ct-minor-second:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 93.75%; }
.ct-minor-second:after {
content: "";
display: table;
clear: both; }
.ct-minor-second > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-major-second {
display: block;
position: relative;
width: 100%; }
.ct-major-second:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 88.8888888889%; }
.ct-major-second:after {
content: "";
display: table;
clear: both; }
.ct-major-second > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-minor-third {
display: block;
position: relative;
width: 100%; }
.ct-minor-third:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 83.3333333333%; }
.ct-minor-third:after {
content: "";
display: table;
clear: both; }
.ct-minor-third > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-major-third {
display: block;
position: relative;
width: 100%; }
.ct-major-third:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 80%; }
.ct-major-third:after {
content: "";
display: table;
clear: both; }
.ct-major-third > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-perfect-fourth {
display: block;
position: relative;
width: 100%; }
.ct-perfect-fourth:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 75%; }
.ct-perfect-fourth:after {
content: "";
display: table;
clear: both; }
.ct-perfect-fourth > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-perfect-fifth {
display: block;
position: relative;
width: 100%; }
.ct-perfect-fifth:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 66.6666666667%; }
.ct-perfect-fifth:after {
content: "";
display: table;
clear: both; }
.ct-perfect-fifth > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-minor-sixth {
display: block;
position: relative;
width: 100%; }
.ct-minor-sixth:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 62.5%; }
.ct-minor-sixth:after {
content: "";
display: table;
clear: both; }
.ct-minor-sixth > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-golden-section {
display: block;
position: relative;
width: 100%; }
.ct-golden-section:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 61.804697157%; }
.ct-golden-section:after {
content: "";
display: table;
clear: both; }
.ct-golden-section > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-major-sixth {
display: block;
position: relative;
width: 100%; }
.ct-major-sixth:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 60%; }
.ct-major-sixth:after {
content: "";
display: table;
clear: both; }
.ct-major-sixth > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-minor-seventh {
display: block;
position: relative;
width: 100%; }
.ct-minor-seventh:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 56.25%; }
.ct-minor-seventh:after {
content: "";
display: table;
clear: both; }
.ct-minor-seventh > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-major-seventh {
display: block;
position: relative;
width: 100%; }
.ct-major-seventh:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 53.3333333333%; }
.ct-major-seventh:after {
content: "";
display: table;
clear: both; }
.ct-major-seventh > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-octave {
display: block;
position: relative;
width: 100%; }
.ct-octave:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 50%; }
.ct-octave:after {
content: "";
display: table;
clear: both; }
.ct-octave > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-major-tenth {
display: block;
position: relative;
width: 100%; }
.ct-major-tenth:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 40%; }
.ct-major-tenth:after {
content: "";
display: table;
clear: both; }
.ct-major-tenth > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-major-eleventh {
display: block;
position: relative;
width: 100%; }
.ct-major-eleventh:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 37.5%; }
.ct-major-eleventh:after {
content: "";
display: table;
clear: both; }
.ct-major-eleventh > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-major-twelfth {
display: block;
position: relative;
width: 100%; }
.ct-major-twelfth:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 33.3333333333%; }
.ct-major-twelfth:after {
content: "";
display: table;
clear: both; }
.ct-major-twelfth > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
.ct-double-octave {
display: block;
position: relative;
width: 100%; }
.ct-double-octave:before {
display: block;
float: left;
content: "";
width: 0;
height: 0;
padding-bottom: 25%; }
.ct-double-octave:after {
content: "";
display: table;
clear: both; }
.ct-double-octave > svg {
display: block;
position: absolute;
top: 0;
left: 0; }
/*# sourceMappingURL=chartist.css.map */

11
dist/chartist.css.map vendored Normal file

File diff suppressed because one or more lines are too long

211
dist/chartist.js vendored
View File

@ -14,10 +14,11 @@
}
}(this, function () {
/* Chartist.js 0.9.5
* Copyright © 2015 Gion Kunz
* Free to use under the WTFPL license.
* http://www.wtfpl.net/
/* Chartist.js 0.9.6
* Copyright © 2016 Gion Kunz
* Free to use under either the WTFPL license or the MIT license.
* https://raw.githubusercontent.com/gionkunz/chartist-js/master/LICENSE-WTFPL
* https://raw.githubusercontent.com/gionkunz/chartist-js/master/LICENSE-MIT
*/
/**
* The core module of Chartist that is mainly providing static functions and higher level functions for chart modules.
@ -25,12 +26,26 @@
* @module Chartist.Core
*/
var Chartist = {
version: '0.9.5'
version: '0.9.6'
};
(function (window, document, Chartist) {
'use strict';
/**
* This object contains all namespaces used within Chartist.
*
* @memberof Chartist.Core
* @type {{svg: string, xmlns: string, xhtml: string, xlink: string, ct: string}}
*/
Chartist.namespaces = {
svg: 'http://www.w3.org/2000/svg',
xmlns: 'http://www.w3.org/2000/xmlns/',
xhtml: 'http://www.w3.org/1999/xhtml',
xlink: 'http://www.w3.org/1999/xlink',
ct: 'http://gionkunz.github.com/chartist-js/ct'
};
/**
* Helps to simplify functional style code
*
@ -311,7 +326,7 @@ var Chartist = {
// Check if there is a previous SVG element in the container that contains the Chartist XML namespace and remove it
// Since the DOM API does not support namespaces we need to manually search the returned list http://www.w3.org/TR/selectors-api/
Array.prototype.slice.call(container.querySelectorAll('svg')).filter(function filterChartistSvgObjects(svg) {
return svg.getAttributeNS('http://www.w3.org/2000/xmlns/', Chartist.xmlNs.prefix);
return svg.getAttributeNS(Chartist.namespaces.xmlns, 'ct');
}).forEach(function removePreviousElement(svg) {
container.removeChild(svg);
});
@ -330,6 +345,44 @@ var Chartist = {
return svg;
};
/**
* Ensures that the data object passed as second argument to the charts is present and correctly initialized.
*
* @param {Object} data The data object that is passed as second argument to the charts
* @return {Object} The normalized data object
*/
Chartist.normalizeData = function(data) {
// Ensure data is present otherwise enforce
data = data || {series: [], labels: []};
data.series = data.series || [];
data.labels = data.labels || [];
// Check if we should generate some labels based on existing series data
if (data.series.length > 0 && data.labels.length === 0) {
var normalized = Chartist.getDataArray(data),
labelCount;
// If all elements of the normalized data array are arrays we're dealing with
// data from Bar or Line charts and we need to find the largest series if they are un-even
if (normalized.every(function(value) {
return value instanceof Array;
})) {
// Getting the series with the the most elements
labelCount = Math.max.apply(null, normalized.map(function(series) {
return series.length;
}));
} else {
// We're dealing with Pie data so we just take the normalized array length
labelCount = normalized.length;
}
// Setting labels to an array with emptry strings using our labelCount estimated above
data.labels = Chartist.times(labelCount).map(function() {
return '';
});
}
return data;
};
/**
* Reverses the series, labels and series data arrays.
@ -532,9 +585,13 @@ var Chartist = {
} else if (highLow.low < 0) {
// If we have the same negative value for the bounds we set bounds.high to 0
highLow.high = 0;
} else {
} else if (highLow.high > 0) {
// If we have the same positive value for the bounds we set bounds.low to 0
highLow.low = 0;
} else {
// If data array was empty, values are Number.MAX_VALUE and -Number.MAX_VALUE. Set bounds to prevent errors
highLow.high = 1;
highLow.low = 0;
}
}
@ -1158,10 +1215,13 @@ var Chartist = {
// This is necessary to treat "holes" in line charts
var segments = splitIntoSegments(pathCoordinates, valueData);
// If the split resulted in more that one segment we need to interpolate each segment individually and join them
// afterwards together into a single path.
if(segments.length > 1) {
var paths = [];
if(!segments.length) {
// If there were no segments return 'Chartist.Interpolation.none'
return Chartist.Interpolation.none()([]);
} else if(segments.length > 1) {
// If the split resulted in more that one segment we need to interpolate each segment individually and join them
// afterwards together into a single path.
var paths = [];
// For each segment we will recurse the cardinal function
segments.forEach(function(segment) {
paths.push(cardinal(segment.pathCoordinates, segment.valueData));
@ -1677,16 +1737,6 @@ var Chartist = {
(function(window, document, Chartist) {
'use strict';
var svgNs = 'http://www.w3.org/2000/svg',
xmlNs = 'http://www.w3.org/2000/xmlns/',
xhtmlNs = 'http://www.w3.org/1999/xhtml';
Chartist.xmlNs = {
qualifiedName: 'xmlns:ct',
prefix: 'ct',
uri: 'http://gionkunz.github.com/chartist-js/ct'
};
/**
* Chartist.Svg creates a new SVG object wrapper with a starting element. You can use the wrapper to fluently create sub-elements and modify them.
*
@ -1703,11 +1753,13 @@ var Chartist = {
if(name instanceof Element) {
this._node = name;
} else {
this._node = document.createElementNS(svgNs, name);
this._node = document.createElementNS(Chartist.namespaces.svg, name);
// If this is an SVG element created then custom namespace
if(name === 'svg') {
this._node.setAttributeNS(xmlNs, Chartist.xmlNs.qualifiedName, Chartist.xmlNs.uri);
this.attr({
'xmlns:ct': Chartist.namespaces.ct
});
}
}
@ -1733,7 +1785,7 @@ var Chartist = {
*
* @memberof Chartist.Svg
* @param {Object|String} attributes An object with properties that will be added as attributes to the SVG element that is created. Attributes with undefined values will not be added. If this parameter is a String then the function is used as a getter and will return the attribute value.
* @param {String} ns If specified, the attributes will be set as namespace attributes with ns as prefix.
* @param {String} ns If specified, the attribute will be obtained using getAttributeNs. In order to write namepsaced attributes you can use the namespace:attribute notation within the attributes object.
* @return {Object|String} The current wrapper object will be returned so it can be used for chaining or the attribute value if used as getter function.
*/
function attr(attributes, ns) {
@ -1751,8 +1803,9 @@ var Chartist = {
return;
}
if(ns) {
this._node.setAttributeNS(ns, [Chartist.xmlNs.prefix, ':', key].join(''), attributes[key]);
if (key.indexOf(':') !== -1) {
var namespacedAttribute = key.split(':');
this._node.setAttributeNS(Chartist.namespaces[namespacedAttribute[0]], key, attributes[key]);
} else {
this._node.setAttribute(key, attributes[key]);
}
@ -1843,7 +1896,7 @@ var Chartist = {
}
// Adding namespace to content element
content.setAttribute('xmlns', xhtmlNs);
content.setAttribute('xmlns', Chartist.namespaces.xmlns);
// Creating the foreignObject without required extension attribute (as described here
// http://www.w3.org/TR/SVG/extend.html#ForeignObjectElement)
@ -1981,43 +2034,23 @@ var Chartist = {
}
/**
* "Save" way to get property value from svg BoundingBox.
* This is a workaround. Firefox throws an NS_ERROR_FAILURE error if getBBox() is called on an invisible node.
* See [NS_ERROR_FAILURE: Component returned failure code: 0x80004005](http://jsfiddle.net/sym3tri/kWWDK/)
*
* @memberof Chartist.Svg
* @param {SVGElement} node The svg node to
* @param {String} prop The property to fetch (ex.: height, width, ...)
* @returns {Number} The value of the given bbox property
*/
function getBBoxProperty(node, prop) {
try {
return node.getBBox()[prop];
} catch(e) {}
return 0;
}
/**
* Get element height with fallback to svg BoundingBox or parent container dimensions:
* See [bugzilla.mozilla.org](https://bugzilla.mozilla.org/show_bug.cgi?id=530985)
* Get element height using `getBoundingClientRect`
*
* @memberof Chartist.Svg
* @return {Number} The elements height in pixels
*/
function height() {
return this._node.clientHeight || Math.round(getBBoxProperty(this._node, 'height')) || this._node.parentNode.clientHeight;
return this._node.getBoundingClientRect().height;
}
/**
* Get element width with fallback to svg BoundingBox or parent container dimensions:
* See [bugzilla.mozilla.org](https://bugzilla.mozilla.org/show_bug.cgi?id=530985)
* Get element width using `getBoundingClientRect`
*
* @memberof Chartist.Core
* @return {Number} The elements width in pixels
*/
function width() {
return this._node.clientWidth || Math.round(getBBoxProperty(this._node, 'width')) || this._node.parentNode.clientWidth;
return this._node.getBoundingClientRect().width;
}
/**
@ -2725,7 +2758,7 @@ var Chartist = {
}
// Skip grid lines and labels where interpolated label values are falsey (execpt for 0)
if(!labelValues[index] && labelValues[index] !== 0) {
if(!Chartist.isFalseyButZero(labelValues[index]) && !labelValues[index] === '') {
return;
}
@ -3042,6 +3075,7 @@ var Chartist = {
*
*/
function createChart(options) {
this.data = Chartist.normalizeData(this.data);
var data = {
raw: this.data,
normalized: Chartist.getDataArray(this.data, options.reverseData, true)
@ -3084,9 +3118,9 @@ var Chartist = {
// Write attributes to series group element. If series name or meta is undefined the attributes will not be written
seriesElement.attr({
'series-name': series.name,
'meta': Chartist.serialize(series.meta)
}, Chartist.xmlNs.uri);
'ct:series-name': series.name,
'ct:meta': Chartist.serialize(series.meta)
});
// Use series class from series data or if not set generate one
seriesElement.addClass([
@ -3136,11 +3170,9 @@ var Chartist = {
x2: pathElement.x + 0.01,
y2: pathElement.y
}, options.classNames.point).attr({
'value': [pathElement.data.value.x, pathElement.data.value.y].filter(function(v) {
return v;
}).join(','),
'meta': pathElement.data.meta
}, Chartist.xmlNs.uri);
'ct:value': [pathElement.data.value.x, pathElement.data.value.y].filter(Chartist.isNum).join(','),
'ct:meta': pathElement.data.meta
});
this.eventEmitter.emit('draw', {
type: 'point',
@ -3214,9 +3246,7 @@ var Chartist = {
// and adding the created DOM elements to the correct series group
var area = seriesElement.elem('path', {
d: areaPath.stringify()
}, options.classNames.area, true).attr({
'values': data.normalized[seriesIndex]
}, Chartist.xmlNs.uri);
}, options.classNames.area, true);
// Emit an event for each area that was drawn
this.eventEmitter.emit('draw', {
@ -3410,8 +3440,6 @@ var Chartist = {
high: undefined,
// Overriding the natural low of the chart allows you to zoom in or limit the charts lowest displayed value
low: undefined,
// Use only integer values (whole numbers) for the scale steps
onlyInteger: false,
// Padding of the chart drawing area to the container element and labels as a number or padding object {top: 5, right: 5, bottom: 5, left: 5}
chartPadding: {
top: 15,
@ -3454,6 +3482,7 @@ var Chartist = {
*
*/
function createChart(options) {
this.data = Chartist.normalizeData(this.data);
var data = {
raw: this.data,
normalized: options.distributeSeries ? Chartist.getDataArray(this.data, options.reverseData, options.horizontalBars ? 'x' : 'y').map(function(value) {
@ -3476,15 +3505,15 @@ var Chartist = {
var seriesGroup = this.svg.elem('g');
var labelGroup = this.svg.elem('g').addClass(options.classNames.labelGroup);
if(options.stackBars) {
if(options.stackBars && data.normalized.length !== 0) {
// If stacked bars we need to calculate the high low from stacked values from each series
var serialSums = Chartist.serialMap(data.normalized, function serialSums() {
return Array.prototype.slice.call(arguments).map(function(value) {
return value;
}).reduce(function(prev, curr) {
return {
x: prev.x + curr.x || 0,
y: prev.y + curr.y || 0
x: prev.x + (curr && curr.x) || 0,
y: prev.y + (curr && curr.y) || 0
};
}, {x: 0, y: 0});
});
@ -3600,9 +3629,9 @@ var Chartist = {
// Write attributes to series group element. If series name or meta is undefined the attributes will not be written
seriesElement.attr({
'series-name': series.name,
'meta': Chartist.serialize(series.meta)
}, Chartist.xmlNs.uri);
'ct:series-name': series.name,
'ct:meta': Chartist.serialize(series.meta)
});
// Use series class from series data or if not set generate one
seriesElement.addClass([
@ -3691,11 +3720,9 @@ var Chartist = {
// Create bar element
bar = seriesElement.elem('line', positions, options.classNames.bar).attr({
'value': [value.x, value.y].filter(function(v) {
return v;
}).join(','),
'meta': Chartist.getMetaData(series, valueIndex)
}, Chartist.xmlNs.uri);
'ct:value': [value.x, value.y].filter(Chartist.isNum).join(','),
'ct:meta': Chartist.getMetaData(series, valueIndex)
});
this.eventEmitter.emit('draw', Chartist.extend({
type: 'bar',
@ -3826,7 +3853,9 @@ var Chartist = {
// Label direction can be 'neutral', 'explode' or 'implode'. The labels anchor will be positioned based on those settings as well as the fact if the labels are on the right or left side of the center of the chart. Usually explode is useful when labels are positioned far away from the center.
labelDirection: 'neutral',
// If true the whole data is reversed including labels, the series order as well as the whole series data arrays.
reverseData: false
reverseData: false,
// If true empty values will be ignored to avoid drawing unncessary slices and labels
ignoreEmptyValues: false
};
/**
@ -3857,6 +3886,7 @@ var Chartist = {
* @param options
*/
function createChart(options) {
this.data = Chartist.normalizeData(this.data);
var seriesGroups = [],
labelsGroup,
chartRect,
@ -3921,13 +3951,16 @@ var Chartist = {
// Draw the series
// initialize series groups
for (var i = 0; i < this.data.series.length; i++) {
// If current value is zero and we are ignoring empty values then skip to next value
if (dataArray[i] === 0 && options.ignoreEmptyValues) continue;
var series = this.data.series[i];
seriesGroups[i] = this.svg.elem('g', null, null, true);
// If the series is an object and contains a name or meta data we add a custom attribute
seriesGroups[i].attr({
'series-name': series.name
}, Chartist.xmlNs.uri);
'ct:series-name': series.name
});
// Use series class from series data or if not set generate one
seriesGroups[i].addClass([
@ -3936,13 +3969,17 @@ var Chartist = {
].join(' '));
var endAngle = startAngle + dataArray[i] / totalDataSum * 360;
// Use slight offset so there are no transparent hairline issues
var overlappigStartAngle = Math.max(0, startAngle - (i === 0 || hasSingleValInSeries ? 0 : 0.2));
// If we need to draw the arc for all 360 degrees we need to add a hack where we close the circle
// with Z and use 359.99 degrees
if(endAngle - startAngle === 360) {
endAngle -= 0.01;
if(endAngle - overlappigStartAngle >= 359.99) {
endAngle = overlappigStartAngle + 359.99;
}
var start = Chartist.polarToCartesian(center.x, center.y, radius, startAngle - (i === 0 || hasSingleValInSeries ? 0 : 0.2)),
var start = Chartist.polarToCartesian(center.x, center.y, radius, overlappigStartAngle),
end = Chartist.polarToCartesian(center.x, center.y, radius, endAngle);
// Create a new path element for the pie chart. If this isn't a donut chart we should close the path for a correct stroke
@ -3963,9 +4000,9 @@ var Chartist = {
// Adding the pie series value to the path
pathElement.attr({
'value': dataArray[i],
'meta': Chartist.serialize(series.meta)
}, Chartist.xmlNs.uri);
'ct:value': dataArray[i],
'ct:meta': Chartist.serialize(series.meta)
});
// If this is a donut, we add the stroke-width as style attribute
if(options.donut) {
@ -3995,7 +4032,7 @@ var Chartist = {
if(options.showLabel) {
// Position at the labelRadius distance from center and between start and end angle
var labelPosition = Chartist.polarToCartesian(center.x, center.y, labelRadius, startAngle + (endAngle - startAngle) / 2),
interpolatedValue = options.labelInterpolationFnc(this.data.labels ? this.data.labels[i] : dataArray[i], i);
interpolatedValue = options.labelInterpolationFnc(this.data.labels && !Chartist.isFalseyButZero(this.data.labels[i]) ? this.data.labels[i] : dataArray[i], i);
if(interpolatedValue || interpolatedValue === 0) {
var labelElement = labelsGroup.elem('text', {
@ -4017,7 +4054,7 @@ var Chartist = {
}
}
// Set next startAngle to current endAngle. Use slight offset so there are no transparent hairline issues
// Set next startAngle to current endAngle.
// (except for last slice)
startAngle = endAngle;
}

13
dist/chartist.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
"name": "chartist",
"title": "Chartist.js",
"description": "Simple, responsive charts",
"version": "0.9.5",
"version": "0.9.6",
"author": "Gion Kunz",
"homepage": "https://gionkunz.github.io/chartist-js",
"repository": {
@ -30,7 +30,11 @@
"licenses": [
{
"type": "WTFPL",
"url": "https://github.com/gionkunz/chartist-js/blob/master/LICENSE"
"url": "https://github.com/gionkunz/chartist-js/blob/master/LICENSE-WTFPL"
},
{
"type": "MIT",
"url": "https://github.com/gionkunz/chartist-js/blob/master/LICENSE-MIT"
}
],
"dependencies": {},
@ -72,7 +76,7 @@
"test": "grunt test"
},
"config": {
"banner": "/* Chartist.js <%= pkg.version %>\n * Copyright © <%= year %> Gion Kunz\n * Free to use under the WTFPL license.\n * http://www.wtfpl.net/\n */\n",
"banner": "/* Chartist.js <%= pkg.version %>\n * Copyright © <%= year %> Gion Kunz\n * Free to use under either the WTFPL license or the MIT license.\n * https://raw.githubusercontent.com/gionkunz/chartist-js/master/LICENSE-WTFPL\n * https://raw.githubusercontent.com/gionkunz/chartist-js/master/LICENSE-MIT\n */\n",
"src": "src",
"dist": "dist",
"site": "site",