vega icon indicating copy to clipboard operation
vega copied to clipboard

Label keeps changing positions when rerun label-transform

Open chanwutk opened this issue 3 years ago • 1 comments

Nov-08-2021 12-13-48

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "width": 100,
  "height": 100,
  "data": [
    {
      "name": "table",
      "values": [12]
    }
  ],
  "marks": [
    {
      "type": "symbol",
      "name": "point",
      "from": {"data": "table"},
      "encode": {
        "enter": {
          "x": {"value": 0},
          "y": {"value": 0}
        },
        "update": {
          "fill": {"value": "#ccc"}
        },
        "hover": {
          "fill": {"value": "pink"}
        }
      }
    },
    {
      "type": "text",
      "from": {"data": "table"},
      "encode": {
        "enter": {
          "x": {"value": 30},
          "y": {"value": 30},
          "text": {"value": "label"}
        }
      },
      "transform": [
        {
          "type": "label",
          "size": {"signal": "[width, height]"},
          "avoidMarks": ["point"]
        }
      ]
    }
  ]
}

Link to the spec: https://vega.github.io/editor/#/url/vega/N4IgJAzgxgFgpgWwIYgFwhgF0wBwqgegIDc4BzJAOjIEtMYBXAI0poHsDp5kTykSArJQBWENgDsQAGhAB3GgBN6aAIwAGNTPg0yWVRpkKkmFKgDaocUgRw0IE0wA2tmcSSOGcCGjMqATAC6AL4BMsgATgDW3uagmACeOLboEPEITGyO0iBWNnY4bDTimNkAZuFsCGigRiZ2Ds4gQTJw4lBsCsmgrZhw4dUgAB4Dbh7Jas0g8SPunmgTkww4tV0gpTSOWaigo3PoAMRQR02TMGyk-dtrG1s7s8kgOEWRJ0HNcYkPvYMlMuWVA1qpnsSCctkmrXanQGPT6A2GV12yQAzBMZNNEfc0KjJt8SpixnZHKC4Fk3rjwkhxBBSmxwlVYvZPkSSVkZBAaAAvVYcshWLYgMzyJQwKQAAm0ukwASaMiQxEKCgAskgojEzI9CsUQMFdUEgA

  • The text mark does not use reactive geometry
  • label-transform on the text mark avoid the point mark.

What happened?:

  • Without reactive geometry, label-transform uses the x/y of the texts to calculate the texts' anchor points.
  • Label-transform changes the x/y of the texts.
  • When the label-transform runs again (as we interact with the point), the label-transform uses the new x/y of the texts as the texts' anchor points.

Todo:

  • remember the original position of the text mark on the first time label-transform runs.

chanwutk avatar Nov 08 '21 20:11 chanwutk

I wonder should we support label-transform without reactive geometry at all. This spec can achieve the same result with reactive geometry, so the position of the label does not keep changing: https://vega.github.io/editor/#/url/vega/N4IgJAzgxgFgpgWwIYgFwhgF0wBwqgegIDc4BzJAOjIEtMYBXAI0poHsDp5kTykSArJQBWENgDsQAGhAB3GgBN6aAIwAGNTPg0yWVRpkKkmFKgDaocUgRw0IE0wA2tmcSSOGcCGjMqATAC6AL4BMsgATgDW3uagmACeOLboEPEITGyO0iBWNnY4bDTimNkAZuFsCGigRiZ2Ds4gQTJw4lBsCsmgrZhw4dUgAB4Dbh7Jas0g8SPunmgTkww4tV0gpTSOWaigo3PoAMRQR02TMGyk-dtrG1s7s8kgOEWRJ0HNcYkPqemZZRVVV1qpnsSCctkmuQeTCQEBcIFa7U6Ax6fQGwyuu2SAGYJjJphj7mgcZMIDQAF6rTHzN5vKQfJL1OCDEoycqVAZAuzQ2FNFptDqrFGXOJMkoEsZ2RyguBZGkyTDhJDiCClNjhAEWeyfSXSrIyUkUgakshWLYgMzyJQwKQAAm0ukwAV5ICQxEKCgAskgojEzI9CsUQKEXW7FAAhGFwL1RNCldywkKJoA

chanwutk avatar Dec 03 '21 22:12 chanwutk