Browse Source

show labels on hover

merge-requests/1/merge
vargburz 3 years ago
parent
commit
7b9a5d724c
  1. 4
      dist/index.d.ts
  2. 47425
      dist/index.js
  3. 41
      src/index.ts

4
dist/index.d.ts vendored

@ -15,6 +15,7 @@ export declare class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, Gaug
private _renderIcon; private _renderIcon;
private _getIconPosition; private _getIconPosition;
private _getIconSize; private _getIconSize;
protected _renderOverlayBackground(): void;
private _renderValue; private _renderValue;
private _renderValueArc; private _renderValueArc;
private _renderThresholdArc; private _renderThresholdArc;
@ -47,6 +48,9 @@ export declare class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, Gaug
onMouseOver(): void; onMouseOver(): void;
onMouseMove(): void; onMouseMove(): void;
onMouseOut(): void; onMouseOut(): void;
onGaugeMouseOver(): void;
onGaugeMouseMove(): void;
onGaugeMouseOut(): void;
renderSharedCrosshair(): void; renderSharedCrosshair(): void;
hideSharedCrosshair(): void; hideSharedCrosshair(): void;
} }

47425
dist/index.js vendored

File diff suppressed because one or more lines are too long

41
src/index.ts

@ -88,7 +88,7 @@ export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions
this.renderNoDataPointsMessage(); this.renderNoDataPointsMessage();
return; return;
} }
this._renderOverlayBackground();
this._renderValueArc(); this._renderValueArc();
this._renderThresholdArc(); this._renderThresholdArc();
this._renderValue(); this._renderValue();
@ -145,7 +145,8 @@ export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions
.attr('x', this._getIconPosition(icon).x) .attr('x', this._getIconPosition(icon).x)
.attr('y', this._getIconPosition(icon).y) .attr('y', this._getIconPosition(icon).y)
.attr('width', `${this._getIconSize(icon)}px`) .attr('width', `${this._getIconSize(icon)}px`)
.attr('height', `${this._getIconSize(icon)}px`); .attr('height', `${this._getIconSize(icon)}px`)
.attr('pointer-events', 'none');
} }
private _getIconPosition(icon: IconConfig): { x: number, y: number } { private _getIconPosition(icon: IconConfig): { x: number, y: number } {
@ -178,6 +179,21 @@ export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions
return this.rescaleWith(icon.size); return this.rescaleWith(icon.size);
} }
protected _renderOverlayBackground(): void {
this.svg
.append('rect')
.attr('x', 0)
.attr('y', 0)
.attr('width', this.width)
.attr('height', this.height)
.classed('overlay', true)
.attr('pointer-events', 'all')
.attr('fill', 'none')
.on('mouseover', this.onGaugeMouseOver.bind(this))
.on('mouseout', this.onGaugeMouseOut.bind(this))
.on('mousemove', this.onGaugeMouseMove.bind(this));
}
private _renderValue(): void { private _renderValue(): void {
this.svg this.svg
.append('text') .append('text')
@ -190,6 +206,7 @@ export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions
.attr('transform', this._gaugeCenterTranform) .attr('transform', this._gaugeCenterTranform)
.attr('text-anchor', 'middle') .attr('text-anchor', 'middle')
.attr('alignment-baseline', 'central') .attr('alignment-baseline', 'central')
.attr('pointer-events', 'none')
.attr('fill', this._mainCircleColor); .attr('fill', this._mainCircleColor);
} }
@ -277,6 +294,8 @@ export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions
.classed('label-background', true) .classed('label-background', true)
.attr('rx', 16) .attr('rx', 16)
.attr('fill', 'gray') .attr('fill', 'gray')
.attr('pointer-events', 'none')
.style('display', 'none')
.attr('fill-opacity', 0.5); .attr('fill-opacity', 0.5);
} }
@ -291,6 +310,8 @@ export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions
.attr('font-size', `${this._valueTextFontSize}px`) .attr('font-size', `${this._valueTextFontSize}px`)
.attr('text-anchor', 'middle') .attr('text-anchor', 'middle')
.attr('alignment-baseline', 'central') .attr('alignment-baseline', 'central')
.attr('pointer-events', 'none')
.style('display', 'none')
.attr('fill', 'white'); .attr('fill', 'white');
} }
@ -464,7 +485,21 @@ export class ChartwerkGaugePod extends ChartwerkPod<GaugeTimeSerie, GaugeOptions
/* handlers and overloads */ /* handlers and overloads */
onMouseOver(): void {} onMouseOver(): void {}
onMouseMove(): void {} onMouseMove(): void {}
onMouseOut(): void { } onMouseOut(): void {}
onGaugeMouseOver(): void {
this.svg.selectAll('.label-text').style('display', null);
this.svg.selectAll('.label-background').style('display', null);
}
onGaugeMouseMove(): void {
this.svg.selectAll('.label-text').style('display', null);
this.svg.selectAll('.label-background').style('display', null);
}
onGaugeMouseOut(): void {
this.svg.selectAll('.label-text').style('display', 'none');
this.svg.selectAll('.label-background').style('display', 'none');
}
renderSharedCrosshair(): void {} renderSharedCrosshair(): void {}
hideSharedCrosshair(): void {} hideSharedCrosshair(): void {}
} }

Loading…
Cancel
Save