-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02cfd14
commit b939ae1
Showing
3 changed files
with
101 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
frontend/src/metabase/visualizations/shared/settings/column.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { getCurrencySymbol } from "metabase/lib/formatting"; | ||
import { isCurrency, isPercentage } from "metabase-lib/v1/types/utils/isa"; | ||
import type { DatasetColumn, VisualizationSettings } from "metabase-types/api"; | ||
|
||
/** | ||
* Helper used for `getDefault` and `getProps` calculations in | ||
* frontend/src/metabase/visualizations/lib/settings/column.js | ||
*/ | ||
export function getCurrency(currency: string, currencyStyle: string) { | ||
return (0) | ||
.toLocaleString("en", { | ||
style: "currency", | ||
currency: currency, | ||
currencyDisplay: currencyStyle, | ||
}) | ||
.replace(/0([.,]0+)?/, "") | ||
.trim(); // strip off actual number | ||
} | ||
|
||
export function getDefaultNumberStyle( | ||
column: DatasetColumn, | ||
settings: VisualizationSettings, | ||
) { | ||
if (isCurrency(column) && settings["currency"]) { | ||
return "currency"; | ||
} | ||
|
||
if (isPercentage(column)) { | ||
return "percent"; | ||
} | ||
|
||
return "decimal"; | ||
} | ||
|
||
export function getDefaultCurrency() { | ||
return "USD"; | ||
} | ||
|
||
export function getDefaultCurrencyStyle( | ||
_column: any, | ||
settings: VisualizationSettings, | ||
) { | ||
const c = settings["currency"] || "USD"; | ||
return getCurrencySymbol(c) !== getCurrency(c, "code") ? "symbol" : "code"; | ||
} | ||
|
||
export function getDefaultCurrencyInHeader() { | ||
return true; | ||
} | ||
|
||
export function getDefaultNumberSeparators() { | ||
return ".,"; | ||
} |