Skip to content

feat(core): add utils#427

Open
ader-h wants to merge 1 commit intoopentiny:devfrom
ader-h:feat-util-0310
Open

feat(core): add utils#427
ader-h wants to merge 1 commit intoopentiny:devfrom
ader-h:feat-util-0310

Conversation

@ader-h
Copy link
Contributor

@ader-h ader-h commented Mar 12, 2026

Summary by CodeRabbit

  • New Features
    • Exposed ECharts utilities as a public API, providing access to tooltip formatting and text truncation features for enhanced chart customization.

@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2026

Walkthrough

A new utility module (src/util.js) was created to consolidate ECharts utilities, including a tooltip formatter, echarts reference, and text truncation utility. This module was then re-exported from the main entry point (src/index.js) to expose it as a public API.

Changes

Cohort / File(s) Summary
Utility Module Consolidation
src/util.js, src/index.js
Created new utility module exporting echarts, tooltip formatter, and text truncation utility. Re-exported from main entry point as public API.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A bundle of tools, all tidy and neat,
Wrapped in a module, a practical feat!
Echarts and formatters, now consolidated,
Through one simple export, utilities liberated!
Hop along, dear code—you're organized bliss! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(core): add utils' directly corresponds to the main changeset, which adds a new util module (src/util.js) and exports it from src/index.js.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/util.js (2)

4-12: Consider documenting dependencies for tooltip.formatter.

The getTooltipContentHtmlStr function (see src/option/config/tooltip/formatter.js) relies on Token.config for styling values like tooltipIconGap, tooltipTitleColor, etc. If consumers call util.tooltip.formatter before the library initializes Token.config, it may produce unexpected results or errors.

Consider either:

  1. Adding documentation about required initialization
  2. Adding defensive defaults within the formatter
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/util.js` around lines 4 - 12, The tooltip formatter
(util.tooltip.formatter pointing to getTooltipContentHtmlStr) depends on
Token.config values (e.g., tooltipIconGap, tooltipTitleColor) and can break if
Token.config is not initialized; update getTooltipContentHtmlStr to defensively
read Token.config with sensible defaults (fall back to explicit default
numbers/strings when Token.config or specific keys are missing) and/or add brief
documentation near util.tooltip.formatter stating that Token.config must be
initialized before calling the formatter (mention Token.config,
getTooltipContentHtmlStr, and util.tooltip.formatter so maintainers can locate
the code).

8-8: Exposing raw echarts bypasses library customizations.

The util.echarts export provides the unmodified echarts instance. Consumers using this will not get any themes, component registrations, or configurations that the library applies internally. If this is intentional (e.g., for advanced users), consider documenting this distinction.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/util.js` at line 8, The util.echarts export currently exposes the raw
echarts instance, which bypasses any internal theme/component registrations;
change the export to expose the configured instance or a getter instead: stop
exporting the unmodified `echarts` value and instead export a `getEcharts()`
function or `configuredEcharts` symbol that returns the instance after the
library's themes, components, and plugins have been applied (or rename the
existing export to `rawEcharts` and add documentation clearly stating it is
unconfigured if you must keep the raw export); update any consumers to call the
new symbol so they receive the customized instance.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/util.js`:
- Around line 4-12: The tooltip formatter (util.tooltip.formatter pointing to
getTooltipContentHtmlStr) depends on Token.config values (e.g., tooltipIconGap,
tooltipTitleColor) and can break if Token.config is not initialized; update
getTooltipContentHtmlStr to defensively read Token.config with sensible defaults
(fall back to explicit default numbers/strings when Token.config or specific
keys are missing) and/or add brief documentation near util.tooltip.formatter
stating that Token.config must be initialized before calling the formatter
(mention Token.config, getTooltipContentHtmlStr, and util.tooltip.formatter so
maintainers can locate the code).
- Line 8: The util.echarts export currently exposes the raw echarts instance,
which bypasses any internal theme/component registrations; change the export to
expose the configured instance or a getter instead: stop exporting the
unmodified `echarts` value and instead export a `getEcharts()` function or
`configuredEcharts` symbol that returns the instance after the library's themes,
components, and plugins have been applied (or rename the existing export to
`rawEcharts` and add documentation clearly stating it is unconfigured if you
must keep the raw export); update any consumers to call the new symbol so they
receive the customized instance.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dd688ef2-a0fb-4bc1-b6ea-e1519d57cb6b

📥 Commits

Reviewing files that changed from the base of the PR and between 2d30e28 and f5f80c0.

📒 Files selected for processing (2)
  • src/index.js
  • src/util.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant