@net7/components 3.0.2-rc.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -844,6 +844,7 @@ class HistogramRangeComponent {
844
844
  const svg = d3
845
845
  .select(`#${containerId}`)
846
846
  .attr('viewBox', `0 0 ${width + margin.left + margin.right} ${height + margin.top + margin.bottom}`);
847
+ this.svg = svg;
847
848
  const scaleHeight = d3
848
849
  .scaleSymlog() // most similar scale to the original
849
850
  .domain([0, d3.max(items, (d) => d.value)])
@@ -892,7 +893,7 @@ class HistogramRangeComponent {
892
893
  .attr('fill', 'url(#gradient)');
893
894
  barsLayer // catch bar events
894
895
  .on('mousemove', (event) => {
895
- const year = XtoLABEL(event.offsetX - margin.left);
896
+ const year = XtoLABEL(this.getEventCoords(event).x);
896
897
  d3.selectAll('rect.bars').attr('fill', (d) => {
897
898
  if (year === d.label)
898
899
  return '#B0CCF8';
@@ -903,7 +904,7 @@ class HistogramRangeComponent {
903
904
  d3.selectAll('rect.bars').attr('fill', (d) => colourBars(d));
904
905
  })
905
906
  .on('click', (event) => {
906
- const label = XtoLABEL(event.offsetX - margin.left);
907
+ const label = XtoLABEL(this.getEventCoords(event).x);
907
908
  const xAxisValue = LABELtoX(label) + LABELtoX.bandwidth() / 2;
908
909
  const newValue = {
909
910
  x: xAxisValue,
@@ -969,8 +970,8 @@ class HistogramRangeComponent {
969
970
  // eslint-disable-next-line @typescript-eslint/no-this-alias
970
971
  const self = this; // FIXME: Allow use of class "this" inside dragging update;
971
972
  /**
972
- * Animate the elements while the user is dragging one of the range selectors
973
- */
973
+ * Animate the elements while the user is dragging one of the range selectors
974
+ */
974
975
  function draggingUpdate(event, data) {
975
976
  const label = XtoLABEL(event.x);
976
977
  const xAxisValue = LABELtoX(label) + LABELtoX.bandwidth() / 2;
@@ -1082,20 +1083,22 @@ class HistogramRangeComponent {
1082
1083
  this.d3.selectAll('rect.bars').attr('fill', (d) => this.colourBars(d));
1083
1084
  };
1084
1085
  /** Public api that allows to dinamically change the slider position */
1085
- this.setSliders = ([startLabel, endLabel]) => {
1086
+ this.setSliders = ([startLabel, endLabel], emit = true) => {
1087
+ // setSliders([1450, 1575])
1086
1088
  this.data.setSliders = [`${startLabel}`, `${endLabel}`];
1087
1089
  this.draw();
1088
1090
  this.d3.selectAll('rect.bars').attr('fill', (d) => this.colourBars(d));
1089
1091
  const range = this.getSelectedRange();
1090
- this.emit('rangeselected', range);
1092
+ if (emit)
1093
+ this.emit('rangeselected', range);
1091
1094
  this.textCollision(this.sliders);
1092
1095
  return range;
1093
1096
  };
1094
1097
  }
1095
1098
  ngAfterContentChecked() {
1096
1099
  /*
1097
- Waits for the dom to be loaded, then fires the draw function
1098
- that renders the chart.
1100
+ Waits for the dom to be loaded, then fires the draw function
1101
+ that renders the chart.
1099
1102
  */
1100
1103
  if (this.data) {
1101
1104
  if (this._loaded)
@@ -1116,7 +1119,7 @@ class HistogramRangeComponent {
1116
1119
  });
1117
1120
  }
1118
1121
  // eslint-disable-next-line dot-notation
1119
- window['setSliders'] = this.setSliders;
1122
+ // window['setSliders'] = this.setSliders;
1120
1123
  });
1121
1124
  });
1122
1125
  }
@@ -1130,6 +1133,17 @@ class HistogramRangeComponent {
1130
1133
  .paddingInner(0.17)
1131
1134
  .paddingOuter(1);
1132
1135
  }
1136
+ /**
1137
+ * Get an event with viewBox coordinates and
1138
+ * parse them in absolute coordinates
1139
+ */
1140
+ getEventCoords(event) {
1141
+ const m = event.target.getScreenCTM();
1142
+ const point = this.svg.node().createSVGPoint();
1143
+ point.x = event.clientX;
1144
+ point.y = event.clientY;
1145
+ return point.matrixTransform(m.inverse());
1146
+ }
1133
1147
  /** Emits an event when the component has loaded */
1134
1148
  emitLoaded(payload) {
1135
1149
  if (!this.emit)
@@ -6666,8 +6680,8 @@ const HISTOGRAM_RANGE_MOCK = {
6666
6680
  accent: '#2F528B',
6667
6681
  },
6668
6682
  margin: {
6669
- left: 30,
6670
- right: 0,
6683
+ left: 25,
6684
+ right: 5,
6671
6685
  top: 10,
6672
6686
  bottom: 45
6673
6687
  },