diff --git a/src/formatValue.ts b/src/formatValue.ts index 97d85629..30cc0ac0 100644 --- a/src/formatValue.ts +++ b/src/formatValue.ts @@ -14,7 +14,7 @@ export function formatValue(value: any, valueToHtml: (value: any) => string, max if (isObject(value)) { let content = ''; - const {title, image, ...rest} = value as any; + const {title, image, ...rest} = value as any; if (title) { content += `

${valueToHtml(title)}

`; @@ -27,7 +27,15 @@ export function formatValue(value: any, valueToHtml: (value: any) => string, max const keys = Object.keys(rest); if (keys.length > 0) { content += ''; + var kv_list = []; + var sort_tooltip: string | undefined = undefined for (const key of keys) { + // Handle sort placeholder. + if (key === "tooltip_sort_placeholder") { + sort_tooltip = (rest as any)[key]; + continue; + } + let val = (rest as any)[key]; // ignore undefined properties @@ -39,7 +47,17 @@ export function formatValue(value: any, valueToHtml: (value: any) => string, max val = stringify(val, maxDepth); } - content += ``; + const kv: [string, any] = [key, val]; + kv_list.push(kv); + } + + // Sort tooltip if specified. + if (sort_tooltip !== undefined) { + const order: number = sort_tooltip === "0" ? 1 : -1; // order = 1: ascending, order = -1: descending + kv_list = kv_list.sort((n1,n2) => order * (n1[1] - n2[1])); // Sort by values. + } + for (const kv of kv_list) { + content += ``; } content += `
${valueToHtml(key)}${valueToHtml(val)}
${valueToHtml(kv[0])}:${valueToHtml(kv[1])}
`; }