dbt-labs / dbt-docs

Auto-generated data documentation site for dbt projects
Apache License 2.0
143 stars 77 forks source link

Add the ability to automatically use different node_color for different materializations #534

Open kdeggelman opened 4 days ago

kdeggelman commented 4 days ago

Describe the feature

When looking at the lineage graph, it would be helpful to visually distinguish models based on their materialization strategies. Ideally the choice of colors would be configurable by the user.

Describe alternatives you've considered

We can manually set the node_color for folders and individual models, so we could organize all of our tables in a folder, views in another folder, incremental in another, etc. This would be a big departure from how we're currently structuring our folders.

Additional context

N/A

Who will this benefit?

What kind of use case will this feature be useful for? Please be specific and provide examples, this will help us prioritize properly. This will benefit all users of dbt-docs who would like to visually distinguish different materializations in their lineage graphs. There have been a few asks about this feature in Slack. For example, here and here.

Are you interested in contributing this feature?

Yes, I'd like to add the code to support this feature. It would be great to hear if the maintainers will be willing to accept a PR with this functionality before I embark.

kdeggelman commented 4 days ago

My first attempt at this was adding an else block here: https://github.com/dbt-labs/dbt-docs/blob/c57ea4c86fc8c2ea0ed32cbe37304cf115c8d31e/src/app/services/graph.service.js#L354-L357

            } else {
                var materialization = _.get(el, ['data', 'config', 'materialized'])
                var colorMap = {
                    'view': '#0094b3',
                    'table': '#4f2d7f',
                    'incremental': '#90004f',
                    'ephemeral': '#adafaf'
                }
                var color = colorMap[materialization]
                if (color) {
                    el.data['node_color'] = color
                }
            }

This worked just fine! But it is my understanding making something like this "opt-in" and adding the ability to customize the colors would require changes in dbt-core to pass the configuration into manifest.json. But at that point, it probably makes more sense to keep logic like this out of dbt-docs and instead have the logic live in dbt-core.

My current thinking is: