Fabric.js group/ungroup - individual objects disappear while ungrouping - angularjs

I have this functions in my angularJS controller:
function group(){
var activegroup = canvas.getActiveGroup();
var objectsInGroup = activegroup.getObjects();
activegroup.clone(function(newgroup) {
canvas.discardActiveGroup();
objectsInGroup.forEach(function(object) {
canvas.remove(object);
});
canvas.add(newgroup);
});
}
function ungroup(){
var activeObject = canvas.getActiveObject();
if(activeObject.type=="group"){
var items = activeObject._objects;
activeObject._restoreObjectsState();
canvas.remove(activeObject);
for(var i = 0; i < items.length; i++) {
canvas.add(items[i]);
canvas.item(canvas.size()-1).hasControls = true;
}
}
canvas.renderAll();
}
Working almost perfectly - jus when I ungroup the objects are not rendered (they are still in the canvas, but not visible). I can select the objects individually even if they are invisible. Selectin multiple object will show them while they are selected – deselecting one will let the other disappear. In short: ungrouping objects will not show as individual objects again.
This applys only to primitives like, box, circle, triangle. Text an images are not affected.
Help is appreciated!

function ungroup(){
var activeObject = canvas.getActiveObject();
if(activeObject.type=="group"){
var items = activeObject._objects;
alert(items);
activeObject._restoreObjectsState();
canvas.remove(activeObject);
for(var i = 0; i < items.length; i++) {
canvas.add(items[i]);
items[i].dirty = true; //set object dirty true
canvas.item(canvas.size()-1).hasControls = true;
}
canvas.renderAll();
}
}
If you set object dirty true, it will render in renderAll() call and redraw again.

Related

Line Chart not updating everytime

So I am using Line from react-chartjs-2 and I've added an onClick event to the labels which blur all the lines except the current one.
Here is my onClick function code:
legend:{
'onClick': function(e, legendItem) {
var index = legendItem.datasetIndex;
var ci = this.chart;
console.log(ci.data.datasets);
//var alreadyHidden = (ci.data.datasets[index].borderColor === ci.data.datasets[index].accentFadedColor) ? false : true;
for(var i=0; i< ci.data.datasets.length;i++){
if (i !== index) {
ci.data.datasets[i].borderColor = ci.data.datasets[i].accentFadedColor;
} else if (i == index){
ci.data.datasets[i].borderColor = ci.data.datasets[i].accentColor;
}
}
that.updateValue(index);
ci.update();
}
The problem is, the function updates the chart on first click but not after that. Though I can see the updates values with console.log()
Any idea what I am doing wrong?
Update:
So apparently my chart is working fine. Inside the onClick() I'm making call to another function ( which sets state ) which is causing this behavior.
Here's a link to stackblitz
Any advice?
So apparently, just making the function call inside onClick() but before updating the datasets solved the problem.
I think rendering after setState and canvas update were somehow mixing up.
Here's the updated code:
legend:{
'onClick': function(e, legendItem) {
var index = legendItem.datasetIndex;
var ci = this.chart;
that.updateValue(index);
for(var i=0; i< ci.data.datasets.length;i++){
if (i !== index) {
ci.data.datasets[i].borderColor = ci.data.datasets[i].accentFadedColor;
ci.data.datasets[i].lineWidth = ci.data.datasets[i].highlightedWidth;
} else if (i == index){
ci.data.datasets[i].borderColor = ci.data.datasets[i].accentColor;
ci.data.datasets[i].lineWidth = ci.data.datasets[i].fadedWidth;
}
}
ci.update(); }

KendoUI Treeview with AngularJS uncheck checkboxes

I'm using KendoUI (v2015.1.318) with AngularJS (v1.3.14). After every click on a node, the data will be fetched from an API.
After selecting some items and clicking on the button "add", the items will be added in a seperated list, the expanded treenodes must stay visible but all the
checked items must be unchecked.
After I iterated through the datasource to uncheck the checked items , I have call SetDataSource again. When I have expanded a lot of nodes and checked a few, the UI freezes some seconds while it's processing.
I was wondering if there wasn't a more efficient way to execute this.
I made an example without API call:
$scope.saveTreeFields = function () {
var data = $scope.tree.dataSource._data;
for (var i = 0, j = data.length; i < j; i++) {
checkChildren(data[i]);
}
function checkChildren(data) {
if (data.checked) {
data.checked = false;
}
if (data.items !== undefined) {
for (var i = 0, j = data.items.length; i < j; i++) {
checkChildren(data.items[i]);
}
}
}
$scope.tree.setDataSource(data)
};
Plunker example
Received an answer from Telerik itself.
you can call the dataItem set("checked", false) method to notify the
model of the field change, and the TreeView will update automatically.
Code changes
$scope.saveTreeFields = function () {
var data = $scope.tree.dataSource.data();
for (var i = 0, j = data.length; i < j; i++) {
checkChildren(data[i]);
}
function checkChildren(data) {
if (data.checked) {
data.set("checked", false);
}
if (data.items !== undefined) {
for (var i = 0, j = data.items.length; i < j; i++) {
checkChildren(data.items[i]);
}
}
}
};

Angular values update in both elements

I am adding same element (json object) into a list (from another list) twice using .copy to break the reference. But even after doing that when I change some values in one both of them are getting updated.
$scope.addProduct = function (item) {
var index = $scope.itemsProduct.indexOf(item);
$scope.scopItem = {};
angular.copy(item , $scope.scopItem);
for(var j in $scope.scopItem['ABC']) {
$scope.scopItem['ABC'][j].dataType='Discount';
$scope.scopItem['ABC'][j]['Discount'] = '';
}
if (index != -1) {
$scope.itemsTags.push($scope.scopItem);
$timeout(function() {
$scope.$apply(function () {
$scope.calculate($scope.scopItem);
});
}, 10);
}
};
$scope.calculateParam = function (indexQ) {
var index = $scope.itemsTags.indexOf(indexQ);
$scope.itemsTags[index]['ABC']['Discount'] = '10'; //or some other logic
}
Need help as even i am not adding the same element(using .copy) and updating the "Discount" property of one updates both??
Note: ABC is a inner list with property as "Discount" and I am changing "Discount"
Some comments:
for(var j in $scope.scopItem['ABC'])
it's absolutely incorrect and should be rewrited to
for(var j=0; j < $scope.scopItem['ABC'].length; j++)
also scopItem is changed in calculate method and stored in itemsTags

CheckBox in ComboBox

I would like to have checkBoxes inside a comboBox, like in this simplified example :
var rawData = [];
for (var i = 0; i < 20; i++) {
rawData.push(i);;
}
var data = new qx.data.Array(rawData);
var list = new qx.ui.form.ComboBox();
list.setWidth(150);
this.getRoot().add(list);
var controller = new qx.data.controller.List(null, list);
var delegate = {
createItem : function() {
return new qx.ui.form.CheckBox();
}
};
controller.setDelegate(delegate);
controller.setModel(data);
It's working but i'm not able to "check" the checkboxes because the combobox is closed when i click on it, so i would like to open/close the combobox only with the button.
How to do it? Thanks in advance.
Some event of the ComboBox is responsible for closing the PopUp (see code on GitHub) before the click can get to an underlying checkbox. If you implement your own ComboBox and overwrite the close method it works.
qx.Class.define("foo.ComboBox", {
extend: qx.ui.form.ComboBox,
members: {
close: function() {
}
}
})
var rawData = [];
for (var i = 0; i < 20; i++) {
rawData.push(i);;
}
var data = new qx.data.Array(rawData);
var list = new foo.ComboBox();
list.setWidth(150);
var controller = new qx.data.controller.List(null, list);
var delegate = {
createItem : function() {
return new qx.ui.form.CheckBox();
}
};
controller.setDelegate(delegate);
controller.setModel(data);
this.getRoot().add(list);
However now you have to think about how you will handle multiple selection of checkboxes and when to close the popup.

How to make an Array visible while also making the other arrays hidden once clicked AS3

I have a set of movieclips setup as arrays in As3. I got the code to work were once a button is clicked a movieclip show on stage; but once the user clicks on another thumbnail the previous movieclip is still on stage. What I am trying to accomplish is I want the other arrays or movieclips to become hidden once the main array or clip that the user clicks becomes visible. I know I probably need a if loop for the arrays heres my code:
var soles:Array = [sle1,sle2,sle3,sle4];
var Slbtn_arr:Array = [sole,sole2,sole3,sole4];
for (var i= 0; i < Slbtn_arr.length; i++)
{
trace(i,Slbtn_arr[i]);
var temp_Slbtn = Slbtn_arr[i];
temp_Slbtn.addEventListener(MouseEvent.CLICK, btnCl);
temp_Slbtn.count = i;
soles[i].visible = false;
soles[0].visible = true;
}
function btnCl(e)
{
var num = e.target.count;
trace(e.target, e.target.count, soles[e.target.count]);
//hideAll()
soles[num].visible = true;
}
function hideAll()
{
for (var i= 0; i < soles.length; i++)
{
soles[i].visible = false;
}
}

Resources