Browse Source

markers conf + events

marker-callback-#25
glitch4347 12 months ago
parent
commit
43241bbcb7
  1. 6
      examples/markers_select.html
  2. 11
      src/components/markers.ts
  3. 5
      src/models/marker.ts

6
examples/markers_select.html

@ -34,7 +34,11 @@
{ {
series: [ series: [
{ data: markersData, color: 'red' }, { data: markersData, color: 'red' },
] ],
events: {
onMouseMove: (el) => { console.log(el); },
onMouseOut: () => { console.log('mouse out'); }
}
} }
); );
pod.render(); pod.render();

11
src/components/markers.ts

@ -37,15 +37,22 @@ export class Markers {
// @ts-ignore // TODO: remove ignore but boxParams are protected // @ts-ignore // TODO: remove ignore but boxParams are protected
.attr('y2', this._state.boxParams.height) .attr('y2', this._state.boxParams.height)
.attr('pointer-events', 'none'); .attr('pointer-events', 'none');
this._d3Holder.append('circle') let circle = this._d3Holder.append('circle')
.attr('class', 'gap-circle') .attr('class', 'gap-circle')
.attr('stroke', serie.color) .attr('stroke', serie.color)
.attr('stroke-width', '2px') .attr('stroke-width', '2px')
.attr('r', 4) .attr('r', 4)
.attr('cx', linePosition) .attr('cx', linePosition)
.attr('cy', 5) .attr('cy', 5)
.attr('pointer-events', 'none') // TODO: make all on implementation of Events
if(this._markerConf !== undefined) {
circle
.attr('pointer-events', 'all')
.style('cursor', 'pointer') .style('cursor', 'pointer')
.on('mousemove', () => this._markerConf.events.onMouseMove(d))
.on('mouseout', () => this._markerConf.events.onMouseOut())
}
}); });
} }

5
src/models/marker.ts

@ -8,5 +8,8 @@ export type MarkerSerie = {
export type MarkersConf = { export type MarkersConf = {
series: MarkerSerie[], series: MarkerSerie[],
onSelect?: (el: MarkerElem[]) => void; events?: {
onMouseMove?: (el: MarkerElem[]) => void;
onMouseOut?: () => void;
}
} }
Loading…
Cancel
Save