adrai / flowchart.js

Draws simple SVG flow chart diagrams from textual representation of the diagram
http://flowchart.js.org/
MIT License
8.49k stars 1.21k forks source link

Using ace text editor #56

Open dvdcastro opened 8 years ago

dvdcastro commented 8 years ago

Hello,

Have you thought of including an optional editor?

I've been using it with Ace (Ajax.org Cloud9 Editor) and with an angular module as well.

    <div id="flow-ace-code" ng-model="flowAceCode",style="height:500px;" ui-ace="{theme:'twilight',mode:'html',onLoad: aceFlowCodeLoaded, onChange: aceFlowCodeChanged}"></div>
    <button ng-click="updateFlowChart()">Update flow chart</button>
    <div id="flowchart-div"></div>

And in an angular controller:

    var self = this;

    //- ... Your controller code

    $scope.updateFlowChart = function() {
      if($scope.flowAceCode) {
        if(self.chart) self.chart.clean();

        self.chart = flowchart.parse($scope.flowAceCode);

        self.chart.drawSVG('flowchart-div', {
          ...
        });
      } else if(self.chart)
        self.chart.clean();
    };

The power of this library relies on the fact that you can write your own syntax highlighter.

Cheers!

adrai commented 8 years ago

PR's are welcome ;-)