cholocate commented on issue #20712:
URL: https://github.com/apache/echarts/issues/20712#issuecomment-2669631035

   @Ovilia There's a better example, currently for echarts, legends are not 
really used for hierarchal charts (which shouldn't be a problem since we use 
our own legend in our platform), but the opacity change (say when you hover 
over a specific data point in the legend) to emphasize on that data, will 
require `Zrender` changes. This is fine during testing but as @lwangsf 
mentioned, we are accessing the `Zrender` APIs and data manually which becomes 
unsafe when further accessed. 
   The example below illustrates my point: 
   
   
https://github.com/user-attachments/assets/03156a23-214d-4eaa-b896-005c44e6004e
   
   ```
         data.eachItemGraphicEl((graphic, index) => {
           if (typeof graphic.setStyle === 'function') {
             graphic.setStyle({
               opacity:
                 dataIndexes.includes(index) || selectedIndexes.includes(index)
                   ? 1
                   : 0.3,
               // legend highlight should add a stroke when there's an active 
selection
               stroke:
                 (dataIndexes.includes(index) && selectedIndexes.length > 0) ||
                 selectedIndexes.includes(index)
                   ? '#000'
                   : '#fff',
             });
           } else {
             graphic._children.map(g => {
               if (typeof g.setStyle === 'function') {
                 g.setStyle({
                   opacity:
                     dataIndexes.includes(index) || 
selectedIndexes.includes(index)
                       ? 1
                       : 0.3,
                   // legend highlight should add a stroke when there's an 
active selection
                   stroke:
                     (dataIndexes.includes(index) && selectedIndexes.length > 
0) ||
                     selectedIndexes.includes(index)
                       ? '#000'
                       : '#fff',
                 });
               }
             });
           }
   ```
   Keypoints for the snippet: 
   - graphic styles are different for hierarchal data which is why i checked 
for `function` beforehand 
   - we are manually searching for the corresponding data indices in the 
payload returned from echarts, then matching that with the data indices from 
the platform (it would be better if there is support to attach the data 
information)
   - The interaction requires resetting the opacity after as well, again 
manipulating `Zrender` instead of using the APIs. 
   
   


-- 
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: [email protected]

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