<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Vega Lite - Text color based on condition, so next white when darker background in Custom Visuals Development Discussion</title>
    <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Vega-Lite-Text-color-based-on-condition-so-next-white-when/m-p/3010846#M6523</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get the Text color of the my Text Mark to be white when the value is over a 1000.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My vega-lite code is below and is not returning the color change, any help in what i am missing is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;"data": {"name": "dataset"},&lt;BR /&gt;"layer": [&lt;BR /&gt;{&lt;BR /&gt;"mark": "rect",&lt;BR /&gt;"encoding": {&lt;BR /&gt;"x": {"field": "Category",&lt;BR /&gt;"type": "nominal"&lt;BR /&gt;},&lt;BR /&gt;"y": {"field": "Sales", "type": "ordinal",&lt;BR /&gt;"bin":{"maxbins":10}},&lt;BR /&gt;"color": {"aggregate": "count", "field": "CustomerID"},&lt;BR /&gt;"tooltip": [&lt;BR /&gt;{"field": "Category", "type": "ordinal"},&lt;BR /&gt;{"aggregate": "count","field": "Metric", "type":"quantitative"}&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"mark": {&lt;BR /&gt;"type": "text",&lt;BR /&gt;"dy":60,&lt;BR /&gt;"dx":-50&lt;BR /&gt;},&lt;BR /&gt;"encoding": {&lt;BR /&gt;"x": {"field": "Category",&lt;BR /&gt;"type": "nominal"&lt;BR /&gt;},&lt;BR /&gt;"y": {"field": "Sales", "type": "ordinal",&lt;BR /&gt;"bin":{"maxbins":10}},&lt;BR /&gt;"text": {"aggregate": "count","field": "CustomerID", "type": "quantitative"},&lt;BR /&gt;"color": {&lt;BR /&gt;"condition": {&lt;BR /&gt;"test": "datum['CustomerID'] &amp;lt; 1000",&lt;BR /&gt;"value": "white"},&lt;BR /&gt;"value": "black"&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;],&lt;BR /&gt;"config": {&lt;BR /&gt;"axis": {"grid": true, "tickBand": "extent"}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Tue, 10 Jan 2023 09:52:52 GMT</pubDate>
    <dc:creator>DW868990</dc:creator>
    <dc:date>2023-01-10T09:52:52Z</dc:date>
    <item>
      <title>Vega Lite - Text color based on condition, so next white when darker background</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Vega-Lite-Text-color-based-on-condition-so-next-white-when/m-p/3010846#M6523</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get the Text color of the my Text Mark to be white when the value is over a 1000.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My vega-lite code is below and is not returning the color change, any help in what i am missing is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;"data": {"name": "dataset"},&lt;BR /&gt;"layer": [&lt;BR /&gt;{&lt;BR /&gt;"mark": "rect",&lt;BR /&gt;"encoding": {&lt;BR /&gt;"x": {"field": "Category",&lt;BR /&gt;"type": "nominal"&lt;BR /&gt;},&lt;BR /&gt;"y": {"field": "Sales", "type": "ordinal",&lt;BR /&gt;"bin":{"maxbins":10}},&lt;BR /&gt;"color": {"aggregate": "count", "field": "CustomerID"},&lt;BR /&gt;"tooltip": [&lt;BR /&gt;{"field": "Category", "type": "ordinal"},&lt;BR /&gt;{"aggregate": "count","field": "Metric", "type":"quantitative"}&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"mark": {&lt;BR /&gt;"type": "text",&lt;BR /&gt;"dy":60,&lt;BR /&gt;"dx":-50&lt;BR /&gt;},&lt;BR /&gt;"encoding": {&lt;BR /&gt;"x": {"field": "Category",&lt;BR /&gt;"type": "nominal"&lt;BR /&gt;},&lt;BR /&gt;"y": {"field": "Sales", "type": "ordinal",&lt;BR /&gt;"bin":{"maxbins":10}},&lt;BR /&gt;"text": {"aggregate": "count","field": "CustomerID", "type": "quantitative"},&lt;BR /&gt;"color": {&lt;BR /&gt;"condition": {&lt;BR /&gt;"test": "datum['CustomerID'] &amp;lt; 1000",&lt;BR /&gt;"value": "white"},&lt;BR /&gt;"value": "black"&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;],&lt;BR /&gt;"config": {&lt;BR /&gt;"axis": {"grid": true, "tickBand": "extent"}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2023 09:52:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Vega-Lite-Text-color-based-on-condition-so-next-white-when/m-p/3010846#M6523</guid>
      <dc:creator>DW868990</dc:creator>
      <dc:date>2023-01-10T09:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Vega Lite - Text color based on condition, so next white when darker background</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Vega-Lite-Text-color-based-on-condition-so-next-white-when/m-p/3012556#M6531</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/421796"&gt;@DW868990&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;In your condition, you have the following test to set the color to white, and this is using the "less than" (&amp;lt;) symbol:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;"test": "datum['CustomerID'] &amp;lt; 1000",&lt;/LI-CODE&gt;
&lt;P&gt;As you want the color to be set if the value exceeds 1000, I'd suggest changing this to use the "greater than" (&amp;gt;) symbol, e.g.:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;"test": "datum['CustomerID'] &amp;gt; 1000",&lt;/LI-CODE&gt;
&lt;H2&gt;Alternative approach&lt;/H2&gt;
&lt;P&gt;As using the &lt;FONT face="courier new,courier"&gt;color&lt;/FONT&gt; encoding channel will create a scale that might cause issues if you bind color elsewhere in your spec, you could also try using the &lt;A href="https://vega.github.io/vega-lite/docs/mark.html#color" target="_self"&gt;color property in the mark directly&lt;/A&gt;, which is better suited for this use case. HEre's how I'd re-write your spec by removing the encoding channel and binding this to the mark's &lt;FONT face="courier new,courier"&gt;color&lt;/FONT&gt; property using an ExprRef, like this (lines 21-23):&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;{
  "data": { "name": "dataset" },
  "layer": [
    {
      "mark": "rect",
      "encoding": {
        "x": { "field": "Category", "type": "nominal" },
        "y": { "field": "Sales", "type": "ordinal", "bin": { "maxbins": 10 } },
        "color": { "aggregate": "count", "field": "CustomerID" },
        "tooltip": [
          { "field": "Category", "type": "ordinal" },
          { "aggregate": "count", "field": "Metric", "type": "quantitative" }
        ]
      }
    },
    {
      "mark": {
        "type": "text",
        "dy": 60,
        "dx": -50,
        "color": {
            "expr": "datum['CustomerID'] &amp;gt; 1000 ? 'white' : 'black'"
        }
      },
      "encoding": {
        "x": { "field": "Category", "type": "nominal" },
        "y": { "field": "Sales", "type": "ordinal", "bin": { "maxbins": 10 } },
        "text": {
          "aggregate": "count",
          "field": "CustomerID",
          "type": "quantitative"
        }
      }
    }
  ],
  "config": {
    "axis": { "grid": true, "tickBand": "extent" }
  }
}
&lt;/LI-CODE&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 02:16:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Vega-Lite-Text-color-based-on-condition-so-next-white-when/m-p/3012556#M6531</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2023-01-11T02:16:15Z</dc:date>
    </item>
  </channel>
</rss>

