@websy/websy-designs 1.7.18 → 1.7.20

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.
@@ -39,6 +39,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
39
39
  WebsyIcons
40
40
  WebsyChart
41
41
  WebsyChartTooltip
42
+ WebsyPie
42
43
  WebsyLegend
43
44
  WebsyMap
44
45
  WebsyKPI
@@ -2454,8 +2455,8 @@ var WebsyDragDrop = /*#__PURE__*/function () {
2454
2455
  el.innerHTML = html;
2455
2456
  this.options.items.forEach(function (item, i) {
2456
2457
  if (item.component) {
2457
- if (item.isQlikPlugin && WebsyDesigns.QlikPlugin[item.component]) {
2458
- item.instance = new WebsyDesigns.QlikPlugin[item.component]("".concat(item.id, "_component"), item.options);
2458
+ if (item.isQlikPlugin && WebsyDesigns.QlikPlugins[item.component]) {
2459
+ item.instance = new WebsyDesigns.QlikPlugins[item.component]("".concat(item.id, "_component"), item.options);
2459
2460
  } else if (WebsyDesigns[item.component]) {
2460
2461
  item.instance = new WebsyDesigns[item.component]("".concat(item.id, "_component"), item.options);
2461
2462
  } else {
@@ -5638,13 +5639,25 @@ var Switch = /*#__PURE__*/function () {
5638
5639
  key: "disable",
5639
5640
  value: function disable() {
5640
5641
  this.options.enabled = false;
5641
- this.render();
5642
+ var method = this.options.enabled === true ? 'add' : 'remove';
5643
+ var el = document.getElementById("".concat(this.elementId, "_switch"));
5644
+ el.classList[method]('enabled');
5645
+
5646
+ if (this.options.onToggle) {
5647
+ this.options.onToggle(this.options.enabled);
5648
+ }
5642
5649
  }
5643
5650
  }, {
5644
5651
  key: "enable",
5645
5652
  value: function enable() {
5646
5653
  this.options.enabled = true;
5647
- this.render();
5654
+ var method = this.options.enabled === true ? 'add' : 'remove';
5655
+ var el = document.getElementById("".concat(this.elementId, "_switch"));
5656
+ el.classList[method]('enabled');
5657
+
5658
+ if (this.options.onToggle) {
5659
+ this.options.onToggle(this.options.enabled);
5660
+ }
5648
5661
  }
5649
5662
  }, {
5650
5663
  key: "handleClick",
@@ -7118,7 +7131,7 @@ var WebsyTable3 = /*#__PURE__*/function () {
7118
7131
  var el = document.getElementById(this.elementId);
7119
7132
 
7120
7133
  if (el) {
7121
- var html = "\n <div id='".concat(this.elementId, "_tableContainer' class='websy-vis-table-3 ").concat(this.options.paging === 'pages' ? 'with-paging' : '', " ").concat(this.options.virtualScroll === true ? 'with-virtual-scroll' : '', "'>\n <!--<div class=\"download-button\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M16 11h5l-9 10-9-10h5v-11h8v11zm1 11h-10v2h10v-2z\"/></svg>\n </div>-->\n <div id=\"").concat(this.elementId, "_tableInner\" class=\"websy-table-inner-container\">\n <table id=\"").concat(this.elementId, "_tableHeader\" class=\"websy-table-header\"></table>\n <table id=\"").concat(this.elementId, "_tableBody\" class=\"websy-table-body\"></table>\n <table id=\"").concat(this.elementId, "_tableFooter\" class=\"websy-table-footer\"></table>\n <div id=\"").concat(this.elementId, "_vScrollContainer\" class=\"websy-v-scroll-container\">\n <div id=\"").concat(this.elementId, "_vScrollHandle\" class=\"websy-scroll-handle websy-scroll-handle-y\"></div>\n </div>\n <div id=\"").concat(this.elementId, "_hScrollContainer\" class=\"websy-h-scroll-container\">\n <div id=\"").concat(this.elementId, "_hScrollHandle\" class=\"websy-scroll-handle websy-scroll-handle-x\"></div>\n </div>\n ");
7134
+ var html = "\n <div id='".concat(this.elementId, "_tableContainer' class='websy-vis-table-3 ").concat(this.options.paging === 'pages' ? 'with-paging' : '', " ").concat(this.options.virtualScroll === true ? 'with-virtual-scroll' : '', " ").concat(this.isTouchDevice === true && this.options.virtualScroll === true ? 'touch-device' : '', "'>\n <!--<div class=\"download-button\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M16 11h5l-9 10-9-10h5v-11h8v11zm1 11h-10v2h10v-2z\"/></svg>\n </div>-->\n <div id=\"").concat(this.elementId, "_tableInner\" class=\"websy-table-inner-container\">\n <table id=\"").concat(this.elementId, "_tableHeader\" class=\"websy-table-header\"></table>\n <table id=\"").concat(this.elementId, "_tableBody\" class=\"websy-table-body\"></table>\n <table id=\"").concat(this.elementId, "_tableFooter\" class=\"websy-table-footer\"></table>\n <div id=\"").concat(this.elementId, "_vScrollContainer\" class=\"websy-v-scroll-container\">\n <div id=\"").concat(this.elementId, "_vScrollHandle\" class=\"websy-scroll-handle websy-scroll-handle-y\"></div>\n </div>\n <div id=\"").concat(this.elementId, "_hScrollContainer\" class=\"websy-h-scroll-container\">\n <div id=\"").concat(this.elementId, "_hScrollHandle\" class=\"websy-scroll-handle websy-scroll-handle-x\"></div>\n </div>\n ");
7122
7135
 
7123
7136
  if (this.isTouchDevice === true && this.options.virtualScroll === true) {
7124
7137
  html += "\n <div id=\"".concat(this.elementId, "_touchScroller\" class=\"websy-table-touch-scroller\"></div>\n ");
@@ -7646,7 +7659,7 @@ var WebsyTable3 = /*#__PURE__*/function () {
7646
7659
  }, {
7647
7660
  key: "handleMouseDown",
7648
7661
  value: function handleMouseDown(event) {
7649
- if (this.isTouchDevice === true) {
7662
+ if (this.isTouchDevice) {
7650
7663
  return;
7651
7664
  }
7652
7665
 
@@ -7659,6 +7672,10 @@ var WebsyTable3 = /*#__PURE__*/function () {
7659
7672
  this.mouseYStart = event.pageY; // console.log('mouse down', this.handleYStart, this.mouseYStart)
7660
7673
  // console.log(scrollHandleEl.offsetTop)
7661
7674
  } else if (event.target.classList.contains('websy-scroll-handle-x')) {
7675
+ if (this.isTouchDevice) {
7676
+ event.preventDefault();
7677
+ }
7678
+
7662
7679
  this.scrollDragging = true;
7663
7680
  this.scrollDirection = 'x';
7664
7681
 
@@ -7673,6 +7690,10 @@ var WebsyTable3 = /*#__PURE__*/function () {
7673
7690
  value: function handleMouseMove(event) {
7674
7691
  // event.preventDefault()
7675
7692
  if (this.scrollDragging === true) {
7693
+ if (this.isTouchDevice) {
7694
+ event.preventDefault();
7695
+ }
7696
+
7676
7697
  if (this.scrollDirection === 'y') {
7677
7698
  var diff = event.pageY - this.mouseYStart;
7678
7699
  this.scrollY(diff);
@@ -7700,21 +7721,40 @@ var WebsyTable3 = /*#__PURE__*/function () {
7700
7721
  event.preventDefault(); // console.log('scrollwheel', event)
7701
7722
 
7702
7723
  if (Math.abs(event.deltaX) > Math.abs(event.deltaY)) {
7703
- this.scrollX(Math.max(-2, Math.min(2, event.deltaX)));
7724
+ // this.scrollX(Math.max(-2, Math.min(2, event.deltaX)))
7725
+ if (this.hScrollRequired === false) {
7726
+ return;
7727
+ }
7728
+
7729
+ var scrollHandleEl = document.getElementById("".concat(this.elementId, "_hScrollHandle"));
7730
+ var scrollContainerEl = document.getElementById("".concat(this.elementId, "_hScrollContainer"));
7731
+ var resolvedDelta = (scrollContainerEl.getBoundingClientRect().width - scrollHandleEl.getBoundingClientRect().width) / this.totalColumnCount;
7732
+
7733
+ if (event.deltaX < 0) {
7734
+ resolvedDelta = resolvedDelta * -1;
7735
+ }
7736
+
7737
+ this.scrollX(resolvedDelta);
7704
7738
  } else {
7705
7739
  // console.log('delta', event.deltaY)
7706
7740
  // force the scroll to be a single row at a time
7707
- var scrollHandleEl = document.getElementById("".concat(this.elementId, "_vScrollHandle"));
7708
- var scrollContainerEl = document.getElementById("".concat(this.elementId, "_vScrollContainer"));
7709
- var resolvedDelta = (scrollContainerEl.getBoundingClientRect().height - scrollHandleEl.getBoundingClientRect().height) / this.totalRowCount;
7741
+ if (this.vScrollRequired === false) {
7742
+ return;
7743
+ }
7744
+
7745
+ var _scrollHandleEl2 = document.getElementById("".concat(this.elementId, "_vScrollHandle"));
7746
+
7747
+ var _scrollContainerEl = document.getElementById("".concat(this.elementId, "_vScrollContainer"));
7748
+
7749
+ var _resolvedDelta = (_scrollContainerEl.getBoundingClientRect().height - _scrollHandleEl2.getBoundingClientRect().height) / this.totalRowCount;
7710
7750
 
7711
7751
  if (event.deltaY < 0) {
7712
- resolvedDelta = resolvedDelta * -1;
7752
+ _resolvedDelta = _resolvedDelta * -1;
7713
7753
  } // console.log('resolvedDelta', resolvedDelta)
7714
7754
  // this.scrollY(Math.max(-2, Math.min(2, event.deltaY)))
7715
7755
 
7716
7756
 
7717
- this.scrollY(resolvedDelta);
7757
+ this.scrollY(_resolvedDelta);
7718
7758
  }
7719
7759
  } else if (this.options.onNativeScroll) {
7720
7760
  var el = document.getElementById("".concat(this.elementId, "_tableBody"));
@@ -7725,12 +7765,19 @@ var WebsyTable3 = /*#__PURE__*/function () {
7725
7765
  key: "handleTouchEnd",
7726
7766
  value: function handleTouchEnd(event) {
7727
7767
  // console.log('touch end fired')
7728
- if (typeof event.targetTouches !== 'undefined') {
7729
- this.isTouchScrolling = false;
7730
- this.touchEndTime = new Date().getTime();
7731
- this.isPerpetual = true; // this.perpetualScroll()
7768
+ this.scrollDragging = false;
7769
+ this.cellDragging = false;
7770
+ this.handleYStart = null;
7771
+ this.mouseYStart = null;
7772
+ this.handleXStart = null;
7773
+ this.mouseXStart = null;
7732
7774
 
7733
- this.touchStartTime = null; // const touchScrollEl = document.getElementById(`${this.elementId}_touchScroller`)
7775
+ if (typeof event.targetTouches !== 'undefined') {
7776
+ this.isTouchScrolling = false; // this.touchEndTime = (new Date()).getTime()
7777
+ // this.isPerpetual = true
7778
+ // this.perpetualScroll()
7779
+ // this.touchStartTime = null
7780
+ // const touchScrollEl = document.getElementById(`${this.elementId}_touchScroller`)
7734
7781
  // touchScrollEl.classList.add('hidden')
7735
7782
  }
7736
7783
  }
@@ -7743,46 +7790,70 @@ var WebsyTable3 = /*#__PURE__*/function () {
7743
7790
  event.stopPropagation();
7744
7791
 
7745
7792
  if (typeof event.targetTouches !== 'undefined' && event.targetTouches.length > 0) {
7746
- var deltaX = this.mouseXStart - event.targetTouches[0].pageX;
7747
- var deltaY = this.mouseYStart - event.targetTouches[0].pageY;
7748
- var hScrollContainerEl = document.getElementById("".concat(this.elementId, "_hScrollContainer"));
7749
- var vScrollContainerEl = document.getElementById("".concat(this.elementId, "_vScrollContainer"));
7750
- var hScrollHandleEl = document.getElementById("".concat(this.elementId, "_hScrollHandle"));
7751
- var vScrollHandleEl = document.getElementById("".concat(this.elementId, "_vScrollHandle"));
7752
- var translatedDeltaX = deltaX * (hScrollHandleEl.getBoundingClientRect().width / vScrollContainerEl.getBoundingClientRect().width);
7753
- var translatedDeltaY = deltaY * (vScrollHandleEl.getBoundingClientRect().height / vScrollContainerEl.getBoundingClientRect().height); // need to adjust the delta so that it scrolls at a reasonable speed/distance
7754
-
7755
- var scrollHandleXEl = document.getElementById("".concat(this.elementId, "_hScrollHandle"));
7756
- var scrollHandleYEl = document.getElementById("".concat(this.elementId, "_vScrollHandle")); // if (Math.abs(deltaY) > this.sizes.cellHeight) {
7757
- // this.isTouchScrolling = true
7758
- // }
7759
- // else {
7760
- // this.isTouchScrolling = false
7761
- // }
7762
- // console.log('delta', this.mouseYStart, event.targetTouches[0].pageY, deltaY)
7763
- // deltaX = deltaX * (scrollHandleXEl.offsetWidth / this.sizes.scrollableWidth)
7764
- // deltaY = deltaY * (scrollHandleYEl.offsetHeight / this.sizes.bodyHeight)
7765
- // console.log('delta', deltaY)
7766
- // NW
7767
- // else if (Math.abs(deltaX) > 50) {
7768
- // this.isTouchScrolling = false
7769
- // }
7793
+ event.deltaX = this.touchXStart - event.targetTouches[0].pageX;
7794
+ event.deltaY = this.touchYStart - event.targetTouches[0].pageY;
7795
+
7796
+ if (Math.abs(event.deltaY) > 50) {
7797
+ event.deltaX = 0;
7798
+ this.handleScrollWheel(event);
7799
+ } else if (Math.abs(event.deltaX) > 50) {
7800
+ event.deltaY = 0;
7801
+ this.handleScrollWheel(event);
7802
+ } // let deltaX = (this.mouseXStart - event.targetTouches[0].pageX)
7803
+ // let deltaY = (this.mouseYStart - event.targetTouches[0].pageY)
7804
+ // const hScrollContainerEl = document.getElementById(`${this.elementId}_hScrollContainer`)
7805
+ // const vScrollContainerEl = document.getElementById(`${this.elementId}_vScrollContainer`)
7806
+ // const hScrollHandleEl = document.getElementById(`${this.elementId}_hScrollHandle`)
7807
+ // const vScrollHandleEl = document.getElementById(`${this.elementId}_vScrollHandle`)
7808
+ // let translatedDeltaX = deltaX * (hScrollHandleEl.getBoundingClientRect().width / vScrollContainerEl.getBoundingClientRect().width)
7809
+ // let translatedDeltaY = deltaY * (vScrollHandleEl.getBoundingClientRect().height / vScrollContainerEl.getBoundingClientRect().height)
7810
+ // // need to adjust the delta so that it scrolls at a reasonable speed/distance
7811
+ // const scrollHandleXEl = document.getElementById(`${this.elementId}_hScrollHandle`)
7812
+ // const scrollHandleYEl = document.getElementById(`${this.elementId}_vScrollHandle`)
7813
+ // // if (Math.abs(deltaY) > this.sizes.cellHeight) {
7814
+ // // this.isTouchScrolling = true
7815
+ // // }
7816
+ // // else {
7817
+ // // this.isTouchScrolling = false
7818
+ // // }
7819
+ // // console.log('delta', this.mouseYStart, event.targetTouches[0].pageY, deltaY)
7820
+ // // deltaX = deltaX * (scrollHandleXEl.offsetWidth / this.sizes.scrollableWidth)
7821
+ // // deltaY = deltaY * (scrollHandleYEl.offsetHeight / this.sizes.bodyHeight)
7822
+ // // console.log('delta', deltaY)
7823
+ // // NW
7824
+ // // else if (Math.abs(deltaX) > 50) {
7825
+ // // this.isTouchScrolling = false
7826
+ // // }
7827
+ // this.currentClientY = event.targetTouches[0].pageY
7828
+ // this.currentTouchtime = (new Date()).getTime()
7829
+ // // end
7830
+ // // delta = Math.min(10, delta)
7831
+ // // delta = Math.max(-10, delta)
7832
+ // if (this.isTouchScrolling === true) {
7833
+ // // this.$scope.scrollTop += (delta / (this.$scope.layout.qHyperCube.qSize.qcy / this.$scope.rowsToLoad / (this.$scope.totalSpaceAvailable / 250)))
7834
+ // if (Math.abs(deltaX) > Math.abs(deltaY) && deltaX > 20) {
7835
+ // // this.scrollX(Math.max(-5, Math.min(5, translatedDeltaX)))
7836
+ // this.scrollX(translatedDeltaX)
7837
+ // }
7838
+ // else if (deltaY > 20) {
7839
+ // // this.scrollY(Math.max(-5, Math.min(5, translatedDeltaY)))
7840
+ // this.scrollY(translatedDeltaY)
7841
+ // }
7842
+ // }
7770
7843
 
7771
- this.currentClientY = event.targetTouches[0].pageY;
7772
- this.currentTouchtime = new Date().getTime(); // end
7773
- // delta = Math.min(10, delta)
7774
- // delta = Math.max(-10, delta)
7775
-
7776
- if (this.isTouchScrolling === true) {
7777
- // this.$scope.scrollTop += (delta / (this.$scope.layout.qHyperCube.qSize.qcy / this.$scope.rowsToLoad / (this.$scope.totalSpaceAvailable / 250)))
7778
- if (Math.abs(deltaX) > Math.abs(deltaY) && deltaX > 20) {
7779
- // this.scrollX(Math.max(-5, Math.min(5, translatedDeltaX)))
7780
- this.scrollX(translatedDeltaX);
7781
- } else if (deltaY > 20) {
7782
- // this.scrollY(Math.max(-5, Math.min(5, translatedDeltaY)))
7783
- this.scrollY(translatedDeltaY);
7784
- }
7785
- }
7844
+ }
7845
+ }
7846
+
7847
+ if (this.scrollDragging === true) {
7848
+ event.preventDefault();
7849
+
7850
+ if (this.scrollDirection === 'y') {
7851
+ var diff = event.targetTouches[0].pageY - this.mouseYStart;
7852
+ this.scrollY(diff);
7853
+ } else if (this.scrollDirection === 'x') {
7854
+ var _diff2 = event.targetTouches[0].pageX - this.mouseXStart;
7855
+
7856
+ this.scrollX(_diff2);
7786
7857
  }
7787
7858
  }
7788
7859
  }
@@ -7798,19 +7869,44 @@ var WebsyTable3 = /*#__PURE__*/function () {
7798
7869
  } // console.log(event.target.classList)
7799
7870
 
7800
7871
 
7801
- if (this.options.virtualScroll === true) {
7802
- this.touchStartTime = new Date().getTime();
7803
- this.isTouchScrolling = true;
7804
- this.isPerpetual = false;
7805
- this.mouseYStart = event.targetTouches[0].pageY;
7806
- this.mouseXStart = event.targetTouches[0].pageX; // const touchScrollEl = document.getElementById(`${this.elementId}_touchScroller`)
7807
- // touchScrollEl.classList.remove('hidden')
7872
+ if (event.target.classList.contains('websy-table-touch-scroller')) {
7873
+ if (this.options.virtualScroll === true) {
7874
+ // this.touchStartTime = (new Date()).getTime()
7875
+ this.isTouchScrolling = true; // this.isPerpetual = false
7808
7876
 
7809
- var handleYEl = document.getElementById("".concat(this.elementId, "_vScrollHandle"));
7810
- this.handleYStart = handleYEl.offsetTop;
7811
- var handleXEl = document.getElementById("".concat(this.elementId, "_hScrollHandle"));
7812
- this.handleXStart = handleXEl.offsetLeft;
7877
+ this.touchYStart = event.targetTouches[0].pageY;
7878
+ this.touchXStart = event.targetTouches[0].pageX;
7879
+ }
7813
7880
  }
7881
+
7882
+ if (event.target.classList.contains('websy-scroll-handle-y')) {
7883
+ // set up the scroll start values
7884
+ this.scrollDragging = true;
7885
+ this.scrollDirection = 'y';
7886
+ var scrollHandleEl = document.getElementById("".concat(this.elementId, "_vScrollHandle"));
7887
+ this.handleYStart = scrollHandleEl.offsetTop;
7888
+ this.mouseYStart = event.targetTouches[0].pageY; // console.log('mouse down', this.handleYStart, this.mouseYStart)
7889
+ // console.log(scrollHandleEl.offsetTop)
7890
+ } else if (event.target.classList.contains('websy-scroll-handle-x')) {
7891
+ if (this.isTouchDevice) {
7892
+ event.preventDefault();
7893
+ }
7894
+
7895
+ this.scrollDragging = true;
7896
+ this.scrollDirection = 'x';
7897
+
7898
+ var _scrollHandleEl3 = document.getElementById("".concat(this.elementId, "_hScrollHandle"));
7899
+
7900
+ this.handleXStart = _scrollHandleEl3.offsetLeft;
7901
+ this.mouseXStart = event.targetTouches[0].pageX;
7902
+ } // // const touchScrollEl = document.getElementById(`${this.elementId}_touchScroller`)
7903
+ // // touchScrollEl.classList.remove('hidden')
7904
+ // const handleYEl = document.getElementById(`${this.elementId}_vScrollHandle`)
7905
+ // this.handleYStart = handleYEl.offsetTop
7906
+ // const handleXEl = document.getElementById(`${this.elementId}_hScrollHandle`)
7907
+ // this.handleXStart = handleXEl.offsetLeft
7908
+ // }
7909
+
7814
7910
  }
7815
7911
  }, {
7816
7912
  key: "hideError",
@@ -7955,7 +8051,7 @@ var WebsyTable3 = /*#__PURE__*/function () {
7955
8051
 
7956
8052
  if (this.hScrollRequired === true) {
7957
8053
  hScrollEl.style.left = "".concat(this.sizes.table.width - this.sizes.scrollableWidth, "px");
7958
- hScrollEl.style.width = "".concat(this.sizes.scrollableWidth - 20, "px");
8054
+ hScrollEl.style.width = "".concat(this.sizes.scrollableWidth - (this.isTouchDevice ? 30 : 20), "px");
7959
8055
  hHandleEl.style.width = Math.max(this.options.minHandleSize, this.sizes.scrollableWidth * (this.sizes.scrollableWidth / this.sizes.totalNonPinnedWidth)) + 'px';
7960
8056
  } else {
7961
8057
  hHandleEl.style.width = '0px';
@@ -9931,7 +10027,9 @@ var WebsyChart = /*#__PURE__*/function () {
9931
10027
  key: "removebar",
9932
10028
  value: function removebar(key) {
9933
10029
  /* global key d3 */
9934
- var bars = this.barLayer.selectAll(".bar_".concat(key)).transition(this.transition).style('fill-opacity', 1e-6).remove();
10030
+ this.barLayer.selectAll(".bar_".concat(key)).transition(this.transition).style('fill-opacity', 1e-6).remove(); // remove from the brush as well
10031
+
10032
+ this.brushArea.selectAll(".bar_".concat(key)).transition(this.transition).style('fill-opacity', 1e-6).remove();
9935
10033
  }
9936
10034
  }, {
9937
10035
  key: "renderLabels",
@@ -10485,6 +10583,469 @@ var WebsyChart = /*#__PURE__*/function () {
10485
10583
 
10486
10584
  return WebsyChart;
10487
10585
  }();
10586
+ /* global include */
10587
+
10588
+
10589
+ var WebsyPie = /*#__PURE__*/function () {
10590
+ function WebsyPie(elementId, options) {
10591
+ _classCallCheck(this, WebsyPie);
10592
+
10593
+ this.elementId = elementId;
10594
+ var DEFAULTS = {
10595
+ labelMode: 'auto',
10596
+ labelLocs: [],
10597
+ showLabels: false,
10598
+ segments: ['#9dbca6', '#e3c080', '#fd7336', '#b12737', '#50424b'],
10599
+ label: {
10600
+ value: {
10601
+ size: '12px',
10602
+ colour: '#BBB',
10603
+ family: 'arial',
10604
+ weight: 'normal'
10605
+ },
10606
+ label: {
10607
+ size: '10px',
10608
+ colour: '#888',
10609
+ family: 'arial',
10610
+ weight: 'normal'
10611
+ }
10612
+ },
10613
+ kpi: {
10614
+ background: '#555',
10615
+ value: {
10616
+ size: '60px',
10617
+ colour: '#CCC',
10618
+ family: 'arial',
10619
+ weight: 'bold'
10620
+ },
10621
+ label: {
10622
+ size: '20px',
10623
+ colour: '#FFF',
10624
+ family: 'arial',
10625
+ weight: 'normal'
10626
+ }
10627
+ }
10628
+ };
10629
+ this.options = _extends({}, DEFAULTS, options);
10630
+ this.listening = true;
10631
+
10632
+ if (!elementId) {
10633
+ console.log('No element Id provided for Websy Chart');
10634
+ return;
10635
+ }
10636
+
10637
+ var el = document.getElementById(this.elementId);
10638
+
10639
+ if (el) {
10640
+ el.classList.add('websy-pie');
10641
+ } else {
10642
+ console.error("No element found with ID ".concat(this.elementId));
10643
+ }
10644
+ }
10645
+
10646
+ _createClass(WebsyPie, [{
10647
+ key: "calculateArcAngle",
10648
+ value: function calculateArcAngle(arcLength, radius) {
10649
+ return this.convertRadiansToDegrees(arcLength / (Math.PI * (2 * radius)));
10650
+ }
10651
+ }, {
10652
+ key: "calculateCircumference",
10653
+ value: function calculateCircumference(perc) {
10654
+ return Math.PI * 2 * perc;
10655
+ }
10656
+ }, {
10657
+ key: "close",
10658
+ value: function close() {}
10659
+ }, {
10660
+ key: "convertDegreesToRadians",
10661
+ value: function convertDegreesToRadians(degrees) {
10662
+ return degrees * (Math.PI / 180);
10663
+ }
10664
+ }, {
10665
+ key: "convertRadiansToDegrees",
10666
+ value: function convertRadiansToDegrees(radians) {
10667
+ return radians * (180 / Math.PI);
10668
+ }
10669
+ }, {
10670
+ key: "createCanvases",
10671
+ value: function createCanvases(element) {
10672
+ /* global element */
10673
+ if (element && !element.target) {
10674
+ if (!this.listening) {
10675
+ // add event listeners to help with responsiveness
10676
+ element.addEventListener('resize', this.render.bind(this), false);
10677
+ window.addEventListener('resize', this.render.bind(this), false);
10678
+ this.listening = true;
10679
+ }
10680
+
10681
+ var height = element.clientHeight;
10682
+ var width = element.clientWidth;
10683
+ this.width = width;
10684
+ this.height = height;
10685
+ this.center = {
10686
+ x: width / 2,
10687
+ y: height / 2
10688
+ };
10689
+ this.outerRadius = Math.min(this.height, this.width) / 2 - 20;
10690
+ console.log('radius is ' + this.outerRadius); // segment canvas
10691
+
10692
+ var segmentCanvas = document.createElement('canvas');
10693
+ this.segmentPaper = {
10694
+ canvas: segmentCanvas,
10695
+ pen: segmentCanvas.getContext('2d')
10696
+ };
10697
+ this.segmentPaper.canvas.style.position = 'absolute';
10698
+ this.segmentPaper.canvas.style.top = '0px';
10699
+ this.segmentPaper.canvas.style.left = '0px';
10700
+ this.segmentPaper.canvas.style.zIndex = '5';
10701
+ this.segmentPaper.canvas.style.width = width + 'px';
10702
+ this.segmentPaper.canvas.style.height = height + 'px'; // make the canvase size double to accommodate for retina displays
10703
+
10704
+ this.segmentPaper.canvas.width = width * 2;
10705
+ this.segmentPaper.canvas.height = height * 2;
10706
+ this.segmentPaper.pen.scale(2, 2);
10707
+ element.appendChild(this.segmentPaper.canvas); // label canvas
10708
+
10709
+ var labelCanvas = document.createElement('canvas');
10710
+ this.labelPaper = {
10711
+ canvas: labelCanvas,
10712
+ pen: labelCanvas.getContext('2d')
10713
+ };
10714
+ this.labelPaper.canvas.style.position = 'absolute';
10715
+ this.labelPaper.canvas.style.top = '0px';
10716
+ this.labelPaper.canvas.style.left = '0px';
10717
+ this.labelPaper.canvas.style.zIndex = '5';
10718
+ this.labelPaper.canvas.style.width = width + 'px';
10719
+ this.labelPaper.canvas.style.height = height + 'px'; // make the canvase size double to accommodate for retina displays
10720
+
10721
+ this.labelPaper.canvas.width = width * 2;
10722
+ this.labelPaper.canvas.height = height * 2;
10723
+ this.labelPaper.pen.scale(2, 2);
10724
+ element.appendChild(this.labelPaper.canvas); // kpi canvas
10725
+
10726
+ var kpiCanvas = document.createElement('canvas');
10727
+ this.kpiPaper = {
10728
+ canvas: kpiCanvas,
10729
+ pen: kpiCanvas.getContext('2d')
10730
+ };
10731
+ this.kpiPaper.canvas.style.position = 'absolute';
10732
+ this.kpiPaper.canvas.style.top = '0px';
10733
+ this.kpiPaper.canvas.style.left = '0px';
10734
+ this.kpiPaper.canvas.style.zIndex = '5';
10735
+ this.kpiPaper.canvas.style.width = width + 'px';
10736
+ this.kpiPaper.canvas.style.height = height + 'px'; // make the canvase size double to accommodate for retina displays
10737
+
10738
+ this.kpiPaper.canvas.width = width * 2;
10739
+ this.kpiPaper.canvas.height = height * 2;
10740
+ this.kpiPaper.pen.scale(2, 2);
10741
+ element.appendChild(this.kpiPaper.canvas);
10742
+ } else {
10743
+ // clear the canvases
10744
+ this.segmentPaper.canvas.width = this.width * 2;
10745
+ this.labelPaper.canvas.width = this.width * 2;
10746
+ this.kpiPaper.canvas.width = this.width * 2;
10747
+ }
10748
+ }
10749
+ }, {
10750
+ key: "drawKPI",
10751
+ value: function drawKPI() {
10752
+ var kpiStyleDefaults = this.options.kpi;
10753
+
10754
+ if (this.kpi) {
10755
+ // draw the circle for the background colour if one has been specified
10756
+ if (!this.kpi.background || this.kpi.background !== 'transparent') {
10757
+ this.kpiPaper.pen.beginPath();
10758
+ this.kpiPaper.pen.fillStyle = this.kpi.background || kpiStyleDefaults.background;
10759
+ this.kpiPaper.pen.moveTo(this.center.x, this.center.y);
10760
+ this.kpiPaper.pen.arc(this.center.x, this.center.y, this.innerRadiusPixels + 5 * !this.addShading + 1, 0, Math.PI * 2);
10761
+ this.kpiPaper.pen.fill();
10762
+ this.kpiPaper.pen.closePath();
10763
+ } // draw the kpi value
10764
+
10765
+
10766
+ if (this.kpi.value) {
10767
+ this.kpiPaper.pen.save();
10768
+ this.kpiPaper.pen.beginPath();
10769
+ this.kpiPaper.pen.moveTo(this.center.x, this.center.y);
10770
+ this.kpiPaper.pen.font = (this.kpi.value.weight || kpiStyleDefaults.value.weight) + ' ' + (this.kpi.value.size || kpiStyleDefaults.value.size) + ' ' + (this.kpi.value.family || kpiStyleDefaults.value.family);
10771
+ this.kpiPaper.pen.textAlign = 'center';
10772
+
10773
+ if (this.kpi.label) {
10774
+ this.kpiPaper.pen.textBaseline = 'text-bottom';
10775
+ } else {
10776
+ this.kpiPaper.pen.textBaseline = 'middle';
10777
+ }
10778
+
10779
+ this.kpiPaper.pen.fillStyle = this.kpi.value.colour || kpiStyleDefaults.value.colour;
10780
+ this.kpiPaper.pen.fillText(this.kpi.value.text, this.center.x, this.center.y);
10781
+ this.kpiPaper.pen.closePath();
10782
+ this.kpiPaper.pen.restore();
10783
+ } // draw the kpi label
10784
+
10785
+
10786
+ if (this.kpi.label) {
10787
+ this.kpiPaper.pen.save();
10788
+ this.kpiPaper.pen.beginPath();
10789
+ this.kpiPaper.pen.moveTo(this.center.x, this.center.y);
10790
+ this.kpiPaper.pen.font = (this.kpi.label.weight || kpiStyleDefaults.label.weight) + ' ' + (this.kpi.label.size || kpiStyleDefaults.label.size) + ' ' + (this.kpi.label.family || kpiStyleDefaults.label.family);
10791
+ this.kpiPaper.pen.textAlign = 'center';
10792
+
10793
+ if (this.kpi.value) {
10794
+ this.kpiPaper.pen.textBaseline = 'top';
10795
+ } else {
10796
+ this.kpiPaper.pen.textBaseline = 'middle';
10797
+ }
10798
+
10799
+ this.kpiPaper.pen.fillStyle = this.kpi.label.colour || kpiStyleDefaults.label.colour;
10800
+ this.kpiPaper.pen.fillText(this.kpi.label.text, this.center.x, this.center.y + 10);
10801
+ this.kpiPaper.pen.closePath();
10802
+ this.kpiPaper.pen.restore();
10803
+ }
10804
+ }
10805
+ }
10806
+ }, {
10807
+ key: "drawLabels",
10808
+ value: function drawLabels() {
10809
+ // this.labelPaper.pen.translate(this.center.x, this.center.y)
10810
+ if (this.options.showLabels) {
10811
+ for (var s in this.data.segments) {
10812
+ this.labelPaper.pen.beginPath();
10813
+ this.labelPaper.pen.font = '20px arial';
10814
+ this.labelPaper.pen.textAlign = 'center';
10815
+ this.labelPaper.pen.textBaseline = 'text-bottom';
10816
+ this.labelPaper.pen.fillStyle = 'black'; // calculate the nearest 90 degrees to the mid point and reduce to within 360 degrees
10817
+
10818
+ var midAngleDeg = this.data.segments[s].midAngleDeg % 360;
10819
+ var nearest90Deg = Math.round(midAngleDeg / 90) * 90 % 360;
10820
+ console.log(Math.abs(nearest90Deg - midAngleDeg));
10821
+ var missingAngleDeg = 270 - Math.abs(nearest90Deg - midAngleDeg);
10822
+ console.log(nearest90Deg);
10823
+ var oppLength = this.outerRadius * Math.sin(this.convertDegreesToRadians(Math.abs(nearest90Deg - midAngleDeg))) / Math.sin(this.convertDegreesToRadians(missingAngleDeg));
10824
+ oppLength = Math.abs(oppLength);
10825
+ var moveLength = this.outerRadius + 5;
10826
+ var slopeMultiplier = 1.2;
10827
+ var flatMultiplier = 1.3;
10828
+
10829
+ if (midAngleDeg > 0 && midAngleDeg <= 45) {
10830
+ this.labelPaper.pen.moveTo(this.center.x + moveLength, this.center.y + oppLength);
10831
+ this.labelPaper.pen.lineTo(this.center.x + moveLength * slopeMultiplier, this.center.y + oppLength * slopeMultiplier);
10832
+ this.labelPaper.pen.lineTo(this.center.x + moveLength * flatMultiplier, this.center.y + oppLength * slopeMultiplier);
10833
+ } else if (midAngleDeg > 45 && midAngleDeg <= 90) {
10834
+ this.labelPaper.pen.moveTo(this.center.x + oppLength, this.center.y + moveLength);
10835
+ this.labelPaper.pen.lineTo(this.center.x + oppLength * slopeMultiplier, this.center.y + moveLength * slopeMultiplier);
10836
+ this.labelPaper.pen.lineTo(this.center.x + oppLength * flatMultiplier, this.center.y + moveLength * slopeMultiplier);
10837
+ } else if (midAngleDeg > 90 && midAngleDeg <= 135) {
10838
+ this.labelPaper.pen.moveTo(this.center.x - oppLength, this.center.y + moveLength);
10839
+ this.labelPaper.pen.lineTo(this.center.x - oppLength * slopeMultiplier, this.center.y + moveLength * slopeMultiplier);
10840
+ this.labelPaper.pen.lineTo(this.center.x - oppLength * flatMultiplier, this.center.y + moveLength * slopeMultiplier);
10841
+ } else if (midAngleDeg > 135 && midAngleDeg <= 180) {
10842
+ this.labelPaper.pen.moveTo(this.center.x - moveLength, this.center.y + oppLength);
10843
+ this.labelPaper.pen.lineTo(this.center.x - moveLength * slopeMultiplier, this.center.y + oppLength * slopeMultiplier);
10844
+ this.labelPaper.pen.lineTo(this.center.x - moveLength * flatMultiplier, this.center.y + oppLength * slopeMultiplier);
10845
+ } else if (midAngleDeg > 180 && midAngleDeg <= 225) {
10846
+ this.labelPaper.pen.moveTo(this.center.x - moveLength, this.center.y - oppLength);
10847
+ this.labelPaper.pen.lineTo(this.center.x - moveLength * slopeMultiplier, this.center.y - oppLength * slopeMultiplier);
10848
+ this.labelPaper.pen.lineTo(this.center.x - moveLength * flatMultiplier, this.center.y - oppLength * slopeMultiplier);
10849
+ } else if (midAngleDeg > 225 && midAngleDeg <= 270) {
10850
+ this.labelPaper.pen.moveTo(this.center.x - oppLength, this.center.y - moveLength);
10851
+ this.labelPaper.pen.lineTo(this.center.x - oppLength * slopeMultiplier, this.center.y - moveLength * slopeMultiplier);
10852
+ this.labelPaper.pen.lineTo(this.center.x - oppLength * flatMultiplier, this.center.y - moveLength * slopeMultiplier);
10853
+ } else if (midAngleDeg > 270 && midAngleDeg <= 315) {
10854
+ this.labelPaper.pen.moveTo(this.center.x + oppLength, this.center.y - moveLength);
10855
+ this.labelPaper.pen.lineTo(this.center.x + oppLength * slopeMultiplier, this.center.y - moveLength * slopeMultiplier);
10856
+ this.labelPaper.pen.lineTo(this.center.x + oppLength * flatMultiplier, this.center.y - moveLength * slopeMultiplier);
10857
+ } else {
10858
+ this.labelPaper.pen.moveTo(this.center.x + moveLength, this.center.y - oppLength);
10859
+ this.labelPaper.pen.lineTo(this.center.x + moveLength * slopeMultiplier, this.center.y - oppLength * slopeMultiplier);
10860
+ this.labelPaper.pen.lineTo(this.center.x + moveLength * flatMultiplier, this.center.y - oppLength * slopeMultiplier);
10861
+ }
10862
+
10863
+ this.labelPaper.pen.strokeStyle = '#cccccc';
10864
+ this.labelPaper.pen.stroke();
10865
+ this.labelPaper.pen.fillText(this.center.x + this.data.segments[s].label.x, this.center.y + this.data.segments[s].label.y, s);
10866
+ this.labelPaper.pen.closePath();
10867
+ }
10868
+ }
10869
+ }
10870
+ }, {
10871
+ key: "drawSegments",
10872
+ value: function drawSegments() {
10873
+ var originalStartPoint = this.convertDegreesToRadians(270);
10874
+ var startPoint = originalStartPoint;
10875
+ var colourIndex = 0;
10876
+
10877
+ for (var s in this.data.segments) {
10878
+ if (colourIndex >= this.options.colors.length) {
10879
+ colourIndex = 0;
10880
+ }
10881
+
10882
+ var segmentColour = this.options.colors[colourIndex];
10883
+ var endPoint = startPoint + this.data.segments[s].circumference;
10884
+ var midAngle = (startPoint + endPoint) / 2;
10885
+ this.data.segments[s].labelCanvasRotation = startPoint;
10886
+ this.data.segments[s].startAngle = startPoint;
10887
+ this.data.segments[s].midAngle = midAngle;
10888
+ this.data.segments[s].endAngle = endPoint;
10889
+ this.data.segments[s].startAngleDeg = this.convertRadiansToDegrees(startPoint);
10890
+ this.data.segments[s].midAngleDeg = this.convertRadiansToDegrees(midAngle);
10891
+ this.data.segments[s].endAngleDeg = this.convertRadiansToDegrees(endPoint);
10892
+ this.segmentPaper.pen.beginPath();
10893
+ this.segmentPaper.pen.moveTo(this.center.x, this.center.y);
10894
+ this.segmentPaper.pen.fillStyle = segmentColour;
10895
+ this.segmentPaper.pen.arc(this.center.x, this.center.y, this.outerRadius, startPoint, endPoint);
10896
+ console.log(this.segmentPaper.pen);
10897
+ this.segmentPaper.pen.fill();
10898
+ this.segmentPaper.pen.closePath();
10899
+ startPoint = endPoint;
10900
+ colourIndex++;
10901
+ } // cut out the center of the pie if an inner radius has been set
10902
+
10903
+
10904
+ if (this.innerRadius && this.innerRadius !== 0) {
10905
+ // inner radius is a percentage so we compare it against outerRadius (px) to calculate the pixel value
10906
+ this.innerRadiusPixels = Math.round(this.outerRadius * (this.innerRadius / 100));
10907
+ this.segmentPaper.pen.save();
10908
+ this.segmentPaper.pen.beginPath();
10909
+ this.segmentPaper.pen.moveTo(this.center.x, this.center.y);
10910
+ this.segmentPaper.pen.arc(this.center.x, this.center.y, this.innerRadiusPixels + 5, 0, Math.PI * 2);
10911
+ this.segmentPaper.pen.clip();
10912
+ this.segmentPaper.pen.clearRect(0, 0, this.width * 2, this.height * 2);
10913
+ this.segmentPaper.pen.closePath();
10914
+ this.segmentPaper.pen.restore(); // add shading if required
10915
+
10916
+ if (this.addShading === true) {
10917
+ startPoint = originalStartPoint;
10918
+ colourIndex = 0;
10919
+
10920
+ for (var _s in this.data.segments) {
10921
+ if (colourIndex >= this.options.colors.length) {
10922
+ colourIndex = 0;
10923
+ }
10924
+
10925
+ var _segmentColour = this.hexToRGBA(this.options.colors[colourIndex], 0.8);
10926
+
10927
+ var _endPoint = startPoint + this.data.segments[_s].circumference;
10928
+
10929
+ this.segmentPaper.pen.beginPath();
10930
+ this.segmentPaper.pen.moveTo(this.center.x, this.center.y);
10931
+ this.segmentPaper.pen.fillStyle = _segmentColour;
10932
+ this.segmentPaper.pen.arc(this.center.x, this.center.y, this.innerRadiusPixels + 6, startPoint, _endPoint);
10933
+ this.segmentPaper.pen.fill();
10934
+ this.segmentPaper.pen.closePath();
10935
+ startPoint = _endPoint;
10936
+ colourIndex++;
10937
+ } // cut out the center again
10938
+
10939
+
10940
+ this.segmentPaper.pen.save();
10941
+ this.segmentPaper.pen.beginPath();
10942
+ this.segmentPaper.pen.moveTo(this.center.x, this.center.y);
10943
+ this.segmentPaper.pen.arc(this.center.x, this.center.y, this.innerRadiusPixels, 0, Math.PI * 2);
10944
+ this.segmentPaper.pen.clip();
10945
+ this.segmentPaper.pen.clearRect(0, 0, this.width * 2, this.height * 2);
10946
+ this.segmentPaper.pen.closePath();
10947
+ this.segmentPaper.pen.restore();
10948
+ }
10949
+ }
10950
+
10951
+ console.log(this.data);
10952
+ }
10953
+ }, {
10954
+ key: "hexToRGBA",
10955
+ value: function hexToRGBA(hex, opacity) {
10956
+ if (!opacity) {
10957
+ opacity = 1;
10958
+ }
10959
+
10960
+ var c;
10961
+
10962
+ if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
10963
+ c = hex.substring(1).split('');
10964
+
10965
+ if (c.length === 3) {
10966
+ c = [c[0], c[0], c[1], c[1], c[2], c[2]];
10967
+ }
10968
+
10969
+ c = '0x' + c.join('');
10970
+ return 'rgba(' + [c >> 16 & 255, c >> 8 & 255, c & 255, opacity].join(',') + ')';
10971
+ }
10972
+
10973
+ console.error("Unable to convert hex (".concat(hex, ") to RGBA"));
10974
+ return 'rgba(0, 0, 0, 1)';
10975
+ }
10976
+ }, {
10977
+ key: "render",
10978
+ value: function render(data) {
10979
+ /* global data */
10980
+ var el = document.getElementById(this.elementId);
10981
+
10982
+ if (el && !el.target) {
10983
+ this.createCanvases(el);
10984
+ }
10985
+
10986
+ if (data && !data.target) {
10987
+ this.originalData = _toConsumableArray(data);
10988
+ }
10989
+
10990
+ this.processData(data);
10991
+ this.drawSegments();
10992
+ this.drawLabels();
10993
+ this.drawKPI();
10994
+ }
10995
+ }, {
10996
+ key: "resize",
10997
+ value: function resize() {}
10998
+ }, {
10999
+ key: "processData",
11000
+ value: function processData(data) {
11001
+ /* global data */
11002
+ var tempData = {};
11003
+ var tempTotal = 0;
11004
+
11005
+ for (var i = 0; i < data.length; i++) {
11006
+ // if the dimension does not exists as a property on tempData, add it
11007
+ if (!tempData[data[i][0].label]) {
11008
+ tempData[data[i][0].label] = {
11009
+ segmentValue: 0,
11010
+ drill: []
11011
+ };
11012
+ } // add the value to the relevent segmentValue
11013
+
11014
+
11015
+ tempData[data[i][0].label].segmentValue += data[i][1].value; // add the value to the total
11016
+
11017
+ tempTotal += data[i][1].value; // if a drill has been specified add the data to the drill property
11018
+
11019
+ if (this.drill && this.drill !== '') {
11020
+ tempData[data[i][0].label].drill.push({
11021
+ label: data[i][0].label,
11022
+ value: data[i][1].value
11023
+ });
11024
+ }
11025
+ } // loop through the full data set to calculate the percentages
11026
+
11027
+
11028
+ for (var s in tempData) {
11029
+ tempData[s].percValue = tempData[s].segmentValue / tempTotal;
11030
+ tempData[s].circumference = this.calculateCircumference(tempData[s].percValue);
11031
+ tempData[s].labelAngle = 360 * (tempData[s].percValue / 2); // calculate where the label should be for that segment
11032
+
11033
+ tempData[s].label = {
11034
+ x: (this.outerRadius + 5) / Math.sin(this.convertDegreesToRadians(90)) * Math.sin(this.convertDegreesToRadians(180 - 90 - tempData[s].labelAngle))
11035
+ };
11036
+ tempData[s].label.y = (this.outerRadius + 5) / Math.sin(this.convertDegreesToRadians(90)) * Math.sin(this.convertDegreesToRadians(tempData[s].labelAngle));
11037
+ }
11038
+
11039
+ this.data = {
11040
+ segments: tempData,
11041
+ total: tempTotal
11042
+ };
11043
+ console.log(this.data);
11044
+ }
11045
+ }]);
11046
+
11047
+ return WebsyPie;
11048
+ }();
10488
11049
 
10489
11050
  var WebsyLegend = /*#__PURE__*/function () {
10490
11051
  function WebsyLegend(elementId, options) {
@@ -11014,6 +11575,8 @@ var WebsyDesigns = {
11014
11575
  Chart: WebsyChart,
11015
11576
  WebsyChartTooltip: WebsyChartTooltip,
11016
11577
  ChartTooltip: WebsyChartTooltip,
11578
+ Pie: WebsyPie,
11579
+ WebsyPie: WebsyPie,
11017
11580
  Legend: WebsyLegend,
11018
11581
  WebsyMap: WebsyMap,
11019
11582
  Map: WebsyMap,