couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From benkeen <...@git.apache.org>
Subject [GitHub] couchdb-fauxton pull request: Gsoc2015 moving to sub
Date Sat, 09 May 2015 00:58:46 GMT
Github user benkeen commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/401#discussion_r29987511
  
    --- Diff: app/addons/documents/revisionTree/component.react.jsx ---
    @@ -0,0 +1,330 @@
    +define([
    +  "app",
    +  "api",
    +  "react",
    +  'addons/documents/revisionTree/stores',
    +  'addons/documents/revisionTree/actions',
    +  ], function(app,FauxtonAPI, React,Stores){
    +
    +    var store = Stores.revTreeStore;
    +
    +    var lineObjs = [];
    +    var nodeObjs = [];
    +    var textObjs = [];
    +
    +    var grid = 100;
    +    var scale = 7;
    +    var r = 15;
    +
    +    var LinesBox = React.createClass({
    +      render: function(){
    +        return (
    +          <g>
    +            {
    +              this.props.data.map(function (element, i) {
    +                return <Line key={i} data={element}/>;
    +              })
    +            }
    +          </g>
    +          );
    +      }
    +    });
    +
    +    var CirclesBox = React.createClass({
    +
    +      render: function(){
    +        return (
    +          <g>
    +            {
    +              this.props.data.map(function (element, i){
    +                return <Circle key={i} data={element}/>;
    +              })
    +            }
    +          </g>
    +          );
    +      }
    +    });
    +
    +    var Circle = React.createClass({
    +      render: function(){
    +        var cx = this.props.data.x;
    +        var cy = this.props.data.y;
    +        var radius = r;
    +        var classVal = this.props.data.class;
    +
    +        return (
    +          <circle cx={cx} cy={cy} r={radius} className={classVal}>{this.props.children}</circle>
    +          );
    +      }
    +    });
    +
    +    var Line = React.createClass({
    +      render: function(){
    +        var x1 = this.props.data.x;
    +        var y1 = this.props.data.y;
    +        var x2 = this.props.data.nextX;
    +        var y2 = this.props.data.nextY;
    +
    +        return (
    +          <line x1={x1} y1={y1} x2={x2} y2={y2}>{this.props.children}</line>
    +          );
    +      }
    +    });
    +
    +    var TextsBox = React.createClass({
    +      render: function(){
    +        return (
    +          <g>{this.props.children}</g>
    +          );
    +      }
    +    });
    +
    +    var SVGComponent = React.createClass({
    +      render: function() {
    +        return (
    +         <svg height="500" width="500">{this.props.children}
    +         </svg>
    +         );
    +      }
    +    });
    +
    +    var Box = React.createClass({
    +      render: function(){
    +        return (
    +          <div className = "visualizeRevTree">
    +            {this.props.children}
    +          </div>
    +          );
    +      }
    +    });
    +
    +    var Text = React.createClass({
    +      render: function(){
    +
    +        var styleVals = {
    +          left: this.props.data.stLeft,
    +          top: this.props.data.stTop
    +        };
    +
    +        return (
    +            <div className = "box" style={styleVals} short={this.props.data.short}
long={this.props.data.long}>
    +              <p>{this.props.data.short}</p>
    +              {this.props.children}
    +            </div>
    +          );
    +      }
    +    });
    +
    +
    +    var draw = function(paths, deleted, winner, minUniq){
    +      var maxX = grid;
    +      var maxY = grid;
    +        var levelCount = []; // numer of nodes on some level (pos)
    +
    +        var map = {}; // map from rev to position
    +
    +        function drawPath(path) {
    +          for (var i = 0; i < path.length; i++) {
    +            var rev = path[i];
    +            var isLeaf = i === 0;
    +            var pos = +rev.split('-')[0];
    +
    +            if (!levelCount[pos]) {
    +              levelCount[pos] = 1;
    +            }
    +            var x = levelCount[pos] * grid;
    +            var y = pos * grid;
    +
    +            if (!isLeaf) {
    +              var nextRev = path[i-1];
    +              var nextX = map[nextRev][0];
    +              var nextY = map[nextRev][1];
    +
    +              if (map[rev]) {
    +                x = map[rev][0];
    +                y = map[rev][1];
    +              }
    +
    +              var lineObj = {
    +                "x" : x,
    +                "y" : y,
    +                "nextX" : nextX,
    +                "nextY" : nextY
    +              };
    +
    +              lineObjs.push(lineObj);
    +            }
    +            if (map[rev]) {
    +              break;
    +            }
    +            maxX = Math.max(x, maxX);
    +            maxY = Math.max(y, maxY);
    +            levelCount[pos]++;
    +
    +            node(x, y, rev, isLeaf, rev in deleted, rev === winner, minUniq);
    +            map[rev] = [x, y];
    +          }
    +        }
    +        paths.forEach(drawPath);
    +      };
    +
    +      var minUniqueLength = function(arr){
    +       function strCommon(a, b){
    +        if (a === b) return a.length;
    +        var i = 0;
    +        while(++i){
    +          if(a[i - 1] !== b[i - 1]) return i;
    +        }
    +      }
    +
    +      var array = arr.slice(0);
    +      var com = 1;
    +      array.sort();
    +      for (var i = 1; i < array.length; i++){
    +        com = Math.max(com, strCommon(array[i], array[i - 1]));
    +      }
    +      return com;
    +    };
    +
    +    function node(x, y, rev, isLeaf, isDeleted, isWinner, shortDescLen){
    +      circ(x, y, r, isLeaf, isDeleted, isWinner);
    +      var pos = rev.split('-')[0];
    +      var id = rev.split('-')[1];
    +      var opened = false;
    +
    +      var textObj = {
    +        "stLeft": (x-40) + "px",
    +        "stTop": (y-30) + "px",
    +        "short": pos + '-' + id.substr(0, shortDescLen),
    +        "long": pos + '-' + id
    +      };
    +
    +      textObjs.push(textObj);
    +    }
    +
    +    var circ = function(x, y, r, isLeaf, isDeleted, isWinner) {
    +
    +      var leafStat = "";
    +
    +      if (isLeaf) {
    +        leafStat = "leaf";
    +      }
    +      if (isWinner) {
    +        leafStat = "winner";
    +      }
    +      if (isDeleted) {
    +        leafStat = "deleted";
    +      }      
    +
    +      var nodeObj = {
    +        "x" : x,
    +        "y" : y,
    +        "class" : leafStat
    +      };
    +
    +      nodeObjs.push(nodeObj);
    +    };
    +
    +    var App = React.createClass({
    +      getInitialState: function() {
    +        return {
    +          lines: [],
    +          treeNodes: [],
    +          nodeTextObjs: []
    +        };
    +      },
    +
    +      componentDidMount: function() {
    +        var result = [];
    +        var paths = [];
    +        var deleted = {};
    +        var optionsVal = store.getTreeOptions();
    +        // var winner = this.props.data.winnerRev;
    +        var winner = optionsVal.winnerRev;
    +        // var url = '/'+this.props.data.db+'/'+this.props.data.docID;
    +        var url = '/'+optionsVal.db+'/'+optionsVal.docID;
    +        // var winner = this.props.data.;
    +        var minUniq = 0;
    +        $.get(app.host+url+'?open_revs=all&revs=true', function(rslt) {
    +          var data = rslt;
    +          if (this.isMounted()) {
    +            var x = data.split(/(\n|\r\n|\r)/);
    +
    +            for (var i = 0; i <x.length; i++) {
    +              if(String(x[i]).charAt(0) == "{"){
    --- End diff --
    
    Once we get down to the nitty gritty, we'll want to get all the code style consistent
with the rest of the codebase, like here: space after the if, triple equals, not double (we
always try to use strict equality). But I won't bore you with picking out all the instance
in the code - just read over the style doc and get to it whenever you refactor. No rush!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message