Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
namnguyen20999 committed Jun 3, 2024
1 parent aaa2323 commit 6bfe97d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
25 changes: 22 additions & 3 deletions frontend/taipy-gui/src/utils/formatConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* specific language governing permissions and limitations under the License.
*/

/**
/*
* Regular expressions used for parsing sprintf format strings.
*/
const re = {
Expand All @@ -20,11 +20,19 @@ const re = {
placeholder: /^\x25?(?:\.(\d+))?([b-giostuvxX])/, // Matches placeholders
};

/*
* This function formats a precision specifier for a number. It takes an optional precision and specifier string.
* If no precision is provided, it defaults to 2. The function returns a string that represents the formatted precision.
*/
const precisionFormat = (precision?: string, specifier?: string): string => {
// Default to precision of 2 if not specified
return "." + (precision?.slice(1) ?? "2") + specifier;
}

/*
* This function parses a sprintf format string and returns an array of strings and objects. Each object has a single
* key, 'placeholder', that contains the placeholder string.
*/
const sprintfParse = (fmt?: string): (string | { placeholder: string; })[] => {
let _fmt = fmt;
let match;
Expand Down Expand Up @@ -54,6 +62,10 @@ const sprintfParse = (fmt?: string): (string | { placeholder: string; })[] => {
return parse_tree;
}

/*
* This function converts a sprintf format string to a D3 format string. It takes an optional sprintf format string and
* returns a D3 format string. If no format string is provided, it returns an empty string.
*/
export const sprintfToD3Converter = (fmt?: string): string => {
const sprintf_fmt_arr = sprintfParse(fmt);
const objectIndex = sprintf_fmt_arr.findIndex((element) => typeof element === 'object');
Expand All @@ -79,9 +91,8 @@ export const sprintfToD3Converter = (fmt?: string): string => {
case "i":
return "d";
case "f":
return precisionFormat(precision, "f");
case "g":
return precisionFormat(precision, "g");
return precisionFormat(precision, type);

Check warning on line 95 in frontend/taipy-gui/src/utils/formatConversion.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 95 in frontend/taipy-gui/src/utils/formatConversion.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
case "u":
return "("
default:
Expand All @@ -90,12 +101,20 @@ export const sprintfToD3Converter = (fmt?: string): string => {
});

Check warning on line 101 in frontend/taipy-gui/src/utils/formatConversion.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

/*
* This function extracts the prefix from a sprintf format string. It takes an optional sprintf format string and returns
* a string that represents the prefix of the format string. If no format string is provided, it returns an empty string.
*/
export const extractPrefix = (fmt?: string): string => {
const sprintf_fmt_arr = sprintfParse(fmt);
const objectIndex = sprintf_fmt_arr.findIndex((element) => typeof element === 'object');
return sprintf_fmt_arr.slice(0, objectIndex).join('');
}

/*
* This function extracts the suffix from a sprintf format string. It takes an optional sprintf format string and returns
* a string that represents the suffix of the format string. If no format string is provided, it returns an empty string.
*/
export const extractSuffix = (fmt?: string): string => {
const sprintf_fmt_arr = sprintfParse(fmt);
const objectIndex = sprintf_fmt_arr.findIndex((element) => typeof element === 'object');
Expand Down
32 changes: 16 additions & 16 deletions taipy/gui/viselements.json
Original file line number Diff line number Diff line change
Expand Up @@ -868,12 +868,6 @@
"default_value": "100",
"doc": "The maximum value of the metric indicator"
},
{
"name": "show_value",
"type": "bool",
"default_value": "True",
"doc": "If set to False, the value is not displayed."
},
{
"name": "delta",
"type": "dynamic(int|float)",
Expand All @@ -885,16 +879,10 @@
"doc": "The threshold value to display."
},
{
"name": "width",
"type": "str|number",
"default_value": "None",
"doc": "The width, in CSS units, of the metric."
},
{
"name": "height",
"type": "str|number",
"default_value": "None",
"doc": "The height, in CSS units, of the metric."
"name": "show_value",
"type": "bool",
"default_value": "True",
"doc": "If set to False, the value is not displayed."
},
{
"name": "format",
Expand All @@ -905,6 +893,18 @@
"name": "delta_format",
"type": "str",
"doc": "The format to use when displaying the delta value.<br/>This uses the <code>printf</code> syntax."
},
{
"name": "width",
"type": "str|number",
"default_value": "None",
"doc": "The width, in CSS units, of the metric."
},
{
"name": "height",
"type": "str|number",
"default_value": "None",
"doc": "The height, in CSS units, of the metric."
}
]
}
Expand Down

0 comments on commit 6bfe97d

Please sign in to comment.