1 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6 | };
|
7 | var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
8 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
9 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11 | };
|
12 | var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
13 | if (kind === "m") throw new TypeError("Private method is not writable");
|
14 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
15 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
16 | return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
17 | };
|
18 | var _DuoyunScatterChartElement_symbolSequences, _DuoyunScatterChartElement_tooltipRender, _DuoyunScatterChartElement_onMouseMove, _DuoyunScatterChartElement_onMouseOut;
|
19 |
|
20 | import { customElement, property } from '@mantou/gem/lib/decorators';
|
21 | import { html, svg } from '@mantou/gem/lib/element';
|
22 | import { classMap } from '@mantou/gem/lib/utils';
|
23 | import { isNullish } from '../lib/types';
|
24 | import { DuoyunChartBaseElement } from './base/chart';
|
25 | import { ChartTooltip } from './chart-tooltip';
|
26 |
|
27 |
|
28 |
|
29 | let DuoyunScatterChartElement = class DuoyunScatterChartElement extends DuoyunChartBaseElement {
|
30 | constructor() {
|
31 | super(...arguments);
|
32 | _DuoyunScatterChartElement_symbolSequences.set(this, []);
|
33 | _DuoyunScatterChartElement_tooltipRender.set(this, (data) => {
|
34 | return html `${data.xValue},${data.values[0].value}`;
|
35 | });
|
36 | _DuoyunScatterChartElement_onMouseMove.set(this, (evt, index, point) => {
|
37 | var _a, _b, _c, _d, _e;
|
38 | if (this.noData || this.loading)
|
39 | return;
|
40 | ChartTooltip.open(evt.x, evt.y, {
|
41 | render: ((_a = this.tooltip) === null || _a === void 0 ? void 0 : _a.render) || __classPrivateFieldGet(this, _DuoyunScatterChartElement_tooltipRender, "f"),
|
42 | xValue: point[0],
|
43 | values: [
|
44 | {
|
45 | value: ((_c = (_b = this.tooltip) === null || _b === void 0 ? void 0 : _b.valueFormatter) === null || _c === void 0 ? void 0 : _c.call(_b, point[1])) || ((_e = (_d = this.yAxi) === null || _d === void 0 ? void 0 : _d.formatter) === null || _e === void 0 ? void 0 : _e.call(_d, point[1], 0)) || String(point[1]),
|
46 | originValue: point[1],
|
47 | color: this.colors[index],
|
48 | label: this.sequences[index].label,
|
49 | },
|
50 | ],
|
51 | });
|
52 | });
|
53 | _DuoyunScatterChartElement_onMouseOut.set(this, () => {
|
54 | ChartTooltip.close();
|
55 | });
|
56 | this.willMount = () => {
|
57 | this.memo(() => {
|
58 | var _a;
|
59 | if (!this.contentRect.width)
|
60 | return;
|
61 | if (!((_a = this.sequences) === null || _a === void 0 ? void 0 : _a.length))
|
62 | return;
|
63 | let xMin = Infinity;
|
64 | let xMax = -Infinity;
|
65 | let yMin = Infinity;
|
66 | let yMax = -Infinity;
|
67 | this.sequences.forEach(({ values }) => {
|
68 | values.forEach(([x, y]) => {
|
69 | if (!isNullish(x)) {
|
70 | xMin = Math.min(xMin, x);
|
71 | xMax = Math.max(xMax, x);
|
72 | }
|
73 | if (!isNullish(y)) {
|
74 | yMin = Math.min(yMin, y);
|
75 | yMax = Math.max(yMax, y);
|
76 | }
|
77 | });
|
78 | });
|
79 | this.initXAxi(xMin, xMax);
|
80 | this.initYAxi(yMin, yMax);
|
81 | this.initViewBox();
|
82 | __classPrivateFieldSet(this, _DuoyunScatterChartElement_symbolSequences, this.sequences.map(({ values }) => {
|
83 | return values.map(([x, y]) => {
|
84 | return isNullish(x) || isNullish(y) ? undefined : this.getStagePoint([x, y]);
|
85 | });
|
86 | }), "f");
|
87 | }, () => [this.sequences, this.contentRect.width]);
|
88 | };
|
89 | this.mounted = () => {
|
90 | return __classPrivateFieldGet(this, _DuoyunScatterChartElement_onMouseOut, "f");
|
91 | };
|
92 | this.render = () => {
|
93 | if (this.loading)
|
94 | return this.renderLoading();
|
95 | if (this.noData)
|
96 | return this.renderNotData();
|
97 | if (!this.contentRect.width || !this.sequences)
|
98 | return html ``;
|
99 | return html `
|
100 | <style>
|
101 | .symbol {
|
102 | opacity: 0.8;
|
103 | }
|
104 | .symbol:hover {
|
105 | opacity: 1;
|
106 | transform-box: fill-box;
|
107 | transform-origin: center;
|
108 | transform: scale(1.2);
|
109 | }
|
110 | .disabled {
|
111 | pointer-events: none;
|
112 | }
|
113 | </style>
|
114 | ${svg `
|
115 | <svg aria-hidden="true" part=${DuoyunChartBaseElement.chart} xmlns="http://www.w3.org/2000/svg" viewBox=${this.viewBox.join(' ')}>
|
116 | ${this.renderXAxi({ grid: true })}
|
117 | ${this.renderYAxi()}
|
118 | ${this.sequences.map(({ label, value, values }, index) => __classPrivateFieldGet(this, _DuoyunScatterChartElement_symbolSequences, "f")[index].map((point, pos) => point
|
119 | ? svg `
|
120 | <circle
|
121 | @mousemove=${(evt) => __classPrivateFieldGet(this, _DuoyunScatterChartElement_onMouseMove, "f").call(this, evt, index, values[pos])}
|
122 | @mouseout=${__classPrivateFieldGet(this, _DuoyunScatterChartElement_onMouseOut, "f")}
|
123 | class=${classMap({
|
124 | symbol: true,
|
125 | disabled: !!this.filtersSet.size && !this.filtersSet.has(value !== null && value !== void 0 ? value : label),
|
126 | })}
|
127 | fill=${this.colors[index]}
|
128 | r=${this.getSVGPixel(5)}
|
129 | cx=${point[0]}
|
130 | cy=${point[1]}
|
131 | />
|
132 | `
|
133 | : ''))}
|
134 | </svg>
|
135 | `}
|
136 | `;
|
137 | };
|
138 | }
|
139 | };
|
140 | _DuoyunScatterChartElement_symbolSequences = new WeakMap(), _DuoyunScatterChartElement_tooltipRender = new WeakMap(), _DuoyunScatterChartElement_onMouseMove = new WeakMap(), _DuoyunScatterChartElement_onMouseOut = new WeakMap();
|
141 | __decorate([
|
142 | property
|
143 | ], DuoyunScatterChartElement.prototype, "sequences", void 0);
|
144 | DuoyunScatterChartElement = __decorate([
|
145 | customElement('dy-scatter-chart')
|
146 | ], DuoyunScatterChartElement);
|
147 | export { DuoyunScatterChartElement };
|
148 |
|
\ | No newline at end of file |