Compare commits

..

7 Commits

Author SHA1 Message Date
softsimon
12dbdf369f Update package.json 2020-11-10 20:56:03 +07:00
softsimon
fc52299b2b
Merge pull request #1 from TechMiX/lineStackMode
add stackedLine option to line chart
2020-11-10 20:30:59 +07:00
TechMiX
0089b61b54 add stackedLine option to line chart 2020-11-10 13:35:18 +01:00
Gion Kunz
e7e78201bf
Merge pull request #1195 from dannyvankooten/develop
Bugfix: only calculate high low from stacked values if stackMode is accumulate
2019-11-01 22:04:36 +01:00
Danny van Kooten
6288745b3b only calculate high low from stacked values if stackMode is set to accumulate 2019-10-28 15:45:15 +01:00
Gion Kunz
de6345e2e4
Update FUNDING.yml 2019-10-25 13:11:51 +02:00
Gion Kunz
682ff28543
Create FUNDING.yml 2019-10-25 13:10:39 +02:00
9 changed files with 55 additions and 14 deletions

3
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,3 @@
# These are supported funding model platforms
github: gionkunz

27
dist/chartist.js vendored
View File

@ -15,7 +15,7 @@
}(this, function () { }(this, function () {
/* Chartist.js 0.11.4 /* Chartist.js 0.11.4
* Copyright © 2019 Gion Kunz * Copyright © 2020 Gion Kunz
* Free to use under either the WTFPL license or the MIT license. * 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-WTFPL
* https://raw.githubusercontent.com/gionkunz/chartist-js/master/LICENSE-MIT * https://raw.githubusercontent.com/gionkunz/chartist-js/master/LICENSE-MIT
@ -3326,6 +3326,8 @@ var Chartist = {
showPoint: true, showPoint: true,
// If the line chart should draw an area // If the line chart should draw an area
showArea: false, showArea: false,
// If the line chart series should be stacked
stackedLine: false,
// The base for the area chart that will be used to close the area shape (is normally 0) // The base for the area chart that will be used to close the area shape (is normally 0)
areaBase: 0, areaBase: 0,
// Specify if the lines should be smoothed. This value can be true or false where true will result in smoothing using the default smoothing interpolation function Chartist.Interpolation.cardinal and false results in Chartist.Interpolation.none. You can also choose other smoothing / interpolation functions available in the Chartist.Interpolation module, or write your own interpolation function. Check the examples for a brief description. // Specify if the lines should be smoothed. This value can be true or false where true will result in smoothing using the default smoothing interpolation function Chartist.Interpolation.cardinal and false results in Chartist.Interpolation.none. You can also choose other smoothing / interpolation functions available in the Chartist.Interpolation module, or write your own interpolation function. Check the examples for a brief description.
@ -3371,7 +3373,23 @@ var Chartist = {
* *
*/ */
function createChart(options) { function createChart(options) {
var data = Chartist.normalizeData(this.data, options.reverseData, true);
var dataToNormalize = this.data;
if (options.stackedLine) {
var dataCopy = JSON.parse(JSON.stringify(this.data));
for (var i=0; i<this.data.series.length; i++) {
dataCopy.series[i].className = this.data.series[i].className;
}
for (var i=1; i<dataCopy.series.length; i++) {
for (var j=0; j<dataCopy.series[i].length; j++) {
dataCopy.series[i][j] += dataCopy.series[i-1][j];
}
}
dataCopy.series.reverse();
dataToNormalize = dataCopy;
}
var data = Chartist.normalizeData(dataToNormalize, options.reverseData, true);
// Create new svg object // Create new svg object
this.svg = Chartist.createSvg(this.container, options.width, options.height, options.classNames.chart); this.svg = Chartist.createSvg(this.container, options.width, options.height, options.classNames.chart);
@ -3419,9 +3437,10 @@ var Chartist = {
}); });
// Use series class from series data or if not set generate one // Use series class from series data or if not set generate one
var relativeSeriesIndex = options.stackedLine? data.raw.series.length - 1 - seriesIndex : seriesIndex;
seriesElement.addClass([ seriesElement.addClass([
options.classNames.series, options.classNames.series,
(series.className || options.classNames.series + '-' + Chartist.alphaNumerate(seriesIndex)) (series.className || options.classNames.series + '-' + Chartist.alphaNumerate(relativeSeriesIndex))
].join(' ')); ].join(' '));
var pathCoordinates = [], var pathCoordinates = [],
@ -3812,7 +3831,7 @@ var Chartist = {
var seriesGroup = this.svg.elem('g'); var seriesGroup = this.svg.elem('g');
var labelGroup = this.svg.elem('g').addClass(options.classNames.labelGroup); var labelGroup = this.svg.elem('g').addClass(options.classNames.labelGroup);
if(options.stackBars && data.normalized.series.length !== 0) { if(options.stackBars && (options.stackMode === 'accumulate' || !options.stackMode) && data.normalized.series.length !== 0) {
// If stacked bars we need to calculate the high low from stacked values from each series // If stacked bars we need to calculate the high low from stacked values from each series
var serialSums = Chartist.serialMap(data.normalized.series, function serialSums() { var serialSums = Chartist.serialMap(data.normalized.series, function serialSums() {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "chartist", "name": "chartist",
"version": "0.11.3", "version": "0.11.4",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,5 +1,5 @@
{ {
"name": "chartist", "name": "@mempool/chartist",
"title": "Chartist.js", "title": "Chartist.js",
"description": "Simple, responsive charts", "description": "Simple, responsive charts",
"version": "0.11.4", "version": "0.11.4",

View File

@ -140,7 +140,7 @@
var seriesGroup = this.svg.elem('g'); var seriesGroup = this.svg.elem('g');
var labelGroup = this.svg.elem('g').addClass(options.classNames.labelGroup); var labelGroup = this.svg.elem('g').addClass(options.classNames.labelGroup);
if(options.stackBars && data.normalized.series.length !== 0) { if(options.stackBars && (options.stackMode === 'accumulate' || !options.stackMode) && data.normalized.series.length !== 0) {
// If stacked bars we need to calculate the high low from stacked values from each series // If stacked bars we need to calculate the high low from stacked values from each series
var serialSums = Chartist.serialMap(data.normalized.series, function serialSums() { var serialSums = Chartist.serialMap(data.normalized.series, function serialSums() {

View File

@ -72,6 +72,8 @@
showPoint: true, showPoint: true,
// If the line chart should draw an area // If the line chart should draw an area
showArea: false, showArea: false,
// If the line chart series should be stacked
stackedLine: false,
// The base for the area chart that will be used to close the area shape (is normally 0) // The base for the area chart that will be used to close the area shape (is normally 0)
areaBase: 0, areaBase: 0,
// Specify if the lines should be smoothed. This value can be true or false where true will result in smoothing using the default smoothing interpolation function Chartist.Interpolation.cardinal and false results in Chartist.Interpolation.none. You can also choose other smoothing / interpolation functions available in the Chartist.Interpolation module, or write your own interpolation function. Check the examples for a brief description. // Specify if the lines should be smoothed. This value can be true or false where true will result in smoothing using the default smoothing interpolation function Chartist.Interpolation.cardinal and false results in Chartist.Interpolation.none. You can also choose other smoothing / interpolation functions available in the Chartist.Interpolation module, or write your own interpolation function. Check the examples for a brief description.
@ -117,7 +119,23 @@
* *
*/ */
function createChart(options) { function createChart(options) {
var data = Chartist.normalizeData(this.data, options.reverseData, true);
var dataToNormalize = this.data;
if (options.stackedLine) {
var dataCopy = JSON.parse(JSON.stringify(this.data));
for (var i=0; i<this.data.series.length; i++) {
dataCopy.series[i].className = this.data.series[i].className;
}
for (var i=1; i<dataCopy.series.length; i++) {
for (var j=0; j<dataCopy.series[i].length; j++) {
dataCopy.series[i][j] += dataCopy.series[i-1][j];
}
}
dataCopy.series.reverse();
dataToNormalize = dataCopy;
}
var data = Chartist.normalizeData(dataToNormalize, options.reverseData, true);
// Create new svg object // Create new svg object
this.svg = Chartist.createSvg(this.container, options.width, options.height, options.classNames.chart); this.svg = Chartist.createSvg(this.container, options.width, options.height, options.classNames.chart);
@ -165,9 +183,10 @@
}); });
// Use series class from series data or if not set generate one // Use series class from series data or if not set generate one
var relativeSeriesIndex = options.stackedLine? data.raw.series.length - 1 - seriesIndex : seriesIndex;
seriesElement.addClass([ seriesElement.addClass([
options.classNames.series, options.classNames.series,
(series.className || options.classNames.series + '-' + Chartist.alphaNumerate(seriesIndex)) (series.className || options.classNames.series + '-' + Chartist.alphaNumerate(relativeSeriesIndex))
].join(' ')); ].join(' '));
var pathCoordinates = [], var pathCoordinates = [],