@websy/websy-designs 1.4.23 → 1.4.25

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.
@@ -188,14 +188,7 @@ class ButtonGroup {
188
188
  handleClick (event) {
189
189
  if (event.target.classList.contains('websy-button-group-item')) {
190
190
  const index = +event.target.getAttribute('data-index')
191
- if (this.options.activeItem !== index) {
192
- if (this.options.onDeactivate && this.options.activeItem !== -1) {
193
- this.options.onDeactivate(this.options.items[this.options.activeItem], this.options.activeItem)
194
- }
195
- this.options.activeItem = index
196
- if (this.options.onActivate) {
197
- this.options.onActivate(this.options.items[index], index, event)
198
- }
191
+ if (this.options.activeItem !== index) {
199
192
  const el = document.getElementById(this.elementId)
200
193
  let buttons = Array.from(el.querySelectorAll('.websy-button-group-item'))
201
194
  buttons.forEach(el => {
@@ -204,7 +197,14 @@ class ButtonGroup {
204
197
  el.classList.remove('active')
205
198
  })
206
199
  event.target.classList.remove('inactive')
207
- event.target.classList.add('active')
200
+ event.target.classList.add('active')
201
+ if (this.options.onDeactivate && this.options.activeItem !== -1) {
202
+ this.options.onDeactivate(this.options.items[this.options.activeItem], this.options.activeItem, true)
203
+ }
204
+ this.options.activeItem = index
205
+ if (this.options.onActivate) {
206
+ this.options.onActivate(this.options.items[index], index, event)
207
+ }
208
208
  }
209
209
  else if (this.options.activeItem === index && this.options.allowNone === true) {
210
210
  if (this.options.onDeactivate) {
@@ -4226,8 +4226,11 @@ class WebsyRouter {
4226
4226
  this.hideView(this.previousPath, group)
4227
4227
  }
4228
4228
  }
4229
- else {
4229
+ else if (group === this.options.defaultGroup) {
4230
4230
  this.hideView(this.previousView, group)
4231
+ }
4232
+ else {
4233
+ this.hideView(this.previousPath, group)
4231
4234
  }
4232
4235
  if (toggle === true && newPath === groupActiveView) {
4233
4236
  return
@@ -6452,7 +6455,7 @@ class WebsyChart {
6452
6455
  constructor (elementId, options) {
6453
6456
  const DEFAULTS = {
6454
6457
  margin: {
6455
- top: 10,
6458
+ top: 20,
6456
6459
  left: 3,
6457
6460
  bottom: 3,
6458
6461
  right: 3,
@@ -6788,6 +6791,7 @@ this.lineLayer = this.svg.append('g').attr('class', 'line-layer')
6788
6791
  this.barLayer = this.svg.append('g').attr('class', 'bar-layer')
6789
6792
  this.labelLayer = this.svg.append('g').attr('class', 'label-layer')
6790
6793
  this.symbolLayer = this.svg.append('g').attr('class', 'symbol-layer')
6794
+ this.refLineLayer = this.svg.append('g').attr('class', 'refline-layer')
6791
6795
  this.trackingLineLayer = this.svg.append('g').attr('class', 'tracking-line-layer')
6792
6796
  this.trackingLineLayer.append('line').attr('class', 'tracking-line')
6793
6797
  this.tooltip = new WebsyDesigns.WebsyChartTooltip(this.svg)
@@ -7046,6 +7050,8 @@ else {
7046
7050
  .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
7047
7051
  this.symbolLayer
7048
7052
  .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
7053
+ this.refLineLayer
7054
+ .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
7049
7055
  this.trackingLineLayer
7050
7056
  .attr('transform', `translate(${this.options.margin.left + this.options.margin.axisLeft}, ${this.options.margin.top + this.options.margin.axisTop})`)
7051
7057
  this.eventLayer
@@ -7281,6 +7287,9 @@ else {
7281
7287
  this.renderLabels(series, index)
7282
7288
  this.renderedKeys[series.key] = series.type
7283
7289
  })
7290
+ if (this.options.refLines && this.options.refLines.length > 0) {
7291
+ this.options.refLines.forEach(l => this.renderRefLine(l))
7292
+ }
7284
7293
  }
7285
7294
  }
7286
7295
 
@@ -7621,6 +7630,45 @@ if (series.showSymbols === true) {
7621
7630
  this.rendersymbol(series, index)
7622
7631
  }
7623
7632
 
7633
+ }
7634
+ renderRefLine (data) {
7635
+ /* global d3 data */
7636
+ let xAxis = 'bottom'
7637
+ let yAxis = 'left'
7638
+ let that = this
7639
+ if (this.options.orientation === 'horizontal') {
7640
+ xAxis = 'left'
7641
+ yAxis = 'bottom'
7642
+ }
7643
+ this.refLineLayer.selectAll('.reference-line').remove()
7644
+ this.refLineLayer.selectAll('.reference-line-label').remove()
7645
+ this.refLineLayer
7646
+ .append('line')
7647
+ .attr('y1', this[`${yAxis}Axis`](data.value))
7648
+ .attr('y2', this[`${yAxis}Axis`](data.value))
7649
+ .attr('x2', this.plotWidth)
7650
+ .attr('class', `reference-line`)
7651
+ .style('stroke', data.color)
7652
+ .style('stroke-width', `${data.lineWidth}px`)
7653
+ .style('stroke-dasharray', data.lineStyle)
7654
+ if (data.label && data.label !== '') {
7655
+ // show the text on the line
7656
+ this.refLineLayer
7657
+ .append('text')
7658
+ .attr('class', `reference-line-label`)
7659
+ .attr('x', this.plotWidth)
7660
+ .attr('y', this[`${yAxis}Axis`](data.value))
7661
+ .attr('font-size', this.options.fontSize)
7662
+ .attr('fill', data.color)
7663
+ .text(data.label)
7664
+ .attr(
7665
+ 'text-anchor', 'end'
7666
+ )
7667
+ .attr(
7668
+ 'alignment-baseline', 'text-after-edge'
7669
+ )
7670
+ }
7671
+
7624
7672
  }
7625
7673
  removeline (key) {
7626
7674
  /* global key d3 */
@@ -243,16 +243,6 @@ var ButtonGroup = /*#__PURE__*/function () {
243
243
  var index = +event.target.getAttribute('data-index');
244
244
 
245
245
  if (this.options.activeItem !== index) {
246
- if (this.options.onDeactivate && this.options.activeItem !== -1) {
247
- this.options.onDeactivate(this.options.items[this.options.activeItem], this.options.activeItem);
248
- }
249
-
250
- this.options.activeItem = index;
251
-
252
- if (this.options.onActivate) {
253
- this.options.onActivate(this.options.items[index], index, event);
254
- }
255
-
256
246
  var el = document.getElementById(this.elementId);
257
247
  var buttons = Array.from(el.querySelectorAll('.websy-button-group-item'));
258
248
  buttons.forEach(function (el) {
@@ -262,6 +252,16 @@ var ButtonGroup = /*#__PURE__*/function () {
262
252
  });
263
253
  event.target.classList.remove('inactive');
264
254
  event.target.classList.add('active');
255
+
256
+ if (this.options.onDeactivate && this.options.activeItem !== -1) {
257
+ this.options.onDeactivate(this.options.items[this.options.activeItem], this.options.activeItem, true);
258
+ }
259
+
260
+ this.options.activeItem = index;
261
+
262
+ if (this.options.onActivate) {
263
+ this.options.onActivate(this.options.items[index], index, event);
264
+ }
265
265
  } else if (this.options.activeItem === index && this.options.allowNone === true) {
266
266
  if (this.options.onDeactivate) {
267
267
  this.options.onDeactivate(this.options.items[this.options.activeItem], this.options.activeItem);
@@ -4642,8 +4642,10 @@ var WebsyRouter = /*#__PURE__*/function () {
4642
4642
  if (this.previousPath !== '') {
4643
4643
  this.hideView(this.previousPath, group);
4644
4644
  }
4645
- } else {
4645
+ } else if (group === this.options.defaultGroup) {
4646
4646
  this.hideView(this.previousView, group);
4647
+ } else {
4648
+ this.hideView(this.previousPath, group);
4647
4649
  }
4648
4650
 
4649
4651
  if (toggle === true && newPath === groupActiveView) {
@@ -7098,7 +7100,7 @@ var WebsyChart = /*#__PURE__*/function () {
7098
7100
 
7099
7101
  var DEFAULTS = {
7100
7102
  margin: {
7101
- top: 10,
7103
+ top: 20,
7102
7104
  left: 3,
7103
7105
  bottom: 3,
7104
7106
  right: 3,
@@ -7484,6 +7486,7 @@ var WebsyChart = /*#__PURE__*/function () {
7484
7486
  this.barLayer = this.svg.append('g').attr('class', 'bar-layer');
7485
7487
  this.labelLayer = this.svg.append('g').attr('class', 'label-layer');
7486
7488
  this.symbolLayer = this.svg.append('g').attr('class', 'symbol-layer');
7489
+ this.refLineLayer = this.svg.append('g').attr('class', 'refline-layer');
7487
7490
  this.trackingLineLayer = this.svg.append('g').attr('class', 'tracking-line-layer');
7488
7491
  this.trackingLineLayer.append('line').attr('class', 'tracking-line');
7489
7492
  this.tooltip = new WebsyDesigns.WebsyChartTooltip(this.svg);
@@ -7772,6 +7775,7 @@ var WebsyChart = /*#__PURE__*/function () {
7772
7775
  this.barLayer.attr('transform', "translate(".concat(this.options.margin.left + this.options.margin.axisLeft, ", ").concat(this.options.margin.top + this.options.margin.axisTop, ")"));
7773
7776
  this.labelLayer.attr('transform', "translate(".concat(this.options.margin.left + this.options.margin.axisLeft, ", ").concat(this.options.margin.top + this.options.margin.axisTop, ")"));
7774
7777
  this.symbolLayer.attr('transform', "translate(".concat(this.options.margin.left + this.options.margin.axisLeft, ", ").concat(this.options.margin.top + this.options.margin.axisTop, ")"));
7778
+ this.refLineLayer.attr('transform', "translate(".concat(this.options.margin.left + this.options.margin.axisLeft, ", ").concat(this.options.margin.top + this.options.margin.axisTop, ")"));
7775
7779
  this.trackingLineLayer.attr('transform', "translate(".concat(this.options.margin.left + this.options.margin.axisLeft, ", ").concat(this.options.margin.top + this.options.margin.axisTop, ")"));
7776
7780
  this.eventLayer.attr('transform', "translate(".concat(this.options.margin.left + this.options.margin.axisLeft, ", ").concat(this.options.margin.top + this.options.margin.axisTop, ")"));
7777
7781
  var that = this;
@@ -7962,6 +7966,12 @@ var WebsyChart = /*#__PURE__*/function () {
7962
7966
 
7963
7967
  _this44.renderedKeys[series.key] = series.type;
7964
7968
  });
7969
+
7970
+ if (this.options.refLines && this.options.refLines.length > 0) {
7971
+ this.options.refLines.forEach(function (l) {
7972
+ return _this44.renderRefLine(l);
7973
+ });
7974
+ }
7965
7975
  }
7966
7976
  }
7967
7977
  }
@@ -8260,6 +8270,28 @@ var WebsyChart = /*#__PURE__*/function () {
8260
8270
  this.rendersymbol(series, index);
8261
8271
  }
8262
8272
  }
8273
+ }, {
8274
+ key: "renderRefLine",
8275
+ value: function renderRefLine(data) {
8276
+ /* global d3 data */
8277
+ var xAxis = 'bottom';
8278
+ var yAxis = 'left';
8279
+ var that = this;
8280
+
8281
+ if (this.options.orientation === 'horizontal') {
8282
+ xAxis = 'left';
8283
+ yAxis = 'bottom';
8284
+ }
8285
+
8286
+ this.refLineLayer.selectAll('.reference-line').remove();
8287
+ this.refLineLayer.selectAll('.reference-line-label').remove();
8288
+ this.refLineLayer.append('line').attr('y1', this["".concat(yAxis, "Axis")](data.value)).attr('y2', this["".concat(yAxis, "Axis")](data.value)).attr('x2', this.plotWidth).attr('class', "reference-line").style('stroke', data.color).style('stroke-width', "".concat(data.lineWidth, "px")).style('stroke-dasharray', data.lineStyle);
8289
+
8290
+ if (data.label && data.label !== '') {
8291
+ // show the text on the line
8292
+ this.refLineLayer.append('text').attr('class', "reference-line-label").attr('x', this.plotWidth).attr('y', this["".concat(yAxis, "Axis")](data.value)).attr('font-size', this.options.fontSize).attr('fill', data.color).text(data.label).attr('text-anchor', 'end').attr('alignment-baseline', 'text-after-edge');
8293
+ }
8294
+ }
8263
8295
  }, {
8264
8296
  key: "removeline",
8265
8297
  value: function removeline(key) {