Created
October 26, 2017 13:20
-
-
Save 197291/b70c365d55c6f0de887efd6d88f9c562 to your computer and use it in GitHub Desktop.
Example_D3_part3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.prototype.editRow = function (config) { | |
if(config.name) { | |
if(this._isUniqueTag(config.name, self.shapes['grouped'])) { | |
d3.select(self.currentGroupForEdit).select('text').text(config.name) | |
} else { | |
alert('Group tag have to be unique. ' + config.name + ' is already existing.') | |
} | |
} | |
if(config.numberOfSeats) { | |
var elements = d3.select(self.currentGroupForEdit).selectAll('g.point'); | |
var i = elements[0].length; | |
var maxD = null; | |
if(config.numberOfSeats == elements[0].length) return; | |
elements[0].reverse(); | |
if(config.numberOfSeats < elements[0].length) { | |
elements.each(function (d) { | |
if(i != config.numberOfSeats) { | |
d.id = null; | |
d3.select(this).remove(); | |
i--; | |
} | |
}); | |
} else { | |
var shapes = []; | |
var groupId = parseInt(d3.select(self.currentGroupForEdit).attr('grpId'), 10); | |
elements.each(function (d) { | |
if(maxD === null) { | |
maxD = d; | |
while(i != config.numberOfSeats) { | |
var newShape = _.clone(d); | |
newShape.id = parseInt(newShape.id, 10) + 1; | |
newShape.number = parseInt(newShape.number, 10) + 1; | |
newShape.x = parseInt(newShape.x, 10) + parseInt(newShape.w, 10); | |
d = _.clone(newShape); | |
shapes.push(newShape); | |
i++; | |
} | |
} | |
}); | |
_.each(self.shapes['grouped'], function(group) { | |
if(parseInt(group.groupId, 10) === groupId) { | |
_.each(shapes, function (shape) { | |
group.groupElements.push(shape); | |
}); | |
d3.select(self.currentGroupForEdit).remove(); | |
self._createShapes({ grouped: [group] }, true, 0); | |
self.saveGraph(); | |
d3.selectAll('g.group').each(function (){ | |
if(parseInt(d3.select(this).attr("grpId"), 10) == groupId) { | |
self.currentGroupForEdit = this; | |
} | |
}); | |
} | |
}); | |
} | |
} | |
if(config.category) { | |
var category = this._getCategory({ name: config.category }); | |
d3.select(self.currentGroupForEdit).selectAll('g.point > .inner').each(function(d){ | |
d.color = self._isHexColorFormat(category.color) ? '#'+category.color : category.color; | |
d3.select(this).attr('fill', d.color); | |
}); | |
} | |
if(config.rotate || config.rotate === 0) { | |
var coords = d3.transform(d3.select(self.currentGroupForEdit).attr("transform")); | |
var grpX = coords.translate[0]; | |
var grpY = coords.translate[1]; | |
d3.select(self.currentGroupForEdit).attr("transform", function () { | |
return d3.svg.transform() | |
.translate(grpX, grpY) | |
.rotate(config.rotate)(); | |
}); | |
} | |
if(config.startFrom) { | |
var counter = config.startFrom; | |
d3.select(self.currentGroupForEdit).selectAll('g.point').each(function (point) { | |
d3.select(this).select('text').text(counter); | |
d3.select(this).selectAll('text').each(function(d){ | |
d.number = counter; | |
}); | |
counter++; | |
}); | |
} | |
this.saveGraph(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment