Home / Class/ VectorWidget Class — react Architecture

VectorWidget Class — react Architecture

Architecture documentation for the VectorWidget class in VectorWidget.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  8c0ea30d_bdcf_61cf_8c63_e215a52a118d["VectorWidget"]
  ed8177df_f67b_e3f8_4ffe_fd0b44509e5e["VectorWidget.js"]
  8c0ea30d_bdcf_61cf_8c63_e215a52a118d -->|defined in| ed8177df_f67b_e3f8_4ffe_fd0b44509e5e
  87a8074d_f910_55f1_a0d7_e75b01730493["componentDidMount()"]
  8c0ea30d_bdcf_61cf_8c63_e215a52a118d -->|method| 87a8074d_f910_55f1_a0d7_e75b01730493
  1f02766d_bca5_b6a9_7d7a_8e9f159a2b50["componentWillUnmount()"]
  8c0ea30d_bdcf_61cf_8c63_e215a52a118d -->|method| 1f02766d_bca5_b6a9_7d7a_8e9f159a2b50
  ef08e186_6fb5_8a3f_28d5_60b0c0ccf5d0["render()"]
  8c0ea30d_bdcf_61cf_8c63_e215a52a118d -->|method| ef08e186_6fb5_8a3f_28d5_60b0c0ccf5d0

Relationship Graph

Source Code

fixtures/art/VectorWidget.js lines 26–119

class VectorWidget extends React.Component {
  /**
   * Initialize state members.
   */
  state = {degrees: 0, velocity: 0, drag: MOUSE_UP_DRAG};

  /**
   * When the component is mounted into the document - this is similar to a
   * constructor, but invoked when the instance is actually mounted into the
   * document. Here, we'll just set up an animation loop that invokes our
   * method. Binding of `this.onTick` is not needed because all React methods
   * are automatically bound before being mounted.
   */
  componentDidMount() {
    this._interval = window.setInterval(this.onTick, 20);
  }

  componentWillUnmount() {
    window.clearInterval(this._interval);
  }

  onTick = () => {
    var nextDegrees = this.state.degrees + BASE_VEL + this.state.velocity;
    var nextVelocity = this.state.velocity * this.state.drag;
    this.setState({degrees: nextDegrees, velocity: nextVelocity});
  };

  /**
   * When mousing down, we increase the friction down the velocity.
   */
  handleMouseDown = () => {
    this.setState({drag: MOUSE_DOWN_DRAG});
  };

  /**
   * Cause the rotation to "spring".
   */
  handleMouseUp = () => {
    var nextVelocity = Math.min(this.state.velocity + CLICK_ACCEL, MAX_VEL);
    this.setState({velocity: nextVelocity, drag: MOUSE_UP_DRAG});
  };

  /**
   * This is the "main" method for any component. The React API allows you to
   * describe the structure of your UI component at *any* point in time.
   */
  render() {
    return (
      <Surface width={700} height={700} style={{cursor: 'pointer'}}>
        {this.renderGraphic(this.state.degrees)}
      </Surface>
    );
  }

  /**
   * Better SVG support for React coming soon.
   */
  renderGraphic = rotation => {
    return (
      <Group onMouseDown={this.handleMouseDown} onMouseUp={this.handleMouseUp}>
        <Group x={210} y={135}>
          <Shape fill="rgba(0,0,0,0.1)" d={BORDER_PATH} />
          <Shape fill="#7BC7BA" d={BG_PATH} />
          <Shape fill="#DCDCDC" d={BAR_PATH} />
          <Shape fill="#D97B76" d={RED_DOT_PATH} />
          <Shape fill="#DBBB79" d={YELLOW_DOT_PATH} />
          <Shape fill="#A6BD8A" d={GREEN_DOT_PATH} />
          <Group x={55} y={29}>
            <Group rotation={rotation} originX={84} originY={89}>
              <Group x={84} y={89}>
                <Circle fill="#FFFFFF" radius={16} />
              </Group>
              <Group>
                <Shape d={RING_ONE_PATH} stroke="#FFFFFF" strokeWidth={8} />
                <Shape
                  d={RING_TWO_PATH}
                  transform={RING_TWO_ROTATE}
                  stroke="#FFFFFF"
                  strokeWidth={8}
                />
                <Shape

Frequently Asked Questions

What is the VectorWidget class?
VectorWidget is a class in the react codebase, defined in fixtures/art/VectorWidget.js.
Where is VectorWidget defined?
VectorWidget is defined in fixtures/art/VectorWidget.js at line 26.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free