@opendata-ai/openchart-engine 9.2.3 → 9.3.0
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/dist/index.js +30 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -31472,6 +31472,9 @@ import {
|
|
|
31472
31472
|
formatDate as formatDate8,
|
|
31473
31473
|
resolveNumberFormatter as resolveNumberFormatter6
|
|
31474
31474
|
} from "@opendata-ai/openchart-core";
|
|
31475
|
+
import { utcFormat as utcFormat3 } from "d3-time-format";
|
|
31476
|
+
var TIME_DIRECTIVE = /%/;
|
|
31477
|
+
var ISO_8601 = /^(\d{4})-(\d{2})-(\d{2})(T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[+-]\d{2}:?\d{2})?$/;
|
|
31475
31478
|
function isNumericValue(value) {
|
|
31476
31479
|
if (typeof value === "number") return Number.isFinite(value);
|
|
31477
31480
|
return false;
|
|
@@ -31480,6 +31483,28 @@ function isDateValue(value) {
|
|
|
31480
31483
|
if (value instanceof Date) return !Number.isNaN(value.getTime());
|
|
31481
31484
|
return false;
|
|
31482
31485
|
}
|
|
31486
|
+
function isRealCalendarDay(year, month, day) {
|
|
31487
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
31488
|
+
return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
31489
|
+
}
|
|
31490
|
+
function toDate2(value) {
|
|
31491
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? void 0 : value;
|
|
31492
|
+
if (typeof value !== "string") return void 0;
|
|
31493
|
+
const parts = ISO_8601.exec(value);
|
|
31494
|
+
if (!parts) return void 0;
|
|
31495
|
+
const [, year, month, day, time, offset] = parts;
|
|
31496
|
+
if (!isRealCalendarDay(Number(year), Number(month), Number(day))) return void 0;
|
|
31497
|
+
const parsed = new Date(time && !offset ? `${value}Z` : value);
|
|
31498
|
+
return Number.isNaN(parsed.getTime()) ? void 0 : parsed;
|
|
31499
|
+
}
|
|
31500
|
+
function formatTemporalValue(value, column) {
|
|
31501
|
+
if (column.type !== "temporal" || !column.format || !TIME_DIRECTIVE.test(column.format)) {
|
|
31502
|
+
return void 0;
|
|
31503
|
+
}
|
|
31504
|
+
const date = toDate2(value);
|
|
31505
|
+
if (!date) return void 0;
|
|
31506
|
+
return utcFormat3(column.format)(date);
|
|
31507
|
+
}
|
|
31483
31508
|
function formatCell(value, column) {
|
|
31484
31509
|
const style = {};
|
|
31485
31510
|
if (value == null) {
|
|
@@ -31499,6 +31524,10 @@ function formatCell(value, column) {
|
|
|
31499
31524
|
};
|
|
31500
31525
|
}
|
|
31501
31526
|
}
|
|
31527
|
+
const temporal = formatTemporalValue(value, column);
|
|
31528
|
+
if (temporal !== void 0) {
|
|
31529
|
+
return { value, formattedValue: temporal, style };
|
|
31530
|
+
}
|
|
31502
31531
|
if (isNumericValue(value)) {
|
|
31503
31532
|
return {
|
|
31504
31533
|
value,
|
|
@@ -31530,7 +31559,7 @@ function formatValueForSearch(value, column) {
|
|
|
31530
31559
|
if (isNumericValue(value)) {
|
|
31531
31560
|
return defaultNumberFormatter11({ surface: "table" })(value);
|
|
31532
31561
|
}
|
|
31533
|
-
return String(value);
|
|
31562
|
+
return formatTemporalValue(value, column) ?? String(value);
|
|
31534
31563
|
}
|
|
31535
31564
|
|
|
31536
31565
|
// src/tables/heatmap.ts
|