UNPKG

@bizcharts/point-bubble

Version:
105 lines (88 loc) • 4.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require("react"); var _react2 = _interopRequireDefault(_react); var _bizcharts = require("bizcharts"); var _mock = require("./mock.json"); var _mock2 = _interopRequireDefault(_mock); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Bubble = function (_React$Component) { _inherits(Bubble, _React$Component); function Bubble() { _classCallCheck(this, Bubble); return _possibleConstructorReturn(this, (Bubble.__proto__ || Object.getPrototypeOf(Bubble)).apply(this, arguments)); } _createClass(Bubble, [{ key: "render", value: function render() { var colorMap = { Asia: _bizcharts.G2.Global.colors[0], Americas: _bizcharts.G2.Global.colors[1], Europe: _bizcharts.G2.Global.colors[2], Oceania: _bizcharts.G2.Global.colors[3] }; var cols = { LifeExpectancy: { alias: "人均寿命(年)" }, Population: { type: "pow", alias: "人口总数" }, GDP: { alias: "人均国内生产总值($)" }, Country: { alias: "国家/地区" } }; return _react2.default.createElement( "div", null, _react2.default.createElement( _bizcharts.Chart, { height: window.innerHeight, data: _mock2.default, scale: cols, forceFit: true }, _react2.default.createElement(_bizcharts.Tooltip, { showTitle: false }), _react2.default.createElement(_bizcharts.Axis, { name: "GDP", label: { formatter: function formatter(value) { return (value / 1000).toFixed(0) + "k"; } // 格式化坐标轴的显示 } }), _react2.default.createElement(_bizcharts.Axis, { name: "LifeExpectancy" }), _react2.default.createElement(_bizcharts.Legend, { reversed: true }), _react2.default.createElement(_bizcharts.Geom, { type: "point", position: "GDP*LifeExpectancy", color: ["continent", function (val) { return colorMap[val]; }], tooltip: "Country*Population*GDP*LifeExpectancy", opacity: 0.65, shape: "circle", size: ["Population", [4, 65]], style: ["continent", { lineWidth: 1, strokeOpacity: 1, fillOpacity: 0.3, opacity: 0.65, stroke: function stroke(val) { return colorMap[val]; } }] }) ) ); } }]); return Bubble; }(_react2.default.Component); exports.default = Bubble;