()
| 46 | |
| 47 | export class Figure extends DOMWidgetView { |
| 48 | initialize() { |
| 49 | this.debouncedRelayout = _.debounce(() => { |
| 50 | this.relayout(); |
| 51 | }, 300); |
| 52 | this.debouncedUpdateDecorators = _.debounce(() => { |
| 53 | this.updateDecorators(); |
| 54 | }, 100); |
| 55 | // Internet Explorer does not support classList for svg elements |
| 56 | this.el.classList.add('bqplot'); |
| 57 | this.el.classList.add('figure'); |
| 58 | this.el.classList.add('jupyter-widgets'); |
| 59 | this.change_theme(); |
| 60 | |
| 61 | const svg = document.createElementNS( |
| 62 | d3.namespaces.svg, |
| 63 | 'svg' |
| 64 | ) as SVGElement; |
| 65 | svg.classList.add('svg-figure'); |
| 66 | this.svg = d3.select<SVGElement, any>(svg); |
| 67 | |
| 68 | const svg_background = document.createElementNS( |
| 69 | d3.namespaces.svg, |
| 70 | 'svg' |
| 71 | ) as SVGElement; |
| 72 | svg_background.classList.add('svg-background'); |
| 73 | this.svg_background = d3.select<SVGElement, any>(svg_background); |
| 74 | |
| 75 | this.el.appendChild(svg_background); |
| 76 | this.el.appendChild(svg); |
| 77 | |
| 78 | this.intersectObserver = new IntersectionObserver( |
| 79 | (entries: IntersectionObserverEntry[]) => { |
| 80 | if (entries[entries.length - 1].isIntersecting) { |
| 81 | this.visible = true; |
| 82 | this.debouncedRelayout(); |
| 83 | } else if (entries[entries.length - 1].rootBounds != null) { |
| 84 | /* When 'rootBounds' is null, 'isIntersecting' is 'false', but the plot is visible, so only change 'visible' |
| 85 | * if rootBonds is set. I can't find any info on this behaviour. */ |
| 86 | this.visible = false; |
| 87 | } |
| 88 | }, |
| 89 | { threshold: 0 } |
| 90 | ); |
| 91 | this.intersectObserver.observe(this.el); |
| 92 | |
| 93 | this.resizeObserver = new ResizeObserver( |
| 94 | (entries: ResizeObserverEntry[]) => { |
| 95 | this.debouncedRelayout(); |
| 96 | } |
| 97 | ); |
| 98 | |
| 99 | this.resizeObserver.observe(this.el); |
| 100 | |
| 101 | super.initialize.apply(this, arguments); |
| 102 | } |
| 103 | |
| 104 | protected getFigureSize(): IFigureSize { |
| 105 | const domSize: IFigureSize = this.el.getBoundingClientRect(); |
nothing calls this directly
no test coverage detected