hyperprop-charting-library 0.1.28 → 0.1.30

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.
@@ -2665,6 +2665,7 @@ function createChart(element, options = {}) {
2665
2665
  };
2666
2666
  const setData = (nextData) => {
2667
2667
  const hadData = data.length > 0;
2668
+ const previousCount = data.length;
2668
2669
  const previousCenterRounded = hadData ? Math.round(xCenter) : 0;
2669
2670
  const previousCenterFraction = hadData ? xCenter - previousCenterRounded : 0;
2670
2671
  const previousCenterTimeMs = hadData && previousCenterRounded >= 0 && previousCenterRounded < data.length ? data[previousCenterRounded]?.time.getTime() ?? null : null;
@@ -2681,7 +2682,11 @@ function createChart(element, options = {}) {
2681
2682
  resetYViewport();
2682
2683
  } else {
2683
2684
  if (mergedOptions.preserveViewportOnDataUpdate) {
2684
- if (previousCenterTimeMs !== null) {
2685
+ const hasNewBars = data.length > previousCount;
2686
+ const wasAtRightEdge = hasNewBars && xCenter + xSpan / 2 >= previousCount - 1;
2687
+ if (wasAtRightEdge) {
2688
+ xCenter = data.length - xSpan / 2 + rightEdgePaddingBars;
2689
+ } else if (hasNewBars && previousCenterTimeMs !== null) {
2685
2690
  const nextCenter = findNearestIndexForTimeMs(previousCenterTimeMs);
2686
2691
  if (nextCenter !== null) {
2687
2692
  xCenter = nextCenter + previousCenterFraction;
@@ -2641,6 +2641,7 @@ function createChart(element, options = {}) {
2641
2641
  };
2642
2642
  const setData = (nextData) => {
2643
2643
  const hadData = data.length > 0;
2644
+ const previousCount = data.length;
2644
2645
  const previousCenterRounded = hadData ? Math.round(xCenter) : 0;
2645
2646
  const previousCenterFraction = hadData ? xCenter - previousCenterRounded : 0;
2646
2647
  const previousCenterTimeMs = hadData && previousCenterRounded >= 0 && previousCenterRounded < data.length ? data[previousCenterRounded]?.time.getTime() ?? null : null;
@@ -2657,7 +2658,11 @@ function createChart(element, options = {}) {
2657
2658
  resetYViewport();
2658
2659
  } else {
2659
2660
  if (mergedOptions.preserveViewportOnDataUpdate) {
2660
- if (previousCenterTimeMs !== null) {
2661
+ const hasNewBars = data.length > previousCount;
2662
+ const wasAtRightEdge = hasNewBars && xCenter + xSpan / 2 >= previousCount - 1;
2663
+ if (wasAtRightEdge) {
2664
+ xCenter = data.length - xSpan / 2 + rightEdgePaddingBars;
2665
+ } else if (hasNewBars && previousCenterTimeMs !== null) {
2661
2666
  const nextCenter = findNearestIndexForTimeMs(previousCenterTimeMs);
2662
2667
  if (nextCenter !== null) {
2663
2668
  xCenter = nextCenter + previousCenterFraction;
package/dist/index.cjs CHANGED
@@ -2665,6 +2665,7 @@ function createChart(element, options = {}) {
2665
2665
  };
2666
2666
  const setData = (nextData) => {
2667
2667
  const hadData = data.length > 0;
2668
+ const previousCount = data.length;
2668
2669
  const previousCenterRounded = hadData ? Math.round(xCenter) : 0;
2669
2670
  const previousCenterFraction = hadData ? xCenter - previousCenterRounded : 0;
2670
2671
  const previousCenterTimeMs = hadData && previousCenterRounded >= 0 && previousCenterRounded < data.length ? data[previousCenterRounded]?.time.getTime() ?? null : null;
@@ -2681,7 +2682,11 @@ function createChart(element, options = {}) {
2681
2682
  resetYViewport();
2682
2683
  } else {
2683
2684
  if (mergedOptions.preserveViewportOnDataUpdate) {
2684
- if (previousCenterTimeMs !== null) {
2685
+ const hasNewBars = data.length > previousCount;
2686
+ const wasAtRightEdge = hasNewBars && xCenter + xSpan / 2 >= previousCount - 1;
2687
+ if (wasAtRightEdge) {
2688
+ xCenter = data.length - xSpan / 2 + rightEdgePaddingBars;
2689
+ } else if (hasNewBars && previousCenterTimeMs !== null) {
2685
2690
  const nextCenter = findNearestIndexForTimeMs(previousCenterTimeMs);
2686
2691
  if (nextCenter !== null) {
2687
2692
  xCenter = nextCenter + previousCenterFraction;
package/dist/index.js CHANGED
@@ -2641,6 +2641,7 @@ function createChart(element, options = {}) {
2641
2641
  };
2642
2642
  const setData = (nextData) => {
2643
2643
  const hadData = data.length > 0;
2644
+ const previousCount = data.length;
2644
2645
  const previousCenterRounded = hadData ? Math.round(xCenter) : 0;
2645
2646
  const previousCenterFraction = hadData ? xCenter - previousCenterRounded : 0;
2646
2647
  const previousCenterTimeMs = hadData && previousCenterRounded >= 0 && previousCenterRounded < data.length ? data[previousCenterRounded]?.time.getTime() ?? null : null;
@@ -2657,7 +2658,11 @@ function createChart(element, options = {}) {
2657
2658
  resetYViewport();
2658
2659
  } else {
2659
2660
  if (mergedOptions.preserveViewportOnDataUpdate) {
2660
- if (previousCenterTimeMs !== null) {
2661
+ const hasNewBars = data.length > previousCount;
2662
+ const wasAtRightEdge = hasNewBars && xCenter + xSpan / 2 >= previousCount - 1;
2663
+ if (wasAtRightEdge) {
2664
+ xCenter = data.length - xSpan / 2 + rightEdgePaddingBars;
2665
+ } else if (hasNewBars && previousCenterTimeMs !== null) {
2661
2666
  const nextCenter = findNearestIndexForTimeMs(previousCenterTimeMs);
2662
2667
  if (nextCenter !== null) {
2663
2668
  xCenter = nextCenter + previousCenterFraction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperprop-charting-library",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "Lightweight TypeScript charting core",
5
5
  "type": "module",
6
6
  "main": "./dist/hyperprop-charting-library.cjs",