| 16 | } |
| 17 | |
| 18 | export class ExampleView extends VComponent<ExampleViewData> { |
| 19 | private div_origs: D3Sel; |
| 20 | renderData: ExampleViewData; |
| 21 | |
| 22 | private _imgWidth = -1; |
| 23 | |
| 24 | |
| 25 | constructor(d3parent: D3Sel, eventHandler?: SimpleEventHandler) { |
| 26 | super(d3parent, eventHandler); |
| 27 | this.superInitHTML(); |
| 28 | this._init(); |
| 29 | } |
| 30 | |
| 31 | public static events = { |
| 32 | request_examples: "ExampleView_re", |
| 33 | hovered_image_pair: "ExampleView_hip", |
| 34 | clicked_image_pair: "ExampleView_cip", |
| 35 | |
| 36 | } |
| 37 | |
| 38 | |
| 39 | protected _current = {}; |
| 40 | protected css_name = "ExampleView"; |
| 41 | protected options = {pos: {x: 0, y: 0}}; |
| 42 | |
| 43 | protected _init() { |
| 44 | this.div_origs = this.base.append('div').attr('class', 'examples'); |
| 45 | |
| 46 | } |
| 47 | |
| 48 | protected _render(rData = this.renderData): void { |
| 49 | if (!rData) return; |
| 50 | |
| 51 | const that = this; |
| 52 | const renderList = rData.orig.res.map(d => [d]); |
| 53 | |
| 54 | if (rData.compare) { |
| 55 | rData.compare.res.map((d, i) => renderList[i].push(d)); |
| 56 | } |
| 57 | |
| 58 | let img_pairs = this.div_origs.selectAll('.img_pair').data(renderList); |
| 59 | img_pairs.exit().remove(); |
| 60 | img_pairs = img_pairs.enter().append('div').attr('class', 'img_pair') |
| 61 | .merge(img_pairs); |
| 62 | |
| 63 | let imgs = img_pairs.selectAll('img').data(d => d); |
| 64 | imgs.exit().remove(); |
| 65 | imgs.enter().append('img') |
| 66 | .merge(imgs) |
| 67 | .attr('src', d => d.d) |
| 68 | .attr('width', this._imgWidth > -1 ? this._imgWidth : null); |
| 69 | |
| 70 | |
| 71 | img_pairs.on('click', function (d) { |
| 72 | const eventDetail: ExampleViewMouseEvent = { |
| 73 | caller: d3.select(this), |
| 74 | images: d |
| 75 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected