Carga
Carga
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
import U from '../../Core/Utilities.js';
|
||||
var defined = U.defined, relativeLength = U.relativeLength;
|
||||
var SankeyColumnComposition;
|
||||
(function (SankeyColumnComposition) {
|
||||
/* *
|
||||
*
|
||||
* Declarations
|
||||
*
|
||||
* */
|
||||
/**
|
||||
* SankeyColumn Composition
|
||||
* @private
|
||||
* @function Highcharts.SankeyColumn#compose
|
||||
*
|
||||
* @param {Array<SankeyPoint>} points
|
||||
* The array of nodes
|
||||
* @param {SankeySeries} series
|
||||
* Series connected to column
|
||||
* @return {ArrayComposition} SankeyColumnArray
|
||||
*/
|
||||
function compose(points, series) {
|
||||
var sankeyColumnArray = points;
|
||||
sankeyColumnArray.sankeyColumn =
|
||||
new SankeyColumnAdditions(sankeyColumnArray, series);
|
||||
return sankeyColumnArray;
|
||||
}
|
||||
SankeyColumnComposition.compose = compose;
|
||||
/* *
|
||||
*
|
||||
* Classes
|
||||
*
|
||||
* */
|
||||
var SankeyColumnAdditions = /** @class */ (function () {
|
||||
function SankeyColumnAdditions(points, series) {
|
||||
this.points = points;
|
||||
this.series = series;
|
||||
}
|
||||
/**
|
||||
* Calculate translation factor used in column and nodes distribution
|
||||
* @private
|
||||
* @function Highcharts.SankeyColumn#getTranslationFactor
|
||||
*
|
||||
* @param {SankeySeries} series
|
||||
* The Series
|
||||
* @return {number} TranslationFactor
|
||||
* Translation Factor
|
||||
*/
|
||||
SankeyColumnAdditions.prototype.getTranslationFactor = function (series) {
|
||||
var column = this.points, nodes = column.slice(), chart = series.chart, minLinkWidth = series.options.minLinkWidth || 0;
|
||||
var skipPoint, factor = 0, i, remainingHeight = ((chart.plotSizeY || 0) -
|
||||
(series.options.borderWidth || 0) -
|
||||
(column.length - 1) * series.nodePadding);
|
||||
// Because the minLinkWidth option doesn't obey the direct
|
||||
// translation, we need to run translation iteratively, check
|
||||
// node heights, remove those nodes affected by minLinkWidth,
|
||||
// check again, etc.
|
||||
while (column.length) {
|
||||
factor = remainingHeight / column.sankeyColumn.sum();
|
||||
skipPoint = false;
|
||||
i = column.length;
|
||||
while (i--) {
|
||||
if (column[i].getSum() * factor < minLinkWidth) {
|
||||
column.splice(i, 1);
|
||||
remainingHeight -= minLinkWidth;
|
||||
skipPoint = true;
|
||||
}
|
||||
}
|
||||
if (!skipPoint) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Re-insert original nodes
|
||||
column.length = 0;
|
||||
nodes.forEach(function (node) {
|
||||
column.push(node);
|
||||
});
|
||||
return factor;
|
||||
};
|
||||
/**
|
||||
* Get the top position of the column in pixels
|
||||
* @private
|
||||
* @function Highcharts.SankeyColumn#top
|
||||
*
|
||||
* @param {number} factor
|
||||
* The Translation Factor
|
||||
* @return {number} top
|
||||
* The top position of the column
|
||||
*/
|
||||
SankeyColumnAdditions.prototype.top = function (factor) {
|
||||
var series = this.series;
|
||||
var nodePadding = series.nodePadding;
|
||||
var height = this.points.reduce(function (height, node) {
|
||||
if (height > 0) {
|
||||
height += nodePadding;
|
||||
}
|
||||
var nodeHeight = Math.max(node.getSum() * factor, series.options.minLinkWidth || 0);
|
||||
height += nodeHeight;
|
||||
return height;
|
||||
}, 0);
|
||||
return ((series.chart.plotSizeY || 0) - height) / 2;
|
||||
};
|
||||
/**
|
||||
* Get the left position of the column in pixels
|
||||
* @private
|
||||
* @function Highcharts.SankeyColumn#top
|
||||
*
|
||||
* @param {number} factor
|
||||
* The Translation Factor
|
||||
* @return {number} left
|
||||
* The left position of the column
|
||||
*/
|
||||
SankeyColumnAdditions.prototype.left = function (factor) {
|
||||
var series = this.series, chart = series.chart, equalNodes = series.options.equalNodes;
|
||||
var maxNodesLength = chart.inverted ?
|
||||
chart.plotHeight : chart.plotWidth, nodePadding = series.nodePadding;
|
||||
var width = this.points.reduce(function (width, node) {
|
||||
if (width > 0) {
|
||||
width += nodePadding;
|
||||
}
|
||||
var nodeWidth = equalNodes ?
|
||||
maxNodesLength / node.series.nodes.length - nodePadding :
|
||||
Math.max(node.getSum() * factor, series.options.minLinkWidth || 0);
|
||||
width += nodeWidth;
|
||||
return width;
|
||||
}, 0);
|
||||
return ((chart.plotSizeX || 0) - Math.round(width)) / 2;
|
||||
};
|
||||
/**
|
||||
* Calculate sum of all nodes inside specific column
|
||||
* @private
|
||||
* @function Highcharts.SankeyColumn#sum
|
||||
*
|
||||
* @param {ArrayComposition} this
|
||||
* Sankey Column Array
|
||||
*
|
||||
* @return {number} sum
|
||||
* Sum of all nodes inside column
|
||||
*/
|
||||
SankeyColumnAdditions.prototype.sum = function () {
|
||||
return this.points.reduce(function (sum, node) {
|
||||
return sum + node.getSum();
|
||||
}, 0);
|
||||
};
|
||||
/**
|
||||
* Get the offset in pixels of a node inside the column
|
||||
* @private
|
||||
* @function Highcharts.SankeyColumn#offset
|
||||
*
|
||||
* @param {SankeyPoint} node
|
||||
* Sankey node
|
||||
* @param {number} factor
|
||||
* Translation Factor
|
||||
* @return {number} offset
|
||||
* Offset of a node inside column
|
||||
*/
|
||||
SankeyColumnAdditions.prototype.offset = function (node, factor) {
|
||||
var column = this.points, series = this.series, nodePadding = series.nodePadding;
|
||||
var offset = 0, totalNodeOffset;
|
||||
if (series.is('organization') && node.hangsFrom) {
|
||||
return {
|
||||
absoluteTop: node.hangsFrom.nodeY
|
||||
};
|
||||
}
|
||||
for (var i = 0; i < column.length; i++) {
|
||||
var sum = column[i].getSum();
|
||||
var height = Math.max(sum * factor, series.options.minLinkWidth || 0);
|
||||
var directionOffset = node.options[series.chart.inverted ?
|
||||
'offsetHorizontal' :
|
||||
'offsetVertical'], optionOffset = node.options.offset || 0;
|
||||
if (sum) {
|
||||
totalNodeOffset = height + nodePadding;
|
||||
}
|
||||
else {
|
||||
// If node sum equals 0 nodePadding is missed #12453
|
||||
totalNodeOffset = 0;
|
||||
}
|
||||
if (column[i] === node) {
|
||||
return {
|
||||
relativeTop: offset + (defined(directionOffset) ?
|
||||
// directionOffset is a percent
|
||||
// of the node height
|
||||
relativeLength(directionOffset, height) :
|
||||
relativeLength(optionOffset, totalNodeOffset))
|
||||
};
|
||||
}
|
||||
offset += totalNodeOffset;
|
||||
}
|
||||
};
|
||||
return SankeyColumnAdditions;
|
||||
}());
|
||||
SankeyColumnComposition.SankeyColumnAdditions = SankeyColumnAdditions;
|
||||
})(SankeyColumnComposition || (SankeyColumnComposition = {}));
|
||||
export default SankeyColumnComposition;
|
||||
@@ -0,0 +1,135 @@
|
||||
/* *
|
||||
*
|
||||
* Sankey diagram module
|
||||
*
|
||||
* (c) 2010-2021 Torstein Honsi
|
||||
*
|
||||
* License: www.highcharts.com/license
|
||||
*
|
||||
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
|
||||
*
|
||||
* */
|
||||
'use strict';
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import Point from '../../Core/Series/Point.js';
|
||||
import SeriesRegistry from '../../Core/Series/SeriesRegistry.js';
|
||||
var ColumnSeries = SeriesRegistry.seriesTypes.column;
|
||||
import U from '../../Core/Utilities.js';
|
||||
var defined = U.defined;
|
||||
/* *
|
||||
*
|
||||
* Class
|
||||
*
|
||||
* */
|
||||
var SankeyPoint = /** @class */ (function (_super) {
|
||||
__extends(SankeyPoint, _super);
|
||||
function SankeyPoint() {
|
||||
/* *
|
||||
*
|
||||
* Properties
|
||||
*
|
||||
* */
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.className = void 0;
|
||||
_this.fromNode = void 0;
|
||||
_this.level = void 0;
|
||||
_this.linkBase = void 0;
|
||||
_this.linksFrom = void 0;
|
||||
_this.linksTo = void 0;
|
||||
_this.mass = void 0;
|
||||
_this.nodeX = void 0;
|
||||
_this.nodeY = void 0;
|
||||
_this.options = void 0;
|
||||
_this.series = void 0;
|
||||
_this.toNode = void 0;
|
||||
return _this;
|
||||
/* eslint-enable valid-jsdoc */
|
||||
}
|
||||
/* *
|
||||
*
|
||||
* Functions
|
||||
*
|
||||
* */
|
||||
/* eslint-disable valid-jsdoc */
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
SankeyPoint.prototype.applyOptions = function (options, x) {
|
||||
Point.prototype.applyOptions.call(this, options, x);
|
||||
// Treat point.level as a synonym of point.column
|
||||
if (defined(this.options.level)) {
|
||||
this.options.column = this.column = this.options.level;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
SankeyPoint.prototype.getClassName = function () {
|
||||
return (this.isNode ? 'highcharts-node ' : 'highcharts-link ') +
|
||||
Point.prototype.getClassName.call(this);
|
||||
};
|
||||
/**
|
||||
* If there are incoming links, place it to the right of the
|
||||
* highest order column that links to this one.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
SankeyPoint.prototype.getFromNode = function () {
|
||||
var node = this;
|
||||
var fromColumn = -1, fromNode;
|
||||
for (var i = 0; i < node.linksTo.length; i++) {
|
||||
var point = node.linksTo[i];
|
||||
if (point.fromNode.column > fromColumn &&
|
||||
point.fromNode !== node // #16080
|
||||
) {
|
||||
fromNode = point.fromNode;
|
||||
fromColumn = fromNode.column;
|
||||
}
|
||||
}
|
||||
return { fromNode: fromNode, fromColumn: fromColumn };
|
||||
};
|
||||
/**
|
||||
* Calculate node.column if it's not set by user
|
||||
* @private
|
||||
*/
|
||||
SankeyPoint.prototype.setNodeColumn = function () {
|
||||
var node = this;
|
||||
if (!defined(node.options.column)) {
|
||||
// No links to this node, place it left
|
||||
if (node.linksTo.length === 0) {
|
||||
node.column = 0;
|
||||
}
|
||||
else {
|
||||
node.column = node.getFromNode().fromColumn + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
SankeyPoint.prototype.isValid = function () {
|
||||
return this.isNode || typeof this.weight === 'number';
|
||||
};
|
||||
return SankeyPoint;
|
||||
}(ColumnSeries.prototype.pointClass));
|
||||
/* *
|
||||
*
|
||||
* Default Export
|
||||
*
|
||||
* */
|
||||
export default SankeyPoint;
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user