Thursday 29 January 2009

RBS ♥ You


While looking through various charts, my friend noticed a cute little pattern in the graph for Royal Bank of Scotland's stock history.



What does this mean? Well, it's conclusive proof that the Royal Bank of Scotland loves you... or that it's bragging about a new boob job? or quiet possibly that it's flashing you it's butt right before it's stock crashes?

More mysteries coming as soon as I implement the cute shape stock matching algorithm.

iGrapher

Wednesday 28 January 2009

Streaming Javascript

One of my favourite features of Javascript is the ability to write more source code on the fly. Usually in most languages I've used before in the past, you'd have to write the code, compile it, link it, then run. In Javascript you can write source code which writes source code and runs it ON-THE-FLY.

So for example I could do this in my code.

// Create a new script element
var bamScript = document.createElement( 'script' );

// Fill in the script element with more source code
bamScript.text = 'function bam() { alert("aahh"); }';

// Add our script to the document
document.body.appendChild( bamScript );

// Run our newly added script.
bam();


This piece of code, would add in a new script element with a function called bam, which we can run right after it's added to our document. AMAZING!

(Note: A few gotchas I came across. Make sure you use the text parameter and not the innerHTML one. InnerHTML will work fine in Firefox, however in Internet Explorer it'll go boom, and on the iPhone's safari, it'll go boom depending on the complexity of the source code you're writing.)

Since the beginning of iGrapher I've been meaning to use this feature of Javascript, however with the use of gzip, my javascript has been small enough to avoid needed to split the program into separate downloadable components. However, since porting to the iPhone, I've found that it takes a good few seconds to load, so I finally pushed ahead the usage of self-writing source code.

So now in v1.56 iGrapher will load in a small script which dynamically streams in more source code using the XMLHttpRequest object. At the moment the source code is split in two, however I plan on breaking it up into further components so at first the necessary components download first, then the non-essentials (top menu, data spanner, etc.)


iGrapher

Tuesday 20 January 2009

My iPhone Gesture Dilemma

Currently in Safari, if you touch the screen with more than one finger, then rotate the phone. Safari will crash in a very perverse way.

The program will still be on the screen however all javascript will not function, the status bar buttons will not function, and you will no longer be able to navigate the Internet, it'll just hang.

The only way around this state is to turn off the phone, then turn it back on.

Now the problem is, I wanted to add the zooming feature to the graphs and I wanted it to make use of the famous pinch technique. Should I disallow multi-touch gestures and use a different technique or just allow pinching in hope no one would rotate their phone?

I decided to allow pinching, but display a warning message, informing the user that if they rotated their phone, it will go boom!

Sigh..

Monday 19 January 2009

iPhone v1.5 Preview

Work on the iPhone version of iGrapher has been on-going all week and we have hit a few milestones this past weekend. The shares menu is much more usable, XML has been ditched for a custom .xg format which is half the size of XML meaning faster data downloads and work on scrolling the graph canvas has started.

Here's a little preview of the iPhone version in action.


iGrapher

Friday 16 January 2009

My iPhone Web App Experience

So I submitted my grapher program to the apple web app directory the other day. Not expecting much of it, I decided to give it a little test run to make sure it all still worked. I had been making sure it functioned on the iPhone, feature by feature as I implemented them on the desktop, however I had never actually tried using it from an end-users point to view.

Needless to say, it was too buggy, with several crashes and annoyances. I wasn't happy! I frantically spent the night fixing bug after bug. The clock hit 4:30am and I had patched it up enough for it to be barely functional.

You couldn't scroll the charts, but at least you could just about click on some buttons without it reacting erratically and be able to rotate the phone, without it crashing.

I uploaded the new version, then checked my e-mail to find a welcome note from apple. So I figured I'd check their web directory...
Woah... Featured with a staff pick. I have no idea how!?

I was pretty sure, I'd get rejected with perhaps some useful advice on how to improve the app, but wow!

The worst problems faced when porting to the iPhone?
Viewport - Don't experiment with different width's and height's, when you do so, it randomly jumps from dimension to dimension when rotating.
I found it best for me to set the scale to be 1.0 for all the scale options..

content="minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0"

So I could always have the same dimension when rotating.

Multi-touch - It's strange this one, if you use a multi-touch gesture (very very fun to do so) and rotate the iPhone at the same time, it goes boom! I tried every permutation possible to get round this issue, but I found it crashes regular websites, and it doesn't just crash in a close down safari friendly way. It keeps Safari running, however the internet becomes unusable, it just hangs forever trying to connect to a website. The only way I found around it was to turn off the phone then turn it back on again. My coding solution was to override the gesturestart event, then fire off an alert if the user tried using multi-touch. I'm defiantly not happy with this, but it's the only way I could get round this issue. Maybe it's just my phone, I'll have to look more into this. Would be nice to hear if anyone else has experienced this?

OnResize - On a desktop PC, by default I had used the onresize event to inform me when I needed to resize my grapher to fit the screen. On the iPhone... BIG MISTAKE! It kept firing the onresize event randomly and relentlessly (probably because my viewport size wasn't set as advised above). However, once I found out that this was the cause of my app crashing, I simply switched over to orientationchange for the iPhone. That event would fire (as long as you never had two fingers on the screen) and you could get the viewport rotation from the window.orientation variable.

Adsense - A quick final tip for adsense users. I'm not a fan of irritating in your face adverts, so I specifically had only used a 468x15 text ad for the non-iPhone version. However, because of the viewport size limitation, I had to switch over to the next smallest thing for the iPhone.

To get a different advert on a different device for the same page, I had originally tried asking google for what to do. However, no one ever got back to me, so I came to the realisation that php was my friend.

[?php
$ua = $_SERVER['HTTP_USER_AGENT'];
if( strpos( $ua, 'iPhone' ) == false )
{
echo '
DESKTOP CODE
';
}
else
{
echo '
iPHONE CODE
';
}
php?
]

Simple huh?

We'll anyway, I'll try coming back here to post some more tips later, but it's 6am here and my alarm clocks going off.

Thanks for reading.

iGrapher

Friday 2 January 2009

Turnaround for the pound?

Analysts have been prediciting the EURO to ascend to the heights of £1.50 per EURO within 6 months. However looking at the latest trades, has the rally for the EURO come to an end?



iGrapher