apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.59k stars 19.62k forks source link

Add Support for Right-to-Left (RTL) Chart Animation #20351

Open zaidqureshi95 opened 1 month ago

zaidqureshi95 commented 1 month ago

What problem does this feature solve?

Hi,

I would like to request a new feature for the library to support right-to-left (RTL) chart animation.

Current Behavior:

Requested Feature:

Use Case:

Implementation Suggestion:

Thank you for considering this feature request! I believe it would greatly benefit apps that cater to RTL language users.

Best regards,
zaid

What does the proposed API look like?

Proposed API Changes

To implement the right-to-left (RTL) chart animation, I propose adding a new optional property to the chart component, such as isRTL. This property will allow developers to specify whether the chart should animate from right to left, depending on the app's language settings.

API Design:

New Property:

Usage Example:

// Import the chart component from the library
import { ChartComponent } from 'chart-library';

const MyChart = () => {
  // Check if the current language is Arabic or any other RTL language
  const isRTL = (currentLanguage === 'ar' || currentLanguage === 'he');

  return (
    <ChartComponent
      data={chartData}
      isRTL={isRTL} // Set the isRTL property based on the app's language setting
      // Other chart properties...
    />
  );
};

How This Solves the Problem:

By introducing the isRTL property:

Proposed Changes in the Library:

  1. Add the isRTL property to the chart component's props.
  2. Modify the chart animation logic to check the value of isRTL:
    • If isRTL is true, adjust the starting point of the animation to the right side.
    • If isRTL is false or not provided, maintain the default left-to-right animation behavior.

Code Sample for Library Implementation:

// Inside the chart component
const ChartComponent = ({ data, isRTL = false, ...props }) => {
  // Determine animation direction
  const animationDirection = isRTL ? 'right-to-left' : 'left-to-right';

  // Apply animation based on the direction
  const animateChart = () => {
    if (animationDirection === 'right-to-left') {
      // Logic to animate from right to left
    } else {
      // Default logic to animate from left to right
    }
  };

  // Rest of the chart rendering logic...

  return (
    <div>
      {/* Render the chart with animation */}
    </div>
  );
};

Conclusion:

This proposed API change will provide a simple, effective solution to support RTL chart animation, enhancing the library's functionality for global usage.

Ovilia commented 1 month ago

Thanks for this. I think it would be a valuable feature for ECharts's i18n ability. We will do some research to see how much work is required for this feature.