我有一个织女星水平条形图与滑块动态改变的值在X轴上.

The code

当鼠标指针悬停在滑块(三角形符号)上时,最初什么都不会发生,并且无法移动滑块. 为了向左或向右滑动,首先我需要点击它,只有在那之后才有可能进行滑动.

enter image description here

预期的行为是将鼠标指针转换为手形,并在发生悬停时使滑块直接移动.

enter image description here

推荐答案

在Enter键上对标记进行填充.

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "width": 700,
  "height": 50,
  "padding": 5,
  "signals": [
    {
      "name": "currentYear0",
      "value": 350,
      "on": [
        {
          "events": "[@handle0:mousedown, window:mouseup] > window:mousemove!",
          "update": "clamp(invert('x', clamp(x(), 0, width)),0, currentYear1-5)"
        }
      ]
    },
    {
      "name": "currentYear1",
      "value": 700,
      "on": [
        {
          "events": "[@handle1:mousedown, window:mouseup] > window:mousemove!",
          "update": "clamp(invert('x', clamp(x(), currentYear0-5, width)),currentYear0-5, 700)"
        }
      ]
    }
  ],
  "scales": [
    {"name": "y", "type": "band", "range": "height", "domain": [1]},
    {"name": "x", "type": "linear", "range": "width", "domain": [0, 700]}
  ],
  "marks": [
    {
      "name": "rect0",
      "type": "rect",
      "encode": {
        "update": {
          "y": {"scale": "y", "value": "0"},
          "height": {"scale": "y", "band": 1, "offset": -1},
          "x": {"scale": "x", "signal": "0"},
          "x2": {"scale": "x", "signal": "currentYear0"},
          "fill": {"value": "#084d95"},
          "fillOpacity": {"value": 1}
        },
        "hover": {"fillOpacity": {"value": 0.5}}
      }
    },
    {
      "name": "rect1",
      "type": "rect",
      "encode": {
        "update": {
          "y": {"scale": "y", "value": "0"},
          "height": {"scale": "y", "band": 1, "offset": -1},
          "x": {"scale": "x", "signal": "currentYear0"},
          "x2": {"scale": "x", "signal": "700"},
          "fill": {"value": "#0ceebb"},
          "fillOpacity": {"value": 1}
        },
        "hover": {"fillOpacity": {"value": 0.5}}
      }
    },
    {
      "name": "handle0",
      "type": "symbol",
      "encode": {
        "enter": {
          "y": {"scale": "x", "value": 0, "offset": -7},
          "shape": {"value": "triangle-down"},
          "size": {"value": 400},
          "stroke": {"value": "#000"},
          "x": {"scale": "x", "field": "y0"},
          "x2": {"scale": "x", "field": "y1"},
          "strokeWidth": {"value": 0.5},
           "fill": {"value": "red"}
        },
        "update": {"x": {"scale": "x", "signal": "currentYear0"}},
        "hover": {
          "fill": {"value": "lemonchiffon"},
          "cursor": {"value": "pointer"}
        }
      }
    },
    {
      "type": "text",
      "encode": {
        "enter": {
          "y": {"value": -20},
          "fontSize": {"value": 16},
          "fontWeight": {"value": "bold"},
          "fill": {"value": "steelblue"},
          "align": {"value": "left"},
          "baseline": {"value": "middle"},
          "angle": {"value": -90},
          "format": ",.2s"
        },
        "update": {
          "text": {"signal": "format(currentYear0,'.1f')"},
          "x": {"scale": "x", "signal": "currentYear0"}
        }
      }
    }
  ],
  "config": {}
}

Json相关问答推荐

使用JSONata将具有相同键的字典合并

Vega通孔信号中的动态梯度

JOLT将对象名作为新属性添加到主体中

使用WSO2 JsonTransform Mediator对空值执行JsonExceptionUndeletedOperationException

如何在Vega中使标记的符号在鼠标指针悬停时可点击

在Jolt中将具有嵌套元素的对象数组转换为单独的对象列表

使用 System.Text.Json 序列化记录成员

如何在 Django 的模板语言中获取 json 键和值?

PowerShell - JSON/PsCustomObject - 为什么我的数组被扁平化为一个对象?

JSON 模式验证

JSON.NET 中特定对象的自定义转换

在 Rails 中使用 JSON 创建嵌套对象

json和空数组

使用 jq 从 bash 中管道分隔的键和值创建 JSON

如何按键查找特定的 JSON 值?

POST:在 url 本身中发送 post 请求

可以在 SharedPreferences 中保存 JSON 数组吗?

为什么 JavaScript 的 eval 需要括号来判断 JSON 数据?

设置对象不是 JSON 可序列化的

从 JSON 到 JSONL 的 Python 转换