@opendata-ai/openchart-core 6.1.5 → 6.2.1

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.d.ts CHANGED
@@ -363,12 +363,14 @@ interface Encoding {
363
363
  /** Radial position for arc marks. */
364
364
  radius?: EncodingChannel;
365
365
  }
366
- /** Encoding channel for graph nodes and edges. Same structure as EncodingChannel. */
366
+ /** Encoding channel for graph nodes and edges. */
367
367
  interface GraphEncodingChannel {
368
368
  /** Data field name on the node/edge object. */
369
369
  field: string;
370
370
  /** How to interpret the field values. */
371
371
  type?: FieldType;
372
+ /** Scale configuration. Auto-derived from data if omitted. */
373
+ scale?: ScaleConfig;
372
374
  }
373
375
  /** Graph-specific encoding mapping visual properties to node/edge data fields. */
374
376
  interface GraphEncoding {
@@ -2399,8 +2401,12 @@ type DateGranularity = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' |
2399
2401
  * @param value - Date object, ISO string, or timestamp number.
2400
2402
  * @param locale - Locale string (currently unused, reserved for i18n).
2401
2403
  * @param granularity - Time granularity for format selection.
2404
+ * @param useUtc - Whether to infer granularity and format using UTC methods.
2405
+ * Pass `false` when formatting ticks from a local-time scale (d3 scaleTime),
2406
+ * so that e.g. midnight local isn't misread as an intra-day UTC time.
2407
+ * Defaults to `true` for backward compatibility.
2402
2408
  */
2403
- declare function formatDate(value: Date | string | number, _locale?: string, granularity?: DateGranularity): string;
2409
+ declare function formatDate(value: Date | string | number, _locale?: string, granularity?: DateGranularity, useUtc?: boolean): string;
2404
2410
  /**
2405
2411
  * Build a formatter for temporal values using a d3-time-format string (e.g. "%Y", "%b %Y").
2406
2412
  * Returns a function that accepts a Date, string, or number and returns the formatted string.
package/dist/index.js CHANGED
@@ -2403,16 +2403,16 @@ var GRANULARITY_FORMATS = {
2403
2403
  hour: "%b %d %H:%M",
2404
2404
  minute: "%H:%M"
2405
2405
  };
2406
- function formatDate(value, _locale, granularity) {
2406
+ function formatDate(value, _locale, granularity, useUtc = true) {
2407
2407
  const date = value instanceof Date ? value : new Date(value);
2408
2408
  if (Number.isNaN(date.getTime())) return String(value);
2409
- const gran = granularity ?? inferGranularity(date);
2409
+ const gran = granularity ?? inferGranularity(date, useUtc);
2410
2410
  if (gran === "quarter") {
2411
- const q = Math.ceil((date.getMonth() + 1) / 3);
2411
+ const q = useUtc ? Math.ceil((date.getUTCMonth() + 1) / 3) : Math.ceil((date.getMonth() + 1) / 3);
2412
2412
  return `Q${q} ${date.getFullYear()}`;
2413
2413
  }
2414
2414
  const formatStr = GRANULARITY_FORMATS[gran];
2415
- if (["year", "month", "day"].includes(gran)) {
2415
+ if (useUtc) {
2416
2416
  return utcFormat(formatStr)(date);
2417
2417
  }
2418
2418
  return timeFormat(formatStr)(date);
@@ -2426,12 +2426,16 @@ function buildTemporalFormatter(formatStr) {
2426
2426
  return fmt(date);
2427
2427
  };
2428
2428
  }
2429
- function inferGranularity(date) {
2430
- if (date.getUTCHours() !== 0 || date.getUTCMinutes() !== 0) {
2431
- return date.getUTCMinutes() !== 0 ? "minute" : "hour";
2429
+ function inferGranularity(date, useUtc = true) {
2430
+ const hours = useUtc ? date.getUTCHours() : date.getHours();
2431
+ const minutes = useUtc ? date.getUTCMinutes() : date.getMinutes();
2432
+ const day = useUtc ? date.getUTCDate() : date.getDate();
2433
+ const month = useUtc ? date.getUTCMonth() : date.getMonth();
2434
+ if (hours !== 0 || minutes !== 0) {
2435
+ return minutes !== 0 ? "minute" : "hour";
2432
2436
  }
2433
- if (date.getUTCDate() !== 1) return "day";
2434
- if (date.getUTCMonth() !== 0) return "month";
2437
+ if (day !== 1) return "day";
2438
+ if (month !== 0) return "month";
2435
2439
  return "year";
2436
2440
  }
2437
2441