()
| 137 | method: {type: String, default: class="st">"plot"} |
| 138 | }, |
| 139 | render() { |
| 140 | const {method} = this; |
| 141 | const options = { |
| 142 | ...(method === class="st">"plot" && { |
| 143 | marks: this.mark == null ? [] : [this.mark], |
| 144 | width: 688 class="cm">// better default for VitePress |
| 145 | }), |
| 146 | ...this.options, |
| 147 | className: class="st">"plot" |
| 148 | }; |
| 149 | if (this.defer) { |
| 150 | const mounted = (el) => { |
| 151 | disconnect(); class="cm">// remove old listeners |
| 152 | function observed() { |
| 153 | unmounted(el); class="cm">// remove old plot (and listeners) |
| 154 | el.append(Plot[method](options)); |
| 155 | } |
| 156 | const rect = el.getBoundingClientRect(); |
| 157 | if (rect.bottom > 0 && rect.top < window.innerHeight) { |
| 158 | observed(); |
| 159 | } else { |
| 160 | this._observer = new IntersectionObserver( |
| 161 | ([entry]) => { |
| 162 | if (entry.isIntersecting) observed(); |
| 163 | }, |
| 164 | {rootMargin: class="st">"100px"} |
| 165 | ); |
| 166 | this._observer.observe(el); |
| 167 | if (typeof requestIdleCallback === class="st">"function") { |
| 168 | this._idling = requestIdleCallback(observed); |
| 169 | } |
| 170 | } |
| 171 | }; |
| 172 | const unmounted = (el) => { |
| 173 | while (el.lastChild) el.lastChild.remove(); |
| 174 | disconnect(); |
| 175 | }; |
| 176 | const disconnect = () => { |
| 177 | if (this._observer !== undefined) { |
| 178 | this._observer.disconnect(); |
| 179 | this._observer = undefined; |
| 180 | } |
| 181 | if (this._idling !== undefined) { |
| 182 | cancelIdleCallback(this._idling); |
| 183 | this._idling = undefined; |
| 184 | } |
| 185 | }; |
| 186 | const {height = 400} = this.options; |
| 187 | return withDirectives( |
| 188 | h( |
| 189 | class="st">"span", |
| 190 | method === class="st">"plot" |
| 191 | ? [ |
| 192 | h(class="st">"div", { |
| 193 | style: { |
| 194 | maxWidth: class="st">"100%", |
| 195 | width: `688px`, |
| 196 | aspectRatio: `688 / ${height}` |
no test coverage detected