@@ -19548,7 +19548,7 @@ exports.default = function (d, defaultTitleFormat, defaultValueFormat, color) {
19548
19548
var name = nameFormat(d[i].name);
19549
19549
var value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index);
19550
19550
var bgcolor = this.levelColor ? this.levelColor(d[i].value) : color(d[i].id);
19551
- if (value) {
19551
+ if (value && !isNaN(value) ) {
19552
19552
text += "<tr class='" + this.CLASS.tooltipName + "-" + d[i].id + "'>";
19553
19553
if (name.indexOf('__tooltip_ignore_name_field__') === -1) {
19554
19554
text += "<td class='name'><span style='background-color:" + bgcolor + "'></span>" + (0, _escapeHtml.escapeHtml)(name) + "</td>";
@@ -20044,6 +20044,26 @@ function defineC3() {
20044
20044
20045
20045
var options = getDefaultOptions.call(this);
20046
20046
20047
+ // 100% for charts
20048
+ var sumArray = calculateSumForPercents(this.dataset.matrix);
20049
+ var oldMatrix = [];
20050
+ if (options.stacking === 'percent' && (type === 'bar' || type === 'horizontal-bar' || type === 'area' || type === 'area-step' || type === 'area-spline')) {
20051
+ oldMatrix = this.dataset.matrix;
20052
+ this.dataset.matrix = [this.dataset.matrix[0]].concat(_toConsumableArray(calculatePercents(this.dataset.matrix, sumArray)));
20053
+ options.axis = {
20054
+ y: {
20055
+ padding: {
20056
+ top: 0
20057
+ },
20058
+ tick: {
20059
+ format: function format(d) {
20060
+ return d + '%';
20061
+ }
20062
+ }
20063
+ }
20064
+ };
20065
+ }
20066
+
20047
20067
if (!!this.config.clearOnRender && options.data.columns.length > 0) {
20048
20068
options.data.columns.splice(1);
20049
20069
}
@@ -20140,6 +20160,7 @@ function defineC3() {
20140
20160
}
20141
20161
20142
20162
if (!(options.tooltip && options.tooltip.show === false) && (options.legend.show === true || options.legend && options.legend.tooltip && options.legend.tooltip.show)) {
20163
+
20143
20164
// Apply custom tooltip
20144
20165
options.tooltip = {
20145
20166
contents: _tooltipContents2.default,
@@ -20149,6 +20170,16 @@ function defineC3() {
20149
20170
var valueFormatted = c3CustomTooltipFiltering.call(_this, _value, ratio, id, index);
20150
20171
if (_this.config.tooltip && _this.config.tooltip.format && _this.config.tooltip.format.value) {
20151
20172
valueFormatted = _this.config.tooltip.format.value.call(_this, valueFormatted, ratio, id, index);
20173
+ // Restore value from percents calculation for stacking 100% charts
20174
+ if (options.stacking === 'percent' && (type === 'bar' || type === 'horizontal-bar' || type === 'area' || type === 'area-step' || type === 'area-spline')) {
20175
+ valueFormatted = parseFloat((valueFormatted / 100 * sumArray[index]).toFixed(2));
20176
+ }
20177
+ return valueFormatted;
20178
+ }
20179
+ // Restore value from percents calculation for stacking 100% charts
20180
+ if (options.stacking === 'percent' && (type === 'bar' || type === 'horizontal-bar' || type === 'area' || type === 'area-step' || type === 'area-spline')) {
20181
+ valueFormatted = (valueFormatted / 100 * sumArray[index]).toFixed(2);
20182
+ return parseFloat(valueFormatted);
20152
20183
}
20153
20184
return valueFormatted;
20154
20185
}
@@ -20250,6 +20281,35 @@ function bindResizeListener(fn) {
20250
20281
}
20251
20282
}
20252
20283
20284
+ function calculateSumForPercents(matrix) {
20285
+ var sumArray = [];
20286
+ matrix.slice(1).forEach(function (d, i) {
20287
+ d.forEach(function (e) {
20288
+ if (typeof e === 'number') {
20289
+ if (!sumArray[i]) {
20290
+ sumArray[i] = e;
20291
+ return sumArray[i];
20292
+ }
20293
+ sumArray[i] += e;
20294
+ }
20295
+ return sumArray[i];
20296
+ });
20297
+ });
20298
+ return sumArray;
20299
+ }
20300
+
20301
+ function calculatePercents(matrix, sumArray) {
20302
+ var newValues = matrix.slice(1).map(function (d, i) {
20303
+ return d.map(function (e) {
20304
+ if (typeof e === 'number') {
20305
+ return e / sumArray[i] * 100;
20306
+ }
20307
+ return e;
20308
+ });
20309
+ });
20310
+ return newValues;
20311
+ }
20312
+
20253
20313
/***/ }),
20254
20314
/* 155 */
20255
20315
/***/ (function(module, exports, __webpack_require__) {
@@ -20489,7 +20549,7 @@ function getDefaultType(parser) {
20489
20549
/* 156 */
20490
20550
/***/ (function(module) {
20491
20551
20492
- module.exports = {"name":"keen-dataviz","description":"Data Visualization SDK for Keen IO","license":"MIT","version":"3.3.2","main":"dist/external_d3_c3/node/keen-dataviz.js","browser":"dist/external_d3_c3/keen-dataviz.js","style":"dist/keen-dataviz.css","scripts":{"start":"concurrently --kill-others \"NODE_ENV=development webpack-dev-server\" \"npm run postcss-watch\"","postcss-watch":"node_modules/postcss-cli/bin/postcss lib/style/keen-dataviz-c3.css -o test/demo/keen-dataviz.css --watch --config postcss.config.js","build":"NODE_ENV=production webpack -p && npm run build:css && NODE_ENV=production OPTIMIZE_MINIMIZE=1 webpack -p && npm run build:css && npm run build:css:min && npm run build:external_d3_c3 && npm run build:external_d3_c3:css && npm run build:external_d3_c3:css:min && npm run build:node","build:css":"node_modules/postcss-cli/bin/postcss lib/style/keen-dataviz-c3.css -o dist/keen-dataviz.css --config postcss.config.js","build:css:min":"OPTIMIZE_MINIMIZE=1 node_modules/postcss-cli/bin/postcss lib/style/keen-dataviz-c3.css -o dist/keen-dataviz.min.css --config postcss.config.js","build:external_d3_c3:css":"node_modules/postcss-cli/bin/postcss lib/style/keen-dataviz.css -o dist/external_d3_c3/keen-dataviz.css --config postcss.config.js","build:external_d3_c3:css:min":"OPTIMIZE_MINIMIZE=1 node_modules/postcss-cli/bin/postcss lib/style/keen-dataviz.css -o dist/external_d3_c3/keen-dataviz.min.css --config postcss.config.js","build:external_d3_c3":"NODE_ENV=production EXTERNAL_D3_C3=1 webpack -p && NODE_ENV=production EXTERNAL_D3_C3=1 OPTIMIZE_MINIMIZE=1 webpack -p","build:node":"TARGET=node NODE_ENV=production EXTERNAL_D3_C3=1 webpack -p","profile":"webpack --profile --json > stats.json","analyze":"webpack-bundle-analyzer stats.json /dist","version":"npm run build && git add .","postversion":"git push && git push --tags","test":"NODE_ENV=test jest","test:watch":"NODE_ENV=test jest --watch"},"repository":{"type":"git","url":"https://github.com/keen/keen-dataviz.js.git"},"bugs":"https://github.com/keen/keen-dataviz.js/issues","author":"Keen.IO <
[email protected] > (https://keen.io/)","contributors":["Dustin Larimer <
[email protected] > (https://github.com/dustinlarimer)","Joanne Cheng <
[email protected] > (https://github.com/joannecheng)","Eric Anderson <
[email protected] > (https://github.com/aroc)","Joe Wegner <
[email protected] > (https://github.com/josephwegner)","Sara Falkoff <
[email protected] (https://github.com/sfalkoff)","Adam Kasprowicz <
[email protected] > (https://github.com/adamkasprowicz)","Dariusz Łacheta <
[email protected] > (https://github.com/dariuszlacheta)"],"homepage":"https://keen.io","keywords":["d3","c3","Analytics","Stats","Statistics","Visualization","Visualizations","Data Visualization","Chart","Charts","Charting","Svg","Dataviz","Plots","Graphs","Funnels"],"dependencies":{"c3":"^0.6.12","d3":"^5.4.0","moment-timezone":"^0.5.21","promise-polyfill":"^8.0.0"},"devDependencies":{"autoprefixer":"^8.2.0","babel-loader":"^7.1.4","babel-plugin-transform-es2015-modules-commonjs":"^6.26.2","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-preset-env":"^1.7.0","concurrently":"^3.5.1","cssnano":"^3.10.0","eslint":"^4.19.1","eslint-config-airbnb":"^16.1.0","eslint-loader":"^2.0.0","eslint-plugin-import":"^2.11.0","eslint-plugin-jsx-a11y":"^6.0.3","eslint-plugin-react":"^7.7.0","html-loader":"^0.5.5","html-webpack-plugin":"^3.2.0","jest":"^22.4.3","jest-environment-jsdom-c3":"^2.0.0","nock":"^9.2.6","postcss":"^6.0.21","postcss-cli":"^5.0.0","postcss-color-function":"^4.0.1","postcss-css-variables":"^0.8.1","postcss-cssnext":"^2.4.0","postcss-import":"^8.0.2","postcss-loader":"^2.1.3","precss":"^3.1.2","regenerator-runtime":"^0.11.1","replace-in-file":"^3.4.0","style-loader":"^0.20.3","webpack":"^4.5.0","webpack-bundle-analyzer":"^2.11.1","webpack-cli":"^2.0.13","webpack-dev-server":"^3.1.1","xhr-mock":"^2.3.2"}};
20552
+ module.exports = {"name":"keen-dataviz","description":"Data Visualization SDK for Keen IO","license":"MIT","version":"3.4.0","main":"dist/external_d3_c3/node/keen-dataviz.js","browser":"dist/external_d3_c3/keen-dataviz.js","style":"dist/keen-dataviz.css","scripts":{"start":"concurrently --kill-others \"NODE_ENV=development webpack-dev-server\" \"npm run postcss-watch\"","postcss-watch":"node_modules/postcss-cli/bin/postcss lib/style/keen-dataviz-c3.css -o test/demo/keen-dataviz.css --watch --config postcss.config.js","build":"NODE_ENV=production webpack -p && npm run build:css && NODE_ENV=production OPTIMIZE_MINIMIZE=1 webpack -p && npm run build:css && npm run build:css:min && npm run build:external_d3_c3 && npm run build:external_d3_c3:css && npm run build:external_d3_c3:css:min && npm run build:node","build:css":"node_modules/postcss-cli/bin/postcss lib/style/keen-dataviz-c3.css -o dist/keen-dataviz.css --config postcss.config.js","build:css:min":"OPTIMIZE_MINIMIZE=1 node_modules/postcss-cli/bin/postcss lib/style/keen-dataviz-c3.css -o dist/keen-dataviz.min.css --config postcss.config.js","build:external_d3_c3:css":"node_modules/postcss-cli/bin/postcss lib/style/keen-dataviz.css -o dist/external_d3_c3/keen-dataviz.css --config postcss.config.js","build:external_d3_c3:css:min":"OPTIMIZE_MINIMIZE=1 node_modules/postcss-cli/bin/postcss lib/style/keen-dataviz.css -o dist/external_d3_c3/keen-dataviz.min.css --config postcss.config.js","build:external_d3_c3":"NODE_ENV=production EXTERNAL_D3_C3=1 webpack -p && NODE_ENV=production EXTERNAL_D3_C3=1 OPTIMIZE_MINIMIZE=1 webpack -p","build:node":"TARGET=node NODE_ENV=production EXTERNAL_D3_C3=1 webpack -p","profile":"webpack --profile --json > stats.json","analyze":"webpack-bundle-analyzer stats.json /dist","version":"npm run build && git add .","postversion":"git push && git push --tags","test":"NODE_ENV=test jest","test:watch":"NODE_ENV=test jest --watch"},"repository":{"type":"git","url":"https://github.com/keen/keen-dataviz.js.git"},"bugs":"https://github.com/keen/keen-dataviz.js/issues","author":"Keen.IO <
[email protected] > (https://keen.io/)","contributors":["Dustin Larimer <
[email protected] > (https://github.com/dustinlarimer)","Joanne Cheng <
[email protected] > (https://github.com/joannecheng)","Eric Anderson <
[email protected] > (https://github.com/aroc)","Joe Wegner <
[email protected] > (https://github.com/josephwegner)","Sara Falkoff <
[email protected] (https://github.com/sfalkoff)","Adam Kasprowicz <
[email protected] > (https://github.com/adamkasprowicz)","Dariusz Łacheta <
[email protected] > (https://github.com/dariuszlacheta)"],"homepage":"https://keen.io","keywords":["d3","c3","Analytics","Stats","Statistics","Visualization","Visualizations","Data Visualization","Chart","Charts","Charting","Svg","Dataviz","Plots","Graphs","Funnels"],"dependencies":{"c3":"^0.6.12","d3":"^5.4.0","moment-timezone":"^0.5.21","promise-polyfill":"^8.0.0"},"devDependencies":{"autoprefixer":"^8.2.0","babel-loader":"^7.1.4","babel-plugin-transform-es2015-modules-commonjs":"^6.26.2","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-preset-env":"^1.7.0","concurrently":"^3.5.1","cssnano":"^3.10.0","eslint":"^4.19.1","eslint-config-airbnb":"^16.1.0","eslint-loader":"^2.0.0","eslint-plugin-import":"^2.11.0","eslint-plugin-jsx-a11y":"^6.0.3","eslint-plugin-react":"^7.7.0","html-loader":"^0.5.5","html-webpack-plugin":"^3.2.0","jest":"^22.4.3","jest-environment-jsdom-c3":"^2.0.0","nock":"^9.2.6","postcss":"^6.0.21","postcss-cli":"^5.0.0","postcss-color-function":"^4.0.1","postcss-css-variables":"^0.8.1","postcss-cssnext":"^2.4.0","postcss-import":"^8.0.2","postcss-loader":"^2.1.3","precss":"^3.1.2","regenerator-runtime":"^0.11.1","replace-in-file":"^3.4.0","style-loader":"^0.20.3","webpack":"^4.5.0","webpack-bundle-analyzer":"^2.11.1","webpack-cli":"^2.0.13","webpack-dev-server":"^3.1.1","xhr-mock":"^2.3.2"}};
20493
20553
20494
20554
/***/ }),
20495
20555
/* 157 */
@@ -21338,6 +21398,11 @@ var Dataviz = exports.Dataviz = function Dataviz() {
21338
21398
this.config.type = convertChartTypes(this.config.type);
21339
21399
}
21340
21400
21401
+ // overwriting stacked when stacking added
21402
+ if (this.config.stacking) {
21403
+ this.config.stacked = true;
21404
+ }
21405
+
21341
21406
// get DOM node by query
21342
21407
if (this.config.container) {
21343
21408
this.el(this.config.container);
0 commit comments