@websy/websy-designs 1.4.34 → 1.4.36

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.
@@ -1153,10 +1153,14 @@ class WebsyDatePicker {
1153
1153
  let start = list[0]
1154
1154
  let end = ''
1155
1155
  if (this.customRangeSelected === true && this.isContinuousRange === true) {
1156
- end = ` - ${list[list.length - 1]}`
1156
+ if (list.length > 0) {
1157
+ end = ` - ${list[list.length - 1]}`
1158
+ }
1157
1159
  if (this.options.mode === 'hour') {
1158
1160
  start = this.options.hours[start].text
1159
- end = `${this.customRangeSelected === true ? ' - ' : ''}${this.options.hours[list[list.length - 1]].text}`
1161
+ if (list.length > 0) {
1162
+ end = `${this.customRangeSelected === true ? ' - ' : ''}${this.options.hours[list[list.length - 1]].text}`
1163
+ }
1160
1164
  }
1161
1165
  }
1162
1166
  else {
@@ -6565,6 +6569,7 @@ class WebsyChart {
6565
6569
  this.renderedKeys = {}
6566
6570
  this.brushedDomain = []
6567
6571
  this.brushBarsInitialized = {}
6572
+ this.brushLinesInitialized = {}
6568
6573
  if (!elementId) {
6569
6574
  console.log('No element Id provided for Websy Chart')
6570
6575
  return
@@ -6699,7 +6704,7 @@ class WebsyChart {
6699
6704
  this.labelLayer.selectAll('*').remove()
6700
6705
  this.symbolLayer.selectAll('*').remove()
6701
6706
  }
6702
- createDomain (side) {
6707
+ createDomain (side, forBrush = false) {
6703
6708
  let domain = []
6704
6709
  /* global d3 side domain:writable forBrush */
6705
6710
  // if we have a brushed domain we use that
@@ -6859,7 +6864,7 @@ else {
6859
6864
  tooltipHTML += tooltipData.map(d => `
6860
6865
  <li>
6861
6866
  <i style='background-color: ${d.color};'></i>
6862
- ${d.tooltipLabel || ''}<span> - ${d.tooltipValue || d.value}</span>
6867
+ ${d.tooltipLabel || ''}<span>: ${d.tooltipValue || d.value}</span>
6863
6868
  </li>
6864
6869
  `).join('')
6865
6870
  tooltipHTML += `</ul>`
@@ -7075,7 +7080,9 @@ else {
7075
7080
  this.longestBottom = this.options.data.bottom.max.toString()
7076
7081
  if (this.options.data.bottom.formatter) {
7077
7082
  this.longestBottom = this.options.data.bottom.formatter(this.options.data.bottom.max).toString()
7078
- firstBottom = this.options.data.bottom.formatter(this.options.data.bottom.data[0].value).toString()
7083
+ if (this.options.data.bottom.data && this.options.data.bottom.data[0] && this.options.data.bottom.data[0].value) {
7084
+ firstBottom = this.options.data.bottom.formatter(this.options.data.bottom.data[0].value).toString()
7085
+ }
7079
7086
  }
7080
7087
  else {
7081
7088
  if (this.options.data.bottom.scale === 'Time') {
@@ -7085,7 +7092,9 @@ else {
7085
7092
  else {
7086
7093
  this.longestBottom = this.options.data.bottom.data.reduce((a, b) => a.length > b.value.length ? a : b.value, '')
7087
7094
  // firstBottom = (this.options.data.bottom.data[0] || [{value: ''}]).value
7088
- firstBottom = this.options.data.bottom.data[0].value
7095
+ if (this.options.data.bottom.data && this.options.data.bottom.data[0] && this.options.data.bottom.data[0].value) {
7096
+ firstBottom = this.options.data.bottom.data[0].value
7097
+ }
7089
7098
  }
7090
7099
  }
7091
7100
  }
@@ -7190,6 +7199,7 @@ else {
7190
7199
  // Define the plot size
7191
7200
  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
7201
  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
7202
+ this.brushNeeded = false
7193
7203
  if (this.options.orientation === 'vertical') {
7194
7204
  if (this.options.maxBandWidth) {
7195
7205
  this.plotWidth = Math.min(this.plotWidth, (this.options.data.bottom.data || []).length * this.options.maxBandWidth)
@@ -7350,6 +7360,7 @@ else {
7350
7360
  // this.brushArea.selectAll('*').remove()
7351
7361
  if (this.brushNeeded) {
7352
7362
  if (!this.brushInitialized) {
7363
+ this.brushLayer.style('visibility', 'visible')
7353
7364
  this.brushInitialized = true
7354
7365
  this.brushLayer
7355
7366
  .select('.brush')
@@ -7358,7 +7369,9 @@ else {
7358
7369
  }
7359
7370
  }
7360
7371
  else {
7361
- this.brushLayer.selectAll().remove()
7372
+ this.brushLayer.style('visibility', 'hidden')
7373
+ // this.brushLayer.selectAll().remove()
7374
+ this.brushArea.selectAll('*').remove()
7362
7375
  }
7363
7376
  if (this.options.margin.axisBottom > 0) {
7364
7377
  let timeFormatPattern = ''
@@ -7947,7 +7960,7 @@ const drawLine = (xAxis, yAxis, curveStyle) => {
7947
7960
  return d3
7948
7961
  .line()
7949
7962
  .x(d => {
7950
- let adjustment = this.options.data[xAxis].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
7963
+ let adjustment = this.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : this[`${xAxis}Axis`].bandwidth() / 2
7951
7964
  return this[`${xAxis}Axis`](this.parseX(d.x.value)) + adjustment
7952
7965
  })
7953
7966
  .y(d => {
@@ -7961,8 +7974,16 @@ if (this.options.orienation === 'horizontal') {
7961
7974
  xAxis = series.axis === 'secondary' ? 'right' : 'left'
7962
7975
  yAxis = 'bottom'
7963
7976
  }
7977
+ let xBrushAxis = 'bottomBrush'
7978
+ let yBrushAxis = 'leftBrush'
7979
+ if (this.options.orienation === 'horizontal') {
7980
+ xBrushAxis = 'leftBrush'
7981
+ yBrushAxis = 'bottomBrush'
7982
+ }
7964
7983
  let lines = this.lineLayer.selectAll(`.line_${series.key}`)
7965
7984
  .data([series.data])
7985
+ let brushLines = this.brushArea.selectAll(`.line_${series.key}`)
7986
+ .data([series.data])
7966
7987
  // Exit
7967
7988
  lines.exit()
7968
7989
  .transition(this.transition)
@@ -7989,6 +8010,35 @@ lines.enter().append('path')
7989
8010
  // .transition(this.transition)
7990
8011
  .style('stroke-opacity', 1)
7991
8012
 
8013
+ if (!this.brushLinesInitialized[series.key]) {
8014
+ this.brushLinesInitialized[series.key] = true
8015
+ // Exit
8016
+ brushLines.exit()
8017
+ .transition(this.transition)
8018
+ .style('stroke-opacity', 1e-6)
8019
+ .remove()
8020
+ // Update
8021
+ brushLines
8022
+ .style('stroke-width', 1)
8023
+ // .attr('id', `line_${series.key}`)
8024
+ // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8025
+ .attr('stroke', series.color)
8026
+ .attr('fill', 'transparent')
8027
+ .transition(this.transition)
8028
+ .attr('d', d => drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d))
8029
+ // Enter
8030
+ brushLines.enter().append('path')
8031
+ .attr('d', d => drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d))
8032
+ .attr('class', `line_${series.key}`)
8033
+ .attr('id', `line_${series.key}`)
8034
+ // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8035
+ .style('stroke-width', 1)
8036
+ .attr('stroke', series.color)
8037
+ .attr('fill', 'transparent')
8038
+ // .transition(this.transition)
8039
+ .style('stroke-opacity', 1)
8040
+ }
8041
+
7992
8042
  if (series.showArea === true) {
7993
8043
  this.renderarea(series, index)
7994
8044
  }
@@ -1273,11 +1273,16 @@ var WebsyDatePicker = /*#__PURE__*/function () {
1273
1273
  var end = '';
1274
1274
 
1275
1275
  if (this.customRangeSelected === true && this.isContinuousRange === true) {
1276
- end = " - ".concat(list[list.length - 1]);
1276
+ if (list.length > 0) {
1277
+ end = " - ".concat(list[list.length - 1]);
1278
+ }
1277
1279
 
1278
1280
  if (this.options.mode === 'hour') {
1279
1281
  start = this.options.hours[start].text;
1280
- end = "".concat(this.customRangeSelected === true ? ' - ' : '').concat(this.options.hours[list[list.length - 1]].text);
1282
+
1283
+ if (list.length > 0) {
1284
+ end = "".concat(this.customRangeSelected === true ? ' - ' : '').concat(this.options.hours[list[list.length - 1]].text);
1285
+ }
1281
1286
  }
1282
1287
  } else {
1283
1288
  if (list.length > 1) {
@@ -7196,6 +7201,7 @@ var WebsyChart = /*#__PURE__*/function () {
7196
7201
  this.renderedKeys = {};
7197
7202
  this.brushedDomain = [];
7198
7203
  this.brushBarsInitialized = {};
7204
+ this.brushLinesInitialized = {};
7199
7205
 
7200
7206
  if (!elementId) {
7201
7207
  console.log('No element Id provided for Websy Chart');
@@ -7345,6 +7351,7 @@ var WebsyChart = /*#__PURE__*/function () {
7345
7351
  }, {
7346
7352
  key: "createDomain",
7347
7353
  value: function createDomain(side) {
7354
+ var forBrush = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
7348
7355
  var domain = [];
7349
7356
  /* global d3 side domain:writable forBrush */
7350
7357
  // if we have a brushed domain we use that
@@ -7543,7 +7550,7 @@ var WebsyChart = /*#__PURE__*/function () {
7543
7550
  });
7544
7551
  tooltipHTML = " \n <ul>\n ";
7545
7552
  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 ");
7553
+ 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
7554
  }).join('');
7548
7555
  tooltipHTML += "</ul>";
7549
7556
  var posOptions = {
@@ -7786,7 +7793,10 @@ var WebsyChart = /*#__PURE__*/function () {
7786
7793
 
7787
7794
  if (this.options.data.bottom.formatter) {
7788
7795
  this.longestBottom = this.options.data.bottom.formatter(this.options.data.bottom.max).toString();
7789
- firstBottom = this.options.data.bottom.formatter(this.options.data.bottom.data[0].value).toString();
7796
+
7797
+ if (this.options.data.bottom.data && this.options.data.bottom.data[0] && this.options.data.bottom.data[0].value) {
7798
+ firstBottom = this.options.data.bottom.formatter(this.options.data.bottom.data[0].value).toString();
7799
+ }
7790
7800
  } else {
7791
7801
  if (this.options.data.bottom.scale === 'Time') {
7792
7802
  this.longestBottom = '01/01/2000';
@@ -7796,7 +7806,9 @@ var WebsyChart = /*#__PURE__*/function () {
7796
7806
  return a.length > b.value.length ? a : b.value;
7797
7807
  }, ''); // firstBottom = (this.options.data.bottom.data[0] || [{value: ''}]).value
7798
7808
 
7799
- firstBottom = this.options.data.bottom.data[0].value;
7809
+ if (this.options.data.bottom.data && this.options.data.bottom.data[0] && this.options.data.bottom.data[0].value) {
7810
+ firstBottom = this.options.data.bottom.data[0].value;
7811
+ }
7800
7812
  }
7801
7813
  }
7802
7814
  }
@@ -7921,6 +7933,7 @@ var WebsyChart = /*#__PURE__*/function () {
7921
7933
 
7922
7934
  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
7935
  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;
7936
+ this.brushNeeded = false;
7924
7937
 
7925
7938
  if (this.options.orientation === 'vertical') {
7926
7939
  if (this.options.maxBandWidth) {
@@ -8012,11 +8025,14 @@ var WebsyChart = /*#__PURE__*/function () {
8012
8025
 
8013
8026
  if (this.brushNeeded) {
8014
8027
  if (!this.brushInitialized) {
8028
+ this.brushLayer.style('visibility', 'visible');
8015
8029
  this.brushInitialized = true;
8016
8030
  this.brushLayer.select('.brush').call(this.brush).call(this.brush.move, [0, brushEnd]);
8017
8031
  }
8018
8032
  } else {
8019
- this.brushLayer.selectAll().remove();
8033
+ this.brushLayer.style('visibility', 'hidden'); // this.brushLayer.selectAll().remove()
8034
+
8035
+ this.brushArea.selectAll('*').remove();
8020
8036
  }
8021
8037
 
8022
8038
  if (this.options.margin.axisBottom > 0) {
@@ -8570,7 +8586,7 @@ var WebsyChart = /*#__PURE__*/function () {
8570
8586
  /* global series index d3 */
8571
8587
  var drawLine = function drawLine(xAxis, yAxis, curveStyle) {
8572
8588
  return d3.line().x(function (d) {
8573
- var adjustment = _this49.options.data[xAxis].scale === 'Time' ? 0 : _this49["".concat(xAxis, "Axis")].bandwidth() / 2;
8589
+ var adjustment = _this49.options.data[xAxis.replace('Brush', '')].scale === 'Time' ? 0 : _this49["".concat(xAxis, "Axis")].bandwidth() / 2;
8574
8590
  return _this49["".concat(xAxis, "Axis")](_this49.parseX(d.x.value)) + adjustment;
8575
8591
  }).y(function (d) {
8576
8592
  return _this49["".concat(yAxis, "Axis")](isNaN(d.y.value) ? 0 : d.y.value);
@@ -8585,7 +8601,16 @@ var WebsyChart = /*#__PURE__*/function () {
8585
8601
  yAxis = 'bottom';
8586
8602
  }
8587
8603
 
8588
- var lines = this.lineLayer.selectAll(".line_".concat(series.key)).data([series.data]); // Exit
8604
+ var xBrushAxis = 'bottomBrush';
8605
+ var yBrushAxis = 'leftBrush';
8606
+
8607
+ if (this.options.orienation === 'horizontal') {
8608
+ xBrushAxis = 'leftBrush';
8609
+ yBrushAxis = 'bottomBrush';
8610
+ }
8611
+
8612
+ var lines = this.lineLayer.selectAll(".line_".concat(series.key)).data([series.data]);
8613
+ var brushLines = this.brushArea.selectAll(".line_".concat(series.key)).data([series.data]); // Exit
8589
8614
 
8590
8615
  lines.exit().transition(this.transition).style('stroke-opacity', 1e-6).remove(); // Update
8591
8616
 
@@ -8601,6 +8626,24 @@ var WebsyChart = /*#__PURE__*/function () {
8601
8626
  .style('stroke-width', series.lineWidth || this.options.lineWidth).attr('stroke', series.color).attr('fill', 'transparent') // .transition(this.transition)
8602
8627
  .style('stroke-opacity', 1);
8603
8628
 
8629
+ if (!this.brushLinesInitialized[series.key]) {
8630
+ this.brushLinesInitialized[series.key] = true; // Exit
8631
+
8632
+ brushLines.exit().transition(this.transition).style('stroke-opacity', 1e-6).remove(); // Update
8633
+
8634
+ brushLines.style('stroke-width', 1) // .attr('id', `line_${series.key}`)
8635
+ // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8636
+ .attr('stroke', series.color).attr('fill', 'transparent').transition(this.transition).attr('d', function (d) {
8637
+ return drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d);
8638
+ }); // Enter
8639
+
8640
+ brushLines.enter().append('path').attr('d', function (d) {
8641
+ return drawLine(xBrushAxis, yBrushAxis, series.curveStyle)(d);
8642
+ }).attr('class', "line_".concat(series.key)).attr('id', "line_".concat(series.key)) // .attr('transform', 'translate('+ (that.bandWidth/2) +',0)')
8643
+ .style('stroke-width', 1).attr('stroke', series.color).attr('fill', 'transparent') // .transition(this.transition)
8644
+ .style('stroke-opacity', 1);
8645
+ }
8646
+
8604
8647
  if (series.showArea === true) {
8605
8648
  this.renderarea(series, index);
8606
8649
  }