How to get unlimited height for stage in Konva and compability issue with IE / Firefox - angularjs

For my project I need to generate a konva page with a lot of nodes. User have to able to add new node and remove it. So far our productive data has around 8000 nodes. I work with angularJS and Konva. The pages must be work in Chrome, IE and Firefox. The codes look like this (modified because of company policy):
angular.module('testModule').controller('compabilityTestCtrl', [
function () {
var compabilityTestCtrl = this;
compabilityTestCtrl.stage = new Konva.Stage({
container: angular.element('<div>')[0],
width: 800,
height: 0
});
var layer = new Konva.Layer({});
var rect = new Konva.Rect({
x: 50,
y: 25,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 4
});
layer.add(rect);
compabilityTestCtrl.stage.height(rect.attrs.y + 50);
for (var i = 1; i < 436; i++) {
var newRect = rect.clone({
y: rect.attrs.y + (i * 75)
});
layer.add(newRect);
compabilityTestCtrl.stage.height(newRect.attrs.y + 75);
if (i == 435) {
console.log("Stage height is: " + compabilityTestCtrl.stage.getHeight());
}
}
compabilityTestCtrl.stage.add(layer);
angular.element('#compabilityTestKonva').append(compabilityTestCtrl.stage.content);
}]);
The problem is following:
1. As you can see, it can generate a node until a stage height of 32725px. If I add one more node (for-Loop to 437), the page will dissapeared (in Chrome). It can only generate until 436 nodes.
2. In Firefox, for 436 nodes the page is not totally generated. It just show 3/4 part of them. If I switched to safe-mode, it showed all of them. More than 436 nodes, it also dissapeared like in Chrome.
3. In IE, it just showed 1/4 of all nodes.
Questions:
Why I can not display all the pages in Firefox and IE?
Why the pages dissapeared if the stage getting bigger (in all browser), in this case.. more than 32725 px? Has Konva a limited height of stage?
I would be very happy for your suggestions.
I just wrote a fiddle, so you know what is actually the problem I have.
JSFiddle
In fiddle, it can generate up to 430 nodes (in Chrome), more than that I see only a blank page. In Firefox it ended on 353 nodes, and in IE it ended on 108 nodes.

The canvas element is like an image.
32725px height is super-duper huge. It will use a lot of resources.
Try to make a stage as small as possible. It will be better to make it not bigger than screen size. You can add some type of scrolling into the stage so users can see all objects.

Related

Print entire page with graph using CTRL+P

I'm trying to print the entire page with graph using CTRL + P, but the graph is always cropped.
I tried to limit the width of the graph using CSS media = "print", but it seems to have no effect on the graph.
print.css
figure{
width: 100% !important;
/* width: 300px !important; //also does not work */
}
If I try to change the size of the graph in CSS media = "screen", the graph will immediately shrink / enlarge.
I know there is a function chart.print(); But it only prints the graph. I need to print the entire page, including the graph. I tried it in Chrome 73. Anychart 8.5.1

AngularJS Microsoft Edge Screen doesn't reflect the DOM

I'm using AngularJS 1.5.0 and Microsoft Edge browser screen doesn't reflect the DOM.
I would like some suggestion how this can be fixed.
I can't really apply a fix for each element as the application is somewhat big with dynamic user content including Angular equations.
Also the app include a lot of dynamic bindings linked to input boxes.
Selecting the text with the mouse turn the 0 into a 2 which is the right value in the example below.
Also changing the position style back and forth seem to force Edge to redraw the element but it's somewhat an ugly fix that I don't like very much and it need to be trigger at so many places (Ajax request, input changes and so on...)
The page start with a value of 0. Then an Ajax call is made and it go fetch the real data. After some experimentation the bug only appears if the new data is 1 character (ex: 2 or 9). And it happens every time. If it's a 2 digit number (ex: 26) then the good number appears.
Any help on this matter would be gladly appreciated.
We were facing the same problem and it stopped occurring after removing the text-transform: uppercase style from the elements that are not updating.
#Sampson, it looks like this is a bug in Edge.
I was able to make a temporary fix with the use of Mutation Observer.
Little script that I made that works for AngularJS elements created server side.
Currently those are the only one causing trouble in my app.
<script>
$(document).ready(function(){
var ua = navigator.userAgent;
var re = new RegExp("Edge/");
if (re.exec(ua) != null){
console.log('edgeMutationObserver ON!!')
var edgeMutationConfig = { characterData: true, subtree: true };
var edgeMutationObserver = new MutationObserver(function(mutations) {
var rgb_p = /rgb\((\d+), (\d+), (\d+)\)/g;
var rgba_p = /rgba\((\d+), (\d+), (\d+), (\d.?\d*)\)/g;
mutations.forEach(function(mutation){
if(mutation.target.nodeType == 3){
var that = mutation.target.parentNode;
// Save the background color
var bgc = that.style.backgroundColor;
// Get applied style from style or css
var bgc_css = bgc || $(that).css('backgroundColor');
var bgc_temp,match;
if(match = rgb_p.exec(bgc_css)){
// rgb transformed in rgba triggers update
bgc_temp = 'rgba('+match[1]+','+match[2]+','+match[3]+',1)';
}else if(match = rgba_p.exec(bgc_css)){
// Slightly modify transparency
var alpha = match[4] == 0 ? 0.01 : match[4] - 0.01 ;
bgc_temp = 'rgba('+match[1]+','+match[2]+','+match[3]+','+alpha+')';
}else{
// If either inline style or css is already equal to transparent the redraw is not made so i choose an alternate color with 0 opacity
bgc_temp = bgc_css != 'transparent' ? 'transparent' : 'rgba(0,0,0,0)';
}
// Change background color to force redraw
that.style.backgroundColor = bgc_temp;
setTimeout(function(){
// Apply back previous style
// Doesn't redraw without a timeout in Edge
that.style.backgroundColor = bgc;
},0);
}
});
});
$('.ng-binding').each(function(){
edgeMutationObserver.observe(this, edgeMutationConfig);
});
}
});
</script>

iPhone 6: InteractionDiaog appears too far down; content hidden

I am trying to implement a chat function in a Codename One app, basically using the tutorial example "Building a Chat App with Codename One". Part of this is an InteractionDialog popping up when someone is trying to contact you. This looks fine in the simulator and on my Android unit, but on iPhone 6 the dialog seems to be drawn too far down, resulting in only the title being visible.
This is the program code:
int h = toast.getPreferredH();
int dh = Display.getInstance().getDisplayHeight(); // just for debugging
toast.show(Display.getInstance().getDisplayHeight() - h - 10, 10, 10, 10);
UITimer uit = new UITimer(() -> {
toast.dispose();
});
Toast height, display height:
Simulator: h=221, dh=480
Android: h=359, dh=1674
iPhone 6: h=304, dh=1334 (This one comes too near the bottom)
Is there something wrong with the screen metrics, and what can I do to solve this? I have had some other, similar problems with InteractionDialog placement previously.
I would be happy to show some screenshots, but I can't post that many links yet.
I think the code for the chat app might have been a bit wrong here change this:
int h = toast.getPreferredH();
int dh = Display.getInstance().getDisplayHeight(); // just for debugging
toast.show(Display.getInstance().getDisplayHeight() - h - 10, 10, 10, 10);
To this:
int h = toast.getPreferredH();
int dh = Display.getCurrent().getContentPane().getHeight();
toast.show(dh - h - 10, 10, 10, 10);
The layered pane (where the InteractionDialog resides) is on top of the content pane area only not the entire display height so the title area/statusbar area aren't taken into account.
FYI in the upcoming version we will have the new ToastBar component.

iCarousel integration to app having Tab bar controller in iOS 6.1

I integrate the iCarousel app with single view application.But when I add the tab bar controller and place this iCarousel code in one tab bar Item viewcontroller.But it does not work(Items are displayed but not scrolled).What is the problem here.
I created iCarousel as below:
iCarousel *categorySubView = [[iCarousel alloc]initWithFrame:CGRectMake(0,200, 300, 125)];
categorySubView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
categorySubView.delegate = self;
categorySubView.dataSource = self;
categorySubView.type=iCarouselTypeRotary;
[self.view addSubview:categorySubView];
I am using the following delegae and data source methods:
-(NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return 5;
}
- (UIView *) carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
UIView *sampleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 250, 300)];
sampleView.backgroundColor=[UIColor whiteColor];
UILabel *labelis=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 20)];
labelis.backgroundColor=[UIColor clearColor];
labelis.text=#"8Apr-14Apr";
[sampleView addsubView:labelis];
return sampleView;
}
Please suggest me.
Thanks inadvance
I notice that your carousel view is much smaller than the size of the items inside it (it's only 125 points high).
iCarousel can draw outside of its bounds, but it cannot detect touch events outside of its bounds, so that might be why you are having trouble scrolling.
A good way to debug this is to set the carousel.clipsToBounds = YES, that way what it draws will match what is touchable. Another option is to set the carousel.backgroundColor so you can see what part of it is touchable on screen.
Another thing to check is that the view that you've placed the carousel inside has userInteractionEnabled set to YES.

GAE images.resize with fixed proportional crop

I need to resize and crop to exactly 60x80px from various size and
aspect ratio. Just before i put into Datastore. Anyone already got
this issue resolved.
Currently i already succed to just transform it to exact height (80px)
with various width which nott look so good when i try to display it on
a list. e.g jcaroussel.
My db.put code is like bellow:
if users.get_current_user():
personal.personal_id = int(self.request.get('personal_id'))
personal.name = self.request.get('name')
personal.latitude = self.request.get('latitude')
personal.info = self.request.get('info')
photo = images.resize(self.request.get('img'), 0, 80)
personal.photo = db.Blob(photo)
personal.lc_id = int(self.request.get('lc_id'))
personal.put()
self.redirect('/admin/personal')
else:
self.response.out.write('I\'m sorry, you don\'t have permission to add this LP Personal Data.')
I just want to do similar result when we upload our avatar on google
talk/google chat.
Anyone solved this?
Thx
After your resize your image down to 80 pixels in height, you would have to use the crop function as defined here. For example:
img = images.Image(self.request.get('img'))
img.resize(0, 80)
resized_img = img.execute_transforms(output_encoding=images.JPEG)
left_x = (resized_img.width - 60) / 2
resized_img.crop(left_x, 0, left_x + 60, 80)
cropped_img = resized_image.execute_transforms(output_encoding=images.JPEG)
In my example it crops to the center of the image.
It assumes that the resized image is at least 60 pixels wide, but obviously you would have to add some checks to confirm this, because a user might not upload an image in the right size.
I used something else:
Resize the original image to your max height (80)
Store the resized (but complete/not cropped) image
Display it inside a <div> that has the following CSS: width: 60px; height: 80px; overflow: hidden;
That way it will show nicely in your list, but you can still display the complete resized picture on your user's profile page (looking at you code I imagine that's what you are trying to do, right?)

Resources