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 _DuoyunChartZoomElement_getMovement, _DuoyunChartZoomElement_getCurrent, _DuoyunChartZoomElement_panAdjust, _DuoyunChartZoomElement_adjust, _DuoyunChartZoomElement_onPanStart, _DuoyunChartZoomElement_onPanStop, _DuoyunChartZoomElement_onNewStart, _DuoyunChartZoomElement_onNewChange, _DuoyunChartZoomElement_onNewEnd, _DuoyunChartZoomElement_onGrabStart, _DuoyunChartZoomElement_onPan, _DuoyunChartZoomElement_onGrabEnd;
|
13 | import { adoptedStyle, customElement, emitter, property } from '@mantou/gem/lib/decorators';
|
14 | import { GemElement, html } from '@mantou/gem/lib/element';
|
15 | import { createCSSSheet, css, styleMap, classMap } from '@mantou/gem/lib/utils';
|
16 | import { clamp } from '../lib/number';
|
17 | import { theme } from '../lib/theme';
|
18 | import './gesture';
|
19 | import './area-chart';
|
20 | const style = createCSSSheet(css `
|
21 | :host(:where(:not([hidden]))) {
|
22 | position: relative;
|
23 | display: block;
|
24 | border-radius: ${theme.normalRound};
|
25 | border: 1px solid ${theme.borderColor};
|
26 | }
|
27 | dy-area-chart {
|
28 | aspect-ratio: 30;
|
29 | pointer-events: none;
|
30 | opacity: 0.4;
|
31 | background: ${theme.lightBackgroundColor};
|
32 | }
|
33 | .bg {
|
34 | cursor: crosshair;
|
35 | position: absolute;
|
36 | inset: 0;
|
37 | }
|
38 | .new-range,
|
39 | .range {
|
40 | position: absolute;
|
41 | height: 100%;
|
42 | top: 0;
|
43 | bottom: 0;
|
44 | background: #2680eb22;
|
45 | border: 1px solid ${theme.describeColor};
|
46 | border-width: 0 1px;
|
47 | border-radius: inherit;
|
48 | }
|
49 | .grab {
|
50 | cursor: grab;
|
51 | height: 50%;
|
52 | }
|
53 | .crosshair {
|
54 | cursor: crosshair;
|
55 | height: 50%;
|
56 | }
|
57 | .grabbing {
|
58 | cursor: grabbing;
|
59 | }
|
60 | .start,
|
61 | .stop {
|
62 | cursor: col-resize;
|
63 | position: absolute;
|
64 | top: 50%;
|
65 | background: ${theme.backgroundColor};
|
66 | height: 1em;
|
67 | width: 3px;
|
68 | border-radius: 10em;
|
69 | border: 1px solid ${theme.describeColor};
|
70 | }
|
71 | .start {
|
72 | left: 0;
|
73 | transform: translate(-50%, -50%);
|
74 | }
|
75 | .stop {
|
76 | right: 0;
|
77 | transform: translate(50%, -50%);
|
78 | }
|
79 | `);
|
80 |
|
81 |
|
82 |
|
83 | let DuoyunChartZoomElement = class DuoyunChartZoomElement extends GemElement {
|
84 | constructor() {
|
85 | super();
|
86 | this.value = [0, 1];
|
87 | this.state = {
|
88 | grabbing: false,
|
89 | };
|
90 | _DuoyunChartZoomElement_getMovement.set(this, (detail) => {
|
91 | const { left, right, width } = this.getBoundingClientRect();
|
92 | if (detail.clientX < left || detail.clientX > right)
|
93 | return 0;
|
94 | return detail.x / width;
|
95 | });
|
96 | _DuoyunChartZoomElement_getCurrent.set(this, (clientX) => {
|
97 | const { left, width } = this.getBoundingClientRect();
|
98 | return clamp(0, (clientX - left) / width, 1);
|
99 | });
|
100 | _DuoyunChartZoomElement_panAdjust.set(this, ([start, stop], detail) => {
|
101 | const movement = __classPrivateFieldGet(this, _DuoyunChartZoomElement_getMovement, "f").call(this, detail);
|
102 | const m = movement < 0 ? Math.max(0 - start, movement) : Math.min(1 - stop, movement);
|
103 | return [start + m, stop + m];
|
104 | });
|
105 | _DuoyunChartZoomElement_adjust.set(this, (detail, isStop) => {
|
106 | let [start, stop] = this.value;
|
107 | if (isStop)
|
108 | [stop, start] = [start, stop];
|
109 | const { left, width } = this.getBoundingClientRect();
|
110 | const newStart = clamp(0, (detail.clientX - left) / width, 1);
|
111 | const newValue = [Math.min(newStart, stop), Math.max(newStart, stop)];
|
112 | if (newValue[1] - newValue[0] < 0.01)
|
113 | return __classPrivateFieldGet(this, _DuoyunChartZoomElement_panAdjust, "f").call(this, this.value, detail);
|
114 | return newValue;
|
115 | });
|
116 | _DuoyunChartZoomElement_onPanStart.set(this, (evt) => {
|
117 | const newValue = __classPrivateFieldGet(this, _DuoyunChartZoomElement_adjust, "f").call(this, evt.detail, false);
|
118 | this.change(newValue);
|
119 | });
|
120 | _DuoyunChartZoomElement_onPanStop.set(this, (evt) => {
|
121 | const newValue = __classPrivateFieldGet(this, _DuoyunChartZoomElement_adjust, "f").call(this, evt.detail, true);
|
122 | this.change(newValue);
|
123 | });
|
124 | _DuoyunChartZoomElement_onNewStart.set(this, ({ clientX }) => {
|
125 | const v = __classPrivateFieldGet(this, _DuoyunChartZoomElement_getCurrent, "f").call(this, clientX);
|
126 | this.setState({ newValue: [v, v] });
|
127 | });
|
128 | _DuoyunChartZoomElement_onNewChange.set(this, ({ detail }) => {
|
129 | const v = __classPrivateFieldGet(this, _DuoyunChartZoomElement_getCurrent, "f").call(this, detail.clientX);
|
130 | this.setState({ newValue: [this.state.newValue[0], v] });
|
131 | });
|
132 | _DuoyunChartZoomElement_onNewEnd.set(this, () => {
|
133 | const { newValue } = this.state;
|
134 | this.change([Math.min(...newValue), Math.max(...newValue)]);
|
135 | this.setState({ newValue: undefined });
|
136 | });
|
137 | _DuoyunChartZoomElement_onGrabStart.set(this, () => {
|
138 | this.setState({ grabbing: true });
|
139 | });
|
140 | _DuoyunChartZoomElement_onPan.set(this, ({ detail }) => {
|
141 | const newValue = __classPrivateFieldGet(this, _DuoyunChartZoomElement_panAdjust, "f").call(this, this.value, detail);
|
142 | this.change(newValue);
|
143 | });
|
144 | _DuoyunChartZoomElement_onGrabEnd.set(this, () => {
|
145 | this.setState({ grabbing: false });
|
146 | });
|
147 | this.render = () => {
|
148 | var _a;
|
149 | const { grabbing, newValue } = this.state;
|
150 | const [start, stop] = this.value;
|
151 | return html `
|
152 | <dy-area-chart
|
153 | .smooth=${Number((_a = this.values) === null || _a === void 0 ? void 0 : _a.length) < 100}
|
154 | .stageHeight=${12}
|
155 | .colors=${[theme.informativeColor]}
|
156 | .xAxi=${null}
|
157 | .yAxi=${null}
|
158 | .sequences=${this.values && [{ label: '', values: this.values }]}
|
159 | ></dy-area-chart>
|
160 | <dy-gesture class="bg" @pointerdown=${__classPrivateFieldGet(this, _DuoyunChartZoomElement_onNewStart, "f")} @pan=${__classPrivateFieldGet(this, _DuoyunChartZoomElement_onNewChange, "f")} @end=${__classPrivateFieldGet(this, _DuoyunChartZoomElement_onNewEnd, "f")}>
|
161 | ${newValue
|
162 | ? html `
|
163 | <div
|
164 | class="new-range"
|
165 | style=${styleMap({
|
166 | left: `calc(${Math.min(...newValue) * 100}% - 1px)`,
|
167 | right: `calc(${(1 - Math.max(...newValue)) * 100}% - 2px)`,
|
168 | })}
|
169 | ></div>
|
170 | `
|
171 | : ''}
|
172 | </dy-gesture>
|
173 | <div
|
174 | class=${classMap({ range: true, grabbing })}
|
175 | style=${styleMap({ left: `calc(${start * 100}% - 1px)`, right: `calc(${(1 - stop) * 100}% - 2px)` })}
|
176 | >
|
177 | <dy-gesture
|
178 | class=${classMap({ grab: true, grabbing })}
|
179 | @pointerdown=${__classPrivateFieldGet(this, _DuoyunChartZoomElement_onGrabStart, "f")}
|
180 | @pan=${__classPrivateFieldGet(this, _DuoyunChartZoomElement_onPan, "f")}
|
181 | @end=${__classPrivateFieldGet(this, _DuoyunChartZoomElement_onGrabEnd, "f")}
|
182 | ></dy-gesture>
|
183 | <dy-gesture
|
184 | class="crosshair"
|
185 | @pointerdown=${__classPrivateFieldGet(this, _DuoyunChartZoomElement_onNewStart, "f")}
|
186 | @pan=${__classPrivateFieldGet(this, _DuoyunChartZoomElement_onNewChange, "f")}
|
187 | @end=${__classPrivateFieldGet(this, _DuoyunChartZoomElement_onNewEnd, "f")}
|
188 | ></dy-gesture>
|
189 | <dy-gesture class="start" @pan=${__classPrivateFieldGet(this, _DuoyunChartZoomElement_onPanStart, "f")}></dy-gesture>
|
190 | <dy-gesture class="stop" @pan=${__classPrivateFieldGet(this, _DuoyunChartZoomElement_onPanStop, "f")}></dy-gesture>
|
191 | </div>
|
192 | `;
|
193 | };
|
194 | this.addEventListener('dblclick', () => this.change([0, 1]));
|
195 | }
|
196 | };
|
197 | _DuoyunChartZoomElement_getMovement = new WeakMap(), _DuoyunChartZoomElement_getCurrent = new WeakMap(), _DuoyunChartZoomElement_panAdjust = new WeakMap(), _DuoyunChartZoomElement_adjust = new WeakMap(), _DuoyunChartZoomElement_onPanStart = new WeakMap(), _DuoyunChartZoomElement_onPanStop = new WeakMap(), _DuoyunChartZoomElement_onNewStart = new WeakMap(), _DuoyunChartZoomElement_onNewChange = new WeakMap(), _DuoyunChartZoomElement_onNewEnd = new WeakMap(), _DuoyunChartZoomElement_onGrabStart = new WeakMap(), _DuoyunChartZoomElement_onPan = new WeakMap(), _DuoyunChartZoomElement_onGrabEnd = new WeakMap();
|
198 | __decorate([
|
199 | property
|
200 | ], DuoyunChartZoomElement.prototype, "values", void 0);
|
201 | __decorate([
|
202 | property
|
203 | ], DuoyunChartZoomElement.prototype, "value", void 0);
|
204 | __decorate([
|
205 | emitter
|
206 | ], DuoyunChartZoomElement.prototype, "change", void 0);
|
207 | DuoyunChartZoomElement = __decorate([
|
208 | customElement('dy-chart-zoom'),
|
209 | adoptedStyle(style)
|
210 | ], DuoyunChartZoomElement);
|
211 | export { DuoyunChartZoomElement };
|
212 |
|
\ | No newline at end of file |