Browse Source

bar events fixes

pull/1/head
rozetko 2 years ago
parent
commit
ae6aa53901
  1. 23
      src/index.ts

23
src/index.ts

@ -27,7 +27,7 @@ export class ChartwerkBarPod extends ChartwerkPod<BarSerie, BarOptions> {
this.renderNoDataPointsMessage(); this.renderNoDataPointsMessage();
return; return;
} }
this.setBarPodScales(); this.setBarPodScales();
this.setSeriesDataForRendering(); this.setSeriesDataForRendering();
this.renderSerie(this._seriesDataForRendring); this.renderSerie(this._seriesDataForRendring);
@ -65,7 +65,6 @@ export class ChartwerkBarPod extends ChartwerkPod<BarSerie, BarOptions> {
.data(d.values) .data(d.values)
.enter().append('rect') .enter().append('rect')
.style('fill', (val, i) => d.colors[i]) .style('fill', (val, i) => d.colors[i])
.style('pointer-events', this.options.contextMenu ? 'all' : 'none')
.attr('opacity', () => this.getBarOpacity(d)) .attr('opacity', () => this.getBarOpacity(d))
.attr('x', (val: number, idx: number) => { .attr('x', (val: number, idx: number) => {
return this.getBarPositionX(d.key, idx); return this.getBarPositionX(d.key, idx);
@ -75,7 +74,10 @@ export class ChartwerkBarPod extends ChartwerkPod<BarSerie, BarOptions> {
}) })
.attr('width', this.barWidth) .attr('width', this.barWidth)
.attr('height', (val: number) => this.getBarHeight(val)) .attr('height', (val: number) => this.getBarHeight(val))
.on('contextmenu', this.contextMenu.bind(this)); .on('contextmenu', this.contextMenu.bind(this))
.on('mouseover', (e) => { this.overlay.node().dispatchEvent(new MouseEvent(d3.event.type, d3.event)); })
.on('mousemove', (e) => { this.overlay.node().dispatchEvent(new MouseEvent(d3.event.type, d3.event)); })
.on('mousedown', () => { d3.event.stopPropagation(); });
// render bar annotations, its all hardcoded // render bar annotations, its all hardcoded
if(_.isEmpty(this.options.barOptions.annotations)) { if(_.isEmpty(this.options.barOptions.annotations)) {
@ -85,13 +87,13 @@ export class ChartwerkBarPod extends ChartwerkPod<BarSerie, BarOptions> {
const series = _.filter(this.series.visibleSeries, serie => _.includes(d.serieTarget, serie.target)); const series = _.filter(this.series.visibleSeries, serie => _.includes(d.serieTarget, serie.target));
const matchedKeys = _.map(series, serie => serie.matchedKey); // here matchedKeys should be equal const matchedKeys = _.map(series, serie => serie.matchedKey); // here matchedKeys should be equal
const key = matchedKeys[0]; const key = matchedKeys[0];
const lastRect = _.last(container.selectAll('rect')?.nodes()); const lastRect = _.last(container.selectAll('rect')?.nodes());
const annotation = _.find(this.options.barOptions.annotations, a => a.key === key); const annotation = _.find(this.options.barOptions.annotations, a => a.key === key);
if(!lastRect || !key || !annotation) { if(!lastRect || !key || !annotation) {
return; return;
} }
const rectSelection = d3.select(lastRect); const rectSelection = d3.select(lastRect);
// render triangle // render triangle
container.append('path') container.append('path')
@ -101,7 +103,10 @@ export class ChartwerkBarPod extends ChartwerkPod<BarSerie, BarOptions> {
const options = { max: this.options.barOptions.maxAnnotationSize, min: this.options.barOptions.minAnnotationSize }; const options = { max: this.options.barOptions.maxAnnotationSize, min: this.options.barOptions.minAnnotationSize };
return this.getTrianglePath(x, y, this.barWidth, options); return this.getTrianglePath(x, y, this.barWidth, options);
}) })
.attr('fill', annotation.color); .attr('fill', annotation.color)
.on('mouseover', (e) => { this.overlay.node().dispatchEvent(new MouseEvent(d3.event.type, d3.event)); })
.on('mousemove', (e) => { this.overlay.node().dispatchEvent(new MouseEvent(d3.event.type, d3.event)); })
.on('mousedown', () => { d3.event.stopPropagation(); });
}); });
} }
@ -112,8 +117,8 @@ export class ChartwerkBarPod extends ChartwerkPod<BarSerie, BarOptions> {
const yOffset = 4; // offset between triangle and bar const yOffset = 4; // offset between triangle and bar
const centerX = x + length / 2; const centerX = x + length / 2;
const correctedLength = _.clamp(length, minTriangleSize, maxTriagleSize); const correctedLength = _.clamp(length, minTriangleSize, maxTriagleSize);
const topY = Math.max(y - correctedLength - yOffset, 4); const topY = Math.max(y - correctedLength - yOffset, 4);
const topLeftCorner = { const topLeftCorner = {
x: centerX - correctedLength / 2, x: centerX - correctedLength / 2,
y: topY, y: topY,
@ -349,7 +354,7 @@ export class ChartwerkBarPod extends ChartwerkPod<BarSerie, BarOptions> {
} else { } else {
const valuesColumns = _.map(this.series.visibleSeries, serie => _.map(serie.datapoints, row => row[1])); const valuesColumns = _.map(this.series.visibleSeries, serie => _.map(serie.datapoints, row => row[1]));
const zippedValuesColumn = _.zip(...valuesColumns); const zippedValuesColumn = _.zip(...valuesColumns);
maxValue = _.max(_.map(zippedValuesColumn, row => _.sum(row))); maxValue = _.max(_.map(zippedValuesColumn, row => _.sum(row)));
} }
} else { } else {
maxValue = _.max( maxValue = _.max(

Loading…
Cancel
Save