Wednesday, February 24, 2010

Calculating nice chart axis ranges

I was working on a project that required calculating nice ranges for chart axes. I found a useful discussion here.

Here is what I used in C# and so far it is working adequately:

var numGridLines = 5;
var magnitude = Math.Floor(Math.Log10((maxValue - minValue) * 1.1));
var basis = Math.Pow(10, (magnitude - 1));
var margin = (maxValue - minValue) * 0.1;
var axisMax = Math.Ceiling((maxValue + margin) / basis) * basis;
var axisMin = Math.Floor((minValue - margin) / 1.1 / basis) * basis;
var majorGrid = Math.Floor((axisMax - axisMin) / basis / numGridLines) * basis;

Friday, February 12, 2010

What do you like about Windows 7?

People ask me if Windows 7 is any better. Sure. Some people are wondering about the security popups and compatibility with old programs. Those questions already have lots of press. But, I'm personally more interested in the small usability features that come in handy several times a day. Here are the ones I've noticed:

  1. The entire organization of the task bar is a huge improvement. Basically the concept of Quick Links has been merged into the task bar functionality. (It acts more like OS X.) In previous versions of Windows, my task bar was always full of running programs, making the task bar difficult to use. Now my task bar stays about half full and my programs (quick links and running) are much easier to access.
  2. Closely related to the previous, is the right click behavior on the task bar icons.
  3. The Recent Document has been replaced. Now recent documents appear to the right of any program that is displayed on the Start's popup. So Word has its own recent documents. Excel has its own etc.
  4. Snap is something I use regularly. You can drag an open application to the top or side of the workspace and it resizes to fill the screen or half of the screen as appropriate. Grabbing an application's border and dragging it towards the top resizes the application to the height of the workspace.
I notice these features several times a day. They are the main reason I like Windows 7.

Wednesday, February 10, 2010

WPF menus that go up

I needed a menu docked to the bottom of an application's window. Docking to the bottom of the window is no problem. However, it did not work well, because by default, WPF menus drop down. I needed it to drop up. I need behavior like the Windows Start menu when it is docked on the bottom of the workspace. I looked for a PopupDirection or some such property -- no luck.

I found a solution.

Using Blender, edit a copy of a menu's ItemContainerStyle. The default style has two Popup elements with a Placement property. Placement = "Top" is a valid option.