UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

114 lines (113 loc) 4.88 kB
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); }; import * as React from 'react'; import { isEqual } from 'lodash'; import { HoneycombChart } from '../core/index'; import { LineChartCom } from './LineChartCom'; import * as style from './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, { data: data.line }))))); }; HoneycombChartComponent.prototype.componentDidMount = function () { if (this.ref) { this.hexagonChart = new HoneycombChart(this.ref, this.addTooltip, this.removeTooltip, this.props.handleClick); this.hexagonChart.render(this.getOption(this.props.option)); } }; HoneycombChartComponent.prototype.componentWillReceiveProps = function (nextProps) { if (!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)); export { HoneycombChartComponent };