plainheart commented on a change in pull request #14214:
URL: https://github.com/apache/echarts/pull/14214#discussion_r570672303



##########
File path: src/component/tooltip/TooltipHTMLContent.ts
##########
@@ -358,6 +358,34 @@ class TooltipHTMLContent {
             + `border-color: ${nearPointColor};`
             + (tooltipModel.get('extraCssText') || '');
 
+        const userWidth = tooltipModel.get(['textStyle', 'width']);
+        if (userWidth != null) {
+            el.style.cssText += `;width:${userWidth}px;`;
+            // `text-overflow_string` has very humble compatibility
+            // shttps://caniuse.com/mdn-css_properties_text-overflow_string
+            const ellipsis = tooltipModel.get(['textStyle', 'ellipsis']);
+            const userOverflow = tooltipModel.get(['textStyle', 'overflow']);
+            switch (userOverflow) {
+                case 'truncate':
+                    el.style.cssText += ';overflow:hidden;'
+                        + `text-overflow:${ellipsis != null ? 
`\'${ellipsis}\'` : 'ellipsis'};`
+                        + 'white-space:nowrap;';
+                    break;
+
+                case 'break':
+                    el.style.cssText += 
';word-break:break-word;white-space:normal;';
+                    break;
+
+                case 'breakAll':
+                    el.style.cssText += 
';word-break:break-all;white-space:normal;';
+                    break;
+
+                default:
+                    el.style.cssText += '';
+                    break;
+            }
+        }

Review comment:
       I'm thinking this logic can be simplified a bit. Just FYI.
   
   ```js
   const ellipsis = retrieve(tooltipModel.get(['textStyle', 'ellipsis']), 
'ellipsis');
   const userOverflow = tooltipModel.get(['textStyle', 'overflow']);
   if (userOverflow) {
       let overflowStyle;
       if (userOverflow === 'truncate') {
           overflowStyle = 
`overflow:hidden;text-overflow:${ellipsis};white-space:nowrap;`
       }
       else {
           const breakMode = userOverflow === 'break'
               ? 'break-word'
               : userOverflow === 'breakAll'
                   ? 'break-all' : '';
           breakMode && (overflowStyle = 
`word-break:${breakMode};white-space:normal;`);
       }
       el.style.cssText += overflowStyle;
   }
   ```




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

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to