aliencharts 0.1.2 → 0.1.4

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 CHANGED
@@ -1118,6 +1118,8 @@ var DASH_LENGTH_PX = 7;
1118
1118
  var DASH_GAP_PX = 5;
1119
1119
  var TOOLTIP_WIDTH = 220;
1120
1120
  var TOOLTIP_OFFSET = 12;
1121
+ var DEFAULT_GRID_X_SPACING = 80;
1122
+ var DEFAULT_GRID_Y_SPACING = 48;
1121
1123
  var DEFAULT_CHART_BACKGROUND = "#f5f9ff";
1122
1124
  var EMPTY_ARRAY = [];
1123
1125
  var EMPTY_OBJECT = {};
@@ -1995,6 +1997,9 @@ function ChartCell({
1995
1997
  hasDrawings = false,
1996
1998
  onClearDrawingsRequest,
1997
1999
  disableDrawings = false,
2000
+ gridLines = false,
2001
+ showToolbar = true,
2002
+ showLatestValueLine = true,
1998
2003
  height = CHART_HEIGHT,
1999
2004
  isFullscreen = false,
2000
2005
  backgroundColor = DEFAULT_CHART_BACKGROUND,
@@ -2011,6 +2016,15 @@ function ChartCell({
2011
2016
  right: RIGHT_AXIS_WIDTH + 6,
2012
2017
  bottom: PLOT_PADDING.bottom + 6
2013
2018
  };
2019
+ const gridOptions = gridLines === true ? EMPTY_OBJECT : gridLines;
2020
+ const gridXSpacing = Math.max(
2021
+ 8,
2022
+ Number(gridOptions?.xSpacing) || DEFAULT_GRID_X_SPACING
2023
+ );
2024
+ const gridYSpacing = Math.max(
2025
+ 8,
2026
+ Number(gridOptions?.ySpacing) || DEFAULT_GRID_Y_SPACING
2027
+ );
2014
2028
  return /* @__PURE__ */ React5.createElement(
2015
2029
  "div",
2016
2030
  {
@@ -2041,6 +2055,20 @@ function ChartCell({
2041
2055
  /* @__PURE__ */ React5.createElement("span", { className: "truncate" }, chart.title)
2042
2056
  )
2043
2057
  ),
2058
+ gridLines ? /* @__PURE__ */ React5.createElement(
2059
+ "div",
2060
+ {
2061
+ className: "pointer-events-none absolute text-border/40",
2062
+ style: {
2063
+ left: PLOT_PADDING.left,
2064
+ right: PLOT_PADDING.right,
2065
+ top: PLOT_PADDING.top,
2066
+ bottom: PLOT_PADDING.bottom,
2067
+ backgroundImage: "linear-gradient(to right, transparent calc(100% - 1px), currentColor calc(100% - 1px)), linear-gradient(to bottom, transparent calc(100% - 1px), currentColor calc(100% - 1px))",
2068
+ backgroundSize: `${gridXSpacing}px 100%, 100% ${gridYSpacing}px`
2069
+ }
2070
+ }
2071
+ ) : null,
2044
2072
  axisOverlay?.showJumpLatest ? /* @__PURE__ */ React5.createElement(
2045
2073
  "button",
2046
2074
  {
@@ -2063,7 +2091,7 @@ function ChartCell({
2063
2091
  },
2064
2092
  /* @__PURE__ */ React5.createElement(ArrowLineRightIcon, { size: 16, weight: "bold" })
2065
2093
  ) : null,
2066
- focused ? /* @__PURE__ */ React5.createElement(
2094
+ focused && showToolbar ? /* @__PURE__ */ React5.createElement(
2067
2095
  ChartToolbar,
2068
2096
  {
2069
2097
  isFullscreen,
@@ -2080,8 +2108,7 @@ function ChartCell({
2080
2108
  disableDrawings
2081
2109
  }
2082
2110
  ) : null,
2083
- /* @__PURE__ */ React5.createElement("div", { className: "pointer-events-none absolute inset-y-8 left-9 border-l border-border/40" }),
2084
- axisOverlay?.latestValues.map(
2111
+ showLatestValueLine && axisOverlay?.latestValues.map(
2085
2112
  (latest) => latest.left >= 0 && latest.left <= axisOverlay.plotWidth ? /* @__PURE__ */ React5.createElement(
2086
2113
  "div",
2087
2114
  {
@@ -2194,7 +2221,7 @@ function CrosshairOverlay({
2194
2221
  )), /* @__PURE__ */ React5.createElement(
2195
2222
  "div",
2196
2223
  {
2197
- className: "pointer-events-none absolute z-30 w-[220px] rounded-sm border border-border bg-popover px-2 py-1.5 text-xs text-popover-foreground shadow-sm",
2224
+ className: "pointer-events-none absolute z-30 w-[220px] rounded-sm border border-border/70 bg-popover/80 px-2 py-1.5 text-xs text-popover-foreground shadow-sm backdrop-blur-sm",
2198
2225
  style: {
2199
2226
  left: crosshair.tooltipX,
2200
2227
  top: crosshair.tooltipY
@@ -2593,7 +2620,7 @@ var drawChartLayouts = ({
2593
2620
  }
2594
2621
  return nextAxisOverlays;
2595
2622
  };
2596
- function LeanChartFullscreenOverlay({
2623
+ function ChartFullscreenOverlay({
2597
2624
  chart,
2598
2625
  dataRevision,
2599
2626
  renderRevision,
@@ -2626,6 +2653,10 @@ function LeanChartFullscreenOverlay({
2626
2653
  topMarkers = EMPTY_ARRAY,
2627
2654
  onTopMarkerClick,
2628
2655
  disableDrawings = false,
2656
+ gridLines = false,
2657
+ showToolbar = true,
2658
+ showLatestValueLine = true,
2659
+ showTooltips = true,
2629
2660
  formatXTick = formatCompactNumber,
2630
2661
  formatXValue = formatNumber,
2631
2662
  formatYValue = formatNumber
@@ -2651,6 +2682,9 @@ function LeanChartFullscreenOverlay({
2651
2682
  const chartDrawings = disableDrawings ? EMPTY_ARRAY : drawings;
2652
2683
  const chartActiveDrawingTool = disableDrawings ? null : activeDrawingTool;
2653
2684
  const chartSelectedDrawingId = disableDrawings ? null : selectedDrawingId;
2685
+ useEffect3(() => {
2686
+ if (!showTooltips) setCrosshair(null);
2687
+ }, [showTooltips]);
2654
2688
  const requestRender = useCallback3(() => {
2655
2689
  setRevision((value) => value + 1);
2656
2690
  }, []);
@@ -2893,15 +2927,15 @@ function LeanChartFullscreenOverlay({
2893
2927
  }).filter(Boolean).filter(
2894
2928
  (nearestPoint) => nearestPoint.x >= layout.plot.x - 1 && nearestPoint.x <= layout.plot.x + layout.plot.width + 1 && nearestPoint.y >= layout.plot.y - 1 && nearestPoint.y <= layout.plot.y + layout.plot.height + 1
2895
2929
  );
2896
- const primaryPoint = nearestPoints[0];
2897
- const tooltipLeft = primaryPoint && primaryPoint.x + TOOLTIP_WIDTH + TOOLTIP_OFFSET > layout.rect.x + layout.rect.width ? primaryPoint.x - TOOLTIP_WIDTH - TOOLTIP_OFFSET : (primaryPoint?.x ?? point.x) + TOOLTIP_OFFSET;
2930
+ const tooltipLeft = point.x + TOOLTIP_WIDTH + TOOLTIP_OFFSET > layout.rect.x + layout.rect.width ? point.x - TOOLTIP_WIDTH - TOOLTIP_OFFSET : point.x + TOOLTIP_OFFSET;
2898
2931
  const tooltipTop = Math.max(
2899
2932
  layout.rect.y + PLOT_PADDING.top,
2900
2933
  Math.min(
2901
- (primaryPoint?.y ?? point.y) + TOOLTIP_OFFSET,
2934
+ point.y + TOOLTIP_OFFSET,
2902
2935
  layout.rect.y + layout.rect.height - 96
2903
2936
  )
2904
2937
  );
2938
+ const primaryPoint = nearestPoints[0];
2905
2939
  setCrosshair({
2906
2940
  chartId: chart.id,
2907
2941
  title: chart.title,
@@ -3078,7 +3112,7 @@ function LeanChartFullscreenOverlay({
3078
3112
  );
3079
3113
  const handlePointerMove = useCallback3(
3080
3114
  (event) => {
3081
- updateCrosshair(event);
3115
+ if (showTooltips) updateCrosshair(event);
3082
3116
  const drawingPoint = getLocalPoint(event);
3083
3117
  const drawingLayout = getLayout();
3084
3118
  if (drawingPoint && drawingLayout) {
@@ -3217,6 +3251,7 @@ function LeanChartFullscreenOverlay({
3217
3251
  initialVisiblePoints,
3218
3252
  onDrawingsChange,
3219
3253
  requestRender,
3254
+ showTooltips,
3220
3255
  updateCrosshair,
3221
3256
  viewStateRef,
3222
3257
  yCenterOffsetRef,
@@ -3482,6 +3517,9 @@ function LeanChartFullscreenOverlay({
3482
3517
  hasDrawings: getDrawingsForChart(chartDrawings, chart.id).length > 0,
3483
3518
  onClearDrawingsRequest,
3484
3519
  disableDrawings,
3520
+ gridLines,
3521
+ showToolbar,
3522
+ showLatestValueLine,
3485
3523
  formatXTick,
3486
3524
  formatYValue,
3487
3525
  setRef: (node) => {
@@ -3544,7 +3582,7 @@ function LeanChartFullscreenOverlay({
3544
3582
  /* @__PURE__ */ React5.createElement(
3545
3583
  CrosshairOverlay,
3546
3584
  {
3547
- crosshair,
3585
+ crosshair: showTooltips ? crosshair : null,
3548
3586
  height: "100%",
3549
3587
  xAxisLabel,
3550
3588
  formatXValue,
@@ -3563,6 +3601,10 @@ function ChartGrid({
3563
3601
  initialVisiblePoints = null,
3564
3602
  backgroundColor = DEFAULT_CHART_BACKGROUND,
3565
3603
  antialiasLines = false,
3604
+ gridLines = false,
3605
+ showToolbar = true,
3606
+ showLatestValueLine = true,
3607
+ showTooltips = true,
3566
3608
  followLatest = false,
3567
3609
  followVisibleLatest = true,
3568
3610
  jumpToLatestRevision = 0,
@@ -3616,6 +3658,9 @@ function ChartGrid({
3616
3658
  const chartDrawings = disableDrawings ? EMPTY_ARRAY : drawings;
3617
3659
  const chartActiveDrawingTool = disableDrawings ? null : activeDrawingTool;
3618
3660
  const chartSelectedDrawingId = disableDrawings ? null : selectedDrawingId;
3661
+ useEffect3(() => {
3662
+ if (!showTooltips) setCrosshair(null);
3663
+ }, [showTooltips]);
3619
3664
  const requestRender = useCallback3(() => {
3620
3665
  setRevision((value) => value + 1);
3621
3666
  }, []);
@@ -4084,15 +4129,15 @@ function ChartGrid({
4084
4129
  }).filter(Boolean).filter(
4085
4130
  (nearestPoint) => nearestPoint.x >= layout.plot.x - 1 && nearestPoint.x <= layout.plot.x + layout.plot.width + 1 && nearestPoint.y >= layout.plot.y - 1 && nearestPoint.y <= layout.plot.y + layout.plot.height + 1
4086
4131
  );
4087
- const primaryPoint = nearestPoints[0];
4088
- const tooltipLeft = primaryPoint && primaryPoint.x + TOOLTIP_WIDTH + TOOLTIP_OFFSET > layout.rect.x + layout.rect.width ? primaryPoint.x - TOOLTIP_WIDTH - TOOLTIP_OFFSET : (primaryPoint?.x ?? point.x) + TOOLTIP_OFFSET;
4132
+ const tooltipLeft = point.x + TOOLTIP_WIDTH + TOOLTIP_OFFSET > layout.rect.x + layout.rect.width ? point.x - TOOLTIP_WIDTH - TOOLTIP_OFFSET : point.x + TOOLTIP_OFFSET;
4089
4133
  const tooltipTop = Math.max(
4090
4134
  layout.rect.y + PLOT_PADDING.top,
4091
4135
  Math.min(
4092
- (primaryPoint?.y ?? point.y) + TOOLTIP_OFFSET,
4136
+ point.y + TOOLTIP_OFFSET,
4093
4137
  layout.rect.y + layout.rect.height - 96
4094
4138
  )
4095
4139
  );
4140
+ const primaryPoint = nearestPoints[0];
4096
4141
  setCrosshair({
4097
4142
  chartId: layout.chart.id,
4098
4143
  title: layout.chart.title,
@@ -4345,7 +4390,7 @@ function ChartGrid({
4345
4390
  const handlePointerMove = useCallback3(
4346
4391
  (event) => {
4347
4392
  if (fullscreenChartId) return;
4348
- updateCrosshair(event);
4393
+ if (showTooltips) updateCrosshair(event);
4349
4394
  const drawingPoint = getLocalPoint(event);
4350
4395
  if (drawingPoint) {
4351
4396
  if (drawingEditRef.current) {
@@ -4491,6 +4536,7 @@ function ChartGrid({
4491
4536
  initialVisiblePoints,
4492
4537
  onDrawingsChange,
4493
4538
  requestRender,
4539
+ showTooltips,
4494
4540
  updateCrosshair
4495
4541
  ]
4496
4542
  );
@@ -4661,6 +4707,7 @@ function ChartGrid({
4661
4707
  );
4662
4708
  useEffect3(() => {
4663
4709
  const handleKeyDown = (event) => {
4710
+ if (fullscreenChartId) return;
4664
4711
  const target = event.target;
4665
4712
  const editable = target instanceof HTMLElement && (target.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(target.tagName));
4666
4713
  if (editable) {
@@ -4805,6 +4852,9 @@ function ChartGrid({
4805
4852
  hasDrawings: getDrawingsForChart(chartDrawings, chart.id).length > 0,
4806
4853
  onClearDrawingsRequest,
4807
4854
  disableDrawings,
4855
+ gridLines,
4856
+ showToolbar,
4857
+ showLatestValueLine,
4808
4858
  formatXTick,
4809
4859
  formatYValue,
4810
4860
  setRef: (node) => {
@@ -4817,7 +4867,7 @@ function ChartGrid({
4817
4867
  /* @__PURE__ */ React5.createElement(
4818
4868
  CrosshairOverlay,
4819
4869
  {
4820
- crosshair: fullscreenChart ? null : crosshair,
4870
+ crosshair: fullscreenChart || !showTooltips ? null : crosshair,
4821
4871
  height: containerRef.current?.scrollHeight ?? "100%",
4822
4872
  xAxisLabel,
4823
4873
  formatXValue,
@@ -4879,7 +4929,7 @@ function ChartGrid({
4879
4929
  })() : null,
4880
4930
  /* @__PURE__ */ React5.createElement(RectangleZoomOverlay, { rect: fullscreenChart ? null : rectangleZoomRect }),
4881
4931
  fullscreenChart ? /* @__PURE__ */ React5.createElement(
4882
- LeanChartFullscreenOverlay,
4932
+ ChartFullscreenOverlay,
4883
4933
  {
4884
4934
  chart: fullscreenChart,
4885
4935
  dataRevision,
@@ -4913,6 +4963,10 @@ function ChartGrid({
4913
4963
  topMarkers,
4914
4964
  onTopMarkerClick,
4915
4965
  disableDrawings,
4966
+ gridLines,
4967
+ showToolbar,
4968
+ showLatestValueLine,
4969
+ showTooltips,
4916
4970
  formatXTick,
4917
4971
  formatXValue,
4918
4972
  formatYValue