@praxisui/core 10.0.0-rc.43 → 10.0.0-rc.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -14
- package/ai/component-registry.json +71 -6
- package/fesm2022/praxisui-core-schema.mjs +550 -60
- package/fesm2022/praxisui-core.mjs +5845 -1417
- package/package.json +1 -1
- package/types/praxisui-core-schema.d.ts +217 -13
- package/types/praxisui-core.d.ts +5494 -4370
|
@@ -214,6 +214,266 @@ function resolvePraxisMicroVisualizationTone(value, thresholds, fallbackTone) {
|
|
|
214
214
|
}
|
|
215
215
|
return fallbackTone ? { tone: fallbackTone } : undefined;
|
|
216
216
|
}
|
|
217
|
+
const STACKED_BAR_TONE_PAINT = {
|
|
218
|
+
info: 'var(--prx-micro-tone-info, var(--p-table-state-info-fg, var(--md-sys-color-primary, #0a6eb4)))',
|
|
219
|
+
success: 'var(--prx-micro-tone-success, var(--p-table-state-success-fg, #1b7a43))',
|
|
220
|
+
warning: 'var(--prx-micro-tone-warning, var(--p-table-state-warning-fg, #d97706))',
|
|
221
|
+
danger: 'var(--prx-micro-tone-danger, var(--p-table-state-danger-fg, var(--md-sys-color-error, #c62828)))',
|
|
222
|
+
critical: 'var(--prx-micro-tone-critical, var(--prx-micro-tone-danger, var(--p-table-state-danger-fg, var(--md-sys-color-error, #9f1239))))',
|
|
223
|
+
neutral: 'var(--prx-micro-tone-neutral, var(--md-sys-color-secondary, #5c6b73))',
|
|
224
|
+
};
|
|
225
|
+
function normalizePraxisHexColor(value) {
|
|
226
|
+
if (typeof value !== 'string') {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
const trimmed = value.trim();
|
|
230
|
+
const match = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(trimmed);
|
|
231
|
+
if (!match) {
|
|
232
|
+
return undefined;
|
|
233
|
+
}
|
|
234
|
+
const raw = match[1].toLowerCase();
|
|
235
|
+
if (raw.length === 3) {
|
|
236
|
+
return `#${raw[0]}${raw[0]}${raw[1]}${raw[1]}${raw[2]}${raw[2]}`;
|
|
237
|
+
}
|
|
238
|
+
return `#${raw}`;
|
|
239
|
+
}
|
|
240
|
+
function getPraxisStackedBarPaintStyle(segment, fallbackTone = 'neutral') {
|
|
241
|
+
const hex = normalizePraxisHexColor(segment?.color);
|
|
242
|
+
const resolvedTone = normalizeEnum$1(segment?.tone, VISUALIZATION_TONES) ??
|
|
243
|
+
normalizeEnum$1(fallbackTone, VISUALIZATION_TONES) ??
|
|
244
|
+
'neutral';
|
|
245
|
+
const paint = hex ?? STACKED_BAR_TONE_PAINT[resolvedTone];
|
|
246
|
+
return {
|
|
247
|
+
'--prx-micro-category-color': paint,
|
|
248
|
+
color: paint,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function resolvePraxisStackedBarSegments(visualization) {
|
|
252
|
+
if (!visualization || visualization.kind !== 'stackedBar') {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
if (Array.isArray(visualization.segments) && visualization.segments.length > 0) {
|
|
256
|
+
return visualization.segments;
|
|
257
|
+
}
|
|
258
|
+
if (Array.isArray(visualization.items) && visualization.items.length > 0) {
|
|
259
|
+
const mapped = [];
|
|
260
|
+
for (let i = 0; i < visualization.items.length; i++) {
|
|
261
|
+
if (!Object.prototype.hasOwnProperty.call(visualization.items, i)) {
|
|
262
|
+
return [];
|
|
263
|
+
}
|
|
264
|
+
const item = visualization.items[i];
|
|
265
|
+
if (!item || typeof item.value !== 'number' || !Number.isFinite(item.value) || item.value < 0) {
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
const hex = normalizePraxisHexColor(item.color);
|
|
269
|
+
mapped.push({
|
|
270
|
+
value: item.value,
|
|
271
|
+
...(item.label ? { label: item.label } : {}),
|
|
272
|
+
...(item.tone ? { tone: item.tone } : {}),
|
|
273
|
+
...(hex ? { color: hex } : {}),
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
return mapped;
|
|
277
|
+
}
|
|
278
|
+
return [];
|
|
279
|
+
}
|
|
280
|
+
function resolvePraxisStackedBarTotal(segments, explicitTotal) {
|
|
281
|
+
if (typeof explicitTotal === 'number' && Number.isFinite(explicitTotal) && explicitTotal >= 0) {
|
|
282
|
+
return explicitTotal;
|
|
283
|
+
}
|
|
284
|
+
return compensatedSum(segments.map((segment) => segment.value));
|
|
285
|
+
}
|
|
286
|
+
function computePraxisStackedBarSegmentWidthPct(value, resolvedTotal) {
|
|
287
|
+
if (!Number.isFinite(value) || value <= 0 || !Number.isFinite(resolvedTotal) || resolvedTotal <= 0) {
|
|
288
|
+
return 0;
|
|
289
|
+
}
|
|
290
|
+
return Math.max(0, Math.min(100, (value / resolvedTotal) * 100));
|
|
291
|
+
}
|
|
292
|
+
function formatPraxisStackedBarPercentage(value, resolvedTotal, locale) {
|
|
293
|
+
const pct = computePraxisStackedBarSegmentWidthPct(value, resolvedTotal);
|
|
294
|
+
const maximumFractionDigits = pct === 0 ? 0 : pct < 0.1 ? 3 : pct < 1 ? 2 : 1;
|
|
295
|
+
return `${new Intl.NumberFormat(locale || undefined, { maximumFractionDigits }).format(pct)}%`;
|
|
296
|
+
}
|
|
297
|
+
function resolvePraxisStackedBarAriaLabel(visualization, segments, resolvedTotal, locale) {
|
|
298
|
+
if (visualization.ariaLabel) {
|
|
299
|
+
return visualization.ariaLabel;
|
|
300
|
+
}
|
|
301
|
+
if (segments.length > 0 &&
|
|
302
|
+
segments.every((segment) => typeof segment.label === 'string' && segment.label.trim().length > 0)) {
|
|
303
|
+
const prefix = visualization.title || visualization.fallbackText;
|
|
304
|
+
const summary = segments
|
|
305
|
+
.map((segment) => `${segment.label} ${formatPraxisStackedBarPercentage(segment.value, resolvedTotal, locale)}`)
|
|
306
|
+
.join(', ');
|
|
307
|
+
return `${prefix}: ${summary}`;
|
|
308
|
+
}
|
|
309
|
+
return visualization.fallbackText;
|
|
310
|
+
}
|
|
311
|
+
function compensatedSum(values) {
|
|
312
|
+
let sum = 0;
|
|
313
|
+
let compensation = 0;
|
|
314
|
+
for (let i = 0; i < values.length; i++) {
|
|
315
|
+
const value = values[i];
|
|
316
|
+
const next = sum + value;
|
|
317
|
+
if (Math.abs(sum) >= Math.abs(value)) {
|
|
318
|
+
compensation += (sum - next) + value;
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
compensation += (value - next) + sum;
|
|
322
|
+
}
|
|
323
|
+
sum = next;
|
|
324
|
+
}
|
|
325
|
+
return sum + compensation;
|
|
326
|
+
}
|
|
327
|
+
function normalizeStackedBarDistribution(value, surface) {
|
|
328
|
+
const isTableCell = surface === 'table-cell';
|
|
329
|
+
const hasSegmentsProp = value.segments !== undefined;
|
|
330
|
+
const hasItemsProp = value.items !== undefined;
|
|
331
|
+
const hasExplicitTotalProp = Object.prototype.hasOwnProperty.call(value, 'total') &&
|
|
332
|
+
value.total !== undefined &&
|
|
333
|
+
value.total !== null;
|
|
334
|
+
const hasDeferredExpr = Boolean(normalizeExpression(value.segmentsExpr, 'segmentsExpr') ||
|
|
335
|
+
normalizeExpression(value.itemsExpr, 'itemsExpr'));
|
|
336
|
+
const rawTitle = isTableCell ? undefined : normalizeText$1(value.title);
|
|
337
|
+
if (!hasSegmentsProp && !hasItemsProp) {
|
|
338
|
+
const explicitTotal = hasExplicitTotalProp ? toFiniteNumber(value.total) : undefined;
|
|
339
|
+
const validDeferredTotal = !hasExplicitTotalProp || (explicitTotal !== undefined && explicitTotal >= 0);
|
|
340
|
+
if (!validDeferredTotal) {
|
|
341
|
+
return {
|
|
342
|
+
valid: false,
|
|
343
|
+
...(typeof value.legend === 'boolean' ? { legend: false } : {}),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
if (!isTableCell && value.legend === true && !hasDeferredExpr) {
|
|
347
|
+
return {
|
|
348
|
+
valid: false,
|
|
349
|
+
legend: false,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
valid: hasDeferredExpr,
|
|
354
|
+
...(explicitTotal !== undefined ? { total: explicitTotal } : {}),
|
|
355
|
+
...(rawTitle && hasDeferredExpr ? { title: rawTitle } : {}),
|
|
356
|
+
...(typeof value.legend === 'boolean'
|
|
357
|
+
? { legend: isTableCell ? false : value.legend }
|
|
358
|
+
: {}),
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
const rawEntries = hasSegmentsProp ? value.segments : value.items;
|
|
362
|
+
if (!Array.isArray(rawEntries) || rawEntries.length === 0) {
|
|
363
|
+
return {
|
|
364
|
+
valid: false,
|
|
365
|
+
...(typeof value.legend === 'boolean' ? { legend: false } : {}),
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
const parsedSegments = [];
|
|
369
|
+
const parsedItems = [];
|
|
370
|
+
for (let i = 0; i < rawEntries.length; i++) {
|
|
371
|
+
if (!Object.prototype.hasOwnProperty.call(rawEntries, i)) {
|
|
372
|
+
return {
|
|
373
|
+
valid: false,
|
|
374
|
+
...(typeof value.legend === 'boolean' ? { legend: false } : {}),
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
const rawEntry = rawEntries[i];
|
|
378
|
+
if (typeof rawEntry === 'number' || typeof rawEntry === 'string') {
|
|
379
|
+
const num = toFiniteNumber(rawEntry);
|
|
380
|
+
if (num === undefined || num < 0) {
|
|
381
|
+
return {
|
|
382
|
+
valid: false,
|
|
383
|
+
...(typeof value.legend === 'boolean' ? { legend: false } : {}),
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
parsedSegments.push({ value: num });
|
|
387
|
+
parsedItems.push({ value: num });
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (!rawEntry || typeof rawEntry !== 'object') {
|
|
391
|
+
return {
|
|
392
|
+
valid: false,
|
|
393
|
+
...(typeof value.legend === 'boolean' ? { legend: false } : {}),
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
const entryObj = rawEntry;
|
|
397
|
+
const num = toFiniteNumber(entryObj.value);
|
|
398
|
+
if (num === undefined || num < 0) {
|
|
399
|
+
return {
|
|
400
|
+
valid: false,
|
|
401
|
+
...(typeof value.legend === 'boolean' ? { legend: false } : {}),
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
const label = normalizeText$1(entryObj.label);
|
|
405
|
+
const entryTone = normalizeEnum$1(entryObj.tone, VISUALIZATION_TONES);
|
|
406
|
+
const entryColor = normalizePraxisHexColor(entryObj.color);
|
|
407
|
+
const id = normalizeText$1(entryObj.id);
|
|
408
|
+
const icon = normalizeText$1(entryObj.icon);
|
|
409
|
+
const state = normalizeText$1(entryObj.state);
|
|
410
|
+
parsedSegments.push({
|
|
411
|
+
value: num,
|
|
412
|
+
...(label ? { label } : {}),
|
|
413
|
+
...(entryTone ? { tone: entryTone } : {}),
|
|
414
|
+
...(entryColor ? { color: entryColor } : {}),
|
|
415
|
+
});
|
|
416
|
+
parsedItems.push({
|
|
417
|
+
value: num,
|
|
418
|
+
...(id ? { id } : {}),
|
|
419
|
+
...(label ? { label } : {}),
|
|
420
|
+
...(icon ? { icon } : {}),
|
|
421
|
+
...(state ? { state } : {}),
|
|
422
|
+
...(entryTone ? { tone: entryTone } : {}),
|
|
423
|
+
...(entryColor ? { color: entryColor } : {}),
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
const sum = compensatedSum(parsedSegments.map((entry) => entry.value));
|
|
427
|
+
if (!Number.isFinite(sum) || sum < 0) {
|
|
428
|
+
return {
|
|
429
|
+
valid: false,
|
|
430
|
+
...(typeof value.legend === 'boolean' ? { legend: false } : {}),
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
let validatedTotal;
|
|
434
|
+
if (hasExplicitTotalProp) {
|
|
435
|
+
const explicitTotal = toFiniteNumber(value.total);
|
|
436
|
+
if (explicitTotal === undefined || !Number.isFinite(explicitTotal) || explicitTotal < 0) {
|
|
437
|
+
return {
|
|
438
|
+
valid: false,
|
|
439
|
+
...(typeof value.legend === 'boolean' ? { legend: false } : {}),
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
if (explicitTotal === 0 && sum > 0) {
|
|
443
|
+
return {
|
|
444
|
+
valid: false,
|
|
445
|
+
...(typeof value.legend === 'boolean' ? { legend: false } : {}),
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
if (explicitTotal > 0) {
|
|
449
|
+
const tolerance = Math.max(4, parsedSegments.length) * Number.EPSILON * Math.max(sum, explicitTotal);
|
|
450
|
+
if (sum - explicitTotal > tolerance) {
|
|
451
|
+
return {
|
|
452
|
+
valid: false,
|
|
453
|
+
...(typeof value.legend === 'boolean' ? { legend: false } : {}),
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
validatedTotal = explicitTotal;
|
|
458
|
+
}
|
|
459
|
+
const normalizedLegend = typeof value.legend === 'boolean' ? (isTableCell ? false : value.legend) : undefined;
|
|
460
|
+
if (!isTableCell && normalizedLegend === true) {
|
|
461
|
+
const allLabeled = parsedSegments.every((entry) => typeof entry.label === 'string' && entry.label.length > 0);
|
|
462
|
+
if (!allLabeled) {
|
|
463
|
+
return {
|
|
464
|
+
valid: false,
|
|
465
|
+
legend: false,
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return {
|
|
470
|
+
valid: true,
|
|
471
|
+
...(hasSegmentsProp ? { segments: parsedSegments } : { items: parsedItems }),
|
|
472
|
+
...(validatedTotal !== undefined ? { total: validatedTotal } : {}),
|
|
473
|
+
...(rawTitle ? { title: rawTitle } : {}),
|
|
474
|
+
...(normalizedLegend !== undefined ? { legend: normalizedLegend } : {}),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
217
477
|
function normalizePraxisPresentationVisualization(value) {
|
|
218
478
|
if (!value || typeof value !== 'object') {
|
|
219
479
|
return undefined;
|
|
@@ -229,7 +489,9 @@ function normalizePraxisPresentationVisualization(value) {
|
|
|
229
489
|
const tone = normalizeEnum$1(value.tone, VISUALIZATION_TONES);
|
|
230
490
|
const ariaLabel = normalizeText$1(value.ariaLabel);
|
|
231
491
|
const valueSuffix = normalizeText$1(value.valueSuffix);
|
|
492
|
+
const normalizedTargetLabel = normalizeText$1(value.targetLabel);
|
|
232
493
|
const thresholdsObj = normalizeThresholds(value.thresholds);
|
|
494
|
+
const isTableCell = surface === 'table-cell';
|
|
233
495
|
let resolvedTone = tone;
|
|
234
496
|
let resolvedAriaLabel = ariaLabel;
|
|
235
497
|
if (!resolvedTone && thresholdsObj?.thresholds?.length) {
|
|
@@ -257,12 +519,66 @@ function normalizePraxisPresentationVisualization(value) {
|
|
|
257
519
|
}
|
|
258
520
|
}
|
|
259
521
|
}
|
|
522
|
+
if (kind === 'stackedBar') {
|
|
523
|
+
const stacked = normalizeStackedBarDistribution(value, surface);
|
|
524
|
+
return {
|
|
525
|
+
kind,
|
|
526
|
+
fallbackText,
|
|
527
|
+
...(surface ? { surface } : {}),
|
|
528
|
+
...(size ? { size } : {}),
|
|
529
|
+
...(scaleScope ? { scaleScope } : {}),
|
|
530
|
+
...(stacked.title ? { title: stacked.title } : {}),
|
|
531
|
+
...(normalizeExpression(value.titleExpr, 'titleExpr') ?? {}),
|
|
532
|
+
...(stacked.legend !== undefined ? { legend: stacked.legend } : {}),
|
|
533
|
+
...(resolvedTone ? { tone: resolvedTone } : {}),
|
|
534
|
+
...(resolvedAriaLabel ? { ariaLabel: resolvedAriaLabel } : {}),
|
|
535
|
+
...(valueSuffix ? { valueSuffix } : {}),
|
|
536
|
+
...(typeof value.compactValue === 'boolean' ? { compactValue: value.compactValue } : {}),
|
|
537
|
+
...(Object.prototype.hasOwnProperty.call(value, 'value') ? { value: value.value } : {}),
|
|
538
|
+
...(normalizeExpression(value.valueExpr, 'valueExpr') ?? {}),
|
|
539
|
+
...(normalizeExpression(value.valueSuffixExpr, 'valueSuffixExpr') ?? {}),
|
|
540
|
+
...(normalizeNumber(value.min, 'min') ?? {}),
|
|
541
|
+
...(normalizeExpression(value.minExpr, 'minExpr') ?? {}),
|
|
542
|
+
...(normalizeNumber(value.max, 'max') ?? {}),
|
|
543
|
+
...(normalizeExpression(value.maxExpr, 'maxExpr') ?? {}),
|
|
544
|
+
...(stacked.total !== undefined ? { total: stacked.total } : {}),
|
|
545
|
+
...(normalizeExpression(value.totalExpr, 'totalExpr') ?? {}),
|
|
546
|
+
...(normalizeNumber(value.target, 'target') ?? {}),
|
|
547
|
+
...(normalizeExpression(value.targetExpr, 'targetExpr') ?? {}),
|
|
548
|
+
...(normalizedTargetLabel ? { targetLabel: normalizedTargetLabel } : {}),
|
|
549
|
+
...(normalizeExpression(value.targetLabelExpr, 'targetLabelExpr') ?? {}),
|
|
550
|
+
...(normalizeNumber(value.baseline, 'baseline') ?? {}),
|
|
551
|
+
...(normalizeExpression(value.baselineExpr, 'baselineExpr') ?? {}),
|
|
552
|
+
...(normalizePoints(value.points) ?? {}),
|
|
553
|
+
...(normalizeExpression(value.pointsExpr, 'pointsExpr') ?? {}),
|
|
554
|
+
...(stacked.segments ? { segments: stacked.segments } : {}),
|
|
555
|
+
...(normalizeExpression(value.segmentsExpr, 'segmentsExpr') ?? {}),
|
|
556
|
+
...(normalizeThresholds(value.thresholds) ?? {}),
|
|
557
|
+
...(normalizeExpression(value.thresholdsExpr, 'thresholdsExpr') ?? {}),
|
|
558
|
+
...(stacked.items ? { items: stacked.items } : {}),
|
|
559
|
+
...(normalizeExpression(value.itemsExpr, 'itemsExpr') ?? {}),
|
|
560
|
+
...(normalizeExpression(value.toneExpr, 'toneExpr') ?? {}),
|
|
561
|
+
...(value.stepLabelWidth !== undefined && (typeof value.stepLabelWidth === 'number' || typeof value.stepLabelWidth === 'string')
|
|
562
|
+
? { stepLabelWidth: value.stepLabelWidth }
|
|
563
|
+
: {}),
|
|
564
|
+
...(typeof value.stepLabelLineClamp === 'number' && Number.isFinite(value.stepLabelLineClamp)
|
|
565
|
+
? { stepLabelLineClamp: value.stepLabelLineClamp }
|
|
566
|
+
: {}),
|
|
567
|
+
...(normalizeExpression(value.ariaLabelExpr, 'ariaLabelExpr') ?? {}),
|
|
568
|
+
...(normalizeExpression(value.fallbackTextExpr, 'fallbackTextExpr') ?? {}),
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
const normalizedTitle = isTableCell ? undefined : normalizeText$1(value.title);
|
|
572
|
+
const normalizedLegend = typeof value.legend === 'boolean' ? (isTableCell ? false : value.legend) : undefined;
|
|
260
573
|
return {
|
|
261
574
|
kind,
|
|
262
575
|
fallbackText,
|
|
263
576
|
...(surface ? { surface } : {}),
|
|
264
577
|
...(size ? { size } : {}),
|
|
265
578
|
...(scaleScope ? { scaleScope } : {}),
|
|
579
|
+
...(normalizedTitle ? { title: normalizedTitle } : {}),
|
|
580
|
+
...(normalizeExpression(value.titleExpr, 'titleExpr') ?? {}),
|
|
581
|
+
...(normalizedLegend !== undefined ? { legend: normalizedLegend } : {}),
|
|
266
582
|
...(resolvedTone ? { tone: resolvedTone } : {}),
|
|
267
583
|
...(resolvedAriaLabel ? { ariaLabel: resolvedAriaLabel } : {}),
|
|
268
584
|
...(valueSuffix ? { valueSuffix } : {}),
|
|
@@ -278,6 +594,8 @@ function normalizePraxisPresentationVisualization(value) {
|
|
|
278
594
|
...(normalizeExpression(value.totalExpr, 'totalExpr') ?? {}),
|
|
279
595
|
...(normalizeNumber(value.target, 'target') ?? {}),
|
|
280
596
|
...(normalizeExpression(value.targetExpr, 'targetExpr') ?? {}),
|
|
597
|
+
...(normalizedTargetLabel ? { targetLabel: normalizedTargetLabel } : {}),
|
|
598
|
+
...(normalizeExpression(value.targetLabelExpr, 'targetLabelExpr') ?? {}),
|
|
281
599
|
...(normalizeNumber(value.baseline, 'baseline') ?? {}),
|
|
282
600
|
...(normalizeExpression(value.baselineExpr, 'baselineExpr') ?? {}),
|
|
283
601
|
...(normalizePoints(value.points) ?? {}),
|
|
@@ -303,6 +621,55 @@ function isPraxisPresentationVisualizationTableSafe(value) {
|
|
|
303
621
|
const normalized = normalizePraxisPresentationVisualization(value);
|
|
304
622
|
return !!normalized && TABLE_SAFE_KINDS.has(normalized.kind);
|
|
305
623
|
}
|
|
624
|
+
function computeMicroSvgIdSuffix(visualization, options) {
|
|
625
|
+
const ptsKey = visualization.points
|
|
626
|
+
?.map((p) => `${p.label ?? ''}:${p.value}:${p.tone ?? ''}`)
|
|
627
|
+
.join(',') ?? '';
|
|
628
|
+
const seed = [
|
|
629
|
+
options.idPrefix ?? '',
|
|
630
|
+
visualization.kind,
|
|
631
|
+
visualization.surface ?? '',
|
|
632
|
+
visualization.tone ?? '',
|
|
633
|
+
String(visualization.value ?? ''),
|
|
634
|
+
String(visualization.total ?? ''),
|
|
635
|
+
String(visualization.target ?? ''),
|
|
636
|
+
visualization.fallbackText,
|
|
637
|
+
visualization.title ?? '',
|
|
638
|
+
ptsKey,
|
|
639
|
+
].join('|');
|
|
640
|
+
let hash = 0x811c9dc5;
|
|
641
|
+
for (let i = 0; i < seed.length; i++) {
|
|
642
|
+
hash ^= seed.charCodeAt(i);
|
|
643
|
+
hash = Math.imul(hash, 0x01000193);
|
|
644
|
+
}
|
|
645
|
+
return (hash >>> 0).toString(36);
|
|
646
|
+
}
|
|
647
|
+
function resolveTargetReferenceLabel(visualization, options) {
|
|
648
|
+
if (visualization.targetLabel) {
|
|
649
|
+
return visualization.targetLabel;
|
|
650
|
+
}
|
|
651
|
+
return options.locale?.toLowerCase().startsWith('pt') ? 'Meta' : 'Target';
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Returns a luminous 3-stop directional color ramp (`[highlight, mid, deep]`)
|
|
655
|
+
* for radial arcs, sector dials, and precision micro-visualizations.
|
|
656
|
+
*/
|
|
657
|
+
function getPraxisMicroToneGradientStops(tone) {
|
|
658
|
+
switch (tone) {
|
|
659
|
+
case 'success':
|
|
660
|
+
return ['#bef264', '#22c55e', '#15803d'];
|
|
661
|
+
case 'info':
|
|
662
|
+
return ['#93c5fd', '#3b82f6', '#3730a3'];
|
|
663
|
+
case 'warning':
|
|
664
|
+
return ['#fde047', '#f59e0b', '#b45309'];
|
|
665
|
+
case 'danger':
|
|
666
|
+
case 'critical':
|
|
667
|
+
return ['#fda4af', '#f43f5e', '#be123c'];
|
|
668
|
+
case 'neutral':
|
|
669
|
+
default:
|
|
670
|
+
return ['#cbd5e1', '#64748b', '#334155'];
|
|
671
|
+
}
|
|
672
|
+
}
|
|
306
673
|
function renderPraxisPresentationVisualizationHtml(value, options = {}) {
|
|
307
674
|
const visualization = normalizePraxisPresentationVisualization(value);
|
|
308
675
|
if (!visualization) {
|
|
@@ -358,7 +725,10 @@ function renderComparisonVisualizationHtml(visualization, options) {
|
|
|
358
725
|
.map((point) => {
|
|
359
726
|
const width = percent(point.value, max);
|
|
360
727
|
const formattedVal = formatVisualizationMetricValue(point.value, options, useCompact, suffix);
|
|
361
|
-
const
|
|
728
|
+
const alreadyPercent = (suffix.trim() === '%' || formattedVal.trim().endsWith('%')) && max === 100;
|
|
729
|
+
const readout = alreadyPercent
|
|
730
|
+
? `${point.label ? `${point.label}: ` : ''}${formattedVal}`
|
|
731
|
+
: `${point.label ? `${point.label}: ` : ''}${formattedVal} (${Math.round(Number(width))}%)`;
|
|
362
732
|
return `
|
|
363
733
|
<span class="pfx-micro-viz__row" data-tone="${escapeHtml(point.tone ?? visualization.tone ?? 'info')}" data-micro-readout="${escapeHtml(readout)}">
|
|
364
734
|
<span class="pfx-micro-viz__label">${escapeHtml(point.label ?? '')}</span>
|
|
@@ -372,40 +742,56 @@ function renderComparisonVisualizationHtml(visualization, options) {
|
|
|
372
742
|
return `<span class="pfx-micro-viz pfx-micro-viz__comparison" role="img" aria-label="${escapeHtml(visualization.ariaLabel ?? visualization.fallbackText)}">${rows}</span>`;
|
|
373
743
|
}
|
|
374
744
|
function renderStackedBarVisualizationHtml(visualization, options) {
|
|
375
|
-
const segments = visualization
|
|
376
|
-
? visualization.segments
|
|
377
|
-
: (visualization.items?.filter((item) => typeof item?.value === 'number' && Number.isFinite(item.value)) ?? []);
|
|
745
|
+
const segments = resolvePraxisStackedBarSegments(visualization);
|
|
378
746
|
if (segments.length === 0) {
|
|
379
747
|
return renderFallbackVisualizationHtml(visualization, visualization.tone ?? 'neutral');
|
|
380
748
|
}
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
: Math.max(1, segments.reduce((sum, segment) => sum + Math.max(0, segment.value), 0));
|
|
749
|
+
const isTable = visualization.surface === 'table-cell';
|
|
750
|
+
const resolvedTotal = resolvePraxisStackedBarTotal(segments, visualization.total);
|
|
384
751
|
const suffix = visualization.valueSuffix ?? '';
|
|
385
752
|
const useCompact = visualization.compactValue === true;
|
|
753
|
+
const fallbackTone = visualization.tone ?? 'neutral';
|
|
754
|
+
const aria = resolvePraxisStackedBarAriaLabel(visualization, segments, resolvedTotal, options.locale);
|
|
755
|
+
const buildSegmentReadout = (segment) => {
|
|
756
|
+
const formattedVal = formatVisualizationMetricValue(segment.value, options, useCompact, suffix);
|
|
757
|
+
const pctText = formatPraxisStackedBarPercentage(segment.value, resolvedTotal, options.locale);
|
|
758
|
+
const alreadyPercent = suffix.trim() === '%' || formattedVal.trim().endsWith('%');
|
|
759
|
+
const metricPart = alreadyPercent ? formattedVal : `${formattedVal} (${pctText})`;
|
|
760
|
+
return segment.label ? `${segment.label}: ${metricPart}` : metricPart;
|
|
761
|
+
};
|
|
386
762
|
const bars = segments
|
|
387
763
|
.map((segment) => {
|
|
388
|
-
const
|
|
389
|
-
const
|
|
390
|
-
const
|
|
764
|
+
const widthPct = computePraxisStackedBarSegmentWidthPct(segment.value, resolvedTotal);
|
|
765
|
+
const isZero = segment.value === 0 || widthPct === 0;
|
|
766
|
+
const paint = getPraxisStackedBarPaintStyle(segment, fallbackTone);
|
|
767
|
+
const paintCss = `--prx-micro-category-color:${paint['--prx-micro-category-color']};color:${paint['color']}`;
|
|
768
|
+
const readout = buildSegmentReadout(segment);
|
|
391
769
|
return `
|
|
392
770
|
<span
|
|
393
771
|
class="pfx-micro-viz__segment"
|
|
394
|
-
data-tone="${escapeHtml(segment.tone ??
|
|
772
|
+
data-tone="${escapeHtml(segment.tone ?? fallbackTone)}"${isZero ? '\n data-zero="true"' : ''}
|
|
395
773
|
data-micro-readout="${escapeHtml(readout)}"
|
|
396
|
-
style="width:${
|
|
397
|
-
title="${escapeHtml(`${segment.label ?? ''} ${formattedVal}`.trim())}"
|
|
774
|
+
style="width:${widthPct}%;${escapeHtml(paintCss)}"
|
|
398
775
|
></span>`;
|
|
399
776
|
})
|
|
400
777
|
.join('');
|
|
401
|
-
const
|
|
402
|
-
.
|
|
403
|
-
|
|
404
|
-
|
|
778
|
+
const titleHtml = !isTable && visualization.title
|
|
779
|
+
? `\n <span class="pfx-micro-viz__title">${escapeHtml(visualization.title)}</span>`
|
|
780
|
+
: '';
|
|
781
|
+
const legendHtml = !isTable && visualization.legend === true
|
|
782
|
+
? `\n <span class="pfx-micro-viz__legend" role="list">${segments
|
|
783
|
+
.map((segment) => {
|
|
784
|
+
const paint = getPraxisStackedBarPaintStyle(segment, fallbackTone);
|
|
785
|
+
const paintCss = `--prx-micro-category-color:${paint['--prx-micro-category-color']};color:${paint['color']}`;
|
|
786
|
+
const pctText = formatPraxisStackedBarPercentage(segment.value, resolvedTotal, options.locale);
|
|
787
|
+
const readout = buildSegmentReadout(segment);
|
|
788
|
+
return `<span class="pfx-micro-viz__legend-item" role="listitem" data-micro-readout="${escapeHtml(readout)}"><span class="pfx-micro-viz__legend-swatch" style="${escapeHtml(paintCss)}" aria-hidden="true"></span><span class="pfx-micro-viz__legend-label">${escapeHtml(segment.label ?? '')}</span><span class="pfx-micro-viz__legend-value">${escapeHtml(pctText)}</span></span>`;
|
|
789
|
+
})
|
|
790
|
+
.join('')}</span>`
|
|
791
|
+
: '';
|
|
405
792
|
return `
|
|
406
|
-
<span class="pfx-micro-viz pfx-micro-viz__stacked" role="img" aria-label="${escapeHtml(
|
|
407
|
-
<span class="pfx-micro-viz__segments">${bars}</span
|
|
408
|
-
<span class="pfx-micro-viz__meta">${meta}</span>
|
|
793
|
+
<span class="pfx-micro-viz pfx-micro-viz__stacked" role="img" aria-label="${escapeHtml(aria)}">${titleHtml}
|
|
794
|
+
<span class="pfx-micro-viz__segments">${bars}</span>${legendHtml}
|
|
409
795
|
</span>`;
|
|
410
796
|
}
|
|
411
797
|
function resolveBulletMax(visualization) {
|
|
@@ -454,13 +840,22 @@ function renderBulletVisualizationHtml(visualization, options) {
|
|
|
454
840
|
return { left, width, tone: t.tone ?? 'info' };
|
|
455
841
|
}).filter(b => parseFloat(b.width) > 0);
|
|
456
842
|
const bandsHtml = bands.map(b => `<span class="pfx-micro-bullet__range" data-tone="${escapeHtml(b.tone)}" style="left: ${b.left}%; width: ${b.width}%;"></span>`).join('');
|
|
843
|
+
const bandsLayerHtml = bandsHtml
|
|
844
|
+
? `<span class="pfx-micro-bullet__bands">${bandsHtml}</span>`
|
|
845
|
+
: '';
|
|
846
|
+
const targetLabel = resolveTargetReferenceLabel(visualization, options);
|
|
847
|
+
const topMetricHtml = visualization.compactValue === false
|
|
848
|
+
? target === undefined
|
|
849
|
+
? ''
|
|
850
|
+
: `<span class="pfx-micro-bullet__target-val">${escapeHtml(targetLabel)}: ${escapeHtml(formatVisualizationMetricValue(target, options, false, suffix))}</span>`
|
|
851
|
+
: `<span class="pfx-micro-bullet__value">
|
|
852
|
+
${escapeHtml(formatVisualizationMetricValue(currentValue, options, false, suffix))}
|
|
853
|
+
${target === undefined ? '' : `<span class="pfx-micro-bullet__target-val">/ ${escapeHtml(targetLabel)}: ${escapeHtml(formatVisualizationMetricValue(target, options, false, suffix))}</span>`}
|
|
854
|
+
</span>`;
|
|
457
855
|
const topHtml = isTable ? '' : `
|
|
458
856
|
<div class="pfx-micro-bullet__top">
|
|
459
|
-
<span class="pfx-micro-bullet__label">${escapeHtml(visualization.fallbackText)}</span>
|
|
460
|
-
|
|
461
|
-
${escapeHtml(formatVisualizationMetricValue(currentValue, options, false, suffix))}
|
|
462
|
-
${target === undefined ? '' : `<span class="pfx-micro-bullet__target-val">/ Target: ${escapeHtml(formatVisualizationMetricValue(target, options, false, suffix))}</span>`}
|
|
463
|
-
</span>
|
|
857
|
+
<span class="pfx-micro-bullet__label">${escapeHtml(visualization.title || visualization.fallbackText)}</span>
|
|
858
|
+
${topMetricHtml}
|
|
464
859
|
</div>`;
|
|
465
860
|
const bottomHtml = isTable ? '' : `
|
|
466
861
|
<div class="pfx-micro-bullet__bottom">
|
|
@@ -476,14 +871,15 @@ function renderBulletVisualizationHtml(visualization, options) {
|
|
|
476
871
|
const diff = target !== undefined ? currentValue - target : undefined;
|
|
477
872
|
const diffSign = diff !== undefined && diff > 0 ? '+' : '';
|
|
478
873
|
const bulletReadout = target !== undefined && diff !== undefined
|
|
479
|
-
? `${currentStr} /
|
|
874
|
+
? `${currentStr} / ${targetLabel} ${formatVisualizationMetricValue(target, options, false, suffix)} (${diffSign}${formatVisualizationMetricValue(diff, options, false, suffix)})`
|
|
480
875
|
: `${currentStr} / ${formatVisualizationMetricValue(max, options, false, suffix)}`;
|
|
481
|
-
const
|
|
876
|
+
const suppressTabIndex = isTable || options.interactiveContainer === true;
|
|
877
|
+
const tabIndexAttr = suppressTabIndex ? '' : ' tabindex="0"';
|
|
482
878
|
return `
|
|
483
879
|
<span class="pfx-micro-viz pfx-micro-viz__bullet"${tabIndexAttr} data-tone="${escapeHtml(visualization.tone ?? 'info')}" data-micro-readout="${escapeHtml(bulletReadout)}" role="img" aria-label="${escapeHtml(visualization.ariaLabel ?? visualization.fallbackText)}">
|
|
484
880
|
${topHtml}
|
|
485
881
|
<span class="pfx-micro-bullet__track">
|
|
486
|
-
${
|
|
882
|
+
${bandsLayerHtml}
|
|
487
883
|
<span class="pfx-micro-bullet__actual" data-tone="${escapeHtml(visualization.tone ?? 'info')}" style="width: ${percent(currentValue, max)}%;"></span>
|
|
488
884
|
${targetLeft === null ? '' : `<span class="pfx-micro-bullet__target" style="left: ${targetLeft}%;"></span>`}
|
|
489
885
|
</span>
|
|
@@ -516,13 +912,15 @@ function renderDeltaVisualizationHtml(visualization, options) {
|
|
|
516
912
|
const target = toFiniteNumber(visualization.target);
|
|
517
913
|
const baseline = toFiniteNumber(visualization.baseline);
|
|
518
914
|
const isTable = visualization.surface === 'table-cell';
|
|
915
|
+
const suppressTabIndex = isTable || options.interactiveContainer === true;
|
|
916
|
+
const targetLabel = resolveTargetReferenceLabel(visualization, options);
|
|
519
917
|
const deltaReadout = target !== undefined
|
|
520
|
-
?
|
|
918
|
+
? `${targetLabel} ${formatVisualizationMetricValue(target, options, false, valueSuffix)}`
|
|
521
919
|
: baseline !== undefined
|
|
522
920
|
? `Base ${formatVisualizationMetricValue(baseline, options, false, valueSuffix)}`
|
|
523
921
|
: null;
|
|
524
922
|
const readoutAttr = deltaReadout
|
|
525
|
-
? `${
|
|
923
|
+
? `${suppressTabIndex ? '' : ' tabindex="0"'} data-micro-readout="${escapeHtml(deltaReadout)}"`
|
|
526
924
|
: '';
|
|
527
925
|
return `
|
|
528
926
|
<span class="pfx-micro-viz pfx-micro-viz__delta" data-tone="${escapeHtml(tone)}" data-direction="${escapeHtml(direction)}"${readoutAttr} role="img" aria-label="${escapeHtml(aria)}">
|
|
@@ -567,8 +965,10 @@ function formatMicroNumber(value, locale, compactValue = false) {
|
|
|
567
965
|
maximumFractionDigits: 1,
|
|
568
966
|
}).format(value);
|
|
569
967
|
}
|
|
968
|
+
const abs = Math.abs(value);
|
|
969
|
+
const hasFraction = Math.abs(value - Math.trunc(value)) > 1e-6;
|
|
570
970
|
return new Intl.NumberFormat(locale || undefined, {
|
|
571
|
-
maximumFractionDigits:
|
|
971
|
+
maximumFractionDigits: abs < 10 ? 2 : hasFraction && abs < 1000 ? 1 : 0,
|
|
572
972
|
}).format(value);
|
|
573
973
|
}
|
|
574
974
|
function escapeHtml(value) {
|
|
@@ -654,10 +1054,12 @@ function normalizeNumericEntries(value) {
|
|
|
654
1054
|
}
|
|
655
1055
|
const label = normalizeText$1(item.label);
|
|
656
1056
|
const tone = normalizeEnum$1(item.tone, VISUALIZATION_TONES);
|
|
1057
|
+
const color = normalizePraxisHexColor(item.color);
|
|
657
1058
|
return {
|
|
658
1059
|
value: num,
|
|
659
1060
|
...(label ? { label } : {}),
|
|
660
1061
|
...(tone ? { tone } : {}),
|
|
1062
|
+
...(color ? { color } : {}),
|
|
661
1063
|
};
|
|
662
1064
|
})
|
|
663
1065
|
.filter((item) => !!item);
|
|
@@ -671,8 +1073,9 @@ function normalizeVisualizationItem(item) {
|
|
|
671
1073
|
const icon = normalizeText$1(item.icon);
|
|
672
1074
|
const state = normalizeText$1(item.state);
|
|
673
1075
|
const tone = normalizeEnum$1(item.tone, VISUALIZATION_TONES);
|
|
1076
|
+
const color = normalizePraxisHexColor(item.color);
|
|
674
1077
|
const normalizedValue = toFiniteNumber(item.value);
|
|
675
|
-
if (!id && !label && normalizedValue === undefined && !icon && !state && !tone) {
|
|
1078
|
+
if (!id && !label && normalizedValue === undefined && !icon && !state && !tone && !color) {
|
|
676
1079
|
return null;
|
|
677
1080
|
}
|
|
678
1081
|
return {
|
|
@@ -682,6 +1085,7 @@ function normalizeVisualizationItem(item) {
|
|
|
682
1085
|
...(icon ? { icon } : {}),
|
|
683
1086
|
...(state ? { state } : {}),
|
|
684
1087
|
...(tone ? { tone } : {}),
|
|
1088
|
+
...(color ? { color } : {}),
|
|
685
1089
|
};
|
|
686
1090
|
}
|
|
687
1091
|
function normalizeNumber(value, key) {
|
|
@@ -708,26 +1112,62 @@ function renderRadialVisualizationHtml(visualization, options) {
|
|
|
708
1112
|
return renderFallbackVisualizationHtml(visualization, visualization.tone ?? 'neutral');
|
|
709
1113
|
}
|
|
710
1114
|
const total = visualization.total && visualization.total > 0 ? visualization.total : 100;
|
|
711
|
-
const
|
|
1115
|
+
const rawPct = Math.max(0, (value / total) * 100);
|
|
1116
|
+
const arcPct = Math.min(100, rawPct);
|
|
712
1117
|
const tone = visualization.tone ?? 'info';
|
|
713
1118
|
const suffix = visualization.valueSuffix ?? '';
|
|
714
|
-
const dashArray = `${
|
|
715
|
-
const
|
|
1119
|
+
const dashArray = `${arcPct.toFixed(1)}, 100`;
|
|
1120
|
+
const hasFractionalPct = rawPct < 100 && Math.abs(rawPct - Math.round(rawPct)) >= 0.05;
|
|
1121
|
+
const displayPctNum = hasFractionalPct ? Number(rawPct.toFixed(1)) : Math.round(rawPct);
|
|
1122
|
+
const radialNumStr = formatMicroNumber(displayPctNum, options.locale, false);
|
|
1123
|
+
const pctText = `${radialNumStr}%`;
|
|
716
1124
|
const aria = visualization.ariaLabel ?? `${visualization.fallbackText} (${pctText})`;
|
|
717
1125
|
const isTable = visualization.surface === 'table-cell';
|
|
1126
|
+
const isZero = rawPct <= 0;
|
|
1127
|
+
const svgSuffix = computeMicroSvgIdSuffix(visualization, options);
|
|
1128
|
+
const gradId = `pfx-rad-grad-${tone}-${svgSuffix}`;
|
|
1129
|
+
const [stop0, stop1, stop2] = getPraxisMicroToneGradientStops(tone);
|
|
1130
|
+
const targetVal = toFiniteNumber(visualization.target);
|
|
1131
|
+
const targetPct = targetVal !== undefined && targetVal > 0
|
|
1132
|
+
? Math.max(0, Math.min(100, (targetVal / total) * 100))
|
|
1133
|
+
: null;
|
|
1134
|
+
const targetArcHtml = targetPct !== null
|
|
1135
|
+
? `<circle class="pfx-micro-radial-svg__target-arc" cx="18" cy="18" r="13.5" pathLength="100" stroke-dasharray="${targetPct.toFixed(1)}, 100" transform="rotate(-90 18 18)" />`
|
|
1136
|
+
: '';
|
|
1137
|
+
const digitTierAttr = radialNumStr.length >= 4
|
|
1138
|
+
? ' data-digits="4"'
|
|
1139
|
+
: radialNumStr.length === 3
|
|
1140
|
+
? ' data-digits="3"'
|
|
1141
|
+
: '';
|
|
718
1142
|
const svgText = isTable
|
|
719
1143
|
? ''
|
|
720
|
-
: `<text x="18" y="
|
|
1144
|
+
: `<text x="18" y="20.6" class="pfx-micro-radial-svg__text"${digitTierAttr}><tspan class="pfx-micro-radial-svg__num">${escapeHtml(radialNumStr)}</tspan><tspan class="pfx-micro-radial-svg__unit">%</tspan></text>`;
|
|
721
1145
|
const externalText = isTable
|
|
722
1146
|
? `<span class="pfx-micro-radial-value">${escapeHtml(pctText)}</span>`
|
|
723
1147
|
: '';
|
|
724
|
-
const
|
|
725
|
-
const
|
|
1148
|
+
const formattedVal = formatVisualizationMetricValue(value, options, false, suffix);
|
|
1149
|
+
const formattedTotal = formatVisualizationMetricValue(total, options, false, suffix);
|
|
1150
|
+
const alreadyPercent = (suffix.trim() === '%' || formattedVal.trim().endsWith('%')) && total === 100;
|
|
1151
|
+
const radialReadout = alreadyPercent
|
|
1152
|
+
? formattedVal
|
|
1153
|
+
: `${formattedVal} / ${formattedTotal} (${pctText})`;
|
|
1154
|
+
const suppressTabIndex = isTable || options.interactiveContainer === true;
|
|
1155
|
+
const tabIndexAttr = suppressTabIndex ? '' : ' tabindex="0"';
|
|
726
1156
|
return `
|
|
727
1157
|
<span class="pfx-micro-viz pfx-micro-viz__radial"${tabIndexAttr} data-tone="${escapeHtml(tone)}" data-micro-readout="${escapeHtml(radialReadout)}" role="img" aria-label="${escapeHtml(aria)}">
|
|
728
1158
|
<svg class="pfx-micro-radial-svg" viewBox="0 0 36 36">
|
|
729
|
-
<
|
|
730
|
-
|
|
1159
|
+
<defs>
|
|
1160
|
+
<linearGradient id="${escapeHtml(gradId)}" x1="100%" y1="55%" x2="10%" y2="15%">
|
|
1161
|
+
<stop offset="0%" stop-color="${stop0}" />
|
|
1162
|
+
<stop offset="52%" stop-color="${stop1}" />
|
|
1163
|
+
<stop offset="100%" stop-color="${stop2}" />
|
|
1164
|
+
</linearGradient>
|
|
1165
|
+
</defs>
|
|
1166
|
+
<circle class="pfx-micro-radial-svg__bezel" cx="18" cy="18" r="17" />
|
|
1167
|
+
<circle class="pfx-micro-radial-svg__track" cx="18" cy="18" r="13.5" pathLength="100" />
|
|
1168
|
+
${targetArcHtml}
|
|
1169
|
+
<circle class="pfx-micro-radial-svg__bar" cx="18" cy="18" r="13.5" pathLength="100"${isZero ? ' data-zero="true"' : ''} stroke="url(#${escapeHtml(gradId)})" stroke-dasharray="${dashArray}" transform="rotate(-90 18 18)" />
|
|
1170
|
+
<circle class="pfx-micro-radial-svg__medallion" cx="18" cy="18" r="9.8" />
|
|
731
1171
|
${svgText}
|
|
732
1172
|
</svg>
|
|
733
1173
|
${externalText}
|
|
@@ -739,28 +1179,47 @@ function renderHarveyBallVisualizationHtml(visualization, options) {
|
|
|
739
1179
|
return renderFallbackVisualizationHtml(visualization, visualization.tone ?? 'neutral');
|
|
740
1180
|
}
|
|
741
1181
|
const total = visualization.total && visualization.total > 0 ? visualization.total : 100;
|
|
742
|
-
const
|
|
1182
|
+
const rawPct = Math.max(0, (value / total) * 100);
|
|
1183
|
+
const arcPct = Math.min(100, rawPct);
|
|
743
1184
|
const tone = visualization.tone ?? 'info';
|
|
744
1185
|
const isTable = visualization.surface === 'table-cell';
|
|
745
|
-
const
|
|
1186
|
+
const suppressTabIndex = isTable || options.interactiveContainer === true;
|
|
1187
|
+
const tabIndexAttr = suppressTabIndex ? '' : ' tabindex="0"';
|
|
746
1188
|
const suffix = visualization.valueSuffix ?? '';
|
|
747
|
-
const
|
|
748
|
-
const
|
|
749
|
-
const
|
|
1189
|
+
const isZero = rawPct <= 0;
|
|
1190
|
+
const svgSuffix = computeMicroSvgIdSuffix(visualization, options);
|
|
1191
|
+
const gradId = `pfx-harvey-grad-${tone}-${svgSuffix}`;
|
|
1192
|
+
const [stop0, stop1, stop2] = getPraxisMicroToneGradientStops(tone);
|
|
1193
|
+
const dashArray = `${arcPct.toFixed(2)} 100`;
|
|
1194
|
+
const roundedPct = Math.round(rawPct);
|
|
1195
|
+
const aria = visualization.ariaLabel ?? `${visualization.fallbackText} (${roundedPct}%)`;
|
|
750
1196
|
const formattedValue = formatVisualizationMetricValue(value, options, false, suffix);
|
|
751
1197
|
const formattedTotal = formatVisualizationMetricValue(total, options, false, suffix);
|
|
752
|
-
const harveyReadout = `${formattedValue}/${formattedTotal} (${
|
|
1198
|
+
const harveyReadout = `${formattedValue}/${formattedTotal} (${roundedPct}%)`;
|
|
1199
|
+
const pctBadgeHtml = isTable
|
|
1200
|
+
? ''
|
|
1201
|
+
: `<span class="pfx-micro-harvey-pct">${roundedPct}%</span>`;
|
|
753
1202
|
return `
|
|
754
1203
|
<span class="pfx-micro-viz pfx-micro-viz__harvey"${tabIndexAttr} data-tone="${escapeHtml(tone)}" data-micro-readout="${escapeHtml(harveyReadout)}" role="img" aria-label="${escapeHtml(aria)}">
|
|
755
1204
|
<svg class="pfx-micro-harvey-svg" viewBox="0 0 36 36">
|
|
756
|
-
<
|
|
757
|
-
|
|
1205
|
+
<defs>
|
|
1206
|
+
<linearGradient id="${escapeHtml(gradId)}" x1="15%" y1="10%" x2="85%" y2="90%">
|
|
1207
|
+
<stop offset="0%" stop-color="${stop0}" />
|
|
1208
|
+
<stop offset="52%" stop-color="${stop1}" />
|
|
1209
|
+
<stop offset="100%" stop-color="${stop2}" />
|
|
1210
|
+
</linearGradient>
|
|
1211
|
+
</defs>
|
|
1212
|
+
<circle class="pfx-micro-harvey-svg__bezel" cx="18" cy="18" r="16.8" />
|
|
1213
|
+
<circle class="pfx-micro-harvey-svg__track" cx="18" cy="18" r="14" />
|
|
1214
|
+
<circle class="pfx-micro-harvey-svg__bar" cx="18" cy="18" r="7" pathLength="100"${isZero ? ' data-zero="true"' : ''} stroke="url(#${escapeHtml(gradId)})" stroke-dasharray="${dashArray}" transform="rotate(-90 18 18)" />
|
|
1215
|
+
<circle class="pfx-micro-harvey-svg__pin" cx="18" cy="18" r="1.8" />
|
|
758
1216
|
</svg>
|
|
759
1217
|
<span class="pfx-micro-harvey-fraction">
|
|
760
1218
|
<strong>${escapeHtml(formattedValue)}</strong>
|
|
761
1219
|
<span class="pfx-separator">/</span>
|
|
762
1220
|
<span class="pfx-total">${escapeHtml(formattedTotal)}</span>
|
|
763
1221
|
</span>
|
|
1222
|
+
${pctBadgeHtml}
|
|
764
1223
|
</span>`;
|
|
765
1224
|
}
|
|
766
1225
|
function resolveTrendBounds(points, visualization, anchorZero = false) {
|
|
@@ -825,6 +1284,11 @@ function renderLineVisualizationHtml(visualization, options) {
|
|
|
825
1284
|
const padding = 4;
|
|
826
1285
|
const coords = getPointsCoordinates(points, width, height, padding, visualization);
|
|
827
1286
|
const pathD = coords.map((c, i) => `${i === 0 ? 'M' : 'L'} ${c.x.toFixed(1)} ${c.y.toFixed(1)}`).join(' ');
|
|
1287
|
+
const firstX = coords[0].x.toFixed(1);
|
|
1288
|
+
const lastCoord = coords[coords.length - 1];
|
|
1289
|
+
const lastX = lastCoord.x.toFixed(1);
|
|
1290
|
+
const glowAreaD = `${pathD} L ${lastX} ${height} L ${firstX} ${height} Z`;
|
|
1291
|
+
const glowGradId = `pfx-line-glow-${tone}-${computeMicroSvgIdSuffix(visualization, options)}`;
|
|
828
1292
|
const refLineHtml = renderTrendReferenceLineHtml(points, width, height, padding, visualization, false);
|
|
829
1293
|
// Highlight extreme/boundary values
|
|
830
1294
|
let minIdx = 0;
|
|
@@ -835,9 +1299,10 @@ function renderLineVisualizationHtml(visualization, options) {
|
|
|
835
1299
|
if (points[i].value > points[maxIdx].value)
|
|
836
1300
|
maxIdx = i;
|
|
837
1301
|
}
|
|
1302
|
+
const lastTone = points[points.length - 1].tone ?? tone;
|
|
838
1303
|
const markers = [
|
|
839
1304
|
{ x: coords[0].x, y: coords[0].y, tone: points[0].tone ?? tone },
|
|
840
|
-
{ x:
|
|
1305
|
+
{ x: lastCoord.x, y: lastCoord.y, tone: lastTone }
|
|
841
1306
|
];
|
|
842
1307
|
if (minIdx !== 0 && minIdx !== coords.length - 1) {
|
|
843
1308
|
markers.push({ x: coords[minIdx].x, y: coords[minIdx].y, tone: points[minIdx].tone ?? 'danger' });
|
|
@@ -845,6 +1310,7 @@ function renderLineVisualizationHtml(visualization, options) {
|
|
|
845
1310
|
if (maxIdx !== 0 && maxIdx !== coords.length - 1) {
|
|
846
1311
|
markers.push({ x: coords[maxIdx].x, y: coords[maxIdx].y, tone: points[maxIdx].tone ?? 'success' });
|
|
847
1312
|
}
|
|
1313
|
+
const endpointHaloHtml = `<circle cx="${lastCoord.x.toFixed(1)}" cy="${lastCoord.y.toFixed(1)}" r="5" class="pfx-micro-trend__endpoint-halo" data-tone="${escapeHtml(lastTone)}" />`;
|
|
848
1314
|
const circlesHtml = markers.map(c => `<circle cx="${c.x.toFixed(1)}" cy="${c.y.toFixed(1)}" r="2.5" class="pfx-micro-trend__marker" data-tone="${escapeHtml(c.tone)}" />`).join('');
|
|
849
1315
|
const scrubLayerHtml = renderTrendScrubLayerHtml(points, coords, width, height, visualization, options);
|
|
850
1316
|
const isTable = visualization.surface === 'table-cell';
|
|
@@ -866,8 +1332,16 @@ function renderLineVisualizationHtml(visualization, options) {
|
|
|
866
1332
|
${leftHtml}
|
|
867
1333
|
<span class="pfx-micro-viz pfx-micro-viz__line" data-tone="${escapeHtml(tone)}" role="img" aria-label="${escapeHtml(visualization.ariaLabel ?? visualization.fallbackText)}">
|
|
868
1334
|
<svg class="pfx-micro-line__svg" viewBox="0 0 100 30">
|
|
1335
|
+
<defs>
|
|
1336
|
+
<linearGradient id="${escapeHtml(glowGradId)}" x1="0%" y1="0%" x2="0%" y2="100%">
|
|
1337
|
+
<stop offset="0%" stop-color="currentColor" stop-opacity="0.16" />
|
|
1338
|
+
<stop offset="100%" stop-color="currentColor" stop-opacity="0" />
|
|
1339
|
+
</linearGradient>
|
|
1340
|
+
</defs>
|
|
869
1341
|
${refLineHtml}
|
|
870
|
-
<path class="pfx-micro-
|
|
1342
|
+
<path class="pfx-micro-line__glow" d="${glowAreaD}" fill="url(#${escapeHtml(glowGradId)})" />
|
|
1343
|
+
<path class="pfx-micro-line__path" d="${pathD}" fill="none" stroke="currentColor" stroke-width="2.1" stroke-linecap="round" stroke-linejoin="round" />
|
|
1344
|
+
${endpointHaloHtml}
|
|
871
1345
|
${circlesHtml}
|
|
872
1346
|
</svg>
|
|
873
1347
|
${scrubLayerHtml}
|
|
@@ -888,8 +1362,10 @@ function renderAreaVisualizationHtml(visualization, options) {
|
|
|
888
1362
|
const lineD = coords.map((c, i) => `${i === 0 ? 'M' : 'L'} ${c.x.toFixed(1)} ${c.y.toFixed(1)}`).join(' ');
|
|
889
1363
|
const refLineHtml = renderTrendReferenceLineHtml(points, width, height, padding, visualization, false);
|
|
890
1364
|
const firstX = coords[0].x.toFixed(1);
|
|
891
|
-
const
|
|
1365
|
+
const lastCoord = coords[coords.length - 1];
|
|
1366
|
+
const lastX = lastCoord.x.toFixed(1);
|
|
892
1367
|
const areaD = `${lineD} L ${lastX} ${height} L ${firstX} ${height} Z`;
|
|
1368
|
+
const areaGradId = `pfx-area-grad-${tone}-${computeMicroSvgIdSuffix(visualization, options)}`;
|
|
893
1369
|
// Highlight extreme/boundary values
|
|
894
1370
|
let minIdx = 0;
|
|
895
1371
|
let maxIdx = 0;
|
|
@@ -899,9 +1375,10 @@ function renderAreaVisualizationHtml(visualization, options) {
|
|
|
899
1375
|
if (points[i].value > points[maxIdx].value)
|
|
900
1376
|
maxIdx = i;
|
|
901
1377
|
}
|
|
1378
|
+
const lastTone = points[points.length - 1].tone ?? tone;
|
|
902
1379
|
const markers = [
|
|
903
1380
|
{ x: coords[0].x, y: coords[0].y, tone: points[0].tone ?? tone },
|
|
904
|
-
{ x:
|
|
1381
|
+
{ x: lastCoord.x, y: lastCoord.y, tone: lastTone }
|
|
905
1382
|
];
|
|
906
1383
|
if (minIdx !== 0 && minIdx !== coords.length - 1) {
|
|
907
1384
|
markers.push({ x: coords[minIdx].x, y: coords[minIdx].y, tone: points[minIdx].tone ?? 'danger' });
|
|
@@ -909,6 +1386,7 @@ function renderAreaVisualizationHtml(visualization, options) {
|
|
|
909
1386
|
if (maxIdx !== 0 && maxIdx !== coords.length - 1) {
|
|
910
1387
|
markers.push({ x: coords[maxIdx].x, y: coords[maxIdx].y, tone: points[maxIdx].tone ?? 'success' });
|
|
911
1388
|
}
|
|
1389
|
+
const endpointHaloHtml = `<circle cx="${lastCoord.x.toFixed(1)}" cy="${lastCoord.y.toFixed(1)}" r="5" class="pfx-micro-trend__endpoint-halo" data-tone="${escapeHtml(lastTone)}" />`;
|
|
912
1390
|
const circlesHtml = markers.map(c => `<circle cx="${c.x.toFixed(1)}" cy="${c.y.toFixed(1)}" r="2.5" class="pfx-micro-trend__marker" data-tone="${escapeHtml(c.tone)}" />`).join('');
|
|
913
1391
|
const scrubLayerHtml = renderTrendScrubLayerHtml(points, coords, width, height, visualization, options);
|
|
914
1392
|
const isTable = visualization.surface === 'table-cell';
|
|
@@ -930,9 +1408,16 @@ function renderAreaVisualizationHtml(visualization, options) {
|
|
|
930
1408
|
${leftHtml}
|
|
931
1409
|
<span class="pfx-micro-viz pfx-micro-viz__area" data-tone="${escapeHtml(tone)}" role="img" aria-label="${escapeHtml(visualization.ariaLabel ?? visualization.fallbackText)}">
|
|
932
1410
|
<svg class="pfx-micro-area__svg" viewBox="0 0 100 30">
|
|
1411
|
+
<defs>
|
|
1412
|
+
<linearGradient id="${escapeHtml(areaGradId)}" x1="0%" y1="0%" x2="0%" y2="100%">
|
|
1413
|
+
<stop offset="0%" stop-color="currentColor" stop-opacity="0.32" />
|
|
1414
|
+
<stop offset="100%" stop-color="currentColor" stop-opacity="0.02" />
|
|
1415
|
+
</linearGradient>
|
|
1416
|
+
</defs>
|
|
933
1417
|
${refLineHtml}
|
|
934
|
-
<path class="pfx-micro-area__fill" d="${areaD}" fill="
|
|
935
|
-
<path class="pfx-micro-area__path" d="${lineD}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
|
|
1418
|
+
<path class="pfx-micro-area__fill" d="${areaD}" fill="url(#${escapeHtml(areaGradId)})" />
|
|
1419
|
+
<path class="pfx-micro-area__path" d="${lineD}" fill="none" stroke="currentColor" stroke-width="2.1" stroke-linecap="round" stroke-linejoin="round" />
|
|
1420
|
+
${endpointHaloHtml}
|
|
936
1421
|
${circlesHtml}
|
|
937
1422
|
</svg>
|
|
938
1423
|
${scrubLayerHtml}
|
|
@@ -962,7 +1447,8 @@ function renderColumnVisualizationHtml(visualization, options) {
|
|
|
962
1447
|
(visualization.thresholds?.length
|
|
963
1448
|
? resolvePraxisMicroVisualizationTone(p.value, visualization.thresholds)?.tone ?? tone
|
|
964
1449
|
: tone);
|
|
965
|
-
|
|
1450
|
+
const latestAttr = i === points.length - 1 ? ' data-latest="true"' : '';
|
|
1451
|
+
return `<rect class="pfx-micro-column__bar" x="${x.toFixed(1)}" y="${rectY.toFixed(1)}" width="${colWidth.toFixed(1)}" height="${rectHeight.toFixed(1)}" rx="2" fill="currentColor" data-tone="${escapeHtml(itemTone)}"${latestAttr} />`;
|
|
966
1452
|
}).join('');
|
|
967
1453
|
const scrubLayerHtml = renderTrendScrubLayerHtml(points, colCoords, width, height, visualization, options);
|
|
968
1454
|
const isTable = visualization.surface === 'table-cell';
|
|
@@ -1297,13 +1783,17 @@ function resolveFieldQuickViewBinding(candidate) {
|
|
|
1297
1783
|
candidate.optionSource.valuePropertyPath.trim().length > 0
|
|
1298
1784
|
? candidate.optionSource.valuePropertyPath.trim()
|
|
1299
1785
|
: 'id';
|
|
1300
|
-
// Quando o campo possui optionSource e seu nome não
|
|
1301
|
-
// optionValueProperty (
|
|
1302
|
-
// campo irmão
|
|
1786
|
+
// Quando o campo possui optionSource e seu nome não coincide com rawValueField, um valueField
|
|
1787
|
+
// igual a 'id'/'value'/'key' ou a optionValueProperty (ex.: 'numero', 'codigo') refere-se à
|
|
1788
|
+
// chave do OptionDTO e nunca ao campo irmão 'id' do registro pai.
|
|
1789
|
+
const isOptionKeyAlias = rawValueField === 'id' ||
|
|
1790
|
+
rawValueField === 'value' ||
|
|
1791
|
+
rawValueField === 'key' ||
|
|
1792
|
+
rawValueField === optionValueProperty;
|
|
1303
1793
|
const effectiveSiblingValueField = rawValueField &&
|
|
1304
1794
|
(!candidate.optionSource ||
|
|
1305
|
-
fieldName ===
|
|
1306
|
-
|
|
1795
|
+
fieldName === rawValueField ||
|
|
1796
|
+
!isOptionKeyAlias)
|
|
1307
1797
|
? rawValueField
|
|
1308
1798
|
: '';
|
|
1309
1799
|
const refCandidate = candidate.resourceReference?.resourceKey
|