Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to find click events on JQuery flowchart? #115

Open
hooshbartar opened this issue Nov 29, 2019 · 0 comments
Open

How to find click events on JQuery flowchart? #115

hooshbartar opened this issue Nov 29, 2019 · 0 comments

Comments

@hooshbartar
Copy link

There is an example of how to use JQuery flowchart in Angular programs here :https://github.com/nephilimboy/Angular_FlowChartJS. What I am trying to do is adding click events to the selected operator in the chart.

These are related codes of the flowchart:

HTML:

  <div id="chart_container" #chart_container>
    <!-- <pan-zoom [config]="panzoomConfig"> -->
    <div class="flowchart-example-container" id="exampleDiv" #exampleDiv></div>
    <!-- </pan-zoom> -->
  </div>



<input type="button" value="add operator" (click)="addNewOperator()">
<input type="button" value="add operator2" (click)="addNewOperator2()">
<input type="button" value="delete" (click)="deleteOperationOrLink()">
<input type="button" value="load" (click)="load()">
<input type="button" value="get" (click)="get()">
<br />
<textarea nbInput fullWidth shape="round" name="diagModel" [(ngModel)]="diagModel" placeholder="model"
  style="height: 300px; width: 500px"></textarea>

CSS:

body {
    font-family: 'Helvetica Neue', Helvetica, Arial, serif;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.5;
    color: #666;
  }
  
  #chart_container {
    width: 100%;
    height: 500px;
    overflow: hidden;
    background: repeating-linear-gradient(
      45deg,
      #eee,
      #eee 10px,
      #e5e5e5 10px,
      #e5e5e5 20px
    );
    border: 1px solid black;
  }

  #exampleDiv {
    width: 2000px;
    height: 2000px;
    background: white;
  }
  
  .flowchart-example-container {
    height: 200px;
    border: 1px solid #BBB;
    margin-bottom: 10px;
  }
  
  /* #exampleDiv {
    width: 100%;
    height: 2000px;
    background: white;
  } */
  
  .draggable_operators_label {
    margin-bottom: 5px;
  }
  
  .draggable_operators_divs {
    margin-bottom: 20px;
  }
  
  .draggable_operator {
    display: inline-block;
    padding: 2px 5px 2px 5px;
    border: 1px solid #ccc;
    cursor: grab;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }




.flowchart-container {
    position: relative;
    overflow: hidden;
}

.flowchart-links-layer, .flowchart-operators-layer, .flowchart-temporary-link-layer {
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
}

.flowchart-operators-layer, .flowchart-temporary-link-layer {
    pointer-events: none;
}

.flowchart-temporary-link-layer {
    display: none;
}



.flowchart-link, .flowchart-operator {
    cursor: default;
}


.flowchart-operator-connector {
    position: relative;
    padding-top: 5px;
    padding-bottom: 5px;
}

.flowchart-operator-connector-label {
    font-size: small;
}

.flowchart-operator-inputs .flowchart-operator-connector-label {
    margin-left: 14px;
}

.flowchart-operator-outputs .flowchart-operator-connector-label {
    text-align: right;
    margin-right: 5px;
}

.flowchart-operator-connector-arrow {
    width: 0px;
    height: 0px;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-left: 10px solid rgb(204, 204, 204);
    position: absolute;
    top: 0px;
}

.flowchart-operator-connector-small-arrow {
    width: 0px;
    height: 0px;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 5px solid transparent; /*rgb(100, 100, 100);*/
    position: absolute;
    top: 5px;
    pointer-events: none;
}

.flowchart-operator-connector:hover .flowchart-operator-connector-arrow {
    border-left: 10px solid rgb(105, 255, 5);
}

.flowchart-operator-inputs .flowchart-operator-connector-arrow {
    left: -1px;
}

.flowchart-operator-outputs .flowchart-operator-connector-arrow {
    right: -10px;
}

.flowchart-operator-inputs .flowchart-operator-connector-small-arrow {
    left: -1px;
}

.flowchart-operator-outputs .flowchart-operator-connector-small-arrow {
    right: -7px;
}

.unselectable {
   -moz-user-select: none;
   -khtml-user-select: none;
   -webkit-user-select: none;

   /*
     Introduced in IE 10.
     See http://ie.microsoft.com/testdrive/HTML5/msUserSelect/
   */
   -ms-user-select: none;
   user-select: none;
}


/* Default Operator */

.flowchart-operator {
    position: absolute;
    width: 140px;
    border: 1px solid #CCCCCC;
    background: #FAFAFA;
    pointer-events: initial;
}

.flowchart-operator:hover {
    border-color: rgb(255, 238, 0) !important;
}

.flowchart-operator.selected {
    /* border-color: #555; */
    border: 5px solid black;
}



.flowchart-operator .flowchart-operator-title {
    width: 100%;
    padding: 5px;
    font-weight: bold;
    box-sizing: border-box;
    border-bottom: 1px solid #DDDDDD;
    /* background: #F0F0F0; */
    height: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: move;
    

    /* background-color: #2aa58f;
    color: white; */
}

.flowchart-operator .flowchart-operator-inputs-outputs {
    display: table;
    width: 100%;
    margin-top: 5px;
    margin-bottom: 5px;
}

.flowchart-operator .flowchart-operator-inputs, .flowchart-default-operator .flowchart-operator-outputs {
    display: table-cell;
    width: 50%;
}


/* .flowchart-link > path{
    stroke: #2aa58f;
} */




.myTest{
    background-color: #2a7ea5;
    color: white;
}

.myTest2{
    background-color: #4c0f8d;;
    color: white;
}

TS:

import { Component, ViewChild, ElementRef, OnInit, AfterViewInit, AfterContentInit, AfterViewChecked, AfterContentChecked } from '@angular/core';
import {
  Compiler,
  ComponentFactory,
  ComponentFactoryResolver,
  ComponentRef,
  Input,
  ModuleWithComponentFactories,
  NgModule,
  ViewContainerRef
} from '@angular/core';
declare var $: any;

@Component({
  selector: 'app-root',
  templateUrl: "./app.component.html",
})
export class AppComponent implements AfterViewInit {

  public diagModel: any;

  private cx: number;
  private cy: number;



  @ViewChild('exampleDiv') exampleDiv: ElementRef;




  constructor() {
  }



  ngAfterViewInit() {


    var container = $('#chart_container');
    this.cx = $('#exampleDiv').width() / 2;
    this.cy = $('#exampleDiv').height() / 2;
    $('#exampleDiv').panzoom({
    });
    $('#exampleDiv').panzoom('pan', -this.cx + container.width() / 2, -this.cy + container.height() / 2);

    var possibleZooms = [0.5, 0.75, 1, 2, 3];
    var currentZoom = 2;
    container.on('mousewheel.focal', function (e) {
      e.preventDefault();
      var delta = (e.delta || e.originalEvent.wheelDelta) || e.originalEvent.detail;
      var zoomOut: any = delta ? delta < 0 : e.originalEvent.deltaY > 0;
      currentZoom = Math.max(0, Math.min(possibleZooms.length - 1, (currentZoom + (zoomOut * 2 - 1))));
      $('#exampleDiv').flowchart('setPositionRatio', possibleZooms[currentZoom]);
      $('#exampleDiv').panzoom('zoom', possibleZooms[currentZoom], {
        animate: false,
        focal: e
      });

    });


    setTimeout(() => {
      $(this.exampleDiv.nativeElement).flowchart({
        data: '',
        multipleLinksOnOutput: true,
      });

    }, 1000);

  }


  getOperatorData($element) {
    var nbInputs = parseInt($element.data('nb-inputs'));
    var nbOutputs = parseInt($element.data('nb-outputs'));
    var data = {
      properties: {
        title: $element.text(),
        inputs: {},
        outputs: {}
      }
    };

    var i = 0;
    for (i = 0; i < nbInputs; i++) {
      data.properties.inputs['input_' + i] = {
        label: 'Input ' + (i + 1)
      };
    }
    for (i = 0; i < nbOutputs; i++) {
      data.properties.outputs['output_' + i] = {
        label: 'Output ' + (i + 1)
      };
    }

    return data;
  }



  operatorI = 0;
  operatorII = 0;
  addNewOperator() {

    var operatorId = 'created_operator_' + this.operatorI;
    var operatorData = {
      top: this.cx,
      left: this.cy,
      properties: {
        title: 'Operator ' + (this.operatorI + 3),
        class: 'myTest',
        inputs: {},
        outputs: {
          output_1: {
            label: 'Output 1',
          },
          output_2: {
            label: 'Output 2',
          },
          output_3: {
            label: 'Output 3',
          },
          output_4: {
            label: 'Output 4',
          },
        }
      }
    }

    this.operatorI++;
    $(this.exampleDiv.nativeElement).flowchart('createOperator', operatorId, operatorData);
  }

  addNewOperator2() {

    var operatorId = 'created_operator_' + this.operatorI;
    var operatorData = {
      top: this.cx,
      left: this.cy,
      properties: {
        title: 'Operator ' + (this.operatorI + 3),
        class: 'myTest2',
        inputs: {
          input_1: {
            label: 'Input 1',
          },
          input_2: {
            label: 'Input 2',
          },
          input_3: {
            label: 'Input 3',
          },
        },
        outputs: {}
      }
    }

    this.operatorI++;
    $(this.exampleDiv.nativeElement).flowchart('createOperator', operatorId, operatorData);
  }



  deleteOperationOrLink() {
    $(this.exampleDiv.nativeElement).flowchart('deleteSelected');
  }

  load() {
    $(this.exampleDiv.nativeElement).flowchart('deleteSelected');
    var data = JSON.parse(this.diagModel);
    $(this.exampleDiv.nativeElement).flowchart('setData', data);
  }


  get() {
    $(this.exampleDiv.nativeElement).flowchart('deleteSelected');
    var data = $(this.exampleDiv.nativeElement).flowchart('getData');
    this.diagModel = JSON.stringify(data, null, 2);
  }

}

When I select operators on the screen, the border color will change and also when hovering it the border becomes yellow. But I don't know how to add click events to them to open a form when I click(select) them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant