I am in the process of porting my app from ionic 3 to ionic 4. I use D3 for the creation of a meter. None of the styling is working. The entire meter is black. I am assuming it has something to do with lazy loading / shadow DOM.
And here is the result - all black. I highlighted the html for the two posts at the top where the rect has the battery-post on it which should fill the posts with -ion-color-success but it stays black:
I have not been able to figure out how to add the svg namespace to each element with D3. I did try replacing:
<ion-content>
<div #battery></div>
</ion-content>
with
<ion-content>
<svg #battery></svg>
</ion-content>
What is frustrating is that this is working with the exact same version of D3 that I am using with the ionic 3 (angular 3) version of the app and comparing with the ionic 4 app - all of the elements and .scss classes in chrome inspector match what I have in the ionic 3 project. It is just that none of the .scss classes are taken affect in the ionic 4 (angular 7 project)
I might have to ditch D3 and use svg directly so I can try your suggestion. I was really hoping moving from ionic 3 to ionic 4 would be a little easier than it has been.
Hey man, I hear you. I am also in the process of migration and indeed its not that easy. But I think the more I learn about differences the more I like it (4) and also the more i learn about Angular and Ionic.
I think the issue that you have most likely can be resolved in not so painful manner but this requires an expert help (which I am not;/). D3 is a popular library so I am sure a thing such as adding a class should be supported with no issues.
The author uses ViewEncapsulation.None as a mean to avoid similar issue that you have - please try?
In the component declaration, we changed the ViewEncapsulation, since the dynamic modifications to the DOM by D3 don’t play well with the default Angular styling. Without this modification, the styles aren’t applied.