@kirbydesign/designsystem 5.0.4 → 5.0.5

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.
Files changed (39) hide show
  1. package/bundles/kirbydesign-designsystem-testing-base.umd.js +1 -0
  2. package/bundles/kirbydesign-designsystem-testing-base.umd.js.map +1 -1
  3. package/bundles/kirbydesign-designsystem-testing-base.umd.min.js +1 -1
  4. package/bundles/kirbydesign-designsystem-testing-base.umd.min.js.map +1 -1
  5. package/bundles/kirbydesign-designsystem.umd.js +482 -30
  6. package/bundles/kirbydesign-designsystem.umd.js.map +1 -1
  7. package/bundles/kirbydesign-designsystem.umd.min.js +1 -1
  8. package/bundles/kirbydesign-designsystem.umd.min.js.map +1 -1
  9. package/esm2015/lib/components/chart/chart-js/chart-js.service.js +137 -19
  10. package/esm2015/lib/components/chart/chart-js/chart-js.service.metadata.json +1 -1
  11. package/esm2015/lib/components/chart/chart-js/chartjs-plugin-marker/chartjs-plugin-marker.js +203 -0
  12. package/esm2015/lib/components/chart/chart-js/chartjs-plugin-marker/chartjs-plugin-marker.metadata.json +1 -0
  13. package/esm2015/lib/components/chart/chart-js/configured-chart-js.js +5 -3
  14. package/esm2015/lib/components/chart/chart-js/configured-chart-js.metadata.json +1 -1
  15. package/esm2015/lib/components/chart/chart.component.js +3 -1
  16. package/esm2015/lib/components/chart/chart.component.metadata.json +1 -1
  17. package/esm2015/lib/components/chart/chart.types.js +1 -1
  18. package/esm2015/lib/components/chart/chart.types.metadata.json +1 -1
  19. package/esm2015/lib/components/chart/configs/global-defaults.config.js +7 -1
  20. package/esm2015/lib/components/chart/configs/type.config.js +118 -1
  21. package/esm2015/lib/components/chart/configs/type.config.metadata.json +1 -1
  22. package/esm2015/lib/helpers/deep-copy.js +11 -2
  23. package/esm2015/lib/helpers/deep-copy.metadata.json +1 -1
  24. package/esm2015/testing-base/lib/components/mock.chart.component.js +2 -1
  25. package/esm2015/testing-base/lib/components/mock.chart.component.metadata.json +1 -1
  26. package/fesm2015/kirbydesign-designsystem-testing-base.js +1 -0
  27. package/fesm2015/kirbydesign-designsystem-testing-base.js.map +1 -1
  28. package/fesm2015/kirbydesign-designsystem.js +476 -25
  29. package/fesm2015/kirbydesign-designsystem.js.map +1 -1
  30. package/kirbydesign-designsystem.metadata.json +1 -1
  31. package/lib/components/chart/chart-js/chart-js.service.d.ts +17 -1
  32. package/lib/components/chart/chart-js/chartjs-plugin-marker/chartjs-plugin-marker.d.ts +14 -0
  33. package/lib/components/chart/chart.component.d.ts +2 -1
  34. package/lib/components/chart/chart.types.d.ts +9 -1
  35. package/lib/components/chart/configs/global-defaults.config.d.ts +6 -0
  36. package/lib/helpers/deep-copy.d.ts +9 -1
  37. package/package.json +5 -2
  38. package/testing-base/kirbydesign-designsystem-testing-base.metadata.json +1 -1
  39. package/testing-base/lib/components/mock.chart.component.d.ts +2 -1
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@kirbydesign/core'), require('@angular/core'), require('@ionic/angular'), require('@angular/router'), require('rxjs'), require('rxjs/operators'), require('@angular/common'), require('highcharts'), require('chart.js'), require('chartjs-plugin-annotation'), require('highcharts/highstock'), require('highcharts/modules/annotations'), require('date-fns'), require('date-fns-tz'), require('date-fns/locale'), require('@angular/forms'), require('inputmask/lib/extensions/inputmask.date.extensions'), require('inputmask/lib/inputmask'), require('inputmask/lib/extensions/inputmask.numeric.extensions'), require('@angular/animations'), require('@kirbydesign/core/loader')) :
3
- typeof define === 'function' && define.amd ? define('@kirbydesign/designsystem', ['exports', '@kirbydesign/core', '@angular/core', '@ionic/angular', '@angular/router', 'rxjs', 'rxjs/operators', '@angular/common', 'highcharts', 'chart.js', 'chartjs-plugin-annotation', 'highcharts/highstock', 'highcharts/modules/annotations', 'date-fns', 'date-fns-tz', 'date-fns/locale', '@angular/forms', 'inputmask/lib/extensions/inputmask.date.extensions', 'inputmask/lib/inputmask', 'inputmask/lib/extensions/inputmask.numeric.extensions', '@angular/animations', '@kirbydesign/core/loader'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.kirbydesign = global.kirbydesign || {}, global.kirbydesign.designsystem = {}), global.core, global.ng.core, global.ionic, global.ng.router, global.rxjs, global.rxjs.operators, global.ng.common, global.highcharts, global.chart_js, global.annotationPlugin, global['highcharts/highstock'], global.highcharts, global['date-fns'], global['date-fns-tz'], global.locale, global.ng.forms, null, global.inputmask, null, global.ng.animations, global.loader));
5
- }(this, (function (exports, core, i0, i1, i1$1, rxjs, operators, common, Highcharts, chart_js, annotationPlugin, Highcharts$1, AnnotationsModule, dateFns, dateFnsTz, locale, forms, inputmask_date_extensions, Inputmask, inputmask_numeric_extensions, animations, loader) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@kirbydesign/core'), require('@angular/core'), require('@ionic/angular'), require('@angular/router'), require('rxjs'), require('rxjs/operators'), require('@angular/common'), require('highcharts'), require('date-fns'), require('ts-deepcopy'), require('chart.js'), require('chartjs-plugin-annotation'), require('chartjs-plugin-datalabels'), require('chart.js/helpers'), require('highcharts/highstock'), require('highcharts/modules/annotations'), require('date-fns-tz'), require('date-fns/locale'), require('@angular/forms'), require('inputmask/lib/extensions/inputmask.date.extensions'), require('inputmask/lib/inputmask'), require('inputmask/lib/extensions/inputmask.numeric.extensions'), require('@angular/animations'), require('@kirbydesign/core/loader')) :
3
+ typeof define === 'function' && define.amd ? define('@kirbydesign/designsystem', ['exports', '@kirbydesign/core', '@angular/core', '@ionic/angular', '@angular/router', 'rxjs', 'rxjs/operators', '@angular/common', 'highcharts', 'date-fns', 'ts-deepcopy', 'chart.js', 'chartjs-plugin-annotation', 'chartjs-plugin-datalabels', 'chart.js/helpers', 'highcharts/highstock', 'highcharts/modules/annotations', 'date-fns-tz', 'date-fns/locale', '@angular/forms', 'inputmask/lib/extensions/inputmask.date.extensions', 'inputmask/lib/inputmask', 'inputmask/lib/extensions/inputmask.numeric.extensions', '@angular/animations', '@kirbydesign/core/loader'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.kirbydesign = global.kirbydesign || {}, global.kirbydesign.designsystem = {}), global.core, global.ng.core, global.ionic, global.ng.router, global.rxjs, global.rxjs.operators, global.ng.common, global.highcharts, global['date-fns'], global._deepCopy, global.chart_js, global.annotationPlugin, global.ChartDataLabels, global.helpers, global['highcharts/highstock'], global.highcharts, global['date-fns-tz'], global.locale, global.ng.forms, null, global.inputmask, null, global.ng.animations, global.loader));
5
+ }(this, (function (exports, core, i0, i1, i1$1, rxjs, operators, common, Highcharts, dateFns, _deepCopy, chart_js, annotationPlugin, ChartDataLabels, helpers, Highcharts$1, AnnotationsModule, dateFnsTz, locale, forms, inputmask_date_extensions, Inputmask, inputmask_numeric_extensions, animations, loader) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -27,7 +27,9 @@
27
27
  }
28
28
 
29
29
  var Highcharts__namespace = /*#__PURE__*/_interopNamespace(Highcharts);
30
+ var _deepCopy__default = /*#__PURE__*/_interopDefaultLegacy(_deepCopy);
30
31
  var annotationPlugin__default = /*#__PURE__*/_interopDefaultLegacy(annotationPlugin);
32
+ var ChartDataLabels__default = /*#__PURE__*/_interopDefaultLegacy(ChartDataLabels);
31
33
  var Highcharts__namespace$1 = /*#__PURE__*/_interopNamespace(Highcharts$1);
32
34
  var AnnotationsModule__default = /*#__PURE__*/_interopDefaultLegacy(AnnotationsModule);
33
35
  var Inputmask__default = /*#__PURE__*/_interopDefaultLegacy(Inputmask);
@@ -3845,8 +3847,16 @@
3845
3847
  cssClass: [{ type: i0.Input }]
3846
3848
  };
3847
3849
 
3850
+ /**
3851
+ * Do a deep copy of object that supports the composite data type Function
3852
+ *
3853
+ * @see https://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-deep-clone-an-object-in-javascript#answer-122704
3854
+ *
3855
+ * @param obj
3856
+ * @returns obj
3857
+ */
3848
3858
  function deepCopy(obj) {
3849
- return JSON.parse(JSON.stringify(obj));
3859
+ return _deepCopy__default['default'](obj);
3850
3860
  }
3851
3861
 
3852
3862
  /*
@@ -3922,6 +3932,13 @@
3922
3932
 
3923
3933
  var fontSize$2 = core.DesignTokenHelper.fontSize;
3924
3934
  var getThemeColorHexString$1 = core.ColorHelper.getThemeColorHexString, getThemeColorRgbString = core.ColorHelper.getThemeColorRgbString;
3935
+ /**
3936
+ * A filter to read a chartpoint from a Chart.js point context (used for chartdata points). Context is provided by Chart.js.
3937
+ */
3938
+ var getChartPointFromContext = function (context) {
3939
+ return context.dataset.data[context.dataIndex];
3940
+ };
3941
+ var ɵ0$6 = getChartPointFromContext;
3925
3942
  var CHART_TYPES_CONFIG = {
3926
3943
  bar: {
3927
3944
  type: 'bar',
@@ -4016,6 +4033,115 @@
4016
4033
  },
4017
4034
  },
4018
4035
  },
4036
+ stock: {
4037
+ type: 'line',
4038
+ options: {
4039
+ responsive: true,
4040
+ animation: {
4041
+ duration: 0,
4042
+ },
4043
+ layout: {
4044
+ padding: {
4045
+ left: 20,
4046
+ right: 20,
4047
+ top: 30,
4048
+ bottom: 0,
4049
+ },
4050
+ },
4051
+ backgroundColor: getThemeColorRgbString('semi-light', 0.5),
4052
+ scales: {
4053
+ x: {
4054
+ grid: {
4055
+ lineWidth: 0,
4056
+ },
4057
+ ticks: {
4058
+ maxRotation: 0,
4059
+ autoSkipPadding: 120,
4060
+ font: {
4061
+ size: parseInt(fontSize$2('xs')),
4062
+ },
4063
+ },
4064
+ },
4065
+ y: {
4066
+ position: 'right',
4067
+ display: true,
4068
+ grid: {
4069
+ drawBorder: false,
4070
+ },
4071
+ ticks: {
4072
+ display: true,
4073
+ font: {
4074
+ size: parseInt(fontSize$2('xs')),
4075
+ },
4076
+ },
4077
+ },
4078
+ },
4079
+ elements: {
4080
+ line: {
4081
+ tension: 0,
4082
+ borderWidth: 2,
4083
+ },
4084
+ point: {
4085
+ hitRadius: 20,
4086
+ radius: 0,
4087
+ hoverRadius: 0,
4088
+ hoverBorderWidth: 0,
4089
+ },
4090
+ },
4091
+ normalized: true,
4092
+ plugins: {
4093
+ tooltip: {
4094
+ padding: 10,
4095
+ enabled: true,
4096
+ mode: 'index',
4097
+ intersect: false,
4098
+ backgroundColor: getThemeColorHexString$1('semi-light'),
4099
+ titleColor: getThemeColorHexString$1('semi-light-contrast'),
4100
+ bodyColor: getThemeColorHexString$1('semi-light-contrast'),
4101
+ caretSize: 0,
4102
+ bodySpacing: 5,
4103
+ titleSpacing: 5,
4104
+ borderColor: 'transparent',
4105
+ callbacks: {
4106
+ labelColor: function (tooltipItem) {
4107
+ return {
4108
+ backgroundColor: tooltipItem.dataset.borderColor,
4109
+ };
4110
+ },
4111
+ },
4112
+ },
4113
+ // A failed attempt to get local typings working.
4114
+ // The chartjs-plugin-marker is rewritten to not
4115
+ // having to rely on own plugin settings, but using
4116
+ // x-axis type time instead.
4117
+ // @todo candidate for refactor once solved.
4118
+ // marker: {
4119
+ // line: {
4120
+ // color: getThemeColorHexString('black-base'),
4121
+ // }
4122
+ // },
4123
+ datalabels: {
4124
+ backgroundColor: function (context) { return context.dataset.borderColor; },
4125
+ color: getThemeColorHexString$1('white'),
4126
+ borderRadius: 3,
4127
+ font: {
4128
+ lineHeight: 1,
4129
+ size: parseInt(fontSize$2('xs')),
4130
+ },
4131
+ padding: {
4132
+ top: 6,
4133
+ left: 5,
4134
+ right: 5,
4135
+ bottom: 5,
4136
+ },
4137
+ offset: 5,
4138
+ align: function (context) { var _a; return (_a = getChartPointFromContext(context)) === null || _a === void 0 ? void 0 : _a.datalabel.position; },
4139
+ display: function (context) { var _a; return !!((_a = getChartPointFromContext(context)) === null || _a === void 0 ? void 0 : _a.datalabel); },
4140
+ formatter: function (value) { return value.datalabel.value; },
4141
+ },
4142
+ },
4143
+ },
4144
+ },
4019
4145
  };
4020
4146
 
4021
4147
  var ChartConfigService = /** @class */ (function () {
@@ -4044,6 +4170,205 @@
4044
4170
  { type: i0.Injectable }
4045
4171
  ];
4046
4172
 
4173
+ // The marker pluin was heavily inspired by https://chartjs-plugin-crosshair.netlify.app
4174
+ var defaultOptions = {
4175
+ line: {
4176
+ color: 'black',
4177
+ width: 1,
4178
+ dashPattern: [],
4179
+ },
4180
+ snap: {
4181
+ enabled: false,
4182
+ },
4183
+ };
4184
+ var hasMarkerConfiguration = function (chart) {
4185
+ var _a, _b, _c;
4186
+ // using another plugins options is not ideal, so the issue with marker plugin
4187
+ // should be resolved. As of right now the only chart that uses
4188
+ // tooltip is stock charts.
4189
+ return chart.config.options.scales.x && ((_c = (_b = (_a = chart.config.options) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.tooltip) === null || _c === void 0 ? void 0 : _c.enabled);
4190
+ // @todo when resolving the typings issue with the markerplugin,
4191
+ // this is a better conditional.
4192
+ // return chart.config.options.scales.x && chart.config.options.plugins.marker
4193
+ };
4194
+ var ɵ0$7 = hasMarkerConfiguration;
4195
+ var MarkerPlugin = {
4196
+ id: 'marker',
4197
+ afterInit: function (chart) {
4198
+ if (!hasMarkerConfiguration(chart)) {
4199
+ return;
4200
+ }
4201
+ var xScaleType = chart.config.options.scales.x.type;
4202
+ if (xScaleType !== 'linear' &&
4203
+ xScaleType !== 'time' &&
4204
+ xScaleType !== 'category' &&
4205
+ xScaleType !== 'logarithmic') {
4206
+ return;
4207
+ }
4208
+ if (chart.options.plugins.marker === undefined) {
4209
+ chart.options.plugins.marker = defaultOptions;
4210
+ }
4211
+ chart.marker = {
4212
+ enabled: false,
4213
+ suppressUpdate: false,
4214
+ x: null,
4215
+ originalData: [],
4216
+ originalXRange: {},
4217
+ dragStarted: false,
4218
+ dragStartX: null,
4219
+ dragEndX: null,
4220
+ suppressTooltips: false,
4221
+ ignoreNextEvents: 0,
4222
+ };
4223
+ },
4224
+ getOption: function (chart, category, name) {
4225
+ return helpers.valueOrDefault(chart.options.plugins.marker[category]
4226
+ ? chart.options.plugins.marker[category][name]
4227
+ : undefined, defaultOptions[category][name]);
4228
+ },
4229
+ getXScale: function (chart) {
4230
+ return chart.data.datasets.length ? chart.scales[chart.getDatasetMeta(0).xAxisID] : null;
4231
+ },
4232
+ getYScale: function (chart) {
4233
+ return chart.scales[chart.getDatasetMeta(0).yAxisID];
4234
+ },
4235
+ afterEvent: function (chart, event) {
4236
+ if (!hasMarkerConfiguration(chart)) {
4237
+ return;
4238
+ }
4239
+ if (chart.config.options.scales.x.length == 0) {
4240
+ return;
4241
+ }
4242
+ var e = event.event;
4243
+ var xScaleType = chart.config.options.scales.x.type;
4244
+ if (xScaleType !== 'linear' &&
4245
+ xScaleType !== 'time' &&
4246
+ xScaleType !== 'category' &&
4247
+ xScaleType !== 'logarithmic') {
4248
+ return;
4249
+ }
4250
+ var xScale = this.getXScale(chart);
4251
+ if (!xScale) {
4252
+ return;
4253
+ }
4254
+ if (chart.marker.ignoreNextEvents > 0) {
4255
+ chart.marker.ignoreNextEvents -= 1;
4256
+ return;
4257
+ }
4258
+ // fix for Safari
4259
+ var buttons = e.native.buttons === undefined ? e.native.which : e.native.buttons;
4260
+ if (e.native.type === 'mouseup') {
4261
+ buttons = 0;
4262
+ }
4263
+ chart.marker.enabled =
4264
+ e.type !== 'mouseout' &&
4265
+ e.x > xScale.getPixelForValue(xScale.min) &&
4266
+ e.x < xScale.getPixelForValue(xScale.max);
4267
+ if (!chart.marker.enabled && !chart.marker.suppressUpdate) {
4268
+ if (e.x > xScale.getPixelForValue(xScale.max)) {
4269
+ // suppress future updates to prevent endless redrawing of chart
4270
+ chart.marker.suppressUpdate = true;
4271
+ chart.update('none');
4272
+ }
4273
+ chart.marker.dragStarted = false; // cancel zoom in progress
4274
+ return false;
4275
+ }
4276
+ chart.marker.suppressUpdate = false;
4277
+ chart.marker.x = e.x;
4278
+ chart.draw();
4279
+ },
4280
+ doDraw: function (chart) {
4281
+ if (!hasMarkerConfiguration(chart)) {
4282
+ return;
4283
+ }
4284
+ if (!chart.marker.enabled) {
4285
+ return;
4286
+ }
4287
+ this.drawTraceLine(chart);
4288
+ this.interpolateValues(chart);
4289
+ this.drawTracePoints(chart);
4290
+ return true;
4291
+ },
4292
+ beforeDraw: function (chart) {
4293
+ return this.doDraw(chart);
4294
+ },
4295
+ // Logic moved to beforeDraw in order
4296
+ // for the vertical line to be drawn
4297
+ // under tooltip and datalabels.
4298
+ // afterDraw: function(chart) {
4299
+ // return this.doDraw(chart);
4300
+ // },
4301
+ drawTraceLine: function (chart) {
4302
+ if (!hasMarkerConfiguration(chart)) {
4303
+ return;
4304
+ }
4305
+ var yScale = this.getYScale(chart);
4306
+ var lineWidth = this.getOption(chart, 'line', 'width');
4307
+ var color = this.getOption(chart, 'line', 'color');
4308
+ var dashPattern = this.getOption(chart, 'line', 'dashPattern');
4309
+ var snapEnabled = this.getOption(chart, 'snap', 'enabled');
4310
+ var lineX = chart.marker.x;
4311
+ if (snapEnabled && chart._active.length) {
4312
+ lineX = chart._active[0].element.x;
4313
+ }
4314
+ chart.ctx.beginPath();
4315
+ chart.ctx.setLineDash(dashPattern);
4316
+ chart.ctx.moveTo(lineX, yScale.getPixelForValue(yScale.max));
4317
+ chart.ctx.lineWidth = lineWidth;
4318
+ chart.ctx.strokeStyle = color;
4319
+ chart.ctx.lineTo(lineX, yScale.getPixelForValue(yScale.min));
4320
+ chart.ctx.stroke();
4321
+ chart.ctx.setLineDash([]);
4322
+ },
4323
+ drawTracePoints: function (chart) {
4324
+ if (!hasMarkerConfiguration(chart)) {
4325
+ return;
4326
+ }
4327
+ for (var chartIndex = 0; chartIndex < chart.data.datasets.length; chartIndex++) {
4328
+ var dataset = chart.data.datasets[chartIndex];
4329
+ var meta = chart.getDatasetMeta(chartIndex);
4330
+ var yScale = chart.scales[meta.yAxisID];
4331
+ if (meta.hidden || !dataset.interpolate) {
4332
+ continue;
4333
+ }
4334
+ chart.ctx.beginPath();
4335
+ chart.ctx.arc(chart.marker.x, yScale.getPixelForValue(dataset.interpolatedValue), 3, 0, 2 * Math.PI, false);
4336
+ chart.ctx.fillStyle = 'white';
4337
+ chart.ctx.lineWidth = 2;
4338
+ chart.ctx.strokeStyle = dataset.borderColor;
4339
+ chart.ctx.fill();
4340
+ chart.ctx.stroke();
4341
+ }
4342
+ },
4343
+ interpolateValues: function (chart) {
4344
+ for (var chartIndex = 0; chartIndex < chart.data.datasets.length; chartIndex++) {
4345
+ var dataset = chart.data.datasets[chartIndex];
4346
+ var meta = chart.getDatasetMeta(chartIndex);
4347
+ var xScale = chart.scales[meta.xAxisID];
4348
+ var xValue = xScale.getValueForPixel(chart.marker.x);
4349
+ if (meta.hidden || !dataset.interpolate) {
4350
+ continue;
4351
+ }
4352
+ var data = dataset.data;
4353
+ var index = data.findIndex(function (o) {
4354
+ return o.x >= xValue;
4355
+ });
4356
+ var prev = data[index - 1];
4357
+ var next = data[index];
4358
+ if (chart.data.datasets[chartIndex].steppedLine && prev) {
4359
+ dataset.interpolatedValue = prev.y;
4360
+ }
4361
+ else if (prev && next) {
4362
+ var slope = (next.y - prev.y) / (next.x - prev.x);
4363
+ dataset.interpolatedValue = prev.y + (xValue - prev.x) * slope;
4364
+ }
4365
+ else {
4366
+ dataset.interpolatedValue = NaN;
4367
+ }
4368
+ }
4369
+ },
4370
+ };
4371
+
4047
4372
  var getThemeColorHexString$2 = core.ColorHelper.getThemeColorHexString;
4048
4373
  var hoverBackgroundColor = getThemeColorHexString$2('primary');
4049
4374
  var backgroundColor = getThemeColorHexString$2('secondary');
@@ -4103,13 +4428,19 @@
4103
4428
  legend: {
4104
4429
  display: false,
4105
4430
  },
4431
+ datalabels: {
4432
+ display: false,
4433
+ },
4434
+ tooltip: {
4435
+ enabled: false,
4436
+ },
4106
4437
  },
4107
4438
  };
4108
4439
 
4109
4440
  var CHART_SCALES = [chart_js.CategoryScale, chart_js.LinearScale];
4110
4441
  var CHART_ELEMENTS = [chart_js.BarElement, chart_js.LineElement, chart_js.PointElement];
4111
4442
  var CHART_CONTROLLERS = [chart_js.BarController, chart_js.LineController];
4112
- var CHART_PLUGINS = [annotationPlugin__default['default'], chart_js.Filler];
4443
+ var CHART_PLUGINS = [annotationPlugin__default['default'], chart_js.Filler, ChartDataLabels__default['default'], chart_js.Tooltip, MarkerPlugin];
4113
4444
  /* Order matters; defaults must be merged after register as
4114
4445
  register modifies the Chart.defaults objects */
4115
4446
  chart_js.Chart.register.apply(chart_js.Chart, __spread([chart_js.Legend], CHART_SCALES, CHART_ELEMENTS, CHART_CONTROLLERS, CHART_PLUGINS));
@@ -4121,14 +4452,23 @@
4121
4452
  chart_js.Chart.defaults[key] = mergedDefaults[key];
4122
4453
  });
4123
4454
 
4455
+ var CHART_LOCALE_DEFAULT = 'en-US';
4124
4456
  var ChartJSService = /** @class */ (function () {
4125
4457
  function ChartJSService(chartConfigService) {
4126
4458
  this.chartConfigService = chartConfigService;
4127
4459
  }
4128
4460
  ChartJSService.prototype.renderChart = function (args) {
4129
- var targetElement = args.targetElement, type = args.type, data = args.data, dataLabels = args.dataLabels, customOptions = args.customOptions, annotations = args.annotations, highlightedElements = args.highlightedElements;
4130
- var datasets = this.createDatasets(data, highlightedElements);
4131
- var options = this.createOptionsObject({ type: type, customOptions: customOptions, annotations: annotations });
4461
+ var targetElement = args.targetElement, type = args.type, data = args.data, dataLabels = args.dataLabels, customOptions = args.customOptions, annotations = args.annotations, dataLabelOptions = args.dataLabelOptions, highlightedElements = args.highlightedElements;
4462
+ this.dataLabelOptions = dataLabelOptions || null;
4463
+ this.highlightedElements = highlightedElements || null;
4464
+ this.chartType = type;
4465
+ this.locale = (dataLabelOptions === null || dataLabelOptions === void 0 ? void 0 : dataLabelOptions.locale) || CHART_LOCALE_DEFAULT;
4466
+ var datasets = this.createDatasets(data);
4467
+ var options = this.createOptionsObject({
4468
+ customOptions: customOptions,
4469
+ annotations: annotations,
4470
+ dataLabelOptions: dataLabelOptions,
4471
+ });
4132
4472
  var config = this.createConfigurationObject(type, datasets, options, dataLabels);
4133
4473
  this.initializeNewChart(targetElement.nativeElement, config);
4134
4474
  };
@@ -4152,15 +4492,20 @@
4152
4492
  this.nonDestructivelyUpdateType(type, customOptions);
4153
4493
  }
4154
4494
  };
4495
+ ChartJSService.prototype.setDataLabelOptions = function (dataLabelOptions) {
4496
+ this.dataLabelOptions = dataLabelOptions;
4497
+ };
4155
4498
  ChartJSService.prototype.updateOptions = function (customOptions, type) {
4156
4499
  var annotations = this.getExistingChartAnnotations();
4157
- this.chart.options = this.createOptionsObject({ type: type, customOptions: customOptions, annotations: annotations });
4500
+ this.chartType = type;
4501
+ this.chart.options = this.createOptionsObject({ customOptions: customOptions, annotations: annotations });
4158
4502
  };
4159
4503
  ChartJSService.prototype.updateAnnotations = function (annotations) {
4160
4504
  var annotationsWithDefaults = this.applyDefaultsToAnnotations(annotations);
4161
4505
  this.chart.options.plugins.annotation.annotations = annotationsWithDefaults;
4162
4506
  };
4163
4507
  ChartJSService.prototype.updateHighlightedElements = function (highlightedElements) {
4508
+ this.highlightedElements = highlightedElements;
4164
4509
  var oldDatasets = this.chart.data.datasets;
4165
4510
  // Clear old datasets of highlighted elements
4166
4511
  oldDatasets.map(function (dataset) {
@@ -4169,7 +4514,7 @@
4169
4514
  delete dataset.kirbyOptions.highlightedElements;
4170
4515
  }
4171
4516
  });
4172
- this.chart.data.datasets = this.createDatasets(oldDatasets, highlightedElements);
4517
+ this.chart.data.datasets = this.createDatasets(oldDatasets);
4173
4518
  };
4174
4519
  ChartJSService.prototype.getExistingChartAnnotations = function () {
4175
4520
  var _a, _b;
@@ -4188,7 +4533,8 @@
4188
4533
  var datasets = this.chart.data.datasets;
4189
4534
  var dataLabels = this.chart.data.labels;
4190
4535
  var annotations = this.getExistingChartAnnotations();
4191
- var options = this.createOptionsObject({ type: type, customOptions: customOptions, annotations: annotations });
4536
+ this.chartType = type;
4537
+ var options = this.createOptionsObject({ customOptions: customOptions, annotations: annotations });
4192
4538
  var config = this.createConfigurationObject(type, datasets, options, dataLabels);
4193
4539
  var canvasElement = this.chart.canvas;
4194
4540
  this.chart.destroy();
@@ -4196,8 +4542,8 @@
4196
4542
  };
4197
4543
  ChartJSService.prototype.nonDestructivelyUpdateType = function (chartType, customOptions) {
4198
4544
  var annotations = this.getExistingChartAnnotations();
4545
+ this.chartType = chartType;
4199
4546
  var options = this.createOptionsObject({
4200
- type: chartType,
4201
4547
  customOptions: customOptions,
4202
4548
  annotations: annotations,
4203
4549
  });
@@ -4230,8 +4576,8 @@
4230
4576
  };
4231
4577
  ChartJSService.prototype.applyInteractionFunctionsExtensions = function (options) {
4232
4578
  var interactionFunctionsExtensions = this.chartConfigService.getInteractionFunctionsExtensions();
4233
- Object.entries(interactionFunctionsExtensions).forEach(function (_c) {
4234
- var _d = __read(_c, 2), key = _d[0], _ = _d[1];
4579
+ Object.entries(interactionFunctionsExtensions).forEach(function (_d) {
4580
+ var _e = __read(_d, 2), key = _e[0], _ = _e[1];
4235
4581
  var callback = options[key];
4236
4582
  options[key] = function (e, a, c) {
4237
4583
  interactionFunctionsExtensions[key](e, a, c, callback);
@@ -4239,21 +4585,74 @@
4239
4585
  });
4240
4586
  return options;
4241
4587
  };
4588
+ ChartJSService.prototype.createStockOptionsObject = function (dataLabelOptions) {
4589
+ var _this = this;
4590
+ return {
4591
+ locale: this.locale,
4592
+ plugins: {
4593
+ tooltip: {
4594
+ callbacks: {
4595
+ title: function (tooltipItems) {
4596
+ var _a, _b;
4597
+ var date = dateFns.toDate((_b = (_a = tooltipItems[0]) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.x);
4598
+ if (date.valueOf()) {
4599
+ return date.toLocaleTimeString(_this.locale, {
4600
+ day: 'numeric',
4601
+ month: 'short',
4602
+ hour: '2-digit',
4603
+ minute: '2-digit',
4604
+ });
4605
+ }
4606
+ },
4607
+ label: function (context) {
4608
+ // It's not possible to add spacing between color legend and text so we
4609
+ // prefix with a space.
4610
+ return ' ' + context.formattedValue + (dataLabelOptions.valueSuffix || '');
4611
+ },
4612
+ },
4613
+ },
4614
+ },
4615
+ scales: {
4616
+ y: {
4617
+ ticks: {
4618
+ callback: function (value) {
4619
+ return value + (dataLabelOptions.valueSuffix || '');
4620
+ },
4621
+ },
4622
+ },
4623
+ },
4624
+ };
4625
+ };
4242
4626
  ChartJSService.prototype.createOptionsObject = function (args) {
4243
- var type = args.type, customOptions = args.customOptions, annotations = args.annotations;
4244
- var typeConfig = this.chartConfigService.getTypeConfig(type);
4627
+ var customOptions = args.customOptions, annotations = args.annotations, chartDataLabelOptions = args.dataLabelOptions;
4628
+ var typeConfig = this.chartConfigService.getTypeConfig(this.chartType);
4245
4629
  var typeConfigOptions = typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.options;
4246
4630
  var annotationPluginOptions = annotations
4247
4631
  ? this.createAnnotationPluginOptionsObject(annotations)
4248
4632
  : {};
4249
- var options = mergeDeepAll(typeConfigOptions, customOptions, annotationPluginOptions);
4633
+ var stockOptions = this.chartType === 'stock' ? this.createStockOptionsObject(chartDataLabelOptions) : {};
4634
+ var options = mergeDeepAll(stockOptions, typeConfigOptions, customOptions, annotationPluginOptions);
4250
4635
  return this.applyInteractionFunctionsExtensions(options);
4251
4636
  };
4637
+ ChartJSService.prototype.getDefaultStockLabels = function (datasets, locale) {
4638
+ var largestDataset = datasets.reduce(function (previousDataset, currentDataset) { return previousDataset.data.length > currentDataset.data.length ? previousDataset : currentDataset; });
4639
+ return largestDataset.data.map(function (point) { return dateFns.toDate(point.x).toLocaleDateString(locale, {
4640
+ month: 'short',
4641
+ day: 'numeric',
4642
+ }); });
4643
+ };
4252
4644
  ChartJSService.prototype.createConfigurationObject = function (type, datasets, options, dataLabels) {
4253
- /* chartJS requires labels; if none is provided create an empty string array
4254
- to make it optional for consumer */
4255
- var labels = !dataLabels ? this.createBlankLabels(datasets) : dataLabels;
4256
4645
  var typeConfig = this.chartConfigService.getTypeConfig(type);
4646
+ // chartJS requires labels; if none is provided create an empty string array
4647
+ // to make it optional for consumer.
4648
+ // However the stock chart, should have autogenerated labels if no
4649
+ // custom labels are supplied.
4650
+ var isStockType = type === 'stock';
4651
+ var labels = !dataLabels
4652
+ ? isStockType
4653
+ ? this.getDefaultStockLabels(datasets, this.locale)
4654
+ : this.createBlankLabels(datasets)
4655
+ : dataLabels;
4257
4656
  return mergeDeepAll(typeConfig, {
4258
4657
  data: {
4259
4658
  labels: labels,
@@ -4263,8 +4662,8 @@
4263
4662
  });
4264
4663
  };
4265
4664
  ChartJSService.prototype.addHighlightedElementsToDatasets = function (highlightedElements, datasets) {
4266
- highlightedElements.forEach(function (_c) {
4267
- var _d = __read(_c, 2), datasetIndex = _d[0], dataIndex = _d[1];
4665
+ highlightedElements.forEach(function (_d) {
4666
+ var _e = __read(_d, 2), datasetIndex = _e[0], dataIndex = _e[1];
4268
4667
  var _a;
4269
4668
  var dataset = datasets[datasetIndex];
4270
4669
  if (!dataset)
@@ -4277,12 +4676,63 @@
4277
4676
  }
4278
4677
  });
4279
4678
  };
4280
- ChartJSService.prototype.createDatasets = function (data, highlightedElements) {
4679
+ ChartJSService.prototype.createDatasets = function (data) {
4680
+ var _a, _b, _c;
4681
+ // We need to modify the datasets in order to add datalabels.
4682
+ if (((_a = this.dataLabelOptions) === null || _a === void 0 ? void 0 : _a.showCurrent) || ((_b = this.dataLabelOptions) === null || _b === void 0 ? void 0 : _b.showMax) || ((_c = this.dataLabelOptions) === null || _c === void 0 ? void 0 : _c.showMin)) {
4683
+ data = this.addDataLabelsData(data);
4684
+ }
4281
4685
  var datasets = isNumberArray(data) ? [{ data: data }] : data;
4282
- if (highlightedElements)
4283
- this.addHighlightedElementsToDatasets(highlightedElements, datasets);
4686
+ if (this.highlightedElements)
4687
+ this.addHighlightedElementsToDatasets(this.highlightedElements, datasets);
4284
4688
  return datasets;
4285
4689
  };
4690
+ /**
4691
+ * Decorate ChartDataset with properties to allow for datalabels.
4692
+ *
4693
+ * @param data
4694
+ * @returns ChartDataset[]
4695
+ */
4696
+ ChartJSService.prototype.addDataLabelsData = function (data) {
4697
+ var _this = this;
4698
+ if (isNumberArray(data)) {
4699
+ throw Error("Currently it's impossible to add dataLabels to non ScatterDataPoint datasets");
4700
+ }
4701
+ var decorateDataPoint = function (set, axis, direction, position) {
4702
+ var _d = _this.locateValueIndexInDataset(set, axis, direction), value = _d.value, pointer = _d.pointer;
4703
+ set.data[pointer] = Object.assign(Object.assign({}, set.data[pointer]), { datalabel: {
4704
+ value: value + (_this.dataLabelOptions.valueSuffix || ''),
4705
+ position: position,
4706
+ } });
4707
+ };
4708
+ data.map(function (set) {
4709
+ if (_this.dataLabelOptions.showMin) {
4710
+ decorateDataPoint(set, 'y', 'low', 'bottom');
4711
+ }
4712
+ if (_this.dataLabelOptions.showMax) {
4713
+ decorateDataPoint(set, 'y', 'high', 'top');
4714
+ }
4715
+ if (_this.dataLabelOptions.showCurrent) {
4716
+ decorateDataPoint(set, 'x', 'high', 'right');
4717
+ }
4718
+ });
4719
+ return data;
4720
+ };
4721
+ ChartJSService.prototype.locateValueIndexInDataset = function (dataset, axis, direction) {
4722
+ var pointer;
4723
+ var value;
4724
+ dataset.data.forEach(function (datapoint, index) {
4725
+ if (direction == 'low' && (!value || datapoint[axis] < value)) {
4726
+ value = datapoint['y'];
4727
+ pointer = index;
4728
+ }
4729
+ if (direction == 'high' && (!value || datapoint[axis] > value)) {
4730
+ value = datapoint['y'];
4731
+ pointer = index;
4732
+ }
4733
+ });
4734
+ return { value: value, pointer: pointer };
4735
+ };
4286
4736
  return ChartJSService;
4287
4737
  }());
4288
4738
  ChartJSService.decorators = [
@@ -4364,6 +4814,7 @@
4364
4814
  dataLabels: this.dataLabels,
4365
4815
  customOptions: this.customOptions,
4366
4816
  annotations: this.annotations,
4817
+ dataLabelOptions: this.dataLabelOptions,
4367
4818
  highlightedElements: this.highlightedElements,
4368
4819
  });
4369
4820
  };
@@ -4407,6 +4858,7 @@
4407
4858
  data: [{ type: i0.Input }],
4408
4859
  dataLabels: [{ type: i0.Input }],
4409
4860
  customOptions: [{ type: i0.Input }],
4861
+ dataLabelOptions: [{ type: i0.Input }],
4410
4862
  annotations: [{ type: i0.Input }],
4411
4863
  highlightedElements: [{ type: i0.Input }],
4412
4864
  _height: [{ type: i0.HostBinding, args: ['style.--kirby-chart-height',] }],
@@ -4415,7 +4867,7 @@
4415
4867
  };
4416
4868
 
4417
4869
  var stockChartDeprecatedOptions = function (locale, height) {
4418
- var options = defaultOptions(locale);
4870
+ var options = defaultOptions$1(locale);
4419
4871
  var transparentColor = 'rgba(255,255,255,0)';
4420
4872
  options.chart.backgroundColor = transparentColor;
4421
4873
  options.chart.height = height;
@@ -4511,7 +4963,7 @@
4511
4963
  },
4512
4964
  };
4513
4965
  };
4514
- var defaultOptions = function (locale) {
4966
+ var defaultOptions$1 = function (locale) {
4515
4967
  return {
4516
4968
  chart: {
4517
4969
  zoomType: 'x',
@@ -4593,7 +5045,7 @@
4593
5045
  ],
4594
5046
  };
4595
5047
  };
4596
- var ɵ0$6 = defaultOptions;
5048
+ var ɵ0$8 = defaultOptions$1;
4597
5049
 
4598
5050
  // @ts-ignore
4599
5051
  AnnotationsModule__default['default'](Highcharts__namespace$1);
@@ -10171,7 +10623,7 @@
10171
10623
  exports.isNumberArray = isNumberArray;
10172
10624
  exports.selectedTabClickEvent = selectedTabClickEvent;
10173
10625
  exports.stockChartDeprecatedOptions = stockChartDeprecatedOptions;
10174
- exports.ɵ0 = ɵ0$6;
10626
+ exports.ɵ0 = ɵ0$8;
10175
10627
  exports.ɵa = ProxyCmp;
10176
10628
  exports.ɵb = AppModule;
10177
10629
  exports.ɵba = ModalWrapperComponent;