
Custom Field Styling (HTML + Markdown)
A huge overhaul to field formatting in the model to open up conditional formatting, markdown, and HTML - including handlers for common patterns like currency (with conversion).
Transcript
This transcript is auto-generated. Names and product terms may be wrong.
Okay. Let me get this going. Uh yeah. Um so, last week I was tasked with like kind of figuring out how to handle currency formats, and then that kind of expanded into just formats in general. So, this week I came up with like three different flavors of how to handle kind of complex formatting cases. Um the first one is just allowing mustache references in format.
So, here we have total cost. It's an aggregate based on the cost, and then it's referencing this product department value. Um and when you reference another field in mustache, it's going to bring it in as a required field, and it will change the grouping. But you can see in the results we have product category, which is a dimension that I've selected, and then the measure has this formatting applied to it, but I'm sorting on the number.
So, this is like the last step of like, okay, you have the actual numeric values, and then you just apply this format. Um and that's kind of nice, but then it also changes the query results in a way in weird ways, cuz you're actually changing the grouping, right? So, you can see like the bar chart has like dipped two steps of grouping here.
Um so, not perfect. And then the next thing was like, okay, well, how do we have more styles to it? You know, there's some tools have like full-blown HTML parameters that you can add to fields. Um and we have markdown. So, we added this, and it's based all on like Richard and Co's work. So, when you add markdown to a dimension and you use it in a table, it's just tied to that dimension now.
So, you don't have to go and like edit the viz specifically. Um but it only works in tables and places that we can actually render markdown. So, that's like the second option, right? You can have a markdown. Um but that's also limited because mustache by, you know, its convention or it's like its whole deal is that there's no conditional logic in mustache.
So, this is like tied to the the values that I want to reference, right? Um so, we need a way to like provide dynamic labeling of things based off of like the filters or the values of fields or maybe like user attributes. So, then we get this third case where it's like, "Okay, let's just expand format uh to to take this argument of depends on."
Um so, now you have a measure, you add this depends on parameter, and then you list the conditions. And right now I'm saying like this this formatting depends on a filter value. Um so, if I go here, I have and the nice thing about this is that this is purely in the format clause, so it's just messing with the strings.
So, it works in charts as well. So, it doesn't it's not dependent on on markdown. Um so, it's going to work in our our viz layer as well as tables. Um and so, I can switch between US, UK, things like that. Um and then the last thing is like, "Okay, well, what if you don't want somebody to control it?"
You just have like a user attribute that is controlling this uh locale or region. You can also do that. So, it's like the format depends on a user attribute, which is region, and then a list of conditions. And this condition stuff is based off of what Rob did for colors. So, there's some uh precedent for for model feature like this.
Um so, those are the three different flavors we have. And uh this is kind of messy, right? Like this long format. So, I think the next step is to have named formats, which I'll probably work on next week. So, you can just reference like a pre-made uh selector like that. And that's that's it. Two, don't leave. I have two questions.
Uh so, today is I thought this is partially built on this the markdown columns that Richard has. Is it behind I think that's still feature flagged. Although, we should probably remove the feature flag. Yeah. Do we need Does that need to be on for this to work? And then two also does this mean we can like add a trivial promote step?
So, like take Richard's front end markdown column builder and then like promote that to store it back to the data model? Yeah, probably. I think so. I I kind of wanted that um when I was messing with this if you edit it, um it'll pull in the markdown definition in the field and then if you swap to like the value, it just defaults back to the modeled markdown.
So, I think there there needs to be a way to override that and then promote it back. Um and did I say did I say it was Rob's markdown stuff? I meant to say Richard's. I don't know. I don't remember. No, I think you said Richard. No, it's awesome. Really cool. But Rob did the color stuff. You know, it's all it's all dependent on everybody else's work, so it's not yeah.
One team, everyone's building. That's awesome. That's it.