Forum Discussion
Dened - Custom Matrix with double headers
- 3 years ago
Hey H_insight. I believe I got everything implemented. Take a look and let me know.
Notes:
- When adjusting the size of the visual, you'll want to adjust the step width/height and the xOffset/yOffset for the rects sitting behind the row and column headers. You'll also want to adjust font size accordingly.
- Although there are alternatives, I added a calculated column to implement the logic for a custom sort order. The column is called "Sort Order". Here you should be able to implement any logic you'd like to determine the sorting of the products.
Spec:
{ "data": {"name": "dataset"}, "facet": { "column": { "field": "Category", "title": null, "header": {"labelFontSize": 14} } }, "spec": { "width": {"step": 70}, "height": {"step": 25}, "encoding": { "y": { "field": "Product", "title": null, "sort": {"field": "Sort Order"}, "axis": { "labelColor": "white", "labelFontWeight": 700 } }, "x": { "field": "Sub Cat", "axis": { "orient": "top", "labelAngle": 0, "labelColor": "white", "labelFontWeight": 700 }, "title": null } }, "layer": [ { "description": "x-axis background rects", "mark": {"type": "rect"}, "encoding": { "y": {"value": 0}, "yOffset": {"value": -25}, "color": { "condition": { "test": "datum['Sub Cat'] == 'Overall'", "value": "#C45920" }, "value": "#325964" } } }, { "description": "y-axis background rects", "mark": { "type": "rect", "opacity": 0.5 }, "encoding": { "x": {"value": 0}, "xOffset": {"value": -80}, "color": {"value": "black"} } }, { "description": "matrix value rects", "mark": {"type": "rect"}, "encoding": { "color": { "field": "Value", "type": "nominal", "scale": { "domain": [1, 2, 3, 4, 5], "range": [ "grey", "amber", "green", "red", "lightBlue" ] }, "legend": null } } }, { "mark": { "type": "text", "tooltip": true, "size": 14 }, "encoding": { "text": { "field": "Value", "type": "quantitative", "format": ",.0f" }, "color": { "field": "Value", "type": "quantitative", "scale": { "domain": [1, 2, 3, 4, 5], "range": [ "white", "white", "white", "white", "black" ] }, "legend": null } } } ] }, "resolve": { "scale": { "x": "independent", "y": "independent" } } }
.pbix here
Thank you very much giammariam. The potential of Deneb is crazy!! Thanks again.
I have a follow-up question when you are free, please:
Is there a way to remove the duplicate x-axis? So it will only show the x-axis at the beginning of the matrix? (this will save space)
Also, how to do a text wrap? Some product names are too long, and they skew the table.
- giammariam3 years agoSolution Sage
Hey H_insight. I have updated this so there is only one y-axis. Moving forward, It's important to not only copy the spec, but the config as well since that has now been updated due to the visual's increased complexity.
For the wrapping, it gets tricky with vega-lite. The only way I'm aware of doing this is by splitting each label into an array based on some delimiter (e.g. a space), or some character count. Then each element in the array for the label could appear on a new line. The other alternative is to use limit. Limit essentially truncates a text string after a specified number of characters and then adds "..." to the end of the text. You can play with limit here by using the input slider. Let me know your thoughts.
Latest .pbix here - H_insight3 years agoHelper V
Hey giammariam, I can't thank you enough for your help.
I will take note of the Config tab in the future. For some reason, I thought the app Specification would set it, but good to know that there is room for changes.
Deneb has so much potential, and the capability so far seems crazy!