@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.
@@ -6977,6 +6977,7 @@ class WebsyChart {
6977
6977
  this.renderedKeys = {}
6978
6978
  this.brushedDomain = []
6979
6979
  this.brushBarsInitialized = {}
6980
+ this.brushLinesInitialized = {}
6980
6981
  if (!elementId) {
6981
6982
  console.log('No element Id provided for Websy Chart')
6982
6983
  return
@@ -7111,7 +7112,7 @@ class WebsyChart {
7111
7112
  this.labelLayer.selectAll('*').remove()
7112
7113
  this.symbolLayer.selectAll('*').remove()
7113
7114
  }
7114
- createDomain (side) {
7115
+ createDomain (side, forBrush = false) {
7115
7116
  let domain = []
7116
7117
  /* global d3 side domain:writable forBrush */
7117
7118
  // if we have a brushed domain we use that
@@ -7271,7 +7272,7 @@ else {
7271
7272
  tooltipHTML += tooltipData.map(d => `
7272
7273
  <li>
7273
7274
  <i style='background-color: ${d.color};'></i>
7274
- ${d.tooltipLabel || ''}<span> - ${d.tooltipValue || d.value}</span>
7275
+ ${d.tooltipLabel || ''}<span>: ${d.tooltipValue || d.value}</span>
7275
7276
  </li>
7276
7277
  `).join('')
7277
7278
  tooltipHTML += `</ul>`
@@ -7602,6 +7603,7 @@ else {
7602
7603
  // Define the plot size
7603
7604
  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
7604
7605
  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
7606
+ this.brushNeeded = false
7605
7607
  if (this.options.orientation === 'vertical') {
7606
7608
  if (this.options.maxBandWidth) {
7607
7609
  this.plotWidth = Math.min(this.plotWidth, (this.options.data.bottom.data || []).length * this.options.maxBandWidth)
@@ -7762,6 +7764,7 @@ else {
7762
7764
  // this.brushArea.selectAll('*').remove()
7763
7765
  if (this.brushNeeded) {
7764
7766
  if (!this.brushInitialized) {
7767
+ this.brushLayer.style('visibility', 'visible')
7765
7768
  this.brushInitialized = true
7766
7769
  this.brushLayer
7767
7770
  .select('.brush')
@@ -7770,7 +7773,9 @@ else {
7770
7773
  }
7771
7774
  }
7772
7775
  else {
7773
- this.brushLayer.selectAll().remove()
7776
+ this.brushLayer.style('visibility', 'hidden')
7777
+ // this.brushLayer.selectAll().remove()
7778
+ this.brushArea.selectAll('*').remove()
7774
7779
  }
7775
7780
  if (this.options.margin.axisBottom > 0) {
7776
7781
  let timeFormatPattern = ''
@@ -8359,7 +8364,7 @@ const drawLine = (xAxis, yAxis, curveStyle) => {
8359
8364
  return d3
8360
8365
  .line()
8361
8366
  .x(d => {
8362
- let adjustment = this.options.data[xAxis].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8367
+ let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
8363
8368
  return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
8364
8369
  })
8365
8370
  .y(d => {
@@ -8373,8 +8378,16 @@ if (this.options.orienation === 'horizontal') {
8373
8378
  xAxis = series.axis === 'secondary' ? 'right' : 'left'
8374
8379
  yAxis = 'bottom'
8375
8380
  }
8381
+ let xBrushAxis = 'bottomBrush'
8382
+ let yBrushAxis = 'leftBrush'
8383
+ if (this.options.orienation === 'horizontal') {
8384
+ xBrushAxis = 'leftBrush'
8385
+ yBrushAxis = 'bottomBrush'
8386
+ }
8376
8387
  let lines = this.lineLayer.selectAll(`.line_${series.key}`)
8377
8388
  .data([series.data])
8389
+ let brushLines = this.brushArea.selectAll(`.line_${series.key}`)
8390
+ .data([series.data])
8378
8391
  // Exit
8379
8392
  lines.exit()
8380
8393
  .transition(this.transition)
@@ -8401,6 +8414,35 @@ lines.enter().append('path')
8401
8414
  // .transition(this.transition)
8402
8415
  .style('stroke-opacity', 1)
8403
8416
 
8417
+ if (!this.brushLinesInitialized[series.key]) {
8418
+ this.brushLinesInitialized[series.key] = true
8419
+ // Exit
8420
+ brushLines.exit()
8421
+ .transition(this.transition)
8422
+ .style('stroke-opacity', 1e-6)
8423
+ .remove()
8424
+ // Update
8425
+ brushLines
8426
+ .style('stroke-width', 1)
8427
+ // .attr('id', `line_${series.key}`)
8428
+ // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8429
+ .attr('stroke', series.color)
8430
+ .attr('fill', 'transparent')
8431
+ .transition(this.transition)
8432
+ .attr('d', d => drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d))
8433
+ // Enter
8434
+ brushLines.enter().append('path')
8435
+ .attr('d', d => drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d))
8436
+ .attr('class', `line_${series.key}`)
8437
+ .attr('id', `line_${series.key}`)
8438
+ // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8439
+ .style('stroke-width', 1)
8440
+ .attr('stroke', series.color)
8441
+ .attr('fill', 'transparent')
8442
+ // .transition(this.transition)
8443
+ .style('stroke-opacity', 1)
8444
+ }
8445
+
8404
8446
  if (series.showArea === true) {
8405
8447
  this.renderarea(series, index)
8406
8448
  }
@@ -7672,6 +7672,7 @@ var WebsyChart = /*#__PURE__*/function () {
7672
7672
  this.renderedKeys = {};
7673
7673
  this.brushedDomain = [];
7674
7674
  this.brushBarsInitialized = {};
7675
+ this.brushLinesInitialized = {};
7675
7676
 
7676
7677
  if (!elementId) {
7677
7678
  console.log('No element Id provided for Websy Chart');
@@ -7821,6 +7822,7 @@ var WebsyChart = /*#__PURE__*/function () {
7821
7822
  }, {
7822
7823
  key: "createDomain",
7823
7824
  value: function createDomain(side) {
7825
+ var forBrush = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
7824
7826
  var domain = [];
7825
7827
  /* global d3 side domain:writable forBrush */
7826
7828
  // if we have a brushed domain we use that
@@ -8019,7 +8021,7 @@ var WebsyChart = /*#__PURE__*/function () {
8019
8021
  });
8020
8022
  tooltipHTML = " \n <ul>\n ";
8021
8023
  tooltipHTML += tooltipData.map(function (d) {
8022
- 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 ");
8024
+ 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 ");
8023
8025
  }).join('');
8024
8026
  tooltipHTML += "</ul>";
8025
8027
  var posOptions = {
@@ -8397,6 +8399,7 @@ var WebsyChart = /*#__PURE__*/function () {
8397
8399
 
8398
8400
  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;
8399
8401
  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;
8402
+ this.brushNeeded = false;
8400
8403
 
8401
8404
  if (this.options.orientation === 'vertical') {
8402
8405
  if (this.options.maxBandWidth) {
@@ -8488,11 +8491,14 @@ var WebsyChart = /*#__PURE__*/function () {
8488
8491
 
8489
8492
  if (this.brushNeeded) {
8490
8493
  if (!this.brushInitialized) {
8494
+ this.brushLayer.style('visibility', 'visible');
8491
8495
  this.brushInitialized = true;
8492
8496
  this.brushLayer.select('.brush').call(this.brush).call(this.brush.move, [0, brushEnd]);
8493
8497
  }
8494
8498
  } else {
8495
- this.brushLayer.selectAll().remove();
8499
+ this.brushLayer.style('visibility', 'hidden'); // this.brushLayer.selectAll().remove()
8500
+
8501
+ this.brushArea.selectAll('*').remove();
8496
8502
  }
8497
8503
 
8498
8504
  if (this.options.margin.axisBottom > 0) {
@@ -9046,7 +9052,7 @@ var WebsyChart = /*#__PURE__*/function () {
9046
9052
  /* global series index d3 */
9047
9053
  var drawLine = function drawLine(xAxis, yAxis, curveStyle) {
9048
9054
  return d3.line().x(function (d) {
9049
- var adjustment = _this52.options.data[xAxis].scale === 'Time' ? 0 : _this52["".concat(xAxis, "Axis")].bandwidth() / 2;
9055
+ var adjustment = _this52.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : _this52["".concat(xAxis, "Axis")].bandwidth() / 2;
9050
9056
  return _this52["".concat(xAxis, "Axis")](_this52.parseX(d.x.value)) + adjustment;
9051
9057
  }).y(function (d) {
9052
9058
  return _this52["".concat(yAxis, "Axis")](isNaN(d.y.value) ? 0 : d.y.value);
@@ -9061,7 +9067,16 @@ var WebsyChart = /*#__PURE__*/function () {
9061
9067
  yAxis = 'bottom';
9062
9068
  }
9063
9069
 
9064
- var lines = this.lineLayer.selectAll(".line_".concat(series.key)).data([series.data]); // Exit
9070
+ var xBrushAxis = 'bottomBrush';
9071
+ var yBrushAxis = 'leftBrush';
9072
+
9073
+ if (this.options.orienation === 'horizontal') {
9074
+ xBrushAxis = 'leftBrush';
9075
+ yBrushAxis = 'bottomBrush';
9076
+ }
9077
+
9078
+ var lines = this.lineLayer.selectAll(".line_".concat(series.key)).data([series.data]);
9079
+ var brushLines = this.brushArea.selectAll(".line_".concat(series.key)).data([series.data]); // Exit
9065
9080
 
9066
9081
  lines.exit().transition(this.transition).style('stroke-opacity', 1e-6).remove(); // Update
9067
9082
 
@@ -9077,6 +9092,24 @@ var WebsyChart = /*#__PURE__*/function () {
9077
9092
  .style('stroke-width', series.lineWidth || this.options.lineWidth).attr('stroke', series.color).attr('fill', 'transparent') // .transition(this.transition)
9078
9093
  .style('stroke-opacity', 1);
9079
9094
 
9095
+ if (!this.brushLinesInitialized[series.key]) {
9096
+ this.brushLinesInitialized[series.key] = true; // Exit
9097
+
9098
+ brushLines.exit().transition(this.transition).style('stroke-opacity', 1e-6).remove(); // Update
9099
+
9100
+ brushLines.style('stroke-width', 1) // .attr('id', `line_${series.key}`)
9101
+ // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
9102
+ .attr('stroke', series.color).attr('fill', 'transparent').transition(this.transition).attr('d', function (d) {
9103
+ return drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d);
9104
+ }); // Enter
9105
+
9106
+ brushLines.enter().append('path').attr('d', function (d) {
9107
+ return drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d);
9108
+ }).attr('class', "line_".concat(series.key)).attr('id', "line_".concat(series.key)) // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
9109
+ .style('stroke-width', 1).attr('stroke', series.color).attr('fill', 'transparent') // .transition(this.transition)
9110
+ .style('stroke-opacity', 1);
9111
+ }
9112
+
9080
9113
  if (series.showArea === true) {
9081
9114
  this.renderarea(series, index);
9082
9115
  }