From 1929fa42658e5e32803a4d25021f57e41fdd13c9 Mon Sep 17 00:00:00 2001 From: Riya Jethwa <76566868+RiyaJethwa@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:12:48 +0530 Subject: [PATCH 1/2] fix(model-csvFile-#1468):time level precision not availabe in date --- packages/core/src/model/cartesian-charts.ts | 52 +++++++++++++++------ 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/packages/core/src/model/cartesian-charts.ts b/packages/core/src/model/cartesian-charts.ts index 018eb9fac3..ad1b8aed8b 100644 --- a/packages/core/src/model/cartesian-charts.ts +++ b/packages/core/src/model/cartesian-charts.ts @@ -32,22 +32,48 @@ export class ChartModelCartesian extends ChartModel { scales.secondaryRange = cartesianScales.secondaryRangeAxisPosition } - Object.keys(scales).forEach((scale: 'primaryDomain' | 'primaryRange' | 'secondaryDomain' | 'secondaryRange') => { - const position = scales[scale] - if (cartesianScales.scales[position]) { - scales[scale] = { - position: position, - label: cartesianScales.getScaleLabel(position), - identifier: getProperty(options, 'axes', position, 'mapsTo') + Object.keys(scales).forEach( + (scale: 'primaryDomain' | 'primaryRange' | 'secondaryDomain' | 'secondaryRange') => { + const position = scales[scale] + if (cartesianScales.scales[position]) { + scales[scale] = { + position: position, + label: cartesianScales.getScaleLabel(position), + identifier: getProperty(options, 'axes', position, 'mapsTo') + } + } else { + scales[scale] = null } - } else { - scales[scale] = null } - }) + ) return scales } + dateFormatter(value: any) { + const options = this.getOptions() + const valueFormatter = getProperty(options, 'dateFormatter') + + if (valueFormatter) { + return valueFormatter(value) + } + + if (typeof value.getTime === 'function') { + return format(value, 'MMM d, yyyy') + } + + try { + // it's a correct ISO format Date string + if (typeof value === 'string' && /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(value)) { + return format(Date.parse(value), 'MMM d, yyyy') + } + } catch (e) { + // not a valid ISO format string + } + + return value.toLocaleString() + } + getTabularDataArray() { const displayData = this.getDisplayData() const options = this.getOptions() @@ -60,7 +86,7 @@ export class ChartModelCartesian extends ChartModel { const domainScaleType = cartesianScales.getDomainAxisScaleType() let domainValueFormatter: any if (domainScaleType === ScaleTypes.TIME) { - domainValueFormatter = (d: any) => format(d, 'MMM d, yyyy') + domainValueFormatter = (d: any) => this.dateFormatter(d) } const result = [ @@ -86,14 +112,14 @@ export class ChartModelCartesian extends ChartModel { datum[secondaryDomain.identifier] === null ? '–' : datum[secondaryDomain.identifier] - ] + ] : []), ...(secondaryRange ? [ datum[secondaryRange.identifier] === null || isNaN(datum[secondaryRange.identifier]) ? '–' : datum[secondaryRange.identifier] - ] + ] : []) ]) ] From 23f56168c3de10f033fe416aca0df714bec7a8c8 Mon Sep 17 00:00:00 2001 From: Riya Jethwa <76566868+RiyaJethwa@users.noreply.github.com> Date: Fri, 6 Oct 2023 12:58:12 +0530 Subject: [PATCH 2/2] fix(model-csv):addition on dateFormatter under model property --- packages/core/src/model/cartesian-charts.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/model/cartesian-charts.ts b/packages/core/src/model/cartesian-charts.ts index ad1b8aed8b..43a32737a7 100644 --- a/packages/core/src/model/cartesian-charts.ts +++ b/packages/core/src/model/cartesian-charts.ts @@ -50,9 +50,9 @@ export class ChartModelCartesian extends ChartModel { return scales } - dateFormatter(value: any) { + modelDateFormatter(value: any) { const options = this.getOptions() - const valueFormatter = getProperty(options, 'dateFormatter') + const valueFormatter = getProperty(options, 'model', 'dateFormatter') if (valueFormatter) { return valueFormatter(value) @@ -86,7 +86,7 @@ export class ChartModelCartesian extends ChartModel { const domainScaleType = cartesianScales.getDomainAxisScaleType() let domainValueFormatter: any if (domainScaleType === ScaleTypes.TIME) { - domainValueFormatter = (d: any) => this.dateFormatter(d) + domainValueFormatter = (d: any) => this.modelDateFormatter(d) } const result = [