@datarailsshared/dr_renderer 1.2.150 → 1.2.152-dragons

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.2.150",
3
+ "version": "1.2.152-dragons",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -7780,6 +7780,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7780
7780
  datesFields = lodash.filter(widget.rows, element => element.type == 'Date');
7781
7781
  datesFields = datesFields.concat(lodash.filter(widget.cols, element => element.type == 'Date'));
7782
7782
 
7783
+ const aggregationConfigs = widget.options?.date_aggregation_configs;
7784
+ if (aggregationConfigs?.length && datesFields?.length) {
7785
+ this.formatDatesWithAggregationIfRequired(aggregationConfigs, datesFields, defaultDateFormat);
7786
+ }
7787
+
7783
7788
  const isCustomSorting = widget.options.sortingFields && Array.isArray(widget.options.sortingFields) && widget.options.sortingFields.length > 0;
7784
7789
  if (isCustomSorting) {
7785
7790
  lodash.forEach(datesFields, function (field) {
@@ -8208,6 +8213,37 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8208
8213
  yAxis.max = !isNaN(maxNumber) ? maxNumber : null;
8209
8214
  }
8210
8215
 
8216
+ highchartsRenderer.formatDatesWithAggregationIfRequired = function(aggregationConfigs, datesFields, defaultDateFormat) {
8217
+ _.forEach(aggregationConfigs, aggregationConfig => {
8218
+ const aggregationTimeframe = aggregationConfig?.aggregate_by;
8219
+ const isFormattingByAggregation = aggregationConfig?.is_formatting_by_aggregation_method;
8220
+
8221
+ if (aggregationTimeframe && isFormattingByAggregation) {
8222
+ const dateField = lodash.find(
8223
+ datesFields,
8224
+ (element) => element.id === aggregationConfig.field_id
8225
+ );
8226
+ if (dateField) {
8227
+ dateField.format = highchartsRenderer.getDateFormatByAggregation(aggregationTimeframe, defaultDateFormat);
8228
+ }
8229
+ }
8230
+ });
8231
+ }
8232
+
8233
+ highchartsRenderer.getDateFormatByAggregation = function(timeframe, defaultDateFormat) {
8234
+ switch (timeframe) {
8235
+ case 'month':
8236
+ return 'MMM-YY';
8237
+ case 'year':
8238
+ return 'YYYY';
8239
+ case 'quarter':
8240
+ return '[Q]Q-YY';
8241
+ case 'day':
8242
+ default:
8243
+ return defaultDateFormat;
8244
+ }
8245
+ }
8246
+
8211
8247
  return highchartsRenderer;
8212
8248
  };
8213
8249