You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "Vanisper (via GitHub)" <gi...@apache.org> on 2023/06/28 07:02:54 UTC

[GitHub] [echarts] Vanisper commented on issue #4445: I'm hitting an infinite loop error inside of Animator.js

Vanisper commented on issue #4445:
URL: https://github.com/apache/echarts/issues/4445#issuecomment-1610879901

   这个问题我发现大都是有关颜色的配置出现问题。
   例如:`rgb(255, 255, 255)`当成rgba写了(多一个参数),或者rgba当成rgb写,诸如此类。
   但是我这里仔细检查了这个问题,并没有以上的错误用法(错误用法是一定会触发这个报错的)
   
   所以我的最终解决办法是避开诸如`rgb`、`rgba`的写法,而是使用hex的颜色色值
   
   ---
   以下提供一个`rgb`、`rgba`的颜色传参转hex颜色传参的封装函数
   ```ts
   function opacityToHex(opacity: number) {
       const alpha = Math.round(opacity * 255);
       return alpha.toString(16).padStart(2, '0');
   }
   
   /**
    * 将 RGBA 颜色转换为哈希色值
    * @param rgbaColor 包含分割的rgb或者rgba的字符串:rgb(255,255,255)、甚至是"255,255,255,0.25"
    * @returns 颜色hex值
    */
   export function rgbaColorToHash(rgbaColor: string): string {
       const rgba = rgbaColor.match(/\d+/g)!;
       const alpha = +(rgba.slice(3, 5).join(".") + rgba.slice(5).join(""));
       const hexColor = `#${parseInt(rgba[0]).toString(16).padStart(2, '0')}${parseInt(rgba[1]).toString(16).padStart(2, '0')}${parseInt(rgba[2]).toString(16).padStart(2, '0')}`;
       return alpha ? `${hexColor}${opacityToHex(alpha)}` : hexColor;
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org