itwinjs-core icon indicating copy to clipboard operation
itwinjs-core copied to clipboard

Extend ratio formatting to support scale factors

Open hl662 opened this issue 4 months ago • 0 comments

This pull request adds comprehensive support for ratio formatting with scale factors to the @itwin/core-quantity and @itwin/ecschema-metadata packages. The changes introduce new properties and types for ratio formats, enhance format parsing and validation, and update schema deserialization and format selection logic to handle ratio units.

Ratio Formatting Enhancements:

  • Added new properties to Format, BaseFormat, and related interfaces/classes to support ratioFormatType, ratioSeparator, ratioType, and ratioUnits, enabling flexible definition and parsing of ratio formats.
  • Introduced the RatioFormatType enum and FormatUnitSpec/ResolvedFormatUnitSpec interfaces to avoid inline types.
  • Added the parseRatioFormatType function for parsing ratio format types from strings.

Schema and Format Parsing/Validation:

  • Updated JSON and XML deserialization logic to validate and load new ratio format properties, including strict checks for the structure and types of ratioUnits.

  • Enhanced the Format class in ecschema-metadata to provide accessors for the new ratio properties and a protected method to add ratio units.

  • Updated FormatterSpec and ParserSpec in quantity to support on the fly unit conversion calculations when ratioUnits is provided. Format Selection and Usage:

  • Updated the SchemaFormatsProvider to correctly select and match formats based on the new ratio unit definitions, ensuring the correct unit system is used whether the format uses composite or ratio units.

hl662 avatar Nov 19 '25 21:11 hl662