@loafmarkets/ui 0.1.2 → 0.1.3

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.mjs CHANGED
@@ -4545,7 +4545,97 @@ var YourOrders = o.forwardRef(
4545
4545
  }
4546
4546
  );
4547
4547
  YourOrders.displayName = "YourOrders";
4548
- var defaultRanges = ["1D", "1W", "1M", "3M", "1Y"];
4548
+ var timeToDate = (time) => {
4549
+ if (typeof time === "number") {
4550
+ return new Date(time * 1e3);
4551
+ }
4552
+ if (typeof time === "object" && time !== null && "year" in time && "month" in time && "day" in time) {
4553
+ const { year, month, day } = time;
4554
+ return new Date(Date.UTC(year, month - 1, day));
4555
+ }
4556
+ return null;
4557
+ };
4558
+ var createTickFormatter = (formatOptions) => {
4559
+ return (time, _tickMarkType, locale) => {
4560
+ const date = timeToDate(time);
4561
+ if (!date) return "";
4562
+ return date.toLocaleString(locale || void 0, formatOptions);
4563
+ };
4564
+ };
4565
+ var getTimeScaleOptions = (range) => {
4566
+ switch (range) {
4567
+ case "15m":
4568
+ return {
4569
+ timeVisible: true,
4570
+ secondsVisible: false,
4571
+ borderColor: "rgba(255,255,255,0.06)",
4572
+ tickMarkFormatter: createTickFormatter({ hour: "2-digit", minute: "2-digit" })
4573
+ };
4574
+ case "1h":
4575
+ return {
4576
+ timeVisible: true,
4577
+ secondsVisible: false,
4578
+ borderColor: "rgba(255,255,255,0.06)",
4579
+ tickMarkFormatter: createTickFormatter({ hour: "2-digit", minute: "2-digit" })
4580
+ };
4581
+ case "4h":
4582
+ return {
4583
+ timeVisible: true,
4584
+ secondsVisible: false,
4585
+ borderColor: "rgba(255,255,255,0.06)",
4586
+ tickMarkFormatter: createTickFormatter({ weekday: "short", hour: "2-digit" })
4587
+ };
4588
+ case "24h":
4589
+ return {
4590
+ timeVisible: true,
4591
+ secondsVisible: false,
4592
+ borderColor: "rgba(255,255,255,0.06)",
4593
+ tickMarkFormatter: createTickFormatter({ month: "short", day: "numeric" })
4594
+ };
4595
+ case "1W":
4596
+ return {
4597
+ timeVisible: true,
4598
+ secondsVisible: false,
4599
+ borderColor: "rgba(255,255,255,0.06)",
4600
+ tickMarkFormatter: createTickFormatter({ month: "short", day: "numeric" })
4601
+ };
4602
+ case "1M":
4603
+ return {
4604
+ timeVisible: true,
4605
+ secondsVisible: false,
4606
+ borderColor: "rgba(255,255,255,0.06)",
4607
+ tickMarkFormatter: createTickFormatter({ month: "short", year: "2-digit" })
4608
+ };
4609
+ default:
4610
+ return {
4611
+ timeVisible: true,
4612
+ secondsVisible: false,
4613
+ borderColor: "rgba(255,255,255,0.06)"
4614
+ };
4615
+ }
4616
+ };
4617
+ var getPriceScaleOptions = (data) => {
4618
+ if (!data.length) return {
4619
+ borderColor: "rgba(230, 200, 126, 0.25)",
4620
+ textColor: "rgba(230, 200, 126, 0.7)"
4621
+ };
4622
+ const prices = data.flatMap((d2) => [d2.open, d2.high, d2.low, d2.close]);
4623
+ const minPrice = Math.min(...prices);
4624
+ const maxPrice = Math.max(...prices);
4625
+ const priceRange = maxPrice - minPrice;
4626
+ let scaleMargins = { top: 0.1, bottom: 0.1 };
4627
+ if (priceRange < 1) {
4628
+ scaleMargins = { top: 0.2, bottom: 0.2 };
4629
+ } else if (priceRange > 1e3) {
4630
+ scaleMargins = { top: 0.05, bottom: 0.05 };
4631
+ }
4632
+ return {
4633
+ borderColor: "rgba(230, 200, 126, 0.25)",
4634
+ textColor: "rgba(230, 200, 126, 0.7)",
4635
+ scaleMargins
4636
+ };
4637
+ };
4638
+ var defaultRanges = ["15m", "1h", "4h", "24h", "1W", "1M"];
4549
4639
  var formatPrice = (value, currencySymbol) => {
4550
4640
  return `${currencySymbol}${value.toLocaleString(void 0, {
4551
4641
  minimumFractionDigits: 2,
@@ -4614,15 +4704,8 @@ var PriceChart = o.forwardRef(
4614
4704
  vertLines: { color: "rgba(255,255,255,0.06)" },
4615
4705
  horzLines: { color: "rgba(255,255,255,0.06)" }
4616
4706
  },
4617
- rightPriceScale: {
4618
- borderColor: "rgba(230, 200, 126, 0.25)",
4619
- textColor: "rgba(230, 200, 126, 0.7)"
4620
- },
4621
- timeScale: {
4622
- borderColor: "rgba(255,255,255,0.06)",
4623
- timeVisible: true,
4624
- secondsVisible: false
4625
- },
4707
+ rightPriceScale: getPriceScaleOptions(data),
4708
+ timeScale: getTimeScaleOptions(selectedRange || defaultRanges[0]),
4626
4709
  crosshair: {
4627
4710
  vertLine: { color: "rgba(255,255,255,0.12)" },
4628
4711
  horzLine: { color: "rgba(255,255,255,0.12)" }
@@ -4643,11 +4726,22 @@ var PriceChart = o.forwardRef(
4643
4726
  chart.remove();
4644
4727
  };
4645
4728
  }, []);
4729
+ o.useEffect(() => {
4730
+ const chart = chartRef.current;
4731
+ if (!chart) return;
4732
+ const effectiveRange = selectedRange ?? ranges?.[0] ?? "1D";
4733
+ chart.applyOptions({
4734
+ timeScale: getTimeScaleOptions(effectiveRange)
4735
+ });
4736
+ }, [selectedRange, ranges]);
4646
4737
  o.useEffect(() => {
4647
4738
  const chart = chartRef.current;
4648
4739
  const series = seriesRef.current;
4649
4740
  if (!chart || !series) return;
4650
4741
  series.setData(data);
4742
+ chart.applyOptions({
4743
+ rightPriceScale: getPriceScaleOptions(data)
4744
+ });
4651
4745
  if (priceLineRef.current) {
4652
4746
  series.removePriceLine(priceLineRef.current);
4653
4747
  priceLineRef.current = null;