@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/chart",
3
- "version": "2.81.10",
3
+ "version": "2.82.0",
4
4
  "description": "hpcc-js - Viz Chart",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es6",
@@ -78,5 +78,5 @@
78
78
  "url": "https://github.com/hpcc-systems/Visualization/issues"
79
79
  },
80
80
  "homepage": "https://github.com/hpcc-systems/Visualization",
81
- "gitHead": "6a9c3dabbcea36fec7d25461ca3149c4846926da"
81
+ "gitHead": "58c474637fb65e0e0f7b22601b283df5fc77f0bd"
82
82
  }
package/src/Column.ts CHANGED
@@ -19,6 +19,7 @@ export class Column extends XYAxis {
19
19
 
20
20
  protected _linearGap: number;
21
21
  private textLocal = d3Local<Text>();
22
+ private stackedTextLocal = d3Local<Text>();
22
23
  private isHorizontal: boolean;
23
24
 
24
25
  constructor() {
@@ -111,34 +112,29 @@ export class Column extends XYAxis {
111
112
  .paddingInner(this.xAxisSeriesPaddingInner())
112
113
  .paddingOuter(0)
113
114
  ;
114
- const rowData = this.adjustedData(host);
115
115
  let domainSums = [];
116
116
  const seriesSums = [];
117
117
  const columnLength = this.columns().length;
118
- if (this.showValue()) {
119
- switch (this.showValueAsPercent()) {
120
- case "series":
121
- rowData.forEach((row) => {
122
- row.filter((_, idx) => idx > 0 && idx < columnLength).forEach((col, idx) => {
123
- if (seriesSums[idx + 1] === undefined) {
124
- seriesSums[idx + 1] = 0;
125
- }
126
- seriesSums[idx + 1] += col;
127
- });
118
+ const rowData = this.data();
119
+ if (this.showValue() && this.showValueAsPercent() === "series") {
120
+ rowData.forEach((row) => {
121
+ row.filter((_, idx) => idx > 0 && idx < columnLength).forEach((col, idx) => {
122
+ if (seriesSums[idx + 1] === undefined) {
123
+ seriesSums[idx + 1] = 0;
124
+ }
125
+ seriesSums[idx + 1] += col;
126
+ });
127
+ });
128
+ }
128
129
 
129
- });
130
- break;
131
- case "domain":
132
- domainSums = rowData.map(row => {
133
- return row.filter((cell, idx) => idx > 0 && idx < columnLength).reduce((sum, cell) => {
134
- return sum + cell;
135
- }, 0);
136
- });
137
- break;
138
- case null:
139
- default:
140
- }
130
+ if (this.showDomainTotal() || (this.showValue() && this.showValueAsPercent() === "domain")) {
131
+ domainSums = rowData.map(row => {
132
+ return row.filter((cell, idx) => idx > 0 && idx < columnLength).reduce((sum, cell) => {
133
+ return sum + cell;
134
+ }, 0);
135
+ });
141
136
  }
137
+
142
138
  const column = element.selectAll(".dataRow")
143
139
  .data(this.adjustedData(host))
144
140
  ;
@@ -209,7 +205,7 @@ export class Column extends XYAxis {
209
205
  valueText = d3Format(context.showValueAsPercentFormat())(valueText / seriesSum);
210
206
  break;
211
207
  case "domain":
212
- const domainSum = typeof dm.sum !== "undefined" ? dm.sum : domainSums[d.idx];
208
+ const domainSum = typeof dm.sum !== "undefined" ? dm.sum : domainSums[d.idx - 1];
213
209
  valueText = d3Format(context.showValueAsPercentFormat())(valueText / domainSum);
214
210
  break;
215
211
  case null:
@@ -360,7 +356,7 @@ export class Column extends XYAxis {
360
356
  ...then ASSUME THERES ROOM ON THE OPPOSITE SIDE
361
357
  */
362
358
  if (isHorizontal) { // Column
363
- noRoomInside = dataRect.height < textSize.height;
359
+ noRoomInside = context.yAxisStacked() ? false : dataRect.height < textSize.height;
364
360
  isOutside = !context.valueCentered() || noRoomInside;
365
361
 
366
362
  pos.x = dataRect.x + (dataRect.width / 2);
@@ -395,8 +391,7 @@ export class Column extends XYAxis {
395
391
  pos.y = dataRect.y + (dataRect.height / 2);
396
392
  }
397
393
  } else { // Bar
398
-
399
- noRoomInside = dataRect.width < textSize.width;
394
+ noRoomInside = context.yAxisStacked() ? false : dataRect.width < textSize.width;
400
395
  isOutside = !context.valueCentered() || noRoomInside;
401
396
 
402
397
  pos.y = dataRect.y + (dataRect.height / 2);
@@ -460,6 +455,59 @@ export class Column extends XYAxis {
460
455
  .style("opacity", 0)
461
456
  .remove()
462
457
  ;
458
+
459
+ const value4pos = host.yAxisStacked() ? domainSums[dataRowIdx] : Math.max(...dataRow.filter((_, idx) => idx > 0 && idx < columnLength));
460
+ const stackedTotalText = element.selectAll(".stackedTotalText").data(context.showDomainTotal() ? [domainSums[dataRowIdx]] : []);
461
+ const stackedTotalTextEnter = stackedTotalText.enter().append("g")
462
+ .attr("class", "stackedTotalText")
463
+ .each(function (this: SVGElement, d) {
464
+ context.stackedTextLocal.set(this, new Text().target(this).colorStroke_default("transparent"));
465
+ });
466
+ stackedTotalTextEnter.merge(stackedTotalText as any)
467
+ .each(function (this: SVGElement, d: any) {
468
+ const pos = { x: 0, y: 0 };
469
+ const domainPos = host.dataPos(dataRow[0]);
470
+ const valuePos = host.valuePos(value4pos);
471
+
472
+ const valueFontFamily = context.valueFontFamily();
473
+ const valueFontSize = context.valueFontSize();
474
+ const textSize = context.textSize(d, valueFontFamily, valueFontSize);
475
+
476
+ const isPositive = parseFloat(d) >= 0;
477
+ let valueAnchor: "start" | "middle" | "end" = "middle";
478
+ if (isHorizontal) {
479
+ pos.x = domainPos;
480
+ if (isPositive) {
481
+ pos.y = valuePos - textSize.height / 2;
482
+ } else {
483
+ pos.y = valuePos + textSize.height / 2;
484
+ }
485
+ } else {
486
+ valueAnchor = "start";
487
+ pos.y = domainPos;
488
+ if (isPositive) {
489
+ pos.x = valuePos + textSize.width / 2;
490
+ } else {
491
+ pos.x = valuePos - textSize.width / 2;
492
+ }
493
+ }
494
+
495
+ context.stackedTextLocal.get(this)
496
+ .pos(pos)
497
+ .anchor(valueAnchor)
498
+ .fontFamily(valueFontFamily)
499
+ .fontSize(valueFontSize)
500
+ .text(d)
501
+ .render()
502
+ ;
503
+
504
+ });
505
+ stackedTotalText.exit()
506
+ .each(function (this: SVGElement, d) {
507
+ context.textLocal.get(this).target(null);
508
+ })
509
+ .remove()
510
+ ;
463
511
  });
464
512
  column.exit().transition().duration(duration)
465
513
  .remove()
@@ -554,6 +602,8 @@ export interface Column {
554
602
  showValueAsPercent(_: null | "series" | "domain"): this;
555
603
  showValueAsPercentFormat(): string;
556
604
  showValueAsPercentFormat(_: string): this;
605
+ showDomainTotal(): boolean;
606
+ showDomainTotal(_: boolean): this;
557
607
  valueCentered(): boolean;
558
608
  valueCentered(_: boolean): this;
559
609
  valueAnchor(): "start" | "middle" | "end";
@@ -589,6 +639,7 @@ Column.prototype.publish("showInnerText", false, "boolean", "Show Label in colum
589
639
  Column.prototype.publish("showValueFormat", ",", "string", "D3 Format for Value", null, { disable: (w: Column) => !w.showValue() || !!w.showValueAsPercent() });
590
640
  Column.prototype.publish("showValueAsPercent", null, "set", "If showValue is true, optionally show value as a percentage by Series or Domain", [null, "series", "domain"], { disable: w => !w.showValue(), optional: true });
591
641
  Column.prototype.publish("showValueAsPercentFormat", ".0%", "string", "D3 Format for %", null, { disable: (w: Column) => !w.showValue() || !w.showValueAsPercent() });
642
+ Column.prototype.publish("showDomainTotal", false, "boolean", "Show Total Value for Stacked Columns", null);
592
643
  Column.prototype.publish("valueCentered", false, "boolean", "Show Value in center of column");
593
644
  Column.prototype.publish("valueAnchor", "middle", "set", "text-anchor for shown value text", ["start", "middle", "end"]);
594
645
  Column.prototype.publish("xAxisSeriesPaddingInner", 0, "number", "Determines the ratio of the range that is reserved for blank space between band (0->1)");
@@ -1,3 +1,3 @@
1
1
  export const PKG_NAME = "@hpcc-js/chart";
2
- export const PKG_VERSION = "2.81.10";
3
- export const BUILD_VERSION = "2.104.37";
2
+ export const PKG_VERSION = "2.82.0";
3
+ export const BUILD_VERSION = "2.105.0";