@websy/websy-designs 1.3.0 → 1.3.2

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.
@@ -414,6 +414,7 @@ var WebsyDatePicker = /*#__PURE__*/function () {
414
414
  var _this2 = this;
415
415
 
416
416
  var isRange = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
417
+ console.trace();
417
418
  var maskEl = document.getElementById("".concat(this.elementId, "_mask"));
418
419
  var contentEl = document.getElementById("".concat(this.elementId, "_content"));
419
420
  var el = document.getElementById(this.elementId);
@@ -435,9 +436,9 @@ var WebsyDatePicker = /*#__PURE__*/function () {
435
436
  hoursOut.push(this.options.hours[i]);
436
437
  }
437
438
 
438
- this.options.onChange(hoursOut, true);
439
+ this.options.onChange(hoursOut, true, this.selectedRange);
439
440
  } else {
440
- this.options.onChange(this.selectedRangeDates, true);
441
+ this.options.onChange(this.selectedRangeDates, true, this.selectedRange);
441
442
  }
442
443
  } else {
443
444
  if (this.options.mode === 'hour') {
@@ -445,9 +446,9 @@ var WebsyDatePicker = /*#__PURE__*/function () {
445
446
  return _this2.options.hours[h];
446
447
  });
447
448
 
448
- this.options.onChange(_hoursOut, true);
449
+ this.options.onChange(_hoursOut, true, this.selectedRange);
449
450
  } else {
450
- this.options.onChange(this.currentselection, isRange);
451
+ this.options.onChange(this.currentselection, isRange, this.selectedRange);
451
452
  }
452
453
  }
453
454
  }
@@ -473,7 +474,7 @@ var WebsyDatePicker = /*#__PURE__*/function () {
473
474
  } // d.setTime(d.getTime() + d.getTimezoneOffset() * 60000)
474
475
 
475
476
 
476
- return new Date(d.setHours(0, 0, 0, 0));
477
+ return new Date(d.setUTCHours(12, 0, 0, 0));
477
478
  }
478
479
  }, {
479
480
  key: "handleClick",
@@ -613,9 +614,10 @@ var WebsyDatePicker = /*#__PURE__*/function () {
613
614
  var rangeEnd = void 0;
614
615
 
615
616
  if (this.options.mode === 'date') {
616
- d = this.floorDate(new Date(this.selectedRangeDates[0].getTime() + _i * this.oneDay));
617
- d.setHours(0, 0, 0, 0);
618
- d = d.getTime();
617
+ d = this.floorDate(new Date(this.selectedRangeDates[0].getTime() + _i * this.oneDay)); // d.setUTCHours(12, 0, 0, 0)
618
+
619
+ d = d.getTime(); // console.log('highlighting', this.selectedRangeDates[0].getTime(), d)
620
+
619
621
  rangeStart = this.selectedRangeDates[0].getTime();
620
622
  rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1].getTime();
621
623
  } else if (this.options.mode === 'year') {
@@ -623,7 +625,9 @@ var WebsyDatePicker = /*#__PURE__*/function () {
623
625
  rangeStart = this.selectedRangeDates[0];
624
626
  rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1];
625
627
  } else if (this.options.mode === 'monthyear') {
626
- d = new Date(this.selectedRangeDates[0].getTime()).setMonth(this.selectedRangeDates[0].getMonth() + _i);
628
+ d = this.floorDate(new Date(this.selectedRangeDates[0].getTime()).setMonth(this.selectedRangeDates[0].getMonth() + _i));
629
+ d = d.getTime();
630
+ console.log('highlighting', this.selectedRangeDates[0].getTime(), d);
627
631
  rangeStart = this.selectedRangeDates[0].getTime();
628
632
  rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1].getTime();
629
633
  } else if (this.options.mode === 'hour') {
@@ -670,9 +674,11 @@ var WebsyDatePicker = /*#__PURE__*/function () {
670
674
  dateEl = document.getElementById("".concat(_this3.elementId, "_").concat(d, "_hour"));
671
675
  }
672
676
 
673
- dateEl.classList.add('selected');
674
- dateEl.classList.add('first');
675
- dateEl.classList.add('last');
677
+ if (dateEl) {
678
+ dateEl.classList.add('selected');
679
+ dateEl.classList.add('first');
680
+ dateEl.classList.add('last');
681
+ }
676
682
  });
677
683
  }
678
684
  }
@@ -920,7 +926,7 @@ var WebsyDatePicker = /*#__PURE__*/function () {
920
926
 
921
927
  html += "<div id='".concat(this.elementId, "_dateList' class='websy-dp-date-list'><ul>");
922
928
  html += yearList.map(function (d) {
923
- return "<li id='".concat(_this4.elementId, "_").concat(d.id, "_year' class='websy-dp-date websy-dp-year ").concat(d.disabled === true ? 'websy-disabled-date' : '', "'>").concat(d.year, "</li>");
929
+ return "<li id='".concat(_this4.elementId, "_").concat(d.id, "_year' data-id='").concat(d.id, "' class='websy-dp-date websy-dp-year ").concat(d.disabled === true ? 'websy-disabled-date' : '', "'>").concat(d.year, "</li>");
924
930
  }).join('');
925
931
  html += "</ul></div>";
926
932
  } else if (this.options.mode === 'monthyear') {
@@ -940,7 +946,7 @@ var WebsyDatePicker = /*#__PURE__*/function () {
940
946
  }
941
947
 
942
948
  html += this.monthYears[year].map(function (d) {
943
- return "<li id='".concat(_this4.elementId, "_").concat(d.id, "_monthyear' data-year='").concat(d.year, "' class='websy-dp-date websy-dp-monthyear'>").concat(d.month, "</li>");
949
+ return "<li id='".concat(_this4.elementId, "_").concat(d.id, "_monthyear' data-id='").concat(d.id, "' data-year='").concat(d.year, "' class='websy-dp-date websy-dp-monthyear'>").concat(d.month, "</li>");
944
950
  }).join('');
945
951
  html += "</ul>";
946
952
  }
@@ -1048,16 +1054,6 @@ var WebsyDatePicker = /*#__PURE__*/function () {
1048
1054
  return d.getTime();
1049
1055
  });
1050
1056
  this.selectedRange = +index;
1051
- var el = document.getElementById("".concat(this.elementId, "_header"));
1052
-
1053
- if (el) {
1054
- if (this.selectedRange === 0) {
1055
- el.classList.remove('range-selected');
1056
- } else {
1057
- el.classList.add('range-selected');
1058
- }
1059
- }
1060
-
1061
1057
  this.highlightRange();
1062
1058
  this.updateRange();
1063
1059
  this.close(confirm, true);
@@ -1069,16 +1065,17 @@ var WebsyDatePicker = /*#__PURE__*/function () {
1069
1065
  var _this6 = this;
1070
1066
 
1071
1067
  this.selectedRange = -1;
1072
- var isContinuousRange = true;
1073
-
1074
- if (rangeInput.length === 1) {
1075
- this.selectedRangeDates = _toConsumableArray(rangeInput);
1076
- this.customRangeSelected = true;
1077
- } else if (rangeInput.length === 2) {
1078
- this.selectedRangeDates = _toConsumableArray(rangeInput);
1079
- this.customRangeSelected = true;
1080
- }
1068
+ var isContinuousRange = true; // if (rangeInput.length === 1) {
1069
+ // this.selectedRangeDates = [...rangeInput]
1070
+ // this.customRangeSelected = true
1071
+ // }
1072
+ // else if (rangeInput.length === 2) {
1073
+ // this.selectedRangeDates = [...rangeInput]
1074
+ // this.customRangeSelected = true
1075
+ // }
1081
1076
 
1077
+ this.selectedRangeDates = _toConsumableArray(rangeInput);
1078
+ this.customRangeSelected = true;
1082
1079
  rangeInput.forEach(function (r, i) {
1083
1080
  if (i > 0) {
1084
1081
  if (_this6.options.mode === 'date' || _this6.options.mode === 'monthyear') {
@@ -1232,6 +1229,16 @@ var WebsyDatePicker = /*#__PURE__*/function () {
1232
1229
  if (labelEl) {
1233
1230
  labelEl.innerHTML = range.label;
1234
1231
  }
1232
+
1233
+ var headerEl = document.getElementById("".concat(this.elementId, "_header"));
1234
+
1235
+ if (headerEl) {
1236
+ if (this.selectedRange === 0) {
1237
+ headerEl.classList.remove('range-selected');
1238
+ } else {
1239
+ headerEl.classList.add('range-selected');
1240
+ }
1241
+ }
1235
1242
  }
1236
1243
  }]);
1237
1244
 
@@ -1251,7 +1258,8 @@ var WebsyDragDrop = /*#__PURE__*/function () {
1251
1258
  var DEFAULTS = {
1252
1259
  items: [],
1253
1260
  orientation: 'horizontal',
1254
- dropPlaceholder: 'Drop item here'
1261
+ dropPlaceholder: 'Drop item here',
1262
+ accepts: 'application/wd-item'
1255
1263
  };
1256
1264
  this.busy = false;
1257
1265
  this.options = _extends({}, DEFAULTS, options);
@@ -1317,7 +1325,7 @@ var WebsyDragDrop = /*#__PURE__*/function () {
1317
1325
  item.id = WebsyDesigns.Utils.createIdentity();
1318
1326
  }
1319
1327
 
1320
- var html = "\n <div id='".concat(item.id, "_item' class='websy-dragdrop-item' draggable='true' data-id='").concat(item.id, "'> \n <div id='").concat(item.id, "_itemInner' class='websy-dragdrop-item-inner' data-id='").concat(item.id, "'>\n ");
1328
+ var html = "\n <div id='".concat(item.id, "_item' class='websy-dragdrop-item ").concat((item.classes || []).join(' '), "' draggable='true' data-id='").concat(item.id, "'> \n <div id='").concat(item.id, "_itemInner' class='websy-dragdrop-item-inner' data-id='").concat(item.id, "'>\n ");
1321
1329
 
1322
1330
  if (item.component) {
1323
1331
  html += "<div id='".concat(item.id, "_component'></div>");
@@ -1347,27 +1355,32 @@ var WebsyDragDrop = /*#__PURE__*/function () {
1347
1355
  value: function handleDragStart(event) {
1348
1356
  this.draggedId = event.target.getAttribute('data-id');
1349
1357
  event.dataTransfer.effectAllowed = 'move';
1350
- event.dataTransfer.setData('application/wd-item', JSON.stringify({
1358
+ event.dataTransfer.setData(this.options.accepts, JSON.stringify({
1351
1359
  el: event.target.id,
1352
1360
  id: this.elementId,
1353
1361
  itemId: this.draggedId
1354
- })); // console.log('drag start', event)
1362
+ }));
1363
+ event.target.classList.add('dragging'); // event.target.style.opacity = 0.5
1355
1364
 
1356
- event.target.style.opacity = 0.5;
1357
1365
  this.dragging = true;
1358
1366
  }
1359
1367
  }, {
1360
1368
  key: "handleDragOver",
1361
1369
  value: function handleDragOver(event) {
1362
- // console.log('drag over', event.target.classList)
1363
1370
  if (event.preventDefault) {
1364
1371
  event.preventDefault();
1365
1372
  }
1366
1373
 
1374
+ console.log('drag', event.target.classList);
1375
+
1367
1376
  if (!event.target.classList.contains('droppable')) {
1368
1377
  return;
1369
1378
  }
1370
1379
 
1380
+ if (event.dataTransfer.types.indexOf(this.options.accepts) === -1) {
1381
+ return;
1382
+ }
1383
+
1371
1384
  event.target.classList.add('drag-over');
1372
1385
  }
1373
1386
  }, {
@@ -1387,8 +1400,8 @@ var WebsyDragDrop = /*#__PURE__*/function () {
1387
1400
  key: "handleDrop",
1388
1401
  value: function handleDrop(event) {
1389
1402
  // console.log('drag drop')
1390
- // console.log(event.dataTransfer.getData('application/wd-item'))
1391
- var data = JSON.parse(event.dataTransfer.getData('application/wd-item'));
1403
+ // console.log(event.dataTransfer.getData('application/wd-item'))
1404
+ var data = JSON.parse(event.dataTransfer.getData(this.options.accepts));
1392
1405
 
1393
1406
  if (event.preventDefault) {
1394
1407
  event.preventDefault();
@@ -1398,6 +1411,10 @@ var WebsyDragDrop = /*#__PURE__*/function () {
1398
1411
  return;
1399
1412
  }
1400
1413
 
1414
+ if (event.dataTransfer.types.indexOf(this.options.accepts) === -1) {
1415
+ return;
1416
+ }
1417
+
1401
1418
  var side = event.target.getAttribute('data-side');
1402
1419
  var id = event.target.getAttribute('data-id');
1403
1420
  var index = this.getItemIndex(id);
@@ -1455,6 +1472,7 @@ var WebsyDragDrop = /*#__PURE__*/function () {
1455
1472
  value: function handleDragEnd(event) {
1456
1473
  // console.log('drag end')
1457
1474
  event.target.style.opacity = 1;
1475
+ event.target.classList.remove('dragging');
1458
1476
  this.draggedId = null;
1459
1477
  this.dragging = false;
1460
1478
  var startEl = document.getElementById("".concat(this.elementId, "start_item"));
@@ -5806,12 +5824,20 @@ var WebsyTable3 = /*#__PURE__*/function () {
5806
5824
  data.forEach(function (row) {
5807
5825
  bodyHtml += "<tr class=\"websy-table-row\">";
5808
5826
  row.forEach(function (cell, cellIndex) {
5827
+ if (typeof sizingColumns[cellIndex] === 'undefined') {
5828
+ return; // need to revisit this logic
5829
+ }
5830
+
5809
5831
  var style = '';
5810
5832
 
5811
5833
  if (cell.style) {
5812
5834
  style += cell.style;
5813
5835
  }
5814
5836
 
5837
+ if (useWidths === true) {
5838
+ style += "max-width: ".concat(sizingColumns[cellIndex].width || sizingColumns[cellIndex].actualWidth, "px!important;");
5839
+ }
5840
+
5815
5841
  if (cell.backgroundColor) {
5816
5842
  style += "background-color: ".concat(cell.backgroundColor, "; ");
5817
5843
 
@@ -5824,7 +5850,8 @@ var WebsyTable3 = /*#__PURE__*/function () {
5824
5850
  style += "color: ".concat(cell.color, "; ");
5825
5851
  }
5826
5852
 
5827
- bodyHtml += "<td \n class='websy-table-cell'\n style='".concat(style, "'\n data-info='").concat(cell.value, "'\n colspan='").concat(cell.colspan || 1, "'\n rowspan='").concat(cell.rowspan || 1, "'\n "); // if (useWidths === true) {
5853
+ console.log('rowspan', cell.rowspan);
5854
+ bodyHtml += "<td \n class='websy-table-cell ".concat((cell.classes || []).join(' '), "'\n style='").concat(style, "'\n data-info='").concat(cell.value, "'\n colspan='").concat(cell.colspan || 1, "'\n rowspan='").concat(cell.rowspan || 1, "'\n "); // if (useWidths === true) {
5828
5855
  // bodyHtml += `
5829
5856
  // style='width: ${sizingColumns[cellIndex].width || sizingColumns[cellIndex].actualWidth}px!important'
5830
5857
  // width='${sizingColumns[cellIndex].width || sizingColumns[cellIndex].actualWidth}'
@@ -5983,10 +6010,16 @@ var WebsyTable3 = /*#__PURE__*/function () {
5983
6010
  this.sizes.totalWidth = this.options.columns[this.options.columns.length - 1].reduce(function (a, b) {
5984
6011
  return a + (b.width || b.actualWidth);
5985
6012
  }, 0);
6013
+ this.sizes.totalNonPinnedWidth = this.options.columns[this.options.columns.length - 1].filter(function (c, i) {
6014
+ return i >= _this37.pinnedColumns;
6015
+ }).reduce(function (a, b) {
6016
+ return a + (b.width || b.actualWidth);
6017
+ }, 0);
5986
6018
  var outerSize = outerEl.getBoundingClientRect();
5987
6019
 
5988
6020
  if (this.sizes.totalWidth < outerSize.width) {
5989
6021
  this.sizes.totalWidth = 0;
6022
+ this.sizes.totalNonPinnedWidth = 0;
5990
6023
  var equalWidth = outerSize.width / this.options.columns[this.options.columns.length - 1].length;
5991
6024
  this.options.columns[this.options.columns.length - 1].forEach(function (c, i) {
5992
6025
  if (!c.width) {
@@ -5997,6 +6030,11 @@ var WebsyTable3 = /*#__PURE__*/function () {
5997
6030
  }
5998
6031
 
5999
6032
  _this37.sizes.totalWidth += c.width || c.actualWidth;
6033
+
6034
+ if (i < _this37.pinnedColumns) {
6035
+ _this37.sizes.totalNonPinnedWidth += c.width || c.actualWidth;
6036
+ }
6037
+
6000
6038
  equalWidth = (outerSize.width - _this37.sizes.totalWidth) / (_this37.options.columns[_this37.options.columns.length - 1].length - (i + 1));
6001
6039
  });
6002
6040
  } // take the height of the last cell as the official height for data cells
@@ -6018,10 +6056,14 @@ var WebsyTable3 = /*#__PURE__*/function () {
6018
6056
 
6019
6057
  if (this.sizes.rowsToRender < this.totalRowCount) {
6020
6058
  this.vScrollRequired = true;
6059
+ } else {
6060
+ this.vScrollRequired = false;
6021
6061
  }
6022
6062
 
6023
6063
  if (this.sizes.totalWidth > this.sizes.outer.width) {
6024
6064
  this.hScrollRequired = true;
6065
+ } else {
6066
+ this.hScrollRequired = false;
6025
6067
  }
6026
6068
 
6027
6069
  this.options.allColumns = this.options.columns.map(function (c) {
@@ -6211,9 +6253,9 @@ var WebsyTable3 = /*#__PURE__*/function () {
6211
6253
  if (this.hScrollRequired === true) {
6212
6254
  hScrollEl.style.left = "".concat(this.sizes.table.width - this.sizes.scrollableWidth, "px");
6213
6255
  hScrollEl.style.width = "".concat(this.sizes.scrollableWidth - 20, "px");
6214
- hHandleEl.style.width = Math.max(this.options.minHandleSize, this.sizes.scrollableWidth * (this.sizes.scrollableWidth / this.sizes.totalWidth)) + 'px';
6256
+ hHandleEl.style.width = Math.max(this.options.minHandleSize, this.sizes.scrollableWidth * (this.sizes.scrollableWidth / this.sizes.totalNonPinnedWidth)) + 'px';
6215
6257
  } else {
6216
- hHandleEl.style.height = '0px';
6258
+ hHandleEl.style.width = '0px';
6217
6259
  }
6218
6260
  }
6219
6261
  }
@@ -6254,8 +6296,6 @@ var WebsyTable3 = /*#__PURE__*/function () {
6254
6296
  el.classList.add('has-error');
6255
6297
  }
6256
6298
 
6257
- var tableEl = document.getElementById("".concat(this.elementId, "_tableInner"));
6258
- tableEl.classList.add('hidden');
6259
6299
  var containerEl = document.getElementById("".concat(this.elementId, "_errorContainer"));
6260
6300
 
6261
6301
  if (containerEl) {
@@ -6281,6 +6321,24 @@ var WebsyTable3 = /*#__PURE__*/function () {
6281
6321
  }, {
6282
6322
  key: "scrollX",
6283
6323
  value: function scrollX(diff) {
6324
+ var el = document.getElementById("".concat(this.elementId, "_tableContainer"));
6325
+
6326
+ if (!el.classList.contains('scrolling')) {
6327
+ el.classList.add('scrolling');
6328
+ }
6329
+
6330
+ if (this.scrollTimeoutFn) {
6331
+ clearTimeout(this.scrollTimeoutFn);
6332
+ }
6333
+
6334
+ this.scrollTimeoutFn = setTimeout(function () {
6335
+ el.classList.remove('scrolling');
6336
+ }, 200);
6337
+
6338
+ if (this.hScrollRequired === false) {
6339
+ return;
6340
+ }
6341
+
6284
6342
  var scrollContainerEl = document.getElementById("".concat(this.elementId, "_hScrollContainer"));
6285
6343
  var scrollHandleEl = document.getElementById("".concat(this.elementId, "_hScrollHandle"));
6286
6344
  var handlePos;
@@ -6296,12 +6354,12 @@ var WebsyTable3 = /*#__PURE__*/function () {
6296
6354
  scrollHandleEl.style.left = Math.min(scrollableSpace, Math.max(0, handlePos)) + 'px';
6297
6355
 
6298
6356
  if (this.options.onScroll) {
6299
- var actualLeft = (this.sizes.totalWidth - this.sizes.scrollableWidth) * (Math.min(scrollableSpace, Math.max(0, handlePos)) / scrollableSpace);
6357
+ var actualLeft = (this.sizes.totalNonPinnedWidth - this.sizes.scrollableWidth) * (Math.min(scrollableSpace, Math.max(0, handlePos)) / scrollableSpace);
6300
6358
  var cumulativeWidth = 0;
6301
6359
  this.startCol = 0;
6302
6360
  this.endCol = 0;
6303
6361
 
6304
- for (var i = 0; i < this.options.allColumns[this.options.allColumns.length - 1].length; i++) {
6362
+ for (var i = this.pinnedColumns; i < this.options.allColumns[this.options.allColumns.length - 1].length; i++) {
6305
6363
  cumulativeWidth += this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth;
6306
6364
  console.log('actualLeft', actualLeft, this.sizes.totalWidth, cumulativeWidth, cumulativeWidth + this.options.allColumns[this.options.allColumns.length - 1][i].actualWidth);
6307
6365
 
@@ -6336,6 +6394,24 @@ var WebsyTable3 = /*#__PURE__*/function () {
6336
6394
  }, {
6337
6395
  key: "scrollY",
6338
6396
  value: function scrollY(diff) {
6397
+ var el = document.getElementById("".concat(this.elementId, "_tableContainer"));
6398
+
6399
+ if (!el.classList.contains('scrolling')) {
6400
+ el.classList.add('scrolling');
6401
+ }
6402
+
6403
+ if (this.scrollTimeoutFn) {
6404
+ clearTimeout(this.scrollTimeoutFn);
6405
+ }
6406
+
6407
+ this.scrollTimeoutFn = setTimeout(function () {
6408
+ el.classList.remove('scrolling');
6409
+ }, 200);
6410
+
6411
+ if (this.vScrollRequired === false) {
6412
+ return;
6413
+ }
6414
+
6339
6415
  var scrollContainerEl = document.getElementById("".concat(this.elementId, "_vScrollContainer"));
6340
6416
  var scrollHandleEl = document.getElementById("".concat(this.elementId, "_vScrollHandle"));
6341
6417
  var handlePos;
@@ -7322,11 +7398,11 @@ var WebsyChart = /*#__PURE__*/function () {
7322
7398
 
7323
7399
  bars.exit().transition(this.transition).style('stroke-opacity', 1e-6).remove();
7324
7400
  bars.attr('width', getBarWidth.bind(this)).attr('height', getBarHeight.bind(this)).attr('x', getBarX.bind(this)).attr('y', getBarY.bind(this)).transition(this.transition).attr('fill', function (d) {
7325
- return d.color || series.color;
7401
+ return d.y.color || d.color || series.color;
7326
7402
  });
7327
7403
  bars.enter().append('rect').attr('width', getBarWidth.bind(this)).attr('height', getBarHeight.bind(this)).attr('x', getBarX.bind(this)).attr('y', getBarY.bind(this)) // .transition(this.transition)
7328
7404
  .attr('fill', function (d) {
7329
- return d.color || series.color;
7405
+ return d.y.color || d.color || series.color;
7330
7406
  }).attr('class', function (d) {
7331
7407
  return "bar bar_".concat(series.key);
7332
7408
  });
@@ -7346,28 +7422,55 @@ var WebsyChart = /*#__PURE__*/function () {
7346
7422
  yAxis = 'bottomAxis';
7347
7423
  }
7348
7424
 
7349
- if (this.options.showLabels) {
7425
+ if (this.options.showLabels === true || series.showLabels === true) {
7350
7426
  // need to add logic to handle positioning options
7351
7427
  // e.g. Inside, Outide, Auto (this will also affect the available plot space)
7352
7428
  // We currently only support 'Auto'
7353
7429
  var labels = this.labelLayer.selectAll(".label_".concat(series.key)).data(series.data);
7354
7430
  labels.exit().transition(this.transition).style('stroke-opacity', 1e-6).remove();
7355
- labels.attr('x', getLabelX.bind(this)).attr('y', getLabelY.bind(this)).attr('class', "label_".concat(series.key)).style('font-size', "".concat(this.options.labelSize || this.options.fontSize, "px")).style('fill', function (d) {
7356
- return _this42.options.labelColor || WebsyDesigns.WebsyUtils.getLightDark(d.color || series.color);
7357
- }).transition(this.transition).text(function (d) {
7431
+ labels.attr('x', getLabelX.bind(this)).attr('y', getLabelY.bind(this)).attr('class', "label_".concat(series.key)).attr('fill', function (d) {
7432
+ return _this42.options.labelColor || WebsyDesigns.WebsyUtils.getLightDark(d.y.color || d.color || series.color);
7433
+ }).style('font-size', "".concat(this.options.labelSize || this.options.fontSize, "px")).transition(this.transition).text(function (d) {
7358
7434
  return d.y.label || d.y.value;
7435
+ }).each(function (d, i) {
7436
+ if (that.options.orientation === 'horizontal') {
7437
+ if (that.options.grouping === 'stacked' && series.labelPosition !== 'outside') {
7438
+ this.setAttribute('text-anchor', 'middle');
7439
+ } else if (that.plotWidth - getLabelX.call(that, d) < this.getComputedTextLength()) {
7440
+ this.setAttribute('text-anchor', 'end');
7441
+ this.setAttribute('x', +this.getAttribute('x') - 8);
7442
+ this.setAttribute('fill', that.options.labelColor || WebsyDesigns.WebsyUtils.getLightDark(d.y.color || d.color || series.color));
7443
+ } else if (series.labelPosition === 'outside') {
7444
+ this.setAttribute('text-anchor', 'start');
7445
+ this.setAttribute('x', +this.getAttribute('x') + 8);
7446
+ this.setAttribute('fill', that.options.labelColor || WebsyDesigns.WebsyUtils.getLightDark('#ffffff'));
7447
+ } else {
7448
+ this.setAttribute('fill', that.options.labelColor || WebsyDesigns.WebsyUtils.getLightDark('#ffffff'));
7449
+ }
7450
+ } else {
7451
+ if (that.plotheight - getLabelX.call(that, d) < (that.options.labelSize || that.options.fontSize)) {
7452
+ this.setAttribute('y', +this.getAttribute('y') + 8);
7453
+ }
7454
+ }
7359
7455
  });
7360
- labels.enter().append('text').attr('class', "label_".concat(series.key)).attr('x', getLabelX.bind(this)).attr('y', getLabelY.bind(this)).attr('alignment-baseline', 'central').attr('text-anchor', this.options.orientation === 'horizontal' ? 'left' : 'middle').style('font-size', "".concat(this.options.labelSize || this.options.fontSize, "px")).style('fill', function (d) {
7361
- return _this42.options.labelColor || WebsyDesigns.WebsyUtils.getLightDark(d.color || series.color);
7362
- }).text(function (d) {
7456
+ labels.enter().append('text').attr('class', "label_".concat(series.key)).attr('x', getLabelX.bind(this)).attr('y', getLabelY.bind(this)).attr('alignment-baseline', 'central').attr('text-anchor', this.options.orientation === 'horizontal' ? 'left' : 'middle').attr('fill', function (d) {
7457
+ return _this42.options.labelColor || WebsyDesigns.WebsyUtils.getLightDark(d.y.color || d.color || series.color);
7458
+ }).style('font-size', "".concat(this.options.labelSize || this.options.fontSize, "px")).text(function (d) {
7363
7459
  return d.y.label || d.y.value;
7364
7460
  }).each(function (d, i) {
7365
7461
  if (that.options.orientation === 'horizontal') {
7366
- if (that.options.grouping === 'stacked') {
7462
+ if (that.options.grouping === 'stacked' && series.labelPosition !== 'outside') {
7367
7463
  this.setAttribute('text-anchor', 'middle');
7368
7464
  } else if (that.plotWidth - getLabelX.call(that, d) < this.getComputedTextLength()) {
7369
7465
  this.setAttribute('text-anchor', 'end');
7370
7466
  this.setAttribute('x', +this.getAttribute('x') - 8);
7467
+ this.setAttribute('fill', that.options.labelColor || WebsyDesigns.WebsyUtils.getLightDark(d.y.color || d.color || series.color));
7468
+ } else if (series.labelPosition === 'outside') {
7469
+ this.setAttribute('text-anchor', 'start');
7470
+ this.setAttribute('x', +this.getAttribute('x') + 8);
7471
+ this.setAttribute('fill', that.options.labelColor || WebsyDesigns.WebsyUtils.getLightDark('#ffffff'));
7472
+ } else {
7473
+ this.setAttribute('fill', that.options.labelColor || WebsyDesigns.WebsyUtils.getLightDark('#ffffff'));
7371
7474
  }
7372
7475
  } else {
7373
7476
  if (that.plotheight - getLabelX.call(that, d) < (that.options.labelSize || that.options.fontSize)) {
@@ -7378,9 +7481,11 @@ var WebsyChart = /*#__PURE__*/function () {
7378
7481
  }
7379
7482
 
7380
7483
  function getLabelX(d) {
7484
+ var labelPosition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'inside';
7485
+
7381
7486
  if (this.options.orientation === 'horizontal') {
7382
7487
  if (this.options.grouping === 'stacked') {
7383
- return this[yAxis](d.y.accumulative) + this[yAxis](d.y.value) / 2;
7488
+ return this[yAxis](d.y.accumulative) + this[yAxis](d.y.value) / (labelPosition === 'inside' ? 2 : 1);
7384
7489
  } else {
7385
7490
  return this[yAxis](isNaN(d.y.value) ? 0 : d.y.value) + 4;
7386
7491
  }
@@ -7390,10 +7495,13 @@ var WebsyChart = /*#__PURE__*/function () {
7390
7495
  }
7391
7496
 
7392
7497
  function getLabelY(d) {
7498
+ var labelPosition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'inside';
7499
+
7393
7500
  if (this.options.orientation === 'horizontal') {
7394
7501
  return this[xAxis](this.parseX(d.x.value)) + this[xAxis].bandwidth() / 2;
7395
7502
  } else {
7396
- if (this.options.grouping === 'stacked') {//
7503
+ if (this.options.grouping === 'stacked') {
7504
+ return this[yAxis](d.y.accumulative) + this[yAxis](d.y.value) / (labelPosition === 'inside' ? 2 : 1);
7397
7505
  } else {
7398
7506
  return this[yAxis](isNaN(d.y.value) ? 0 : d.y.value) - 4;
7399
7507
  }