Skip to content

feat(core): add utils#426

Closed
ader-h wants to merge 1 commit intoopentiny:devfrom
ader-h:feat-util-0309
Closed

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

Conversation

@ader-h
Copy link
Copy Markdown
Contributor

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

Summary by CodeRabbit

  • Refactor
    • Established a new centralized utility module consolidating utilities for tooltip configuration, chart library access, and text formatting capabilities.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2026

Walkthrough

This PR introduces a new utility module at src/utils.js that consolidates and re-exports commonly used utilities, including tooltip configuration, echarts library access, and text formatting functions into a centralized object.

Changes

Cohort / File(s) Summary
New Utility Module
src/utils.js
Creates a centralized utility object exporting tooltip formatter configuration, echarts library reference, and text truncation utility from echarts.format.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Hops of joy through utils.js so neat,
Where tooltips, formats, and echarts all meet!
A cozy burrow of functions, organized tight,
Making our code utilities shine bright!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'feat(core): add utils' is vague and generic. While it indicates a new feature is being added to the core, it doesn't convey what the utils module contains or what specific functionality it provides. Consider using a more descriptive title that specifies the purpose, such as 'feat(core): add utils module with tooltip formatter and text utilities' or 'feat(core): add centralized utils with echarts helpers'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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
Copy Markdown

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/utils.js (1)

4-12: Consider adding JSDoc comments for the exported utility object.

Since this is a public-facing utility module, documenting the expected usage patterns and parameter requirements would help consumers use it correctly.

📝 Add documentation
+/**
+ * Utility helpers for tiny-charts.
+ * `@property` {Object} tooltip - Tooltip utilities
+ * `@property` {Function} tooltip.formatter - Builds tooltip HTML from a config object.
+ *   Note: This is NOT a direct ECharts formatter. It expects (tipConfig, tooltipOptions)
+ *   where tipConfig = { title, children, hideEmpty, isMobile }.
+ * `@property` {Object} echarts - The echarts library namespace
+ * `@property` {Object} format - Text formatting utilities
+ * `@property` {Function} format.truncateText - Truncates text to fit within a given width
+ */
 const util = {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils.js` around lines 4 - 12, Add JSDoc comments to the exported util
object: document the util object itself and each child property (tooltip with
formatter -> getTooltipContentHtmlStr, echarts, and format.truncateText)
describing purpose, expected input types/return types, and usage examples;
annotate that tooltip.formatter expects the same args as
getTooltipContentHtmlStr, note that format.truncateText forwards to
echarts.format.truncateText and specify its parameter meanings (text, options),
and include `@module/`@exports tags so consumers can discover these utilities
easily.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/utils.js`:
- Around line 5-7: The current util export exposes getTooltipContentHtmlStr
which expects a pre-built tipConfig ({title, children, hideEmpty, isMobile}) but
ECharts calls tooltip.formatter with (params, ticket, callback); fix by adding a
wrapper factory named createEChartsTooltipFormatter (or similar) that returns a
function with the ECharts signature which converts the incoming params into the
tipConfig shape and then calls getTooltipContentHtmlStr, and update
util.tooltip.formatter to reference the new wrapper (or rename
getTooltipContentHtmlStr to buildTooltipHtml and export both the helper and the
wrapper); ensure the wrapper handles both single and array params and preserves
the optional async callback path so existing callers (e.g.,
ProcessChart/handleOption.js and BarChart/handleSeries.js) can still use the
helper directly if needed.

---

Nitpick comments:
In `@src/utils.js`:
- Around line 4-12: Add JSDoc comments to the exported util object: document the
util object itself and each child property (tooltip with formatter ->
getTooltipContentHtmlStr, echarts, and format.truncateText) describing purpose,
expected input types/return types, and usage examples; annotate that
tooltip.formatter expects the same args as getTooltipContentHtmlStr, note that
format.truncateText forwards to echarts.format.truncateText and specify its
parameter meanings (text, options), and include `@module/`@exports tags so
consumers can discover these utilities easily.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 765f710e-3175-4309-bbb4-dbe75827870f

📥 Commits

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

📒 Files selected for processing (1)
  • src/utils.js

Comment thread src/utils.js
Comment on lines +5 to +7
tooltip: {
formatter: getTooltipContentHtmlStr
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Function signature mismatch: getTooltipContentHtmlStr cannot be used directly as an ECharts formatter.

The exposed getTooltipContentHtmlStr expects (tipConfig, tooltip) where tipConfig is a pre-constructed object with { title, children, hideEmpty, isMobile }. However, ECharts calls the formatter callback with (params, ticket, callback).

If a user assigns util.tooltip.formatter directly to their chart's tooltip.formatter, it will receive raw ECharts params instead of the expected config object, causing incorrect output or errors.

Looking at existing usages (e.g., ProcessChart/handleOption.js:172, BarChart/handleSeries.js:684), all properly wrap this function to transform ECharts params before calling it.

Consider either:

  1. Renaming to clarify it's a helper, not a drop-in formatter (e.g., buildTooltipHtml)
  2. Providing a wrapper that handles the ECharts signature
  3. Adding documentation explaining the required transformation
Option 1: Rename to clarify usage
 const util = {
   tooltip: {
-    formatter: getTooltipContentHtmlStr
+    buildTooltipHtml: getTooltipContentHtmlStr
   },
Option 2: Provide a factory function
+// Factory that creates an ECharts-compatible formatter
+function createTooltipFormatter(options = {}) {
+  return (params, ticket, callback) => {
+    const config = {
+      title: Array.isArray(params) ? params[0]?.name : params?.name,
+      children: [],
+      hideEmpty: options.hideEmpty,
+      isMobile: options.isMobile
+    };
+    // User should customize children population based on their data
+    return getTooltipContentHtmlStr(config, options);
+  };
+}
+
 const util = {
   tooltip: {
-    formatter: getTooltipContentHtmlStr
+    buildTooltipHtml: getTooltipContentHtmlStr,
+    createFormatter: createTooltipFormatter
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
tooltip: {
formatter: getTooltipContentHtmlStr
},
tooltip: {
buildTooltipHtml: getTooltipContentHtmlStr
},
Suggested change
tooltip: {
formatter: getTooltipContentHtmlStr
},
// Factory that creates an ECharts-compatible formatter
function createTooltipFormatter(options = {}) {
return (params, ticket, callback) => {
const config = {
title: Array.isArray(params) ? params[0]?.name : params?.name,
children: [],
hideEmpty: options.hideEmpty,
isMobile: options.isMobile
};
// User should customize children population based on their data
return getTooltipContentHtmlStr(config, options);
};
}
const util = {
tooltip: {
buildTooltipHtml: getTooltipContentHtmlStr,
createFormatter: createTooltipFormatter
},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils.js` around lines 5 - 7, The current util export exposes
getTooltipContentHtmlStr which expects a pre-built tipConfig ({title, children,
hideEmpty, isMobile}) but ECharts calls tooltip.formatter with (params, ticket,
callback); fix by adding a wrapper factory named createEChartsTooltipFormatter
(or similar) that returns a function with the ECharts signature which converts
the incoming params into the tipConfig shape and then calls
getTooltipContentHtmlStr, and update util.tooltip.formatter to reference the new
wrapper (or rename getTooltipContentHtmlStr to buildTooltipHtml and export both
the helper and the wrapper); ensure the wrapper handles both single and array
params and preserves the optional async callback path so existing callers (e.g.,
ProcessChart/handleOption.js and BarChart/handleSeries.js) can still use the
helper directly if needed.

@ader-h ader-h closed this Mar 12, 2026
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