@websy/websy-designs 1.4.34 → 1.4.35

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.
@@ -6565,6 +6565,7 @@ class WebsyChart {
6565
6565
  this.renderedKeys = {}
6566
6566
  this.brushedDomain = []
6567
6567
  this.brushBarsInitialized = {}
6568
+ this.brushLinesInitialized = {}
6568
6569
  if (!elementId) {
6569
6570
  console.log('No element Id provided for Websy Chart')
6570
6571
  return
@@ -6699,7 +6700,7 @@ class WebsyChart {
6699
6700
  this.labelLayer.selectAll('*').remove()
6700
6701
  this.symbolLayer.selectAll('*').remove()
6701
6702
  }
6702
- createDomain (side) {
6703
+ createDomain (side, forBrush = false) {
6703
6704
  let domain = []
6704
6705
  /* global d3 side domain:writable forBrush */
6705
6706
  // if we have a brushed domain we use that
@@ -6859,7 +6860,7 @@ else {
6859
6860
  tooltipHTML += tooltipData.map(d => `
6860
6861
  <li>
6861
6862
  <i style='background-color: ${d.color};'></i>
6862
- ${d.tooltipLabel || ''}<span> - ${d.tooltipValue || d.value}</span>
6863
+ ${d.tooltipLabel || ''}<span>: ${d.tooltipValue || d.value}</span>
6863
6864
  </li>
6864
6865
  `).join('')
6865
6866
  tooltipHTML += `</ul>`
@@ -7190,6 +7191,7 @@ else {
7190
7191
  // Define the plot size
7191
7192
  this.plotWidth = this.width - this.options.margin.legendLeft - this.options.margin.legendRight - this.options.margin.left - this.options.margin.right - this.options.margin.axisLeft - this.options.margin.axisRight
7192
7193
  this.plotHeight = this.height - this.options.margin.legendTop - this.options.margin.legendBottom - this.options.margin.top - this.options.margin.bottom - this.options.margin.axisBottom - this.options.margin.axisTop
7194
+ this.brushNeeded = false
7193
7195
  if (this.options.orientation === 'vertical') {
7194
7196
  if (this.options.maxBandWidth) {
7195
7197
  this.plotWidth = Math.min(this.plotWidth, (this.options.data.bottom.data || []).length * this.options.maxBandWidth)
@@ -7350,6 +7352,7 @@ else {
7350
7352
  // this.brushArea.selectAll('*').remove()
7351
7353
  if (this.brushNeeded) {
7352
7354
  if (!this.brushInitialized) {
7355
+ this.brushLayer.style('visibility', 'visible')
7353
7356
  this.brushInitialized = true
7354
7357
  this.brushLayer
7355
7358
  .select('.brush')
@@ -7358,7 +7361,9 @@ else {
7358
7361
  }
7359
7362
  }
7360
7363
  else {
7361
- this.brushLayer.selectAll().remove()
7364
+ this.brushLayer.style('visibility', 'hidden')
7365
+ // this.brushLayer.selectAll().remove()
7366
+ this.brushArea.selectAll('*').remove()
7362
7367
  }
7363
7368
  if (this.options.margin.axisBottom > 0) {
7364
7369
  let timeFormatPattern = ''
@@ -7947,7 +7952,7 @@ const drawLine = (xAxis, yAxis, curveStyle) => {
7947
7952
  return d3
7948
7953
  .line()
7949
7954
  .x(d => {
7950
- let adjustment = this.options.data[xAxis].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
7955
+ let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
7951
7956
  return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
7952
7957
  })
7953
7958
  .y(d => {
@@ -7961,8 +7966,16 @@ if (this.options.orienation === 'horizontal') {
7961
7966
  xAxis = series.axis === 'secondary' ? 'right' : 'left'
7962
7967
  yAxis = 'bottom'
7963
7968
  }
7969
+ let xBrushAxis = 'bottomBrush'
7970
+ let yBrushAxis = 'leftBrush'
7971
+ if (this.options.orienation === 'horizontal') {
7972
+ xBrushAxis = 'leftBrush'
7973
+ yBrushAxis = 'bottomBrush'
7974
+ }
7964
7975
  let lines = this.lineLayer.selectAll(`.line_${series.key}`)
7965
7976
  .data([series.data])
7977
+ let brushLines = this.brushArea.selectAll(`.line_${series.key}`)
7978
+ .data([series.data])
7966
7979
  // Exit
7967
7980
  lines.exit()
7968
7981
  .transition(this.transition)
@@ -7989,6 +8002,35 @@ lines.enter().append('path')
7989
8002
  // .transition(this.transition)
7990
8003
  .style('stroke-opacity', 1)
7991
8004
 
8005
+ if (!this.brushLinesInitialized[series.key]) {
8006
+ this.brushLinesInitialized[series.key] = true
8007
+ // Exit
8008
+ brushLines.exit()
8009
+ .transition(this.transition)
8010
+ .style('stroke-opacity', 1e-6)
8011
+ .remove()
8012
+ // Update
8013
+ brushLines
8014
+ .style('stroke-width', 1)
8015
+ // .attr('id', `line_${series.key}`)
8016
+ // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8017
+ .attr('stroke', series.color)
8018
+ .attr('fill', 'transparent')
8019
+ .transition(this.transition)
8020
+ .attr('d', d => drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d))
8021
+ // Enter
8022
+ brushLines.enter().append('path')
8023
+ .attr('d', d => drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d))
8024
+ .attr('class', `line_${series.key}`)
8025
+ .attr('id', `line_${series.key}`)
8026
+ // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8027
+ .style('stroke-width', 1)
8028
+ .attr('stroke', series.color)
8029
+ .attr('fill', 'transparent')
8030
+ // .transition(this.transition)
8031
+ .style('stroke-opacity', 1)
8032
+ }
8033
+
7992
8034
  if (series.showArea === true) {
7993
8035
  this.renderarea(series, index)
7994
8036
  }
@@ -7196,6 +7196,7 @@ var WebsyChart = /*#__PURE__*/function () {
7196
7196
  this.renderedKeys = {};
7197
7197
  this.brushedDomain = [];
7198
7198
  this.brushBarsInitialized = {};
7199
+ this.brushLinesInitialized = {};
7199
7200
 
7200
7201
  if (!elementId) {
7201
7202
  console.log('No element Id provided for Websy Chart');
@@ -7345,6 +7346,7 @@ var WebsyChart = /*#__PURE__*/function () {
7345
7346
  }, {
7346
7347
  key: "createDomain",
7347
7348
  value: function createDomain(side) {
7349
+ var forBrush = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
7348
7350
  var domain = [];
7349
7351
  /* global d3 side domain:writable forBrush */
7350
7352
  // if we have a brushed domain we use that
@@ -7543,7 +7545,7 @@ var WebsyChart = /*#__PURE__*/function () {
7543
7545
  });
7544
7546
  tooltipHTML = " \n <ul>\n ";
7545
7547
  tooltipHTML += tooltipData.map(function (d) {
7546
- return "\n <li>\n <i style='background-color: ".concat(d.color, ";'></i>\n ").concat(d.tooltipLabel || '', "<span> - ").concat(d.tooltipValue || d.value, "</span>\n </li>\n ");
7548
+ return "\n <li>\n <i style='background-color: ".concat(d.color, ";'></i>\n ").concat(d.tooltipLabel || '', "<span>: ").concat(d.tooltipValue || d.value, "</span>\n </li>\n ");
7547
7549
  }).join('');
7548
7550
  tooltipHTML += "</ul>";
7549
7551
  var posOptions = {
@@ -7921,6 +7923,7 @@ var WebsyChart = /*#__PURE__*/function () {
7921
7923
 
7922
7924
  this.plotWidth = this.width - this.options.margin.legendLeft - this.options.margin.legendRight - this.options.margin.left - this.options.margin.right - this.options.margin.axisLeft - this.options.margin.axisRight;
7923
7925
  this.plotHeight = this.height - this.options.margin.legendTop - this.options.margin.legendBottom - this.options.margin.top - this.options.margin.bottom - this.options.margin.axisBottom - this.options.margin.axisTop;
7926
+ this.brushNeeded = false;
7924
7927
 
7925
7928
  if (this.options.orientation === 'vertical') {
7926
7929
  if (this.options.maxBandWidth) {
@@ -8012,11 +8015,14 @@ var WebsyChart = /*#__PURE__*/function () {
8012
8015
 
8013
8016
  if (this.brushNeeded) {
8014
8017
  if (!this.brushInitialized) {
8018
+ this.brushLayer.style('visibility', 'visible');
8015
8019
  this.brushInitialized = true;
8016
8020
  this.brushLayer.select('.brush').call(this.brush).call(this.brush.move, [0, brushEnd]);
8017
8021
  }
8018
8022
  } else {
8019
- this.brushLayer.selectAll().remove();
8023
+ this.brushLayer.style('visibility', 'hidden'); // this.brushLayer.selectAll().remove()
8024
+
8025
+ this.brushArea.selectAll('*').remove();
8020
8026
  }
8021
8027
 
8022
8028
  if (this.options.margin.axisBottom > 0) {
@@ -8570,7 +8576,7 @@ var WebsyChart = /*#__PURE__*/function () {
8570
8576
  /* global series index d3 */
8571
8577
  var drawLine = function drawLine(xAxis, yAxis, curveStyle) {
8572
8578
  return d3.line().x(function (d) {
8573
- var adjustment = _this49.options.data[xAxis].scale === 'Time' ? 0 : _this49["".concat(xAxis, "Axis")].bandwidth() / 2;
8579
+ var adjustment = _this49.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : _this49["".concat(xAxis, "Axis")].bandwidth() / 2;
8574
8580
  return _this49["".concat(xAxis, "Axis")](_this49.parseX(d.x.value)) + adjustment;
8575
8581
  }).y(function (d) {
8576
8582
  return _this49["".concat(yAxis, "Axis")](isNaN(d.y.value) ? 0 : d.y.value);
@@ -8585,7 +8591,16 @@ var WebsyChart = /*#__PURE__*/function () {
8585
8591
  yAxis = 'bottom';
8586
8592
  }
8587
8593
 
8588
- var lines = this.lineLayer.selectAll(".line_".concat(series.key)).data([series.data]); // Exit
8594
+ var xBrushAxis = 'bottomBrush';
8595
+ var yBrushAxis = 'leftBrush';
8596
+
8597
+ if (this.options.orienation === 'horizontal') {
8598
+ xBrushAxis = 'leftBrush';
8599
+ yBrushAxis = 'bottomBrush';
8600
+ }
8601
+
8602
+ var lines = this.lineLayer.selectAll(".line_".concat(series.key)).data([series.data]);
8603
+ var brushLines = this.brushArea.selectAll(".line_".concat(series.key)).data([series.data]); // Exit
8589
8604
 
8590
8605
  lines.exit().transition(this.transition).style('stroke-opacity', 1e-6).remove(); // Update
8591
8606
 
@@ -8601,6 +8616,24 @@ var WebsyChart = /*#__PURE__*/function () {
8601
8616
  .style('stroke-width', series.lineWidth || this.options.lineWidth).attr('stroke', series.color).attr('fill', 'transparent') // .transition(this.transition)
8602
8617
  .style('stroke-opacity', 1);
8603
8618
 
8619
+ if (!this.brushLinesInitialized[series.key]) {
8620
+ this.brushLinesInitialized[series.key] = true; // Exit
8621
+
8622
+ brushLines.exit().transition(this.transition).style('stroke-opacity', 1e-6).remove(); // Update
8623
+
8624
+ brushLines.style('stroke-width', 1) // .attr('id', `line_${series.key}`)
8625
+ // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8626
+ .attr('stroke', series.color).attr('fill', 'transparent').transition(this.transition).attr('d', function (d) {
8627
+ return drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d);
8628
+ }); // Enter
8629
+
8630
+ brushLines.enter().append('path').attr('d', function (d) {
8631
+ return drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d);
8632
+ }).attr('class', "line_".concat(series.key)).attr('id', "line_".concat(series.key)) // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8633
+ .style('stroke-width', 1).attr('stroke', series.color).attr('fill', 'transparent') // .transition(this.transition)
8634
+ .style('stroke-opacity', 1);
8635
+ }
8636
+
8604
8637
  if (series.showArea === true) {
8605
8638
  this.renderarea(series, index);
8606
8639
  }