@sproutsocial/seeds-react-data-viz 0.7.9 → 0.7.11

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/esm/index.js CHANGED
@@ -634,13 +634,28 @@ var yAxisLabelFormatter = ({
634
634
  };
635
635
 
636
636
  // src/helpers/xAxisLabelFormatter.ts
637
+ var getDatePartsInTimezone = (date, timezone) => {
638
+ const formatter = new Intl.DateTimeFormat("en-US", {
639
+ year: "numeric",
640
+ month: "numeric",
641
+ day: "numeric",
642
+ timeZone: timezone
643
+ });
644
+ const parts = formatter.formatToParts(date);
645
+ return {
646
+ day: parseInt(parts.find((p) => p.type === "day")?.value ?? "0", 10),
647
+ month: parseInt(parts.find((p) => p.type === "month")?.value ?? "0", 10),
648
+ year: parseInt(parts.find((p) => p.type === "year")?.value ?? "0", 10)
649
+ };
650
+ };
637
651
  var xAxisLabelFormatter = ({
638
652
  textLocale,
639
653
  tickPositions = [],
640
654
  unitName,
641
655
  value,
642
656
  // optional
643
- timeFormat = "12"
657
+ timeFormat = "12",
658
+ timezone = "UTC"
644
659
  }) => {
645
660
  if (typeof value === "string") {
646
661
  return `<span>${value}</span>`;
@@ -649,26 +664,28 @@ var xAxisLabelFormatter = ({
649
664
  const isFirst = tickIndex === 0;
650
665
  const previousValue = tickPositions[tickIndex - 1];
651
666
  const valueDate = new Date(value);
652
- const previousValueDate = new Date(previousValue);
667
+ const valueParts = getDatePartsInTimezone(valueDate, timezone);
668
+ const previousValueDate = previousValue ? new Date(previousValue) : void 0;
669
+ const previousValueParts = previousValueDate ? getDatePartsInTimezone(previousValueDate, timezone) : void 0;
653
670
  let firstPartOptions = {};
654
671
  let secondPartOptions = {};
655
672
  switch (unitName) {
656
673
  case "hour":
657
674
  firstPartOptions = timeFormat === "24" ? { hour: "numeric", minute: "numeric", hour12: false } : { hour: "numeric" };
658
- if (isFirst || valueDate.getUTCDate() !== previousValueDate.getUTCDate()) {
675
+ if (isFirst || valueParts.day !== previousValueParts?.day) {
659
676
  secondPartOptions = { day: "numeric", month: "short" };
660
677
  }
661
678
  break;
662
679
  case "day":
663
680
  case "week":
664
681
  firstPartOptions = { day: "numeric" };
665
- if (isFirst || valueDate.getUTCMonth() !== previousValueDate.getUTCMonth()) {
682
+ if (isFirst || valueParts.month !== previousValueParts?.month) {
666
683
  secondPartOptions = { month: "short" };
667
684
  }
668
685
  break;
669
686
  case "month":
670
687
  firstPartOptions = { month: "short" };
671
- if (isFirst || valueDate.getUTCFullYear() !== previousValueDate.getUTCFullYear()) {
688
+ if (isFirst || valueParts.year !== previousValueParts?.year) {
672
689
  secondPartOptions = { year: "numeric" };
673
690
  }
674
691
  break;
@@ -681,11 +698,11 @@ var xAxisLabelFormatter = ({
681
698
  }
682
699
  const firstPart = new Intl.DateTimeFormat(textLocale, {
683
700
  ...firstPartOptions,
684
- timeZone: "UTC"
701
+ timeZone: timezone
685
702
  }).format(valueDate);
686
703
  const secondPart = Object.keys(secondPartOptions).length > 0 ? new Intl.DateTimeFormat(textLocale, {
687
704
  ...secondPartOptions,
688
- timeZone: "UTC"
705
+ timeZone: timezone
689
706
  }).format(valueDate) : void 0;
690
707
  return `<span>${firstPart}</span>${secondPart ? `<span>${secondPart}</span>` : ""}`;
691
708
  };
@@ -1086,6 +1103,7 @@ var useTimeSeriesChartOptions = ({
1086
1103
  yAxisLabelFormatter: yAxisLabelFormatter2,
1087
1104
  onClick,
1088
1105
  timeFormat = "12",
1106
+ timezone = "UTC",
1089
1107
  xAxisLabelFormatter: xAxisLabelFormatter2
1090
1108
  }) => {
1091
1109
  const [chart, setChart] = useState3(null);
@@ -1264,6 +1282,7 @@ var useTimeSeriesChartOptions = ({
1264
1282
  textLocale,
1265
1283
  tickPositions,
1266
1284
  timeFormat,
1285
+ timezone,
1267
1286
  unitName,
1268
1287
  value
1269
1288
  });
@@ -1519,6 +1538,7 @@ var AreaChartWithData = memo14(function AreaChartWithData2({
1519
1538
  onClick,
1520
1539
  tooltipClickLabel,
1521
1540
  timeFormat = "12",
1541
+ timezone = "UTC",
1522
1542
  xAnnotations
1523
1543
  }) {
1524
1544
  const { options, chart, callback } = useTimeSeriesChartOptions({
@@ -1532,6 +1552,7 @@ var AreaChartWithData = memo14(function AreaChartWithData2({
1532
1552
  yAxisLabelFormatter: yAxisLabelFormatter2,
1533
1553
  onClick,
1534
1554
  timeFormat,
1555
+ timezone,
1535
1556
  xAnnotations
1536
1557
  });
1537
1558
  const colors = data.map(
@@ -2081,6 +2102,7 @@ var LineChartWithData = memo23(function LineChartWithData2({
2081
2102
  onClick,
2082
2103
  tooltipClickLabel,
2083
2104
  timeFormat = "12",
2105
+ timezone = "UTC",
2084
2106
  xAnnotations,
2085
2107
  xAxisLabelFormatter: xAxisLabelFormatter2
2086
2108
  }) {
@@ -2095,6 +2117,7 @@ var LineChartWithData = memo23(function LineChartWithData2({
2095
2117
  yAxisLabelFormatter: yAxisLabelFormatter2,
2096
2118
  onClick,
2097
2119
  timeFormat,
2120
+ timezone,
2098
2121
  xAnnotations,
2099
2122
  xAxisLabelFormatter: xAxisLabelFormatter2
2100
2123
  });