@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
136 lines (135 loc) • 5.93 kB
JavaScript
;
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) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HoneycombChartComponent = void 0;
var React = __importStar(require("react"));
var lodash_1 = require("lodash");
var index_1 = require("../core/index");
var LineChartCom_1 = require("./LineChartCom");
var style = __importStar(require("./style.mless"));
var HoneycombChartComponent = /** @class */ (function (_super) {
__extends(HoneycombChartComponent, _super);
function HoneycombChartComponent() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.ref = null;
_this.hexagonChart = null;
_this.setRef = function (ref) {
_this.ref = ref;
};
_this.state = {
showTooltip: false,
position: {
x: 0,
y: 0
},
data: {
name: '',
value: 0,
color: '',
line: []
}
};
_this.addTooltip = function (position, data) {
_this.setState({
showTooltip: true,
position: position,
data: data
});
};
_this.removeTooltip = function () {
_this.setState({
showTooltip: false
});
};
return _this;
}
HoneycombChartComponent.prototype.getOption = function (option) {
var margin = option.margin, honeycomb = option.honeycomb, groups = option.groups, series = option.series;
return {
margin: __assign({ top: 0, left: 0, right: 0, bottom: 0 }, margin),
honeycomb: __assign({ maxRadius: 100, minRadius: 10, distance: 0.06 }, honeycomb),
groups: __assign({ honeycombNum: 6, lineGroupNum: 3, titleHeight: 20, showTitle: false }, groups),
series: series || []
};
};
HoneycombChartComponent.prototype.render = function () {
var _a = this.state, showTooltip = _a.showTooltip, data = _a.data, position = _a.position;
var tooltip = data.name + ":" + data.value;
var offsetWidth = document.body.offsetWidth;
var positionX = position.x;
if (offsetWidth - position.x - tooltip.length * 8 < 10) {
positionX = position.x - tooltip.length * 8;
}
var _b = this.props, width = _b.width, height = _b.height;
return (React.createElement("div", { className: style.honeycombChart },
React.createElement("div", { className: style.chart, ref: this.setRef, style: { width: width, height: height } }),
showTooltip && (React.createElement("div", { className: style.tooltip, style: {
transform: "translate(" + positionX + "px, " + position.y + "px)"
} },
React.createElement("div", { className: style.tooltipHeader },
React.createElement("span", { className: style.tooltipIndicator, style: { background: data.color } }),
tooltip),
data.line.length > 0 && React.createElement(LineChartCom_1.LineChartCom, { data: data.line })))));
};
HoneycombChartComponent.prototype.componentDidMount = function () {
if (this.ref) {
this.hexagonChart = new index_1.HoneycombChart(this.ref, this.addTooltip, this.removeTooltip, this.props.handleClick);
this.hexagonChart.render(this.getOption(this.props.option));
}
};
HoneycombChartComponent.prototype.componentWillReceiveProps = function (nextProps) {
if (!lodash_1.isEqual(nextProps.option, this.props.option)) {
if (this.ref) {
this.hexagonChart.render(this.getOption(nextProps.option));
}
}
};
HoneycombChartComponent.prototype.componentWillUnmount = function () {
var _a;
(_a = this.hexagonChart) === null || _a === void 0 ? void 0 : _a.dispose();
};
return HoneycombChartComponent;
}(React.Component));
exports.HoneycombChartComponent = HoneycombChartComponent;