@hpcc-js/chart 2.81.10 → 2.82.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5,8 +5,8 @@
5
5
  })(this, (function (exports, api, common, util) { 'use strict';
6
6
 
7
7
  var PKG_NAME = "@hpcc-js/chart";
8
- var PKG_VERSION = "2.81.10";
9
- var BUILD_VERSION = "2.104.37";
8
+ var PKG_VERSION = "2.82.0";
9
+ var BUILD_VERSION = "2.105.0";
10
10
 
11
11
  /******************************************************************************
12
12
  Copyright (c) Microsoft Corporation.
@@ -2934,6 +2934,7 @@
2934
2934
  function Column() {
2935
2935
  var _this = _super.call(this) || this;
2936
2936
  _this.textLocal = common.local();
2937
+ _this.stackedTextLocal = common.local();
2937
2938
  api.INDChart.call(_this);
2938
2939
  api.ITooltip.call(_this);
2939
2940
  _this._selection.skipBringToTop(true);
@@ -3014,30 +3015,26 @@
3014
3015
  .rangeRound(isHorizontal ? [0, dataLen] : [dataLen, 0])
3015
3016
  .paddingInner(this.xAxisSeriesPaddingInner())
3016
3017
  .paddingOuter(0);
3017
- var rowData = this.adjustedData(host);
3018
3018
  var domainSums = [];
3019
3019
  var seriesSums = [];
3020
3020
  var columnLength = this.columns().length;
3021
- if (this.showValue()) {
3022
- switch (this.showValueAsPercent()) {
3023
- case "series":
3024
- rowData.forEach(function (row) {
3025
- row.filter(function (_, idx) { return idx > 0 && idx < columnLength; }).forEach(function (col, idx) {
3026
- if (seriesSums[idx + 1] === undefined) {
3027
- seriesSums[idx + 1] = 0;
3028
- }
3029
- seriesSums[idx + 1] += col;
3030
- });
3031
- });
3032
- break;
3033
- case "domain":
3034
- domainSums = rowData.map(function (row) {
3035
- return row.filter(function (cell, idx) { return idx > 0 && idx < columnLength; }).reduce(function (sum, cell) {
3036
- return sum + cell;
3037
- }, 0);
3038
- });
3039
- break;
3040
- }
3021
+ var rowData = this.data();
3022
+ if (this.showValue() && this.showValueAsPercent() === "series") {
3023
+ rowData.forEach(function (row) {
3024
+ row.filter(function (_, idx) { return idx > 0 && idx < columnLength; }).forEach(function (col, idx) {
3025
+ if (seriesSums[idx + 1] === undefined) {
3026
+ seriesSums[idx + 1] = 0;
3027
+ }
3028
+ seriesSums[idx + 1] += col;
3029
+ });
3030
+ });
3031
+ }
3032
+ if (this.showDomainTotal() || (this.showValue() && this.showValueAsPercent() === "domain")) {
3033
+ domainSums = rowData.map(function (row) {
3034
+ return row.filter(function (cell, idx) { return idx > 0 && idx < columnLength; }).reduce(function (sum, cell) {
3035
+ return sum + cell;
3036
+ }, 0);
3037
+ });
3041
3038
  }
3042
3039
  var column = element.selectAll(".dataRow")
3043
3040
  .data(this.adjustedData(host));
@@ -3102,7 +3099,7 @@
3102
3099
  valueText = common.format(context.showValueAsPercentFormat())(valueText / seriesSum);
3103
3100
  break;
3104
3101
  case "domain":
3105
- var domainSum = typeof dm.sum !== "undefined" ? dm.sum : domainSums[d.idx];
3102
+ var domainSum = typeof dm.sum !== "undefined" ? dm.sum : domainSums[d.idx - 1];
3106
3103
  valueText = common.format(context.showValueAsPercentFormat())(valueText / domainSum);
3107
3104
  break;
3108
3105
  case null:
@@ -3233,7 +3230,7 @@
3233
3230
  ...then ASSUME THERES ROOM ON THE OPPOSITE SIDE
3234
3231
  */
3235
3232
  if (isHorizontal) { // Column
3236
- noRoomInside = dataRect.height < textSize.height;
3233
+ noRoomInside = context.yAxisStacked() ? false : dataRect.height < textSize.height;
3237
3234
  isOutside = !context.valueCentered() || noRoomInside;
3238
3235
  pos.x = dataRect.x + (dataRect.width / 2);
3239
3236
  if (isOutside) {
@@ -3273,7 +3270,7 @@
3273
3270
  }
3274
3271
  }
3275
3272
  else { // Bar
3276
- noRoomInside = dataRect.width < textSize.width;
3273
+ noRoomInside = context.yAxisStacked() ? false : dataRect.width < textSize.width;
3277
3274
  isOutside = !context.valueCentered() || noRoomInside;
3278
3275
  pos.y = dataRect.y + (dataRect.height / 2);
3279
3276
  if (isOutside) {
@@ -3336,6 +3333,55 @@
3336
3333
  columnGRect.exit().transition().duration(duration)
3337
3334
  .style("opacity", 0)
3338
3335
  .remove();
3336
+ var value4pos = host.yAxisStacked() ? domainSums[dataRowIdx] : Math.max.apply(Math, dataRow.filter(function (_, idx) { return idx > 0 && idx < columnLength; }));
3337
+ var stackedTotalText = element.selectAll(".stackedTotalText").data(context.showDomainTotal() ? [domainSums[dataRowIdx]] : []);
3338
+ var stackedTotalTextEnter = stackedTotalText.enter().append("g")
3339
+ .attr("class", "stackedTotalText")
3340
+ .each(function (d) {
3341
+ context.stackedTextLocal.set(this, new common.Text().target(this).colorStroke_default("transparent"));
3342
+ });
3343
+ stackedTotalTextEnter.merge(stackedTotalText)
3344
+ .each(function (d) {
3345
+ var pos = { x: 0, y: 0 };
3346
+ var domainPos = host.dataPos(dataRow[0]);
3347
+ var valuePos = host.valuePos(value4pos);
3348
+ var valueFontFamily = context.valueFontFamily();
3349
+ var valueFontSize = context.valueFontSize();
3350
+ var textSize = context.textSize(d, valueFontFamily, valueFontSize);
3351
+ var isPositive = parseFloat(d) >= 0;
3352
+ var valueAnchor = "middle";
3353
+ if (isHorizontal) {
3354
+ pos.x = domainPos;
3355
+ if (isPositive) {
3356
+ pos.y = valuePos - textSize.height / 2;
3357
+ }
3358
+ else {
3359
+ pos.y = valuePos + textSize.height / 2;
3360
+ }
3361
+ }
3362
+ else {
3363
+ valueAnchor = "start";
3364
+ pos.y = domainPos;
3365
+ if (isPositive) {
3366
+ pos.x = valuePos + textSize.width / 2;
3367
+ }
3368
+ else {
3369
+ pos.x = valuePos - textSize.width / 2;
3370
+ }
3371
+ }
3372
+ context.stackedTextLocal.get(this)
3373
+ .pos(pos)
3374
+ .anchor(valueAnchor)
3375
+ .fontFamily(valueFontFamily)
3376
+ .fontSize(valueFontSize)
3377
+ .text(d)
3378
+ .render();
3379
+ });
3380
+ stackedTotalText.exit()
3381
+ .each(function (d) {
3382
+ context.textLocal.get(this).target(null);
3383
+ })
3384
+ .remove();
3339
3385
  });
3340
3386
  column.exit().transition().duration(duration)
3341
3387
  .remove();
@@ -3422,6 +3468,7 @@
3422
3468
  Column.prototype.publish("showValueFormat", ",", "string", "D3 Format for Value", null, { disable: function (w) { return !w.showValue() || !!w.showValueAsPercent(); } });
3423
3469
  Column.prototype.publish("showValueAsPercent", null, "set", "If showValue is true, optionally show value as a percentage by Series or Domain", [null, "series", "domain"], { disable: function (w) { return !w.showValue(); }, optional: true });
3424
3470
  Column.prototype.publish("showValueAsPercentFormat", ".0%", "string", "D3 Format for %", null, { disable: function (w) { return !w.showValue() || !w.showValueAsPercent(); } });
3471
+ Column.prototype.publish("showDomainTotal", false, "boolean", "Show Total Value for Stacked Columns", null);
3425
3472
  Column.prototype.publish("valueCentered", false, "boolean", "Show Value in center of column");
3426
3473
  Column.prototype.publish("valueAnchor", "middle", "set", "text-anchor for shown value text", ["start", "middle", "end"]);
3427
3474
  Column.prototype.publish("xAxisSeriesPaddingInner", 0, "number", "Determines the ratio of the range that is reserved for blank space between band (0->1)");