New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

d3plus-hierarchy

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3plus-hierarchy - npm Package Compare versions

Comparing version 0.8.6 to 0.8.7

2

build/d3plus-hierarchy.min.js
/*
d3plus-hierarchy v0.8.6
d3plus-hierarchy v0.8.7
Nested, hierarchical, and cluster charts built on D3

@@ -4,0 +4,0 @@ Copyright (c) 2019 D3plus - https://d3plus.org

@@ -5,2 +5,2 @@ export { default as Donut } from "./src/Donut";

export { default as Tree } from "./src/Tree";
export { default as Treemap } from "./src/Treemap";
export { default as Treemap } from "./src/Treemap";

@@ -0,1 +1,15 @@

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
import { min } from "d3-array";

@@ -9,3 +23,7 @@ import { default as Pie } from "./Pie";

export default class Donut extends Pie {
var Donut =
/*#__PURE__*/
function (_Pie) {
_inherits(Donut, _Pie);
/**

@@ -16,10 +34,20 @@ @memberof Donut

*/
constructor() {
super();
function Donut() {
var _this;
this._innerRadius = () => min([this._width - this._margin.left - this._margin.right, this._height - this._margin.top - this._margin.bottom]) / 4;
_classCallCheck(this, Donut);
this._padPixel = 2;
_this = _possibleConstructorReturn(this, _getPrototypeOf(Donut).call(this));
_this._innerRadius = function () {
return min([_this._width - _this._margin.left - _this._margin.right, _this._height - _this._margin.top - _this._margin.bottom]) / 4;
};
_this._padPixel = 2;
return _this;
}
}
return Donut;
}(Pie);
export { Donut as default };

@@ -11,7 +11,9 @@ import { nest } from "d3-collection";

if (!(keys instanceof Array)) keys = [keys];
const dataNest = nest();
var dataNest = nest();
for (let i = 0; i < keys.length; i++) dataNest.key(keys[i]);
for (var i = 0; i < keys.length; i++) {
dataNest.key(keys[i]);
}
const nestedData = dataNest.entries(data);
var nestedData = dataNest.entries(data);
return bubble(nestedData);

@@ -26,3 +28,3 @@ }

function bubble(values) {
return values.map(d => {
return values.map(function (d) {
if (d.key && d.values) {

@@ -29,0 +31,0 @@ if (d.values[0].key === "undefined") return d.values[0].values[0];else d.values = bubble(d.values);

@@ -0,1 +1,31 @@

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
/**

@@ -11,5 +41,7 @@ @external Viz

const recursionCircles = (d, arr = []) => {
var recursionCircles = function recursionCircles(d) {
var arr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
if (d.values) {
d.values.forEach(h => {
d.values.forEach(function (h) {
arr.push(h);

@@ -31,3 +63,7 @@ recursionCircles(h, arr);

export default class Pack extends Viz {
var Pack =
/*#__PURE__*/
function (_Viz) {
_inherits(Pack, _Viz);
/**

@@ -38,19 +74,28 @@ @memberof Pack

*/
constructor() {
super();
this._layoutPadding = 1;
function Pack() {
var _this;
this._on.mouseenter = () => {};
_classCallCheck(this, Pack);
const defaultMouseMoveLegend = this._on["mousemove.legend"];
_this = _possibleConstructorReturn(this, _getPrototypeOf(Pack).call(this));
_this._layoutPadding = 1;
this._on["mousemove.legend"] = (d, i) => {
_this._on.mouseenter = function () {};
var defaultMouseMoveLegend = _this._on["mousemove.legend"];
_this._on["mousemove.legend"] = function (d, i) {
defaultMouseMoveLegend(d, i);
const ids = this._ids(d, i);
var ids = _this._ids(d, i);
const hoverData = recursionCircles(d);
this.hover(h => {
const hover = Object.keys(h).filter(key => key !== "value").every(key => d[key] && d[key].includes(h[key]));
if (hover) hoverData.push(h);else if (ids.includes(h.key)) hoverData.push(...recursionCircles(h, [h]));
var hoverData = recursionCircles(d);
_this.hover(function (h) {
var hover = Object.keys(h).filter(function (key) {
return key !== "value";
}).every(function (key) {
return d[key] && d[key].includes(h[key]);
});
if (hover) hoverData.push(h);else if (ids.includes(h.key)) hoverData.push.apply(hoverData, _toConsumableArray(recursionCircles(h, [h])));
return hoverData.includes(h);

@@ -60,25 +105,35 @@ });

const defaultMouseMoveShape = this._on["mousemove.shape"];
var defaultMouseMoveShape = _this._on["mousemove.shape"];
this._on["mousemove.shape"] = (d, i) => {
_this._on["mousemove.shape"] = function (d, i) {
if (d.__d3plusTooltip__) defaultMouseMoveShape(d, i);
this.hover(h => recursionCircles(d, [d]).includes(h));
_this.hover(function (h) {
return recursionCircles(d, [d]).includes(h);
});
};
this._pack = pack();
this._packOpacity = constant(0.25);
this._shape = constant("Circle");
this._shapeConfig = assign(this._shapeConfig, {
_this._pack = pack();
_this._packOpacity = constant(0.25);
_this._shape = constant("Circle");
_this._shapeConfig = assign(_this._shapeConfig, {
Circle: {
label: d => d.parent && !d.children ? d.id : false,
label: function label(d) {
return d.parent && !d.children ? d.id : false;
},
labelConfig: {
fontResize: true
},
opacity: d => d.__d3plusOpacity__
opacity: function opacity(d) {
return d.__d3plusOpacity__;
}
}
});
this._sort = (a, b) => b.value - a.value;
_this._sort = function (a, b) {
return b.value - a.value;
};
this._sum = accessor("value");
_this._sum = accessor("value");
return _this;
}

@@ -91,105 +146,124 @@ /**

_draw(callback) {
super._draw(callback);
_createClass(Pack, [{
key: "_draw",
value: function _draw(callback) {
var _this2 = this;
const height = this._height - this._margin.top - this._margin.bottom,
_get(_getPrototypeOf(Pack.prototype), "_draw", this).call(this, callback);
var height = this._height - this._margin.top - this._margin.bottom,
width = this._width - this._margin.left - this._margin.right;
const diameter = Math.min(height, width);
const transform = `translate(${(width - diameter) / 2}, ${(height - diameter) / 2})`;
let nestedData = nest();
var diameter = Math.min(height, width);
var transform = "translate(".concat((width - diameter) / 2, ", ").concat((height - diameter) / 2, ")");
var nestedData = nest();
for (let i = 0; i <= this._drawDepth; i++) nestedData.key(this._groupBy[i]);
nestedData = nestedData.entries(this._filteredData);
const packData = this._pack.padding(this._layoutPadding).size([diameter, diameter])(hierarchy({
key: nestedData.key,
values: nestedData
}, d => d.values).sum(this._sum).sort(this._sort)).descendants();
packData.forEach((d, i) => {
d.__d3plus__ = true;
d.i = i;
d.id = d.parent ? d.parent.data.key : null;
d.data.__d3plusOpacity__ = d.height ? this._packOpacity(d.data, i) : 1;
d.data.__d3plusTooltip__ = !d.height ? true : false;
});
this._shapes.push(new Circle().data(packData).select(elem("g.d3plus-Pack", {
parent: this._select,
enter: {
transform
},
update: {
transform
for (var i = 0; i <= this._drawDepth; i++) {
nestedData.key(this._groupBy[i]);
}
}).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Circle")).render());
return this;
}
/**
@memberof Pack
@desc If *value* is specified, sets the hover method to the specified function and returns the current class instance.
@param {Function} [*value*]
@chainable
*/
nestedData = nestedData.entries(this._filteredData);
var packData = this._pack.padding(this._layoutPadding).size([diameter, diameter])(hierarchy({
key: nestedData.key,
values: nestedData
}, function (d) {
return d.values;
}).sum(this._sum).sort(this._sort)).descendants();
hover(_) {
this._hover = _;
packData.forEach(function (d, i) {
d.__d3plus__ = true;
d.i = i;
d.id = d.parent ? d.parent.data.key : null;
d.data.__d3plusOpacity__ = d.height ? _this2._packOpacity(d.data, i) : 1;
d.data.__d3plusTooltip__ = !d.height ? true : false;
});
this._shapes.forEach(s => s.hover(_));
this._shapes.push(new Circle().data(packData).select(elem("g.d3plus-Pack", {
parent: this._select,
enter: {
transform: transform
},
update: {
transform: transform
}
}).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Circle")).render());
if (this._legend) this._legendClass.hover(_);
return this;
}
/**
@memberof Pack
@desc If *value* is specified, sets the opacity accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current pack opacity accessor.
@param {Function|Number} [*value*]
*/
return this;
}
/**
@memberof Pack
@desc If *value* is specified, sets the hover method to the specified function and returns the current class instance.
@param {Function} [*value*]
@chainable
*/
}, {
key: "hover",
value: function hover(_) {
this._hover = _;
layoutPadding(_) {
return arguments.length ? (this._layoutPadding = _, this) : this._layoutPadding;
}
/**
@memberof Pack
@desc If *value* is specified, sets the padding accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current pack opacity accessor.
@param {Function|Number} [*value*]
*/
this._shapes.forEach(function (s) {
return s.hover(_);
});
if (this._legend) this._legendClass.hover(_);
return this;
}
/**
@memberof Pack
@desc If *value* is specified, sets the opacity accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current pack opacity accessor.
@param {Function|Number} [*value*]
*/
packOpacity(_) {
return arguments.length ? (this._packOpacity = typeof _ === "function" ? _ : constant(_), this) : this._packOpacity;
}
/**
@memberof Pack
@desc If *comparator* is specified, sets the sort order for the pack using the specified comparator function. If *comparator* is not specified, returns the current group sort order, which defaults to descending order by the associated input data's numeric value attribute.
@param {Array} [*comparator*]
@example
function comparator(a, b) {
return b.value - a.value;
}
*/
}, {
key: "layoutPadding",
value: function layoutPadding(_) {
return arguments.length ? (this._layoutPadding = _, this) : this._layoutPadding;
}
/**
@memberof Pack
@desc If *value* is specified, sets the padding accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current pack opacity accessor.
@param {Function|Number} [*value*]
*/
}, {
key: "packOpacity",
value: function packOpacity(_) {
return arguments.length ? (this._packOpacity = typeof _ === "function" ? _ : constant(_), this) : this._packOpacity;
}
/**
@memberof Pack
@desc If *comparator* is specified, sets the sort order for the pack using the specified comparator function. If *comparator* is not specified, returns the current group sort order, which defaults to descending order by the associated input data's numeric value attribute.
@param {Array} [*comparator*]
@example
function comparator(a, b) {
return b.value - a.value;
}
*/
sort(_) {
return arguments.length ? (this._sort = _, this) : this._sort;
}
/**
@memberof Pack
@desc If *value* is specified, sets the sum accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current sum accessor.
@param {Function|Number} [*value*]
@example
function sum(d) {
return d.sum;
}
*/
}, {
key: "sort",
value: function sort(_) {
return arguments.length ? (this._sort = _, this) : this._sort;
}
/**
@memberof Pack
@desc If *value* is specified, sets the sum accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current sum accessor.
@param {Function|Number} [*value*]
@example
function sum(d) {
return d.sum;
}
*/
}, {
key: "sum",
value: function sum(_) {
return arguments.length ? (this._sum = typeof _ === "function" ? _ : accessor(_), this) : this._sum;
}
}]);
sum(_) {
return arguments.length ? (this._sum = typeof _ === "function" ? _ : accessor(_), this) : this._sum;
}
return Pack;
}(Viz);
}
export { Pack as default };

@@ -0,1 +1,23 @@

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
import { min } from "d3-array";

@@ -12,3 +34,7 @@ import { arc, pie } from "d3-shape";

export default class Pie extends Viz {
var Pie =
/*#__PURE__*/
function (_Viz) {
_inherits(Pie, _Viz);
/**

@@ -19,6 +45,12 @@ @memberof Pie

*/
constructor() {
super();
this._shapeConfig = assign(this._shapeConfig, {
ariaLabel: (d, i) => this._pieData ? `${++this._pieData[i].index}. ${this._drawLabel(d, i)}, ${this._value(d, i)}.` : "",
function Pie() {
var _this;
_classCallCheck(this, Pie);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Pie).call(this));
_this._shapeConfig = assign(_this._shapeConfig, {
ariaLabel: function ariaLabel(d, i) {
return _this._pieData ? "".concat(++_this._pieData[i].index, ". ").concat(_this._drawLabel(d, i), ", ").concat(_this._value(d, i), ".") : "";
},
Path: {

@@ -30,12 +62,17 @@ labelConfig: {

});
this._innerRadius = 0;
_this._innerRadius = 0;
this._legendSort = (a, b) => this._value(b) - this._value(a);
_this._legendSort = function (a, b) {
return _this._value(b) - _this._value(a);
};
this._padPixel = 0;
this._pie = pie();
_this._padPixel = 0;
_this._pie = pie();
this._sort = (a, b) => this._value(b) - this._value(a);
_this._sort = function (a, b) {
return _this._value(b) - _this._value(a);
};
this._value = accessor("value");
_this._value = accessor("value");
return _this;
}

@@ -48,93 +85,108 @@ /**

_draw(callback) {
super._draw(callback);
_createClass(Pie, [{
key: "_draw",
value: function _draw(callback) {
var _this2 = this;
const height = this._height - this._margin.top - this._margin.bottom,
_get(_getPrototypeOf(Pie.prototype), "_draw", this).call(this, callback);
var height = this._height - this._margin.top - this._margin.bottom,
width = this._width - this._margin.left - this._margin.right;
const outerRadius = min([width, height]) / 2;
var outerRadius = min([width, height]) / 2;
const pieData = this._pieData = this._pie.padAngle(this._padAngle || this._padPixel / outerRadius).sort(this._sort).value(this._value)(this._filteredData);
var pieData = this._pieData = this._pie.padAngle(this._padAngle || this._padPixel / outerRadius).sort(this._sort).value(this._value)(this._filteredData);
pieData.forEach((d, i) => {
d.__d3plus__ = true;
d.i = i;
});
const arcData = arc().innerRadius(this._innerRadius).outerRadius(outerRadius);
const transform = `translate(${width / 2 + this._margin.left}, ${height / 2 + this._margin.top})`;
pieData.forEach(function (d, i) {
d.__d3plus__ = true;
d.i = i;
});
var arcData = arc().innerRadius(this._innerRadius).outerRadius(outerRadius);
var transform = "translate(".concat(width / 2 + this._margin.left, ", ").concat(height / 2 + this._margin.top, ")");
this._shapes.push(new Path().data(pieData).d(arcData).select(elem("g.d3plus-Pie", {
parent: this._select,
enter: {
transform
},
update: {
transform
}
}).node()).config({
id: d => this._ids(d).join("-"),
x: 0,
y: 0
}).label(this._drawLabel).config(configPrep.bind(this)(this._shapeConfig, "shape", "Path")).render());
this._shapes.push(new Path().data(pieData).d(arcData).select(elem("g.d3plus-Pie", {
parent: this._select,
enter: {
transform: transform
},
update: {
transform: transform
}
}).node()).config({
id: function id(d) {
return _this2._ids(d).join("-");
},
x: 0,
y: 0
}).label(this._drawLabel).config(configPrep.bind(this)(this._shapeConfig, "shape", "Path")).render());
return this;
}
/**
@memberof Pie
@desc If *value* is specified, sets the inner radius accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current inner radius accessor.
@param {Function|Number} [*value*]
*/
return this;
}
/**
@memberof Pie
@desc If *value* is specified, sets the inner radius accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current inner radius accessor.
@param {Function|Number} [*value*]
*/
}, {
key: "innerRadius",
value: function innerRadius(_) {
return arguments.length ? (this._innerRadius = _, this) : this._innerRadius;
}
/**
@memberof Pie
@desc If *value* is specified, sets the arc padding to the specified radian value and returns the current class instance. If *value* is not specified, returns the current radian padding.
@param {Number} [*value*]
*/
innerRadius(_) {
return arguments.length ? (this._innerRadius = _, this) : this._innerRadius;
}
/**
@memberof Pie
@desc If *value* is specified, sets the arc padding to the specified radian value and returns the current class instance. If *value* is not specified, returns the current radian padding.
@param {Number} [*value*]
*/
}, {
key: "padAngle",
value: function padAngle(_) {
return arguments.length ? (this._padAngle = _, this) : this._padAngle;
}
/**
@memberof Pie
@desc If *value* is specified, sets the arc padding to the specified pixel value and returns the current class instance. If *value* is not specified, returns the current pixel padding.
@param {Number} [*value*]
*/
}, {
key: "padPixel",
value: function padPixel(_) {
return arguments.length ? (this._padPixel = _, this) : this._padPixel;
}
/**
@memberof Pie
@desc If *comparator* is specified, sets the sort order for the pie slices using the specified comparator function. If *comparator* is not specified, returns the current sort order, which defaults to descending order by the associated input data's numeric value attribute.
@param {Array} [*comparator*]
@example
function comparator(a, b) {
return b.value - a.value;
}
*/
padAngle(_) {
return arguments.length ? (this._padAngle = _, this) : this._padAngle;
}
/**
@memberof Pie
@desc If *value* is specified, sets the arc padding to the specified pixel value and returns the current class instance. If *value* is not specified, returns the current pixel padding.
@param {Number} [*value*]
*/
}, {
key: "sort",
value: function sort(_) {
return arguments.length ? (this._sort = _, this) : this._sort;
}
/**
@memberof Pie
@desc If *value* is specified, sets the value accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current value accessor.
@param {Function|String} *value*
@example
function value(d) {
return d.value;
}
*/
}, {
key: "value",
value: function value(_) {
return arguments.length ? (this._value = typeof _ === "function" ? _ : accessor(_), this) : this._value;
}
}]);
padPixel(_) {
return arguments.length ? (this._padPixel = _, this) : this._padPixel;
}
/**
@memberof Pie
@desc If *comparator* is specified, sets the sort order for the pie slices using the specified comparator function. If *comparator* is not specified, returns the current sort order, which defaults to descending order by the associated input data's numeric value attribute.
@param {Array} [*comparator*]
@example
function comparator(a, b) {
return b.value - a.value;
}
*/
return Pie;
}(Viz);
sort(_) {
return arguments.length ? (this._sort = _, this) : this._sort;
}
/**
@memberof Pie
@desc If *value* is specified, sets the value accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current value accessor.
@param {Function|String} *value*
@example
function value(d) {
return d.value;
}
*/
value(_) {
return arguments.length ? (this._value = typeof _ === "function" ? _ : accessor(_), this) : this._value;
}
}
export { Pie as default };

@@ -0,1 +1,25 @@

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
import { extent, min, max } from "d3-array";

@@ -14,3 +38,7 @@ import { hierarchy, tree } from "d3-hierarchy";

export default class Tree extends Viz {
var Tree =
/*#__PURE__*/
function (_Viz) {
_inherits(Tree, _Viz);
/**

@@ -21,11 +49,19 @@ @memberof Tree

*/
constructor() {
super();
this._orient = "vertical";
function Tree() {
var _this;
this._separation = (a, b) => a.parent === b.parent ? 1 : 2;
_classCallCheck(this, Tree);
this._shape = constant("Circle");
this._shapeConfig = assign(this._shapeConfig, {
ariaLabel: (d, i) => this._treeData ? `${this._treeData[i].depth}. ${this._drawLabel(d, i)}.` : "",
_this = _possibleConstructorReturn(this, _getPrototypeOf(Tree).call(this));
_this._orient = "vertical";
_this._separation = function (a, b) {
return a.parent === b.parent ? 1 : 2;
};
_this._shape = constant("Circle");
_this._shapeConfig = assign(_this._shapeConfig, {
ariaLabel: function ariaLabel(d, i) {
return _this._treeData ? "".concat(_this._treeData[i].depth, ". ").concat(_this._drawLabel(d, i), ".") : "";
},
labelConfig: {

@@ -43,3 +79,4 @@ fontColor: "#444"

});
this._tree = tree();
_this._tree = tree();
return _this;
}

@@ -52,141 +89,174 @@ /**

_draw(callback) {
super._draw(callback);
_createClass(Tree, [{
key: "_draw",
value: function _draw(callback) {
var _this2 = this;
const height = this._orient === "vertical" ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right,
_get(_getPrototypeOf(Tree.prototype), "_draw", this).call(this, callback);
var height = this._orient === "vertical" ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right,
left = this._orient === "vertical" ? "left" : "top",
that = this,
transform = `translate(${this._margin.left}, ${this._margin.top})`,
transform = "translate(".concat(this._margin.left, ", ").concat(this._margin.top, ")"),
width = this._orient === "horizontal" ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right;
const treeData = this._treeData = this._tree.separation(this._separation).size([width, height])(hierarchy({
key: "root",
values: nest(this._filteredData, this._groupBy.slice(0, this._drawDepth + 1))
}, d => d.key && d.values ? d.values : null).sort(this._sort)).descendants().filter(d => d.depth <= this._groupBy.length && d.parent);
/**
Merges the values of a given nest branch.
@private
*/
var treeData = this._treeData = this._tree.separation(this._separation).size([width, height])(hierarchy({
key: "root",
values: nest(this._filteredData, this._groupBy.slice(0, this._drawDepth + 1))
}, function (d) {
return d.key && d.values ? d.values : null;
}).sort(this._sort)).descendants().filter(function (d) {
return d.depth <= _this2._groupBy.length && d.parent;
});
/**
Merges the values of a given nest branch.
@private
*/
function flattenBranchData(branch) {
return merge(branch.values.map(l => l.key && l.values ? flattenBranchData(l) : l), that._aggs);
}
function flattenBranchData(branch) {
return merge(branch.values.map(function (l) {
return l.key && l.values ? flattenBranchData(l) : l;
}), that._aggs);
}
treeData.forEach((d, i) => {
if (d.data.key && d.data.values) d.data = flattenBranchData(d.data);
d.__d3plus__ = true;
d.i = i;
});
let r = this._shapeConfig.r;
if (typeof r !== "function") r = constant(r);
const rBufferRoot = max(treeData, d => d.depth === 1 ? r(d.data, d.i) : 0);
const rBufferEnd = max(treeData, d => d.children ? 0 : r(d.data, d.i));
const yExtent = extent(treeData, d => d.y);
this._labelHeight = min([this._orient === "vertical" ? 50 : 100, (yExtent[1] - rBufferRoot - rBufferEnd) / (this._groupBy.length + 1)]);
this._labelWidths = nest(treeData, d => d.depth).map(d => d.values.reduce((num, v, i) => {
const next = i < d.values.length - 1 ? d.values[i + 1].x : width + this._margin[left],
prev = i ? d.values[i - 1].x : this._margin[left];
return min([num, next - v.x, v.x - prev]);
}, width));
const yScale = scaleLinear().domain(yExtent).range([rBufferRoot + this._labelHeight, height - rBufferEnd - this._labelHeight]);
treeData.forEach(d => {
const val = yScale(d.y);
treeData.forEach(function (d, i) {
if (d.data.key && d.data.values) d.data = flattenBranchData(d.data);
d.__d3plus__ = true;
d.i = i;
});
var r = this._shapeConfig.r;
if (typeof r !== "function") r = constant(r);
var rBufferRoot = max(treeData, function (d) {
return d.depth === 1 ? r(d.data, d.i) : 0;
});
var rBufferEnd = max(treeData, function (d) {
return d.children ? 0 : r(d.data, d.i);
});
var yExtent = extent(treeData, function (d) {
return d.y;
});
this._labelHeight = min([this._orient === "vertical" ? 50 : 100, (yExtent[1] - rBufferRoot - rBufferEnd) / (this._groupBy.length + 1)]);
this._labelWidths = nest(treeData, function (d) {
return d.depth;
}).map(function (d) {
return d.values.reduce(function (num, v, i) {
var next = i < d.values.length - 1 ? d.values[i + 1].x : width + _this2._margin[left],
prev = i ? d.values[i - 1].x : _this2._margin[left];
return min([num, next - v.x, v.x - prev]);
}, width);
});
var yScale = scaleLinear().domain(yExtent).range([rBufferRoot + this._labelHeight, height - rBufferEnd - this._labelHeight]);
treeData.forEach(function (d) {
var val = yScale(d.y);
if (this._orient === "horizontal") {
d.y = d.x;
d.x = val;
} else d.y = val;
});
const elemObject = {
parent: this._select,
enter: {
transform
},
update: {
transform
}
};
if (_this2._orient === "horizontal") {
d.y = d.x;
d.x = val;
} else d.y = val;
});
var elemObject = {
parent: this._select,
enter: {
transform: transform
},
update: {
transform: transform
}
};
this._shapes.push(new Path().data(treeData.filter(d => d.depth > 1)).select(elem("g.d3plus-Tree-Links", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Path")).config({
d: d => {
let r = this._shapeConfig.r;
if (typeof r === "function") r = r(d.data, d.i);
const px = d.parent.x - d.x + (this._orient === "vertical" ? 0 : r),
py = d.parent.y - d.y + (this._orient === "vertical" ? r : 0),
x = this._orient === "vertical" ? 0 : -r,
y = this._orient === "vertical" ? -r : 0;
return this._orient === "vertical" ? `M${x},${y}C${x},${(y + py) / 2} ${px},${(y + py) / 2} ${px},${py}` : `M${x},${y}C${(x + px) / 2},${y} ${(x + px) / 2},${py} ${px},${py}`;
},
id: (d, i) => this._ids(d, i).join("-")
}).render());
this._shapes.push(new Path().data(treeData.filter(function (d) {
return d.depth > 1;
})).select(elem("g.d3plus-Tree-Links", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Path")).config({
d: function d(_d) {
var r = _this2._shapeConfig.r;
if (typeof r === "function") r = r(_d.data, _d.i);
var px = _d.parent.x - _d.x + (_this2._orient === "vertical" ? 0 : r),
py = _d.parent.y - _d.y + (_this2._orient === "vertical" ? r : 0),
x = _this2._orient === "vertical" ? 0 : -r,
y = _this2._orient === "vertical" ? -r : 0;
return _this2._orient === "vertical" ? "M".concat(x, ",").concat(y, "C").concat(x, ",").concat((y + py) / 2, " ").concat(px, ",").concat((y + py) / 2, " ").concat(px, ",").concat(py) : "M".concat(x, ",").concat(y, "C").concat((x + px) / 2, ",").concat(y, " ").concat((x + px) / 2, ",").concat(py, " ").concat(px, ",").concat(py);
},
id: function id(d, i) {
return _this2._ids(d, i).join("-");
}
}).render());
this._shapes.push(new Circle().data(treeData).select(elem("g.d3plus-Tree-Shapes", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Circle")).config({
id: (d, i) => this._ids(d, i).join("-"),
label: (d, i) => {
if (this._label) return this._label(d.data, i);
this._shapes.push(new Circle().data(treeData).select(elem("g.d3plus-Tree-Shapes", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Circle")).config({
id: function id(d, i) {
return _this2._ids(d, i).join("-");
},
label: function label(d, i) {
if (_this2._label) return _this2._label(d.data, i);
const ids = this._ids(d, i).slice(0, d.depth);
var ids = _this2._ids(d, i).slice(0, d.depth);
return ids[ids.length - 1];
},
labelConfig: {
textAnchor: d => this._orient === "vertical" ? "middle" : d.data.children && d.data.depth !== this._groupBy.length ? "end" : "start",
verticalAlign: d => this._orient === "vertical" ? d.data.depth === 1 ? "bottom" : "top" : "middle"
},
hitArea: (d, i, s) => {
const h = this._labelHeight,
w = this._labelWidths[d.depth - 1];
return {
width: this._orient === "vertical" ? w : s.r * 2 + w,
height: this._orient === "horizontal" ? h : s.r * 2 + h,
x: this._orient === "vertical" ? -w / 2 : d.children && d.depth !== this._groupBy.length ? -(s.r + w) : -s.r,
y: this._orient === "horizontal" ? -h / 2 : d.children && d.depth !== this._groupBy.length ? -(s.r + this._labelHeight) : -s.r
};
},
labelBounds: (d, i, s) => {
const h = this._labelHeight,
height = this._orient === "vertical" ? "height" : "width",
w = this._labelWidths[d.depth - 1],
width = this._orient === "vertical" ? "width" : "height",
x = this._orient === "vertical" ? "x" : "y",
y = this._orient === "vertical" ? "y" : "x";
return {
[width]: w,
[height]: h,
[x]: -w / 2,
[y]: d.children && d.depth !== this._groupBy.length ? -(s.r + h) : s.r
};
}
}).render());
return ids[ids.length - 1];
},
labelConfig: {
textAnchor: function textAnchor(d) {
return _this2._orient === "vertical" ? "middle" : d.data.children && d.data.depth !== _this2._groupBy.length ? "end" : "start";
},
verticalAlign: function verticalAlign(d) {
return _this2._orient === "vertical" ? d.data.depth === 1 ? "bottom" : "top" : "middle";
}
},
hitArea: function hitArea(d, i, s) {
var h = _this2._labelHeight,
w = _this2._labelWidths[d.depth - 1];
return {
width: _this2._orient === "vertical" ? w : s.r * 2 + w,
height: _this2._orient === "horizontal" ? h : s.r * 2 + h,
x: _this2._orient === "vertical" ? -w / 2 : d.children && d.depth !== _this2._groupBy.length ? -(s.r + w) : -s.r,
y: _this2._orient === "horizontal" ? -h / 2 : d.children && d.depth !== _this2._groupBy.length ? -(s.r + _this2._labelHeight) : -s.r
};
},
labelBounds: function labelBounds(d, i, s) {
var _ref;
return this;
}
/**
@memberof Tree
@desc If *value* is specified, sets the orientation to the specified value. If *value* is not specified, returns the current orientation.
@param {String} [*value* = "vertical"] Accepts either "vertical" or "horizontal".
*/
var h = _this2._labelHeight,
height = _this2._orient === "vertical" ? "height" : "width",
w = _this2._labelWidths[d.depth - 1],
width = _this2._orient === "vertical" ? "width" : "height",
x = _this2._orient === "vertical" ? "x" : "y",
y = _this2._orient === "vertical" ? "y" : "x";
return _ref = {}, _defineProperty(_ref, width, w), _defineProperty(_ref, height, h), _defineProperty(_ref, x, -w / 2), _defineProperty(_ref, y, d.children && d.depth !== _this2._groupBy.length ? -(s.r + h) : s.r), _ref;
}
}).render());
return this;
}
/**
@memberof Tree
@desc If *value* is specified, sets the orientation to the specified value. If *value* is not specified, returns the current orientation.
@param {String} [*value* = "vertical"] Accepts either "vertical" or "horizontal".
*/
orient(_) {
return arguments.length ? (this._orient = _, this) : this._orient;
}
/**
@memberof Tree
@desc If *value* is specified, sets the separation accessor to the specified function. If *value* is not specified, returns the current separation accessor.
From the [d3-hierarchy documentation](https://github.com/d3/d3-hierarchy#tree_separation):
> The separation accessor is used to separate neighboring nodes. The separation function is passed two nodes a and b, and must return the desired separation. The nodes are typically siblings, though the nodes may be more distantly related if the layout decides to place such nodes adjacent.
@param {Function} [*value*]
@example
function separation(a, b) {
return a.parent === b.parent ? 1 : 2;
}
*/
}, {
key: "orient",
value: function orient(_) {
return arguments.length ? (this._orient = _, this) : this._orient;
}
/**
@memberof Tree
@desc If *value* is specified, sets the separation accessor to the specified function. If *value* is not specified, returns the current separation accessor.
From the [d3-hierarchy documentation](https://github.com/d3/d3-hierarchy#tree_separation):
> The separation accessor is used to separate neighboring nodes. The separation function is passed two nodes a and b, and must return the desired separation. The nodes are typically siblings, though the nodes may be more distantly related if the layout decides to place such nodes adjacent.
@param {Function} [*value*]
@example
function separation(a, b) {
return a.parent === b.parent ? 1 : 2;
}
*/
}, {
key: "separation",
value: function separation(_) {
return arguments.length ? (this._separation = _, this) : this._separation;
}
}]);
separation(_) {
return arguments.length ? (this._separation = _, this) : this._separation;
}
return Tree;
}(Viz);
}
export { Tree as default };

@@ -0,1 +1,23 @@

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
import { sum } from "d3-array";

@@ -14,3 +36,7 @@ import { nest } from "d3-collection";

export default class Treemap extends Viz {
var Treemap =
/*#__PURE__*/
function (_Viz) {
_inherits(Treemap, _Viz);
/**

@@ -21,12 +47,18 @@ @memberof Treemap

*/
constructor() {
super();
this._layoutPadding = 1;
function Treemap() {
var _this;
this._legendSort = (a, b) => this._sum(b) - this._sum(a);
_classCallCheck(this, Treemap);
this._shapeConfig = assign({}, this._shapeConfig, {
ariaLabel: (d, i) => {
const rank = this._rankData ? `${this._rankData.indexOf(d) + 1}. ` : "";
return `${rank}${this._drawLabel(d, i)}, ${this._sum(d, i)}.`;
_this = _possibleConstructorReturn(this, _getPrototypeOf(Treemap).call(this));
_this._layoutPadding = 1;
_this._legendSort = function (a, b) {
return _this._sum(b) - _this._sum(a);
};
_this._shapeConfig = assign({}, _this._shapeConfig, {
ariaLabel: function ariaLabel(d, i) {
var rank = _this._rankData ? "".concat(_this._rankData.indexOf(d) + 1, ". ") : "";
return "".concat(rank).concat(_this._drawLabel(d, i), ", ").concat(_this._sum(d, i), ".");
},

@@ -41,17 +73,23 @@ labelConfig: {

this._sort = (a, b) => {
const aggA = isAggregated(a);
const aggB = isAggregated(b);
_this._sort = function (a, b) {
var aggA = isAggregated(a);
var aggB = isAggregated(b);
return aggA && !aggB ? 1 : !aggA && aggB ? -1 : b.value - a.value;
};
this._sum = accessor("value");
this._thresholdKey = this._sum;
this._tile = treemapSquarify;
this._tooltipConfig = assign({}, this._tooltipConfig, {
tbody: [["Share", (d, i, x) => `${formatAbbreviate(x.share * 100, this._locale)}%`]]
_this._sum = accessor("value");
_this._thresholdKey = _this._sum;
_this._tile = treemapSquarify;
_this._tooltipConfig = assign({}, _this._tooltipConfig, {
tbody: [["Share", function (d, i, x) {
return "".concat(formatAbbreviate(x.share * 100, _this._locale), "%");
}]]
});
this._treemap = treemap().round(true);
_this._treemap = treemap().round(true);
const isAggregated = leaf => leaf.children && leaf.children.length === 1 && leaf.children[0].data._isAggregation;
var isAggregated = function isAggregated(leaf) {
return leaf.children && leaf.children.length === 1 && leaf.children[0].data._isAggregation;
};
return _this;
}

@@ -65,235 +103,262 @@ /**

_draw(callback) {
super._draw(callback);
_createClass(Treemap, [{
key: "_draw",
value: function _draw(callback) {
var _this2 = this;
let nestedData = nest();
_get(_getPrototypeOf(Treemap.prototype), "_draw", this).call(this, callback);
for (let i = 0; i <= this._drawDepth; i++) nestedData.key(this._groupBy[i]);
var nestedData = nest();
nestedData = nestedData.entries(this._filteredData);
for (var i = 0; i <= this._drawDepth; i++) {
nestedData.key(this._groupBy[i]);
}
const tmapData = this._treemap.padding(this._layoutPadding).size([this._width - this._margin.left - this._margin.right, this._height - this._margin.top - this._margin.bottom]).tile(this._tile)(hierarchy({
values: nestedData
}, d => d.values).sum(this._sum).sort(this._sort));
nestedData = nestedData.entries(this._filteredData);
const shapeData = [],
var tmapData = this._treemap.padding(this._layoutPadding).size([this._width - this._margin.left - this._margin.right, this._height - this._margin.top - this._margin.bottom]).tile(this._tile)(hierarchy({
values: nestedData
}, function (d) {
return d.values;
}).sum(this._sum).sort(this._sort));
var shapeData = [],
that = this;
/**
@memberof Treemap
@desc Flattens and merges treemap data.
@private
*/
/**
@memberof Treemap
@desc Flattens and merges treemap data.
@private
*/
function extractLayout(children) {
for (let i = 0; i < children.length; i++) {
const node = children[i];
if (node.depth <= that._drawDepth) extractLayout(node.children);else {
const index = node.data.values.length === 1 ? that._filteredData.indexOf(node.data.values[0]) : undefined;
node.__d3plus__ = true;
node.id = node.data.key;
node.i = index > -1 ? index : undefined;
node.data = merge(node.data.values);
node.x = node.x0 + (node.x1 - node.x0) / 2;
node.y = node.y0 + (node.y1 - node.y0) / 2;
shapeData.push(node);
function extractLayout(children) {
for (var _i = 0; _i < children.length; _i++) {
var node = children[_i];
if (node.depth <= that._drawDepth) extractLayout(node.children);else {
var index = node.data.values.length === 1 ? that._filteredData.indexOf(node.data.values[0]) : undefined;
node.__d3plus__ = true;
node.id = node.data.key;
node.i = index > -1 ? index : undefined;
node.data = merge(node.data.values);
node.x = node.x0 + (node.x1 - node.x0) / 2;
node.y = node.y0 + (node.y1 - node.y0) / 2;
shapeData.push(node);
}
}
}
}
if (tmapData.children) extractLayout(tmapData.children);
this._rankData = shapeData.sort(this._sort).map(d => d.data);
const total = tmapData.value;
shapeData.forEach(d => {
d.share = this._sum(d.data, d.i) / total;
});
const transform = `translate(${this._margin.left}, ${this._margin.top})`;
const rectConfig = configPrep.bind(this)(this._shapeConfig, "shape", "Rect");
const fontMin = rectConfig.labelConfig.fontMin;
const padding = rectConfig.labelConfig.padding;
if (tmapData.children) extractLayout(tmapData.children);
this._rankData = shapeData.sort(this._sort).map(function (d) {
return d.data;
});
var total = tmapData.value;
shapeData.forEach(function (d) {
d.share = _this2._sum(d.data, d.i) / total;
});
var transform = "translate(".concat(this._margin.left, ", ").concat(this._margin.top, ")");
var rectConfig = configPrep.bind(this)(this._shapeConfig, "shape", "Rect");
var fontMin = rectConfig.labelConfig.fontMin;
var padding = rectConfig.labelConfig.padding;
this._shapes.push(new Rect().data(shapeData).label(d => [this._drawLabel(d.data, d.i), `${formatAbbreviate(d.share * 100, this._locale)}%`]).select(elem("g.d3plus-Treemap", {
parent: this._select,
enter: {
transform
},
update: {
transform
}
}).node()).config({
height: d => d.y1 - d.y0,
labelBounds: (d, i, s) => {
const h = s.height;
let sh = Math.min(50, (h - padding * 2) * 0.5);
if (sh < fontMin) sh = 0;
return [{
width: s.width,
height: h - sh,
x: -s.width / 2,
y: -h / 2
}, {
width: s.width,
height: sh + padding * 2,
x: -s.width / 2,
y: h / 2 - sh - padding * 2
}];
},
labelConfig: {
textAnchor: (d, i, x) => {
let line,
parent = x;
this._shapes.push(new Rect().data(shapeData).label(function (d) {
return [_this2._drawLabel(d.data, d.i), "".concat(formatAbbreviate(d.share * 100, _this2._locale), "%")];
}).select(elem("g.d3plus-Treemap", {
parent: this._select,
enter: {
transform: transform
},
update: {
transform: transform
}
}).node()).config({
height: function height(d) {
return d.y1 - d.y0;
},
labelBounds: function labelBounds(d, i, s) {
var h = s.height;
var sh = Math.min(50, (h - padding * 2) * 0.5);
if (sh < fontMin) sh = 0;
return [{
width: s.width,
height: h - sh,
x: -s.width / 2,
y: -h / 2
}, {
width: s.width,
height: sh + padding * 2,
x: -s.width / 2,
y: h / 2 - sh - padding * 2
}];
},
labelConfig: {
textAnchor: function textAnchor(d, i, x) {
var line,
parent = x;
while (typeof line === "undefined" && parent) {
if (typeof parent.l !== "undefined") line = parent.l;
parent = parent.__d3plusParent__;
}
while (typeof line === "undefined" && parent) {
if (typeof parent.l !== "undefined") line = parent.l;
parent = parent.__d3plusParent__;
}
return line ? "middle" : "start";
},
verticalAlign: (d, i, x) => {
let line,
parent = x;
return line ? "middle" : "start";
},
verticalAlign: function verticalAlign(d, i, x) {
var line,
parent = x;
while (typeof line === "undefined" && parent) {
if (typeof parent.l !== "undefined") line = parent.l;
parent = parent.__d3plusParent__;
while (typeof line === "undefined" && parent) {
if (typeof parent.l !== "undefined") line = parent.l;
parent = parent.__d3plusParent__;
}
return line ? "bottom" : "top";
}
return line ? "bottom" : "top";
},
width: function width(d) {
return d.x1 - d.x0;
}
},
width: d => d.x1 - d.x0
}).config(rectConfig).render());
}).config(rectConfig).render());
return this;
}
/**
* Applies the threshold algorithm for Treemaps.
* @param {Array} data The data to process.
*/
return this;
}
/**
* Applies the threshold algorithm for Treemaps.
* @param {Array} data The data to process.
*/
}, {
key: "_thresholdFunction",
value: function _thresholdFunction(data, tree) {
var aggs = this._aggs;
var drawDepth = this._drawDepth;
var groupBy = this._groupBy;
var threshold = this._threshold;
var thresholdKey = this._thresholdKey;
_thresholdFunction(data, tree) {
const aggs = this._aggs;
const drawDepth = this._drawDepth;
const groupBy = this._groupBy;
const threshold = this._threshold;
const thresholdKey = this._thresholdKey;
if (threshold && thresholdKey) {
var finalDataset = data.slice();
var totalSum = sum(finalDataset, this._thresholdKey);
var n = tree.length;
if (threshold && thresholdKey) {
const finalDataset = data.slice();
const totalSum = sum(finalDataset, this._thresholdKey);
let n = tree.length;
while (n--) {
var branch = tree[n];
thresholdByDepth(finalDataset, totalSum, data, branch, 0);
}
while (n--) {
const branch = tree[n];
thresholdByDepth(finalDataset, totalSum, data, branch, 0);
return finalDataset;
}
/**
* @memberof Treemap
* @desc Explores the data tree recursively and merges elements under the indicated threshold.
* @param {object[]} finalDataset The array of data that will be returned after modifications.
* @param {number} totalSum The total sum of the values in the initial dataset.
* @param {object[]} currentDataset The current subset of the dataset to work on.
* @param {object} branch The branch of the dataset tree to explore.
* @param {number} depth The depth of the current branch.
* @private
*/
return finalDataset;
}
/**
* @memberof Treemap
* @desc Explores the data tree recursively and merges elements under the indicated threshold.
* @param {object[]} finalDataset The array of data that will be returned after modifications.
* @param {number} totalSum The total sum of the values in the initial dataset.
* @param {object[]} currentDataset The current subset of the dataset to work on.
* @param {object} branch The branch of the dataset tree to explore.
* @param {number} depth The depth of the current branch.
* @private
*/
function thresholdByDepth(finalDataset, totalSum, currentDataset, branch, depth) {
if (depth >= drawDepth) return;
var currentAccesor = groupBy[depth];
var nextDataset = currentDataset.filter(function (item) {
return currentAccesor(item) === branch.key;
});
function thresholdByDepth(finalDataset, totalSum, currentDataset, branch, depth) {
if (depth >= drawDepth) return;
const currentAccesor = groupBy[depth];
const nextDataset = currentDataset.filter(item => currentAccesor(item) === branch.key);
if (depth + 1 === drawDepth) {
var removedItems = [];
var thresholdPercent = Math.min(1, Math.max(0, threshold(nextDataset)));
if (!isFinite(thresholdPercent) || isNaN(thresholdPercent)) return;
var thresholdValue = thresholdPercent * totalSum;
var _n = nextDataset.length;
if (depth + 1 === drawDepth) {
const removedItems = [];
const thresholdPercent = Math.min(1, Math.max(0, threshold(nextDataset)));
if (!isFinite(thresholdPercent) || isNaN(thresholdPercent)) return;
const thresholdValue = thresholdPercent * totalSum;
let n = nextDataset.length;
while (_n--) {
var item = nextDataset[_n];
while (n--) {
const item = nextDataset[n];
if (thresholdKey(item) < thresholdValue) {
var index = finalDataset.indexOf(item);
finalDataset.splice(index, 1);
removedItems.push(item);
}
}
if (thresholdKey(item) < thresholdValue) {
const index = finalDataset.indexOf(item);
finalDataset.splice(index, 1);
removedItems.push(item);
if (removedItems.length > 0) {
var mergedItem = merge(removedItems, aggs);
mergedItem._isAggregation = true;
mergedItem._threshold = thresholdPercent;
finalDataset.push(mergedItem);
}
}
} else {
var leaves = branch.values;
var _n2 = leaves.length;
if (removedItems.length > 0) {
const mergedItem = merge(removedItems, aggs);
mergedItem._isAggregation = true;
mergedItem._threshold = thresholdPercent;
finalDataset.push(mergedItem);
while (_n2--) {
thresholdByDepth(finalDataset, totalSum, nextDataset, leaves[_n2], depth + 1);
}
}
} else {
const leaves = branch.values;
let n = leaves.length;
}
while (n--) {
thresholdByDepth(finalDataset, totalSum, nextDataset, leaves[n], depth + 1);
}
}
return data;
}
/**
@memberof Treemap
@desc If *value* is specified, sets the inner and outer padding accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current padding accessor.
@param {Function|Number} [*value*]
*/
return data;
}
/**
@memberof Treemap
@desc If *value* is specified, sets the inner and outer padding accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current padding accessor.
@param {Function|Number} [*value*]
*/
}, {
key: "layoutPadding",
value: function layoutPadding(_) {
return arguments.length ? (this._layoutPadding = typeof _ === "function" ? _ : constant(_), this) : this._layoutPadding;
}
/**
@memberof Treemap
@desc If *comparator* is specified, sets the sort order for the treemap using the specified comparator function. If *comparator* is not specified, returns the current group sort order, which defaults to descending order by the associated input data's numeric value attribute.
@param {Array} [*comparator*]
@example
function comparator(a, b) {
return b.value - a.value;
}
*/
}, {
key: "sort",
value: function sort(_) {
return arguments.length ? (this._sort = _, this) : this._sort;
}
/**
@memberof Treemap
@desc If *value* is specified, sets the sum accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current sum accessor.
@param {Function|Number} [*value*]
@example
function sum(d) {
return d.sum;
}
*/
layoutPadding(_) {
return arguments.length ? (this._layoutPadding = typeof _ === "function" ? _ : constant(_), this) : this._layoutPadding;
}
/**
@memberof Treemap
@desc If *comparator* is specified, sets the sort order for the treemap using the specified comparator function. If *comparator* is not specified, returns the current group sort order, which defaults to descending order by the associated input data's numeric value attribute.
@param {Array} [*comparator*]
@example
function comparator(a, b) {
return b.value - a.value;
}
*/
}, {
key: "sum",
value: function sum(_) {
if (arguments.length) {
this._sum = typeof _ === "function" ? _ : accessor(_);
this._thresholdKey = this._sum;
return this;
} else return this._sum;
}
/**
@memberof Treemap
@desc If *value* is specified, sets the [tiling method](https://github.com/d3/d3-hierarchy#treemap-tiling) to the specified function and returns the current class instance. If *value* is not specified, returns the current [tiling method](https://github.com/d3/d3-hierarchy#treemap-tiling).
@param {Function} [*value*]
*/
}, {
key: "tile",
value: function tile(_) {
return arguments.length ? (this._tile = _, this) : this._tile;
}
}]);
sort(_) {
return arguments.length ? (this._sort = _, this) : this._sort;
}
/**
@memberof Treemap
@desc If *value* is specified, sets the sum accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current sum accessor.
@param {Function|Number} [*value*]
@example
function sum(d) {
return d.sum;
}
*/
return Treemap;
}(Viz);
sum(_) {
if (arguments.length) {
this._sum = typeof _ === "function" ? _ : accessor(_);
this._thresholdKey = this._sum;
return this;
} else return this._sum;
}
/**
@memberof Treemap
@desc If *value* is specified, sets the [tiling method](https://github.com/d3/d3-hierarchy#treemap-tiling) to the specified function and returns the current class instance. If *value* is not specified, returns the current [tiling method](https://github.com/d3/d3-hierarchy#treemap-tiling).
@param {Function} [*value*]
*/
tile(_) {
return arguments.length ? (this._tile = _, this) : this._tile;
}
}
export { Treemap as default };
{
"name": "d3plus-hierarchy",
"version": "0.8.6",
"version": "0.8.7",
"description": "Nested, hierarchical, and cluster charts built on D3",

@@ -31,5 +31,5 @@ "main": "build/d3plus-hierarchy.js",

"d3-shape": "^1.3.5",
"d3plus-common": "^0.6.50",
"d3plus-shape": "^0.16.9",
"d3plus-viz": "^0.12.34"
"d3plus-common": "^0.6.51",
"d3plus-shape": "^0.16.10",
"d3plus-viz": "^0.12.35"
},

@@ -46,3 +46,3 @@ "scripts": {

"devDependencies": {
"d3plus-dev": "^0.7.1"
"d3plus-dev": "^0.7.2"
},

@@ -49,0 +49,0 @@ "module": "es/index",

@@ -396,2 +396,2 @@ # d3plus-hierarchy

###### <sub>Documentation generated on Mon, 08 Jul 2019 21:45:27 GMT</sub>
###### <sub>Documentation generated on Thu, 11 Jul 2019 13:27:20 GMT</sub>

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc