@axdspub/axiom-charts 0.0.11 → 0.0.12
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.
- package/library/Libraries/axiom/index.js +186 -17
- package/library/Libraries/axiom/index.js.map +1 -1
- package/library/axiom-charts.d.ts +15 -1
- package/library/browser.js +11 -0
- package/library/browser.js.map +1 -1
- package/library/cjs.js +11 -0
- package/library/cjs.js.map +1 -1
- package/library/index.js +11 -0
- package/library/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequestItem } from '@axdspub/axiom-ui-data-services';
|
|
2
|
-
import { extent, sum } from 'd3-array';
|
|
2
|
+
import { extent, bisectCenter, sum } from 'd3-array';
|
|
3
3
|
import { groupBy, debounce } from 'lodash';
|
|
4
4
|
import { create } from 'd3-selection';
|
|
5
5
|
import { scaleUtc, scaleLinear, scaleRadial } from 'd3-scale';
|
|
@@ -123,6 +123,7 @@ var PlotRoot = /** @class */ (function (_super) {
|
|
|
123
123
|
_this.chart = props.chart;
|
|
124
124
|
_this.dimensions = props.dimensions;
|
|
125
125
|
_this.style = props.style;
|
|
126
|
+
_this.scrubbing = props.scrubbing;
|
|
126
127
|
_this.axisSettings = props.axisSettings;
|
|
127
128
|
_this.runtime = {};
|
|
128
129
|
return _this;
|
|
@@ -249,6 +250,13 @@ var PlotRoot = /** @class */ (function (_super) {
|
|
|
249
250
|
});
|
|
250
251
|
});
|
|
251
252
|
};
|
|
253
|
+
PlotRoot.prototype.drawScrubbing = function (mouseX) {
|
|
254
|
+
console.log('drawScrubbing not implemented');
|
|
255
|
+
};
|
|
256
|
+
PlotRoot.prototype.getScrubPosition = function (mouseX) {
|
|
257
|
+
console.log('getScrubPosition not implemented');
|
|
258
|
+
return undefined;
|
|
259
|
+
};
|
|
252
260
|
PlotRoot.prototype.destroy = function () {
|
|
253
261
|
};
|
|
254
262
|
return PlotRoot;
|
|
@@ -259,6 +267,7 @@ var ChartRoot = /** @class */ (function () {
|
|
|
259
267
|
this.plots = props.plots.map(function (p) { return (__assign({}, p)); });
|
|
260
268
|
this.settings = props.settings;
|
|
261
269
|
this.element = props.element;
|
|
270
|
+
this.onScrub = props.onScrub;
|
|
262
271
|
this.runtime = {
|
|
263
272
|
prevWidth: 0,
|
|
264
273
|
prevHeight: 0
|
|
@@ -493,6 +502,8 @@ var ChartRoot = /** @class */ (function () {
|
|
|
493
502
|
};
|
|
494
503
|
ChartRoot.prototype.showXAxes = function (xAxes) {
|
|
495
504
|
};
|
|
505
|
+
ChartRoot.prototype.adjustYAxis = function () {
|
|
506
|
+
};
|
|
496
507
|
ChartRoot.prototype.draw = function () {
|
|
497
508
|
return __awaiter(this, void 0, void 0, function () {
|
|
498
509
|
var plotImplementations;
|
|
@@ -549,7 +560,9 @@ var AxiomPlotRoot = /** @class */ (function (_super) {
|
|
|
549
560
|
var AxiomLine = /** @class */ (function (_super) {
|
|
550
561
|
__extends(AxiomLine, _super);
|
|
551
562
|
function AxiomLine() {
|
|
552
|
-
|
|
563
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
564
|
+
_this.addedScrubbingListener = false;
|
|
565
|
+
return _this;
|
|
553
566
|
}
|
|
554
567
|
AxiomLine.prototype.getDomainAccessor = function (axis) {
|
|
555
568
|
var _a, _b, _c;
|
|
@@ -564,15 +577,19 @@ var AxiomLine = /** @class */ (function (_super) {
|
|
|
564
577
|
AxiomLine.prototype.draw = function () {
|
|
565
578
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
566
579
|
return __awaiter(this, void 0, void 0, function () {
|
|
567
|
-
var style, data,
|
|
580
|
+
var style, data, xAccessor, yAccessor, chart, ctx, xAxisScale, yAxisScale, xPosition, yPosition, isDefined, line$1;
|
|
581
|
+
var _this = this;
|
|
568
582
|
return __generator(this, function (_m) {
|
|
569
583
|
switch (_m.label) {
|
|
570
584
|
case 0:
|
|
571
585
|
style = this.style !== undefined ? this.style : {};
|
|
586
|
+
if (!(this.parsedData === undefined)) return [3 /*break*/, 2];
|
|
572
587
|
return [4 /*yield*/, this.getData()];
|
|
573
588
|
case 1:
|
|
574
589
|
data = _m.sent();
|
|
575
|
-
parsedData = (_a = data === null || data === void 0 ? void 0 : data.parsed) === null || _a === void 0 ? void 0 : _a.data;
|
|
590
|
+
this.parsedData = (_a = data === null || data === void 0 ? void 0 : data.parsed) === null || _a === void 0 ? void 0 : _a.data;
|
|
591
|
+
_m.label = 2;
|
|
592
|
+
case 2:
|
|
576
593
|
xAccessor = this.getAccessorAtAxis('x');
|
|
577
594
|
yAccessor = this.getAccessorAtAxis('y');
|
|
578
595
|
chart = this.chart;
|
|
@@ -582,33 +599,36 @@ var AxiomLine = /** @class */ (function (_super) {
|
|
|
582
599
|
}
|
|
583
600
|
xAxisScale = (_c = (_b = this === null || this === void 0 ? void 0 : this.axes) === null || _b === void 0 ? void 0 : _b.x) === null || _c === void 0 ? void 0 : _c.scale;
|
|
584
601
|
yAxisScale = (_e = (_d = this === null || this === void 0 ? void 0 : this.axes) === null || _d === void 0 ? void 0 : _d.y) === null || _e === void 0 ? void 0 : _e.scale;
|
|
585
|
-
if (xAxisScale === undefined || yAxisScale === undefined || parsedData === undefined || xAccessor === undefined || yAccessor === undefined) {
|
|
602
|
+
if (xAxisScale === undefined || yAxisScale === undefined || this.parsedData === undefined || xAccessor === undefined || yAccessor === undefined) {
|
|
586
603
|
return [2 /*return*/, undefined];
|
|
587
604
|
}
|
|
588
|
-
offset = {
|
|
605
|
+
this.offset = {
|
|
589
606
|
x: ((_h = (_g = (_f = this === null || this === void 0 ? void 0 : this.axes) === null || _f === void 0 ? void 0 : _f.x) === null || _g === void 0 ? void 0 : _g.offset) === null || _h === void 0 ? void 0 : _h.x) !== undefined ? this.axes.x.offset.x : 0,
|
|
590
607
|
y: ((_l = (_k = (_j = this === null || this === void 0 ? void 0 : this.axes) === null || _j === void 0 ? void 0 : _j.y) === null || _k === void 0 ? void 0 : _k.offset) === null || _l === void 0 ? void 0 : _l.y) !== undefined ? this.axes.y.offset.y : 0
|
|
591
608
|
};
|
|
592
|
-
xScale = chart.getD3XScale(xAxisScale);
|
|
609
|
+
this.xScale = chart.getD3XScale(xAxisScale);
|
|
593
610
|
xPosition = function (d) {
|
|
611
|
+
if (_this.xScale === undefined || _this.offset === undefined)
|
|
612
|
+
return 0;
|
|
594
613
|
var v = xAccessor(d);
|
|
595
|
-
var p = xScale(v);
|
|
596
|
-
return p === undefined ? 0 : (p + offset.x);
|
|
614
|
+
var p = _this.xScale(v);
|
|
615
|
+
return p === undefined ? 0 : (p + _this.offset.x);
|
|
597
616
|
};
|
|
598
|
-
yScale = chart.getD3YScale(yAxisScale);
|
|
617
|
+
this.yScale = chart.getD3YScale(yAxisScale);
|
|
599
618
|
yPosition = function (d) {
|
|
619
|
+
if (_this.yScale === undefined || _this.offset === undefined)
|
|
620
|
+
return 0;
|
|
600
621
|
var v = yAccessor(d);
|
|
601
|
-
var p = yScale(v);
|
|
602
|
-
return p === undefined ? 0 : (p + offset.y);
|
|
622
|
+
var p = _this.yScale(v);
|
|
623
|
+
return p === undefined ? 0 : (p + _this.offset.y);
|
|
603
624
|
};
|
|
604
625
|
isDefined = function (d) {
|
|
605
626
|
var v = yAccessor(d);
|
|
606
627
|
return !!((v !== undefined && v !== null && !isNaN(+v)));
|
|
607
628
|
};
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
ctx.
|
|
611
|
-
ctx.lineWidth = style.strokeWidth !== undefined ? style.strokeWidth : 1;
|
|
629
|
+
ctx.strokeStyle = this.getStrokeStyle();
|
|
630
|
+
ctx.lineWidth = this.getLineWidth();
|
|
631
|
+
ctx.setLineDash([]);
|
|
612
632
|
line$1 = line()
|
|
613
633
|
.x(xPosition)
|
|
614
634
|
.y(yPosition)
|
|
@@ -618,13 +638,65 @@ var AxiomLine = /** @class */ (function (_super) {
|
|
|
618
638
|
if ((style === null || style === void 0 ? void 0 : style.strokeDash) !== undefined) {
|
|
619
639
|
ctx.setLineDash(style.strokeDash);
|
|
620
640
|
}
|
|
621
|
-
line$1(parsedData);
|
|
641
|
+
line$1(this.parsedData);
|
|
622
642
|
ctx.stroke();
|
|
623
643
|
return [2 /*return*/];
|
|
624
644
|
}
|
|
625
645
|
});
|
|
626
646
|
});
|
|
627
647
|
};
|
|
648
|
+
AxiomLine.prototype.getScrubPosition = function (mouseX) {
|
|
649
|
+
if (this.xScale === undefined || this.yScale === undefined || this.parsedData === undefined || this.offset === undefined)
|
|
650
|
+
return undefined;
|
|
651
|
+
var newDate = this.xScale.invert(mouseX - this.offset.x);
|
|
652
|
+
var i = bisectCenter(this.parsedData.map(function (row) { return row.time; }), newDate);
|
|
653
|
+
var lineX = this.xScale(this.parsedData[i].time) + this.offset.x;
|
|
654
|
+
var yValue = this.parsedData[i].value;
|
|
655
|
+
var yPx = this.yScale(yValue) + this.offset.y;
|
|
656
|
+
return {
|
|
657
|
+
xPosition: lineX,
|
|
658
|
+
xValue: newDate,
|
|
659
|
+
yPosition: yPx,
|
|
660
|
+
yValue: yValue
|
|
661
|
+
};
|
|
662
|
+
};
|
|
663
|
+
AxiomLine.prototype.drawScrubbing = function (mouseX) {
|
|
664
|
+
var chart = this.chart;
|
|
665
|
+
var ctx = chart.getCanvasContext();
|
|
666
|
+
if (ctx === null) {
|
|
667
|
+
return undefined;
|
|
668
|
+
}
|
|
669
|
+
var scrubPosition = this.getScrubPosition(mouseX);
|
|
670
|
+
if (scrubPosition === undefined)
|
|
671
|
+
return;
|
|
672
|
+
var xPosition = scrubPosition.xPosition, yPosition = scrubPosition.yPosition;
|
|
673
|
+
this.drawScrubCircle(xPosition, yPosition, ctx);
|
|
674
|
+
this.drawScrubLine(xPosition, ctx);
|
|
675
|
+
};
|
|
676
|
+
AxiomLine.prototype.drawScrubCircle = function (x, y, ctx) {
|
|
677
|
+
ctx.beginPath();
|
|
678
|
+
ctx.setLineDash([]);
|
|
679
|
+
ctx.arc(x, y, 6, 0, 2 * Math.PI, true);
|
|
680
|
+
ctx.strokeStyle = this.getStrokeStyle();
|
|
681
|
+
ctx.lineWidth = this.getLineWidth();
|
|
682
|
+
ctx.stroke();
|
|
683
|
+
};
|
|
684
|
+
AxiomLine.prototype.drawScrubLine = function (x, ctx) {
|
|
685
|
+
var lineHeight = this.chart.settings.height - this.chart.settings.margin.bottom;
|
|
686
|
+
ctx.setLineDash([1, 1]);
|
|
687
|
+
ctx.beginPath();
|
|
688
|
+
ctx.moveTo(x, 0);
|
|
689
|
+
ctx.lineTo(x, lineHeight);
|
|
690
|
+
ctx.stroke();
|
|
691
|
+
};
|
|
692
|
+
AxiomLine.prototype.getStrokeStyle = function () {
|
|
693
|
+
var style = this.style !== undefined ? this.style : {};
|
|
694
|
+
return style.strokeColor !== undefined ? style.strokeColor : '#333';
|
|
695
|
+
};
|
|
696
|
+
AxiomLine.prototype.getLineWidth = function () {
|
|
697
|
+
var style = this.style !== undefined ? this.style : {};
|
|
698
|
+
return style.strokeWidth !== undefined ? style.strokeWidth : 1;
|
|
699
|
+
};
|
|
628
700
|
return AxiomLine;
|
|
629
701
|
}(AxiomPlotRoot));
|
|
630
702
|
|
|
@@ -742,6 +814,13 @@ var AxiomArea = /** @class */ (function (_super) {
|
|
|
742
814
|
});
|
|
743
815
|
});
|
|
744
816
|
};
|
|
817
|
+
AxiomArea.prototype.drawScrubbing = function (mouseX) {
|
|
818
|
+
console.error('AxiomArea.drawScrubbing not implemented');
|
|
819
|
+
};
|
|
820
|
+
AxiomArea.prototype.getScrubPosition = function (mouseX) {
|
|
821
|
+
console.error('AxiomArea.getScrubPosition not implemented');
|
|
822
|
+
return undefined;
|
|
823
|
+
};
|
|
745
824
|
return AxiomArea;
|
|
746
825
|
}(AxiomPlotRoot));
|
|
747
826
|
|
|
@@ -823,6 +902,12 @@ var AxiomScatter = /** @class */ (function (_super) {
|
|
|
823
902
|
});
|
|
824
903
|
});
|
|
825
904
|
};
|
|
905
|
+
AxiomScatter.prototype.getScrubPosition = function (mouseX) {
|
|
906
|
+
throw new Error('Method not implemented.');
|
|
907
|
+
};
|
|
908
|
+
AxiomScatter.prototype.drawScrubbing = function (mouseX) {
|
|
909
|
+
throw new Error('Method not implemented.');
|
|
910
|
+
};
|
|
826
911
|
return AxiomScatter;
|
|
827
912
|
}(AxiomPlotRoot));
|
|
828
913
|
|
|
@@ -929,6 +1014,22 @@ var AxiomChart = /** @class */ (function (_super) {
|
|
|
929
1014
|
};
|
|
930
1015
|
return axisG;
|
|
931
1016
|
};
|
|
1017
|
+
AxiomChart.prototype.adjustYAxis = function () {
|
|
1018
|
+
console.log('here');
|
|
1019
|
+
var chartElements = this.getChartElements();
|
|
1020
|
+
if (chartElements === undefined)
|
|
1021
|
+
return;
|
|
1022
|
+
var svg = chartElements.svg, canvas = chartElements.canvas;
|
|
1023
|
+
var node = svg.selectAll('.y-axis').nodes()[0];
|
|
1024
|
+
if (node === null || node === undefined)
|
|
1025
|
+
return;
|
|
1026
|
+
node = node;
|
|
1027
|
+
// const yAxisWidth = node.getBoundingClientRect()
|
|
1028
|
+
console.log(node);
|
|
1029
|
+
svg.selectAll('.y-axis').attr('translate', 'transform(100px, 100px)').attr('width', 100);
|
|
1030
|
+
canvas.attr('width', this.getWidth() - 45.7);
|
|
1031
|
+
canvas.attr('transform', "translate(".concat(45.7, ", 0)"));
|
|
1032
|
+
};
|
|
932
1033
|
AxiomChart.prototype.showYAxes = function (axes) {
|
|
933
1034
|
var _this = this;
|
|
934
1035
|
var chartElements = this.getChartElements();
|
|
@@ -1077,6 +1178,8 @@ var AxiomChart = /** @class */ (function (_super) {
|
|
|
1077
1178
|
this.element.append(canvasNode);
|
|
1078
1179
|
}
|
|
1079
1180
|
}
|
|
1181
|
+
// TODO: conditional
|
|
1182
|
+
this.addScrubbing();
|
|
1080
1183
|
};
|
|
1081
1184
|
AxiomChart.prototype.createPlot = function (plot) {
|
|
1082
1185
|
var props = this.getPlotImplementationProps(plot);
|
|
@@ -1091,6 +1194,65 @@ var AxiomChart = /** @class */ (function (_super) {
|
|
|
1091
1194
|
}
|
|
1092
1195
|
return new PlotRoot(props);
|
|
1093
1196
|
};
|
|
1197
|
+
AxiomChart.prototype.clearCanvas = function () {
|
|
1198
|
+
var ctx = this.getCanvasContext();
|
|
1199
|
+
if (ctx !== null) {
|
|
1200
|
+
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
|
1201
|
+
}
|
|
1202
|
+
};
|
|
1203
|
+
AxiomChart.prototype.addScrubbing = function () {
|
|
1204
|
+
var _this = this;
|
|
1205
|
+
var ctx = this.getCanvasContext();
|
|
1206
|
+
if (ctx === null) {
|
|
1207
|
+
return;
|
|
1208
|
+
}
|
|
1209
|
+
ctx.canvas.addEventListener('touchmove', function (event) {
|
|
1210
|
+
var touch = event.touches[0];
|
|
1211
|
+
var touchOffset = 20; // TODO: figure out why touch.clientX is always off to the right
|
|
1212
|
+
_this.onScrubTriggered(touch.clientX - touchOffset);
|
|
1213
|
+
});
|
|
1214
|
+
ctx.canvas.addEventListener('mousemove', function (event) { _this.onScrubTriggered(event.offsetX); });
|
|
1215
|
+
};
|
|
1216
|
+
AxiomChart.prototype.onScrubTriggered = function (cursorX) {
|
|
1217
|
+
var _this = this;
|
|
1218
|
+
if (this.plotImplementations === undefined)
|
|
1219
|
+
return;
|
|
1220
|
+
var plotsWithScrubbingEnabled = this.plotImplementations.filter(function (plot) { var _a; return ((_a = plot.scrubbing) !== null && _a !== void 0 ? _a : false) && plot.type === EPlotTypes.line; });
|
|
1221
|
+
var plotScrubPositions = this.getScrubPositions(cursorX, plotsWithScrubbingEnabled);
|
|
1222
|
+
// console.log(plotScrubPositions)
|
|
1223
|
+
if (this.onScrub !== undefined) {
|
|
1224
|
+
this.onScrub(plotScrubPositions);
|
|
1225
|
+
}
|
|
1226
|
+
this.runtime.busy = true;
|
|
1227
|
+
this.clearCanvas();
|
|
1228
|
+
var drawPromises = this.plotImplementations.map(function (plot) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1229
|
+
switch (_a.label) {
|
|
1230
|
+
case 0: return [4 /*yield*/, plot.draw()];
|
|
1231
|
+
case 1:
|
|
1232
|
+
_a.sent();
|
|
1233
|
+
return [2 /*return*/];
|
|
1234
|
+
}
|
|
1235
|
+
}); }); });
|
|
1236
|
+
Promise.all(drawPromises).then(function () {
|
|
1237
|
+
plotsWithScrubbingEnabled.forEach(function (plot) {
|
|
1238
|
+
var position = plotScrubPositions[plot.id];
|
|
1239
|
+
plot.drawScrubbing(position.xPosition);
|
|
1240
|
+
});
|
|
1241
|
+
_this.runtime.busy = false;
|
|
1242
|
+
}).catch(function (error) {
|
|
1243
|
+
console.error(error);
|
|
1244
|
+
});
|
|
1245
|
+
};
|
|
1246
|
+
AxiomChart.prototype.getScrubPositions = function (mouseX, plots) {
|
|
1247
|
+
var plotScrubPositions = {};
|
|
1248
|
+
plots.forEach(function (plot) {
|
|
1249
|
+
var scrubPosition = plot.getScrubPosition(mouseX);
|
|
1250
|
+
if (scrubPosition !== undefined) {
|
|
1251
|
+
plotScrubPositions[plot.id] = scrubPosition;
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
return plotScrubPositions;
|
|
1255
|
+
};
|
|
1094
1256
|
AxiomChart.prototype.init = function (drawImmediately) {
|
|
1095
1257
|
if (drawImmediately === void 0) { drawImmediately = false; }
|
|
1096
1258
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1318,6 +1480,13 @@ var AxiomRadialArea = /** @class */ (function (_super) {
|
|
|
1318
1480
|
});
|
|
1319
1481
|
});
|
|
1320
1482
|
};
|
|
1483
|
+
AxiomRadialArea.prototype.drawScrubbing = function (mouseX) {
|
|
1484
|
+
console.error('AxiomRadialArea.drawScrubbing not implemented');
|
|
1485
|
+
};
|
|
1486
|
+
AxiomRadialArea.prototype.getScrubPosition = function (mouseX) {
|
|
1487
|
+
console.error('AxiomRadialArea.getScrubPosition not implemented');
|
|
1488
|
+
return undefined;
|
|
1489
|
+
};
|
|
1321
1490
|
return AxiomRadialArea;
|
|
1322
1491
|
}(AxiomArea));
|
|
1323
1492
|
|