Skip to content

[Feature] Allow overriding bar space zoom limits via a global configuration hook #793

@DeeeeLAN

Description

@DeeeeLAN

Feature Description

Summary

It would be useful if klinecharts allowed the bar space zoom limits to be overridden at runtime instead of being hard-coded to:

{ MIN: 1, MAX: 50 }

Right now those limits appear fixed inside the distributed bundle, which makes it difficult for applications with dense historical datasets or specialized zoom behavior to support narrower or wider bar spacing without patching the package.

Current behavior

The library currently defines fixed limits similar to:

var BarSpaceLimitConstants = {
  MIN: 1,
  MAX: 50
};

And uses them when setting bar spacing:

if (barSpace < BarSpaceLimitConstants.MIN || barSpace > BarSpaceLimitConstants.MAX || this._barSpace === barSpace) {
  return;
}

Requested behavior

Allow consumers to override these limits through a supported configuration mechanism.

One lightweight option would be to read from a global override if present, and fall back to the existing defaults otherwise. That would preserve current behavior for all existing users while making the limits configurable for advanced integrations.

Proposed implementation

Something along these lines:

var __kline_bar_space_limit_override = {
  MIN: 1,
  MAX: 50
};

function getBarSpaceLimitConstants() {
  var override =
    typeof globalThis !== "undefined"
      ? globalThis.KLINE_BAR_SPACE_LIMIT_CONSTANTS
      : void 0;
  return override || __kline_bar_space_limit_override;
}

var BarSpaceLimitConstants = getBarSpaceLimitConstants();

And then in setBarSpace:

var limit = getBarSpaceLimitConstants();
if (barSpace < limit.MIN || barSpace > limit.MAX || this._barSpace === barSpace) {
  return;
}

Why this would help

  • It removes the need to maintain a local patch for a small but important behavior change.
  • It keeps the current defaults intact for existing users.
  • It enables more flexibility for applications that need different zoom bounds because of their dataset size or UX requirements.
  • It is a minimal, backward-compatible extension point.

Suggested API alternatives

If a global hook is not desirable, any of these would also solve the problem cleanly:

  1. Expose minBarSpace / maxBarSpace in chart options.
  2. Add a dedicated API such as setBarSpaceLimit({ min, max }).
  3. Export the defaults and allow them to be overridden during initialization.

Backward compatibility

This request is intended to be fully backward compatible:

  • default behavior remains unchanged
  • existing consumers do not need to update anything
  • only applications that need custom limits would opt in

Context

At the moment this requires patching the built output locally, which is fragile across upgrades. Having an official extension point upstream would make this much easier to maintain.

To Do

  1. Add a supported way to override the default bar space limits.
  2. Update setBarSpace to use the configured limits instead of fixed constants.
  3. Keep existing defaults unchanged for backward compatibility.
  4. Add tests for default and overridden limit behavior.
  5. Document the new configuration option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions