(presenter: VegaDeckGl.Presenter, specCapabilities: SpecCapabilities, columns: SpecColumns, stage: VegaDeckGl.types.Stage, clickHandler: AxisSelectionHandler, highlightColor: string, polygonZ: number)
| 17 | } |
| 18 | |
| 19 | export function axisSelectionLayer(presenter: VegaDeckGl.Presenter, specCapabilities: SpecCapabilities, columns: SpecColumns, stage: VegaDeckGl.types.Stage, clickHandler: AxisSelectionHandler, highlightColor: string, polygonZ: number) { |
| 20 | const polygons: SelectPolygon[] = []; |
| 21 | const xRole = specCapabilities.roles.filter(r => r.role === 'x')[0]; |
| 22 | if (xRole && xRole.axisSelection) { |
| 23 | stage.axes.x.filter(axis => axis.tickText.length).forEach(axis => { |
| 24 | polygons.push.apply(polygons, axisSelectionPolygons(axis, false, xRole.axisSelection, columns.x)); |
| 25 | }); |
| 26 | } |
| 27 | const yRole = specCapabilities.roles.filter(r => r.role === 'y')[0]; |
| 28 | if (yRole && yRole.axisSelection) { |
| 29 | stage.axes.y.filter(axis => axis.tickText.length).forEach(axis => { |
| 30 | polygons.push.apply(polygons, axisSelectionPolygons(axis, true, yRole.axisSelection, columns.y)); |
| 31 | }); |
| 32 | } |
| 33 | if (stage.facets && columns.facet) { |
| 34 | polygons.push.apply(polygons, facetSelectionPolygons(stage.facets)); |
| 35 | } |
| 36 | //move polygons to Z |
| 37 | polygons.forEach(datum => { |
| 38 | (datum.polygon as number[][]).forEach(p => { |
| 39 | p[2] = polygonZ; |
| 40 | }); |
| 41 | }); |
| 42 | const onClick: VegaDeckGl.LayerInputHandler = (o, e) => clickHandler(e.srcEvent, (o.object as SelectPolygon).search); |
| 43 | const polygonLayer = new VegaDeckGl.base.layers.PolygonLayer<SelectPolygon>({ |
| 44 | autoHighlight: true, |
| 45 | coordinateSystem: VegaDeckGl.base.deck.COORDINATE_SYSTEM.CARTESIAN, |
| 46 | data: polygons, |
| 47 | extruded: false, |
| 48 | highlightColor: VegaDeckGl.util.colorFromString(highlightColor), |
| 49 | id: 'selections', |
| 50 | onHover: (o, e) => { |
| 51 | if (o.index === -1) { |
| 52 | presenter.deckgl.interactiveState.onAxisSelection = false; |
| 53 | } else { |
| 54 | presenter.deckgl.interactiveState.onAxisSelection = true; |
| 55 | } |
| 56 | }, |
| 57 | onClick, |
| 58 | getElevation: () => 0, |
| 59 | getFillColor: () => [0, 0, 0, 0], |
| 60 | pickable: true, |
| 61 | stroked: false, |
| 62 | }); |
| 63 | |
| 64 | return polygonLayer; |
| 65 | } |
| 66 | |
| 67 | interface SelectPolygon { |
| 68 | polygon: VegaDeckGl.Position[] |
no test coverage detected