VisActor / VChart

VChart, more than just a cross-platform charting library, but also an expressive data storyteller.
https://www.visactor.io/vchart
MIT License
920 stars 62 forks source link

[Bug] label's refX/refY/dx/dy can not work in `type-step` markLine #2739

Closed kkxxkk2019 closed 4 months ago

kkxxkk2019 commented 4 months ago

Version

lastest

Link to Minimal Reproduction

none

Steps to Reproduce

const spec = {
  "direction": "vertical",
  "type": "common",
  "color": [
    "#00295C",
    "#2568BD",
    "#9F9F9F",
    "#C5C5C5",
    "#00B0F0",
    "#4BCFFF",
    "#C2C2C2",
    "#D7D7D7"
  ],
  "series": [
    {
      "type": "bar",
      "stack": true,
      "direction": "vertical",
      "bar": {
        "style": {
          "stroke": "",
          "lineWidth": 1
        },
        "state": {
          "hover": {
            "stroke": "#000",
            "lineWidth": 1
          }
        }
      },
      "barBackground": {
        "style": {
          "stroke": "",
          "lineWidth": 1
        }
      },
      "label": {
        "visible": true,
        "position": "inside",
        "style": {
          "lineHeight": "100%",
          "fontSize": 16,
          "fontWeight": "bold"
        },
        "overlap": {
          "strategy": []
        },
        "smartInvert": true,
        "interactive": true
      },
      "totalLabel": {
        "visible": true,
        "position": "top",
        "overlap": false,
        "clampForce": false,
        "formatConfig": {
          "fixed": 0,
          "content": "value"
        },
        "style": {
          "lineHeight": "100%",
          "lineWidth": 1,
          "fill": "#1F2329",
          "stroke": "#ffffff",
          "fontSize": 16,
          "fontWeight": "bold"
        },
        "interactive": true
      },
      "seriesLabel": {
        "visible": true,
        "position": "end",
        "label": {
          "style": {
            "lineHeight": "100%",
            "lineWidth": 1,
            "stroke": "#ffffff",
            "fontSize": 16,
            "fontWeight": "bold"
          },
          "space": 10
        }
      },
      "xField": "_editor_dimension_field",
      "yField": "_editor_value_field",
      "dataId": "0",
      "id": "series-0",
      "EDITOR_SERIES_DATA_KEY": "a",
      "seriesField": "_editor_type_field"
    },
    {
      "type": "bar",
      "stack": true,
      "direction": "vertical",
      "bar": {
        "style": {
          "stroke": "",
          "lineWidth": 1
        },
        "state": {
          "hover": {
            "stroke": "#000",
            "lineWidth": 1
          }
        }
      },
      "barBackground": {
        "style": {
          "stroke": "",
          "lineWidth": 1
        }
      },
      "label": {
        "visible": true,
        "position": "inside",
        "style": {
          "lineHeight": "100%",
          "fontSize": 16,
          "fontWeight": "bold"
        },
        "overlap": {
          "strategy": []
        },
        "smartInvert": true,
        "interactive": true
      },
      "totalLabel": {
        "visible": true,
        "position": "top",
        "overlap": false,
        "clampForce": false,
        "formatConfig": {
          "fixed": 0,
          "content": "value"
        },
        "style": {
          "lineHeight": "100%",
          "lineWidth": 1,
          "fill": "#1F2329",
          "stroke": "#ffffff",
          "fontSize": 16,
          "fontWeight": "bold"
        },
        "interactive": true
      },
      "seriesLabel": {
        "visible": true,
        "position": "end",
        "label": {
          "style": {
            "lineHeight": "100%",
            "lineWidth": 1,
            "stroke": "#ffffff",
            "fontSize": 16,
            "fontWeight": "bold"
          },
          "space": 10
        }
      },
      "xField": "_editor_dimension_field",
      "yField": "_editor_value_field",
      "dataId": "1",
      "id": "series-1",
      "EDITOR_SERIES_DATA_KEY": "b",
      "seriesField": "_editor_type_field"
    }
  ],
  "legends": {
    "id": "legend-discrete",
    "visible": false,
    "autoPage": false,
    "position": "start",
    "interactive": false,
    "item": {
      "label": {
        "style": {
          "fill": "#1F2329",
          "fontSize": 16
        }
      }
    }
  },
  "region": [
    {
      "id": "region-0"
    }
  ],
  "tooltip": {
    "visible": true
  },
  "axes": [
    {
      "orient": "left",
      "id": "axis-left",
      "type": "linear",
      "label": {
        "autoLimit": false,
        "style": {
          "fill": "#1F2329",
          "fontSize": 16
        },
        "formatMethod": null
      },
      "domainLine": {
        "visible": true,
        "style": {
          "stroke": "#000000"
        }
      },
      "tick": {
        "visible": true,
        "style": {
          "stroke": "#000000"
        }
      },
      "grid": {
        "visible": false,
        "style": {
          "stroke": "#bbbfc4"
        }
      },
      "autoIndent": false,
      "maxWidth": null,
      "maxHeight": null
    },
    {
      "orient": "bottom",
      "id": "axis-bottom",
      "type": "band",
      "label": {
        "autoLimit": false,
        "style": {
          "fill": "#1F2329",
          "fontSize": 16
        }
      },
      "domainLine": {
        "visible": true,
        "style": {
          "stroke": "#000000"
        },
        "onZero": true
      },
      "tick": {
        "visible": true,
        "style": {
          "stroke": "#000000"
        }
      },
      "grid": {
        "visible": false,
        "style": {
          "stroke": "#bbbfc4"
        }
      },
      "autoIndent": false,
      "maxWidth": null,
      "maxHeight": null,
      "trimPadding": false,
      "paddingInner": [
        0.2,
        0
      ],
      "paddingOuter": [
        0.2,
        0
      ]
    }
  ],
  "data": [
    {
      "id": "0",
      "sourceKey": "a",
      "values": [
        {
          "_editor_dimension_field": "x1",
          "_editor_value_field": 20,
          "_editor_type_field": "a"
        },
        {
          "_editor_dimension_field": "x2",
          "_editor_value_field": 23,
          "_editor_type_field": "a"
        },
        {
          "_editor_dimension_field": "x3",
          "_editor_value_field": 26,
          "_editor_type_field": "a"
        }
      ]
    },
    {
      "id": "1",
      "sourceKey": "b",
      "values": [
        {
          "_editor_dimension_field": "x1",
          "_editor_value_field": 20,
          "_editor_type_field": "b"
        },
        {
          "_editor_dimension_field": "x2",
          "_editor_value_field": 99,
          "_editor_type_field": "b"
        },
        {
          "_editor_dimension_field": "x3",
          "_editor_value_field": 29,
          "_editor_type_field": "b"
        }
      ]
    }
  ],
  "markArea": [],
  "markLine": [
    {
      "_originValue_": [
        40,
        122
      ],
      "connectDirection": "top",
      "coordinates": [
        {
          "VGRAMMAR_DATA_ID_KEY_1211": 0,
          "__VCHART_DEFAULT_DATA_INDEX": 0,
          "__VCHART_DEFAULT_DATA_KEY": 0,
          "__VCHART_STACK_END": 40,
          "__VCHART_STACK_END_PERCENT": 1,
          "__VCHART_STACK_KEY": "x1",
          "__VCHART_STACK_START": 20,
          "__VCHART_STACK_START_PERCENT": 0.5,
          "__VCHART_STACK_TOTAL": 40,
          "__VCHART_STACK_TOTAL_PERCENT": 1,
          "__VCHART_STACK_TOTAL_TOP": true,
          "_editor_dimension_field": "x1",
          "_editor_type_field": "b",
          "_editor_value_field": 40,
          "refRelativeSeriesId": "series-1"
        },
        {
          "VGRAMMAR_DATA_ID_KEY_1211": 1,
          "__VCHART_DEFAULT_DATA_INDEX": 1,
          "__VCHART_DEFAULT_DATA_KEY": 1,
          "__VCHART_STACK_END": 122,
          "__VCHART_STACK_END_PERCENT": 1,
          "__VCHART_STACK_KEY": "x2",
          "__VCHART_STACK_START": 23,
          "__VCHART_STACK_START_PERCENT": 0.1885245901639344,
          "__VCHART_STACK_TOTAL": 122,
          "__VCHART_STACK_TOTAL_PERCENT": 1,
          "__VCHART_STACK_TOTAL_TOP": true,
          "_editor_dimension_field": "x2",
          "_editor_type_field": "b",
          "_editor_value_field": 122,
          "refRelativeSeriesId": "series-1"
        }
      ],
      "coordinatesOffset": [
        {
          "x": 0,
          "y": -25.99999999999997
        },
        {
          "x": 0,
          "y": -25.999999999999986
        }
      ],
      "endSymbol": {
        "refX": -4,
        "size": 12,
        "style": {
          "fill": "#000",
          "lineWidth": 0,
          "stroke": null
        },
        "symbolType": "M -0.0625 -0.3167 C -0.0625 -0.2821 -0.0346 -0.2542 0 -0.2542 C 0.0346 -0.2542 0.0625 -0.2821 0.0625 -0.3167 C 0.0625 -0.3167 -0.0625 -0.3167 -0.0625 -0.3167 Z M 0.0442 -0.4025 C 0.0196 -0.4271 -0.0196 -0.4271 -0.0442 -0.4025 C -0.0442 -0.4025 -0.4421 -0.0046 -0.4421 -0.0046 C -0.4662 0.0196 -0.4662 0.0592 -0.4421 0.0838 C -0.4175 0.1079 -0.3779 0.1079 -0.3538 0.0838 C -0.3538 0.0838 0 -0.27 0 -0.27 C 0 -0.27 0.3538 0.0838 0.3538 0.0838 C 0.3779 0.1079 0.4175 0.1079 0.4421 0.0838 C 0.4662 0.0592 0.4662 0.0196 0.4421 -0.0046 C 0.4421 -0.0046 0.0442 -0.4025 0.0442 -0.4025 Z M 0.0625 -0.3167 C 0.0625 -0.3167 0.0625 -0.3583 0.0625 -0.3583 C 0.0625 -0.3583 -0.0625 -0.3583 -0.0625 -0.3583 C -0.0625 -0.3583 -0.0625 -0.3167 -0.0625 -0.3167 C -0.0625 -0.3167 0.0625 -0.3167 0.0625 -0.3167 Z",
        "visible": true
      },
      "expandDistance": "3.8353488869863206%",
      "expression": null,
      "id": "797de537-7131-4db9-b3b0-62ac625b7240",
      "interactive": true,
      "label": {
        "__position__": "top",
        "childrenPickable": false,
        "labelBackground": {
          "padding": {
            "bottom": 2,
            "left": 4,
            "right": 4,
            "top": 2
          },
          "style": {
            "cornerRadius": 4,
            "fill": "#fff",
            "fillOpacity": 1,
            "lineWidth": 1,
            "stroke": "#000"
          }
        },
        "pickable": true,
        "position": "middle",
        "refX": -29,
        "refY": 0,
        "style": {
          "fill": "#1F2329",
          "fontSize": 16,
          "fontStyle": "normal",
          "fontWeight": "bold"
        },
        "text": "205%"
      },
      "line": {
        "style": {
          "cornerRadius": 4,
          "lineDash": [
            0
          ],
          "lineWidth": 1,
          "pickStrokeBuffer": 10,
          "stroke": "#000"
        }
      },
      "name": "total-diff-line",
      "startSymbol": {
        "size": 10,
        "style": {
          "fill": "#606773",
          "lineWidth": 0,
          "stroke": null
        },
        "symbolType": "triangle",
        "visible": false
      },
      "type": "type-step",
      "zIndex": 510
    },
    {
      "_originValue_": [
        20,
        122
      ],
      "connectDirection": "right",
      "coordinates": [
        {
          "VGRAMMAR_DATA_ID_KEY_1206": 0,
          "__VCHART_DEFAULT_DATA_INDEX": 0,
          "__VCHART_DEFAULT_DATA_KEY": 0,
          "__VCHART_STACK_END": 20,
          "__VCHART_STACK_END_PERCENT": 0.5,
          "__VCHART_STACK_KEY": "x1",
          "__VCHART_STACK_START": 0,
          "__VCHART_STACK_START_PERCENT": 0,
          "__VCHART_STACK_TOTAL": 40,
          "__VCHART_STACK_TOTAL_PERCENT": 1,
          "_editor_dimension_field": "x1",
          "_editor_type_field": "a",
          "_editor_value_field": 20,
          "refRelativeSeriesId": "series-0"
        },
        {
          "VGRAMMAR_DATA_ID_KEY_1211": 1,
          "__VCHART_DEFAULT_DATA_INDEX": 1,
          "__VCHART_DEFAULT_DATA_KEY": 1,
          "__VCHART_STACK_END": 122,
          "__VCHART_STACK_END_PERCENT": 1,
          "__VCHART_STACK_KEY": "x2",
          "__VCHART_STACK_START": 23,
          "__VCHART_STACK_START_PERCENT": 0.1885245901639344,
          "__VCHART_STACK_TOTAL": 122,
          "__VCHART_STACK_TOTAL_PERCENT": 1,
          "__VCHART_STACK_TOTAL_TOP": true,
          "_editor_dimension_field": "x2",
          "_editor_type_field": "b",
          "_editor_value_field": 122,
          "refRelativeSeriesId": "series-1"
        }
      ],
      "endSymbol": {
        "refX": -4,
        "size": 12,
        "style": {
          "fill": "#000",
          "lineWidth": 0,
          "stroke": null
        },
        "symbolType": "M -0.0625 -0.3167 C -0.0625 -0.2821 -0.0346 -0.2542 0 -0.2542 C 0.0346 -0.2542 0.0625 -0.2821 0.0625 -0.3167 C 0.0625 -0.3167 -0.0625 -0.3167 -0.0625 -0.3167 Z M 0.0442 -0.4025 C 0.0196 -0.4271 -0.0196 -0.4271 -0.0442 -0.4025 C -0.0442 -0.4025 -0.4421 -0.0046 -0.4421 -0.0046 C -0.4662 0.0196 -0.4662 0.0592 -0.4421 0.0838 C -0.4175 0.1079 -0.3779 0.1079 -0.3538 0.0838 C -0.3538 0.0838 0 -0.27 0 -0.27 C 0 -0.27 0.3538 0.0838 0.3538 0.0838 C 0.3779 0.1079 0.4175 0.1079 0.4421 0.0838 C 0.4662 0.0592 0.4662 0.0196 0.4421 -0.0046 C 0.4421 -0.0046 0.0442 -0.4025 0.0442 -0.4025 Z M 0.0625 -0.3167 C 0.0625 -0.3167 0.0625 -0.3583 0.0625 -0.3583 C 0.0625 -0.3583 -0.0625 -0.3583 -0.0625 -0.3583 C -0.0625 -0.3583 -0.0625 -0.3167 -0.0625 -0.3167 C -0.0625 -0.3167 0.0625 -0.3167 0.0625 -0.3167 Z",
        "visible": true
      },
      "expandDistance": "15.625%",
      "expression": "##",
      "id": "dcae47f8-c87a-44cb-ba94-2a970b05dd16",
      "interactive": true,
      "label": {
        "__position__": "center",
        "childrenPickable": false,
        "labelBackground": {
          "padding": {
            "bottom": 2,
            "left": 4,
            "right": 4,
            "top": 2
          },
          "style": {
            "cornerRadius": 4,
            "fill": "#fff",
            "fillOpacity": 1,
            "lineWidth": 1,
            "stroke": "#000"
          }
        },
        "pickable": true,
        "position": "middle",
        "refX": 0,
        "refY": 0,
        "style": {
          "fill": "#1F2329",
          "fontSize": 16,
          "fontStyle": "normal",
          "fontWeight": "bold"
        },
        "text": [
          "510%"
        ]
      },
      "line": {
        "mainSegmentIndex": 1,
        "multiSegment": true,
        "style": [
          {
            "lineDash": [
              3,
              3
            ],
            "lineWidth": 1,
            "pickStrokeBuffer": 10,
            "stroke": "#000"
          },
          {
            "lineWidth": 1,
            "pickStrokeBuffer": 10,
            "stroke": "#000"
          },
          {
            "lineDash": [
              3,
              3
            ],
            "lineWidth": 1,
            "pickStrokeBuffer": 10,
            "stroke": "#000"
          }
        ]
      },
      "name": "hierarchy-diff-line",
      "startSymbol": {
        "refX": -4,
        "size": 12,
        "style": {
          "fill": "#000",
          "lineWidth": 0,
          "stroke": null
        },
        "symbolType": "M -0.0625 -0.3167 C -0.0625 -0.2821 -0.0346 -0.2542 0 -0.2542 C 0.0346 -0.2542 0.0625 -0.2821 0.0625 -0.3167 C 0.0625 -0.3167 -0.0625 -0.3167 -0.0625 -0.3167 Z M 0.0442 -0.4025 C 0.0196 -0.4271 -0.0196 -0.4271 -0.0442 -0.4025 C -0.0442 -0.4025 -0.4421 -0.0046 -0.4421 -0.0046 C -0.4662 0.0196 -0.4662 0.0592 -0.4421 0.0838 C -0.4175 0.1079 -0.3779 0.1079 -0.3538 0.0838 C -0.3538 0.0838 0 -0.27 0 -0.27 C 0 -0.27 0.3538 0.0838 0.3538 0.0838 C 0.3779 0.1079 0.4175 0.1079 0.4421 0.0838 C 0.4662 0.0592 0.4662 0.0196 0.4421 -0.0046 C 0.4421 -0.0046 0.0442 -0.4025 0.0442 -0.4025 Z M 0.0625 -0.3167 C 0.0625 -0.3167 0.0625 -0.3583 0.0625 -0.3583 C 0.0625 -0.3583 -0.0625 -0.3583 -0.0625 -0.3583 C -0.0625 -0.3583 -0.0625 -0.3167 -0.0625 -0.3167 C -0.0625 -0.3167 0.0625 -0.3167 0.0625 -0.3167 Z",
        "visible": false
      },
      "type": "type-step",
      "zIndex": 510
    }
  ],
  "width": 640,
  "height": 360,
  "background": "transparent"
};
const vchart = new VChart(spec, { dom: CONTAINER_ID });
vchart.renderSync();

// Just for the convenience of console debugging, DO NOT COPY!
window['vchart'] = vchart;

Current Behavior

image

Expected Behavior

fix it

Environment

- OS:
- Browser:
- Framework:

Any additional comments?

No response