Skip to content

Commit

Permalink
Merge pull request #255 from AUS-DOH-Safety-and-Quality/multi-dates
Browse files Browse the repository at this point in the history
Fix handling of multiple non-Hierarchy date inputs
  • Loading branch information
andrjohns authored Mar 11, 2024
2 parents f21c6db + d574ee7 commit 12a5401
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pbiviz.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"displayName":"SPC Charts",
"guid":"PBISPC",
"visualClassName":"Visual",
"version":"1.4.1.2",
"version":"1.4.1.3",
"description":"A PowerBI custom visual for SPC charts",
"supportUrl":"https://github.com/AUS-DOH-Safety-and-Quality/PowerBI-SPC",
"gitHubUrl":"https://github.com/AUS-DOH-Safety-and-Quality/PowerBI-SPC"
Expand Down
15 changes: 13 additions & 2 deletions src/Functions/extractDataColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type DataViewValueColumn = powerbi.DataViewValueColumn;
type DataViewCategorical = powerbi.DataViewCategorical;
type VisualTooltipDataItem = powerbi.extensibility.VisualTooltipDataItem;
import type { defaultSettingsType } from "../Classes/";
import { formatPrimitiveValue, dateSettingsToFormatOptions, parseInputDates } from "../Functions";
import { formatPrimitiveValue, dateSettingsToFormatOptions, parseInputDates, rep } from "../Functions";
type TargetT = number[] | string[] | number | string | VisualTooltipDataItem[][];

function datePartsToRecord(dateParts: Intl.DateTimeFormatPart[]) {
Expand All @@ -19,9 +19,20 @@ function extractKeys(inputView: DataViewCategorical, inputSettings: defaultSetti
if (col.length === 1 && !(col[0].source.type?.temporal)) {
return col[0].values.map(d => d === null ? null : String(d));
}
const delim: string = inputSettings.dates.date_format_delim;
// If multiple inputs are passed but not as a 'Date Hierarchy' type then
// just concatenate and do not attempt to format
// TODO(Andrew): Support formatting individual date parts
// - e.g., Mixing Date Hierarchy and string inputs
if (!(col.every(d => d.source?.type?.temporal))) {
const blankKey: string = rep("", col.length).join(delim)
return col[0].values.map((_, idx) => {
const currKey: string = col.map(keyCol => keyCol.values[idx]).join(delim)
return currKey === blankKey ? null : currKey
})
}
const inputDates = parseInputDates(col)
const formatter = new Intl.DateTimeFormat(inputSettings.dates.date_format_locale, dateSettingsToFormatOptions(inputSettings.dates));
const delim: string = inputSettings.dates.date_format_delim;
return inputDates.dates.map((value: Date, idx) => {
if (value === null) {
return null
Expand Down

0 comments on commit 12a5401

Please sign in to comment.