Chart

支持的交互

  • 自适应宽度

    Action

  1. class ChartResize extends Action() {
  2. forceFit() {
  3. const context = this.context;
  4. const chart = context.chart;
  5. chart.forceFit();
  6. }
  7. }

语法

  1. G2.RegisterInteraction({
  2. start: [
  3. {trigger: 'widown:resize', action: 'chart-resize:forceFit'},
  4. {trigger: 'container:resize', action: 'chart-resize:forceFit'}
  5. ]
  6. })

View

支持的交互

  • 显示、隐藏
  • 调整宽度
  • 调整位置
  • 内部平移、缩放

    Action

    ```javascript class ViewAction extends Action { show() {} hide() {} }

class ViewDelegation extends Action { showDelegation() {} changeDelegation() {} hideDelegation() {} }

class ViewResize extends Action { showEnable() {} hideEnable() {} start() {} resize() {} }

class ViewPosition extends Action { showEnable() {} hideEnable() {} start() {} move() {} }

class ViewTranslate extends Action { start() {} translate(){} reset(){} }

class ViewScale extends Action { scale() {} reset() {} }

  1. <a name="SUAQz"></a>
  2. ### 语法
  3. 拖拽改变 view 的大小
  4. ```javascript
  5. G2.RegisterInteraction('view-resize', {
  6. showEnable: [
  7. {trigger: 'view:plotenter', action: 'view-resize:showEnable'},
  8. {trigger: 'view:plotleave', action: 'view-resize:hideEnable'}
  9. ],
  10. start: [
  11. {trigger: 'view-resize-icon:dragstart', action: 'view-resize:start'},
  12. {trigger: 'view-resize-icon:dragstart', action: 'view-delegation:show'}
  13. ],
  14. processing: [
  15. {trigger: 'view-resize-icon:drag', action: 'view-delegation:change'}
  16. ],
  17. end: [
  18. {trigger: 'view-resize-icon:dragend', action: 'view-delegation:hide'},
  19. {trigger: 'view-resize-icon:dragend', action: 'view-resize:resize'},
  20. ],
  21. rollback: [
  22. {trigger: 'view-resize-icon:dblclick', action: 'view-resize:reset'}
  23. ]
  24. });

拖拽改变 view 的位置

  1. G2.RegisterInteraction('view-move', {
  2. showEnable: [
  3. {trigger: 'view:plotenter', action: 'view-position:showEnable'},
  4. {trigger: 'view:plotleave', action: 'view-position:hideEnable'}
  5. ],
  6. start: [
  7. {trigger: 'view-resize-icon:dragstart', action: 'view-position:start'},
  8. {trigger: 'view-resize-icon:dragstart', action: 'view-delegation:show'}
  9. ],
  10. processing: [
  11. {trigger: 'view-resize-icon:drag', action: 'view-delegation:change'}
  12. ],
  13. end: [
  14. {trigger: 'view-resize-icon:dragend', action: 'view-delegation:hide'},
  15. {trigger: 'view-resize-icon:dragend', action: 'view-position:move'},
  16. ],
  17. rollback: [
  18. {trigger: 'view-resize-icon:dblclick', action: 'view-position:reset'}
  19. ]
  20. });

拖拽 view 内部平移

  1. G2.RegisterInteraction('view-translate', {
  2. showEnable: [
  3. {trigger: 'view:plotenter', action: 'cursor:move'},
  4. {trigger: 'view:plotleave', action: 'cursor:default'}
  5. ],
  6. start: [
  7. {trigger: 'view:mousedown', action: 'view-translate:start'},
  8. ],
  9. processing: [
  10. {trigger: 'view:mousemove', action: 'view-translate:translate'},
  11. ],
  12. end: [
  13. {trigger: 'view:mouseup'},
  14. ],
  15. rollback: [
  16. {trigger: 'view:dblclick', action: 'view-translate:reset'}
  17. ]
  18. });

滚轮 view 内部缩放

  1. G2.RegisterInteraction('view-scale', {
  2. start: [
  3. {trigger: 'view:scroll', action: 'view-scale:scale'},
  4. ],
  5. rollback: [
  6. {trigger: 'view:dblclick', action: 'view-scale:reset'}
  7. ]
  8. });

Geometry

支持的交互

Geometry 在 G2 中是 Elements 的集合,支持的交互有:

  • 显示、隐藏

    Action

    1. class GeometryAction extends Action {
    2. change() {}
    3. show() {}
    4. hide() {}
    5. }

语法

  1. G2.RegisterInteraction('view-scale', {
  2. start: [
  3. {trigger: 'legend-item:checkchanged', action: 'geometry:change'},
  4. ]
  5. });