What does brushing and linking mean in information visualization?

Visualization systems generally consist of several independent visualizations, each allowing exploration of a different aspect of data. Over years, researchers have developed several interaction techniques to allow users to explore data. Two of these several techniques are Brushing and Linking.

Brushing refers to several interaction techniques that allow the user to select a subset of data in a visualization. Consider the following node-link visualization:

A node-link graph with several nodes and images.

A node-link graph with several nodes and images.

It contains several nodes and edges making it difficult to make sense of the graph. Suppose the user only wants to focus his exploration on a certain node and all its connected nodes. To do this she would select a subset of nodes. This selection as shown in the following figure is called brushing.

A subset of nodes selected in the graph.

A subset of nodes selected in the graph.

 

As I mentioned that most visualization software consist of several different types of visualization. It is often required to visualize a subset of data in different visualizations. This requirement is facilitated by the interaction technique called Linking. When a set of data elements is selected in a visualization, the same set gets selected in the other visualizations as well. For instance, consider the document view in CZSaw for VAST 2010 mini-challenge1 data-set.

Document view in CZSaw that brushes the entities selected in a list to a document.

Document view in CZSaw that brushes the entities selected in a list to a document.

In the document view of CZSaw, when a set of data elements (called entities) is selected in a list of entities, they get selected in the in corresponding document as well as any other visualization such as the hybrid view below:Screenshot from 2013-05-24 14:03:02

Brushing and Linking are two important interaction techniques that are supported in almost every visualization software. Brushing used with Linking form form a very powerful interaction and exploration of data in different visualization software.

Using switch-case for String in Java6

Until Java 7, developers were not able to use String in switch-case construct. The only option was to write a huge if-else block like this

 
if(str.equals("Opt1")){
...
}else if(str.equals("Opt2")) {
...
}else if(str.equals("Opt3")){
...
}

In my opinion, switch-case although somewhat limited than if-else, is a cleaner construct.

With Java 7, one can use String in a switch-case just like an integer:

switch(str){
case "Opt1": ...
case "Opt2": ...
case "Opt3": ...
}

However, as there is still a substantial amount of Java 6 development, I thought I would share a cleaner alternative for conditionals involving String. However, this alternative is applicable only for cases where the existing conditionals use equals() method. Suppose you have an if-else block like the one shown above, then you can convert it into a switch-case construct like this:

First, define an Enum containing all the options

enum Options{
 Opt1, Opt2, Opt3
}

Then replace the if-else by switch-case like this:

Options option = Options.valueOf(str);
switch(option){
case OPT1: <task1>; break;
case OPT2: <task2>; break;
case OPT3: ...; break;
}

Update:
However, the switch-case alternative although cleaner, might appear slower in some cases. If the time taken by the tasks (taks1, task2 etc…) is very small compared to Options.valueOf() then the switch-case would appear slower as the valueOf method does several complex operations to return the correct enum.

If you would like to compare performance difference between the two alternatives, I have written a simple test available here.

How to run a loom project from sublime?

Loom is a game engine that provides live update functionality which makes testing code very easy. It is slowly gaining popularity at least among the newbie game developers and students (ones like me) as it is free and provides normal developers to take a shot a game development. without too much investment.

As it does not come with any IDE, I tend to use Sublime Text for development with loom. If you are doing the same, you might need some build system to build+run loom from within Sublime. Below I am sharing the steps that I took to achieve the same. Although I am using Windows for my example, you can use any OS to achieve the same with appropriate changes. Here it is:

Go to Tool > Build System > New Build System...

Then add the following code to the build script that you get

{
"cmd": ["loom.bat", "run"],
"selector": "source.ls",
"path": "C:\\Program Files (x86)\\Loom\\bin"
}

and save the file in the Packages directory.

Update:

I recently found this project that is allows much more than just running a project.

Dealing with missing headers and files on Debian when compiling software and libraries.

If you are using any Debian-based OS like Ubuntu for some time, it is possible that you might have tried to compile some library or software and encountered the same old error like this

fatal error: xyz.h: No such file or directory

At this time, you are really pissed off as you do not know where to find this header. Now, first you will try to google it and if you are not lucky (which happens with me a lot), you will not find any useful thing. However, I recently discovered that at this point too, there is some hope left.

If the header belongs to some Debian package, you can use apt-file tool to find which package it belongs to. To do this, first install apt-file.

sudo aptitude install apt-file

Then update it using

sudo apt-file update

This will load the relevant information to find what you are looking for. Then do

apt-file search xyz.h

And if it is indeed a header file from a debian package, you by now have gotten the relevant information to install the appropriate package.

What is the fastest way to find if a number is prime?

Quoting wikipedia,

prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.

So, at times you might find a need to check if a number is prime. And if the numbers to be checked for primality, you might need the fastest implementation. In this post, I am sharing the implementation as suggested by the algorithm here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
boolean isPrime(long number) {
	if (number == 2) {
	    return true; // 2 is a prime
	}
 
	// if the number is even
	if (number % 2 == 0 || number &lt; 1) {
	    return false; // not a prime.
	}
 
	// a number would be prime if it is not divisible by a number less than or equal to its square root.
	double root = Math.sqrt(number);
 
	//we start the loop from 3 (2 is already checked above)
	//Additionally, we will increment i by 2 as checking for even divisor is not required at this point.
	for (double i = 3; i &lt;= root; i = i + 2) {
	    if (number % i == 0) {
		return false;
	    }
	}
 
	return true;
}

Processing: My first impressions

Long I have not known about an interesting environment for working on graphics and animation. It is called Processing. I have long been using Java for all my desktop application needs (with occasional also some animation/custom component coding in Swing). So, I know the pains of developing even a simple visualization, animation or even a worthy UI using Java/Swing.

Recently I started working for a visualization group as an RA/Lead Developer. At work, it is often a requirement to prototype some visualization real fast and hence I was introduced to Processing. And to put it in words, it was like “I was given a power that I could not wield”, and this was not because Processing was ugly or complicated. Rather, it is because it is very different from what I have been doing so far with Swing. In this post, I will try to discuss my first reactions to Processing, which do not include any code samples (that is for later).

I think Processing is wonderful when it comes to rapid Prototyping. It might however take some time to get your head around the plethora of globals that the environment provides (it might drive you a bit crazy at first, so be careful!) and the way it cares of animation or visualizing a component. The reason why I think is wonderful is and as I mentioned before, is the power of rapid prototyping that it gives. Creating STUFF in Processing is very easy, quick and clean (although some might argue).

Additionally, as I am always interested in things that revolve around making school-going kids learning to program, I see Processing as a great selling point. But, only as far as developing that first attraction to programming is concerned. I say that because I think (and in agreement with Learnable Programming) that it is an awful thing to use for making students learn programming.

Programming is not just about executing some commands. It see it as an art and a way of thinking (as discussed in learnable programming). Although, Processing takes away a “boat load of bloat” when compared to modern programming languages like Java, when it comes to creating visual products, it still does not qualify as way to dive into the ocean of programming and software development. Giving kids an enviroment where they can get started with creating visual artifacts to feel the power is one thing, teaching them to program is another. And in my opinion, Processing completely fails on that ground. If you want details on why, Bret Victor has done a wonderful job of explaining why in his post.

At last, these were just my first impressions. Keeping aside the problems with using Processing to learn programming, I still suspect it to be a wonderful environment to test animations and even visualizations. As I am not sure if it offers anything in terms of writing maintable modular code base, it is something I plan explore next( maybe by writing a small game in Processing). Stay tuned for more…

How to get the calling class name from the static method of the superclass in Java?

While coding Java for one of my projects, I came across a  weird requirement. I had a super class that had a static method and I wanted to know the name of the sub classes of my super class that called the method. Let me explain that by example.

I have a class Super that contains a static method superStaticMethod() that prints the name of the class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package example;
 
/** Super.java **/
public class Super {
 
	/** prints the name of the calling class **/
	public static void aStaticMethod() {
		System.err.println("Super static method called from " + getClassName());
	}
 
	private static String getClassName() {
		return Super.class.getName();
	}
 
}

Now I have another class Sub that extends the Super class.

package example;
 
/** Sub.java **/
public class Sub extends Super {
	// nothing here.
}

Now, whether I call Super.aStaticMethod() or Sub.aStaticMethod(), I will get the same output :

Super static method called from example.Super

This is precisely because Super class has no idea of which class actually called the method. Had this been a simple instance method, it was simple. I can just use this.class.getName(). But achieving the same effect is tricky because there is no instance involved when calling the static method and calling Sub.aStaticMethod() is same as calling Super.aStaticMethod().

However, after battling with reflection, I found some way which I would like to share. Here is how its done. The trick is that you hide inside the Super class a spy that can tell you who called the method. This spy will actually be a nested static class that will reveal the details of the calling class.

What you need to do is modify the Super class to this:

 
package example2;
 
public class Super {
 
	public static void aStaticMethod() {
		System.err.println("Super static method called from "
				+ new Spy().revealTheCallingClass());
	}
 
	/** This class helps get the class name */
	static class Spy extends SecurityManager {
 
		public String revealTheCallingClass() {
			Class[] classes = getClassContext();
			for (Class cls : classes) {
				// check if the class is a sub class and its the Super class
				// itself.
				if (Super.class.isAssignableFrom(cls) && cls != Super.class) {
					return cls.getName();
				}
			}
 
			return null;
		}
	}
 
}

Now if you modify the class for Sub to

package example2;
 
public class Sub extends Super{
 
  public static void useSuperClassName(){
    aStaticMethod();
  }
}

Calling Sub.useSuperClassName() will print example2.Sub. Note however that calling Sub.aStaticMethod() will still print null or the name of the class in which it is called (if that class is a subclass of Super) which is something that I will try to rectify in future, if possible.

Animating the console!

There are times when I love to use command-line/terminal (whatever you want to call it). And when I do I like to do something fun with it, and not just putting text to read. This post contains two examples of some fun code that you might wanna use to make something nice of your command-line application.

The first example is a rolling piece of text on console (something similar to what you might get from the HTML marquee.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* MarqueeOnConsole.java
* Following piece of code available to use without any fee for any closed/open-source project.
* Creates a HTML-marquee-like text on console.
*
* @author Ankit Gupta
* @version 1.0
*/
public class MarqueeOnConsole{
 
	/** Width of the marquee in terms of character. **/
	public static final int CONSOLE_LENGTH=40;
 
	/** Creates a rolling marquee on console. **/
	public static void main(String []agrs) throws InterruptedException{
		String text = "This text is rolling!";
		int prefixLength=-1;
		while(true){
			String prefix = "\r";
			prefixLength++;
			if(prefixLength>CONSOLE_LENGTH){
				prefixLength=0;
			}
			for(int i=0; i < prefixLength;i++){
				prefix += " ";
			}
			int endIndex = CONSOLE_LENGTH-prefixLength;
			if(endIndex > text.length()){
				endIndex = text.length();
			}
			String printableText = text.substring(0,endIndex);
			System.out.print(prefix + printableText);
			Thread.sleep(100);
		}
	}
}

This second example is the one that simulates the process completion that you see on console with increasing percent.

Animated Console (GIF created by http://www.screencast-o-matic.com/screen_recorder)

/**
* Console Animation.
* Following piece of code available to use without any fee for any * closed/open-source project.
* @author Ankit Gupta
* @version 1.0
*/
public class AnimatingConsole {
 
 public static void main(String []args) throws InterruptedException {
   for(int i=0; i < 1000; i++){
    String ch="";
    switch(i%3){
     case 0: ch="\\"; break;
     case 1: ch="-";  break;
     case 2: ch="/";  break;
    }
    System.out.print("\r\t\t\t\t\t\t\t\t Processing Stuff... Please wait! \t\t\t\t\t\t"+i/10.0+"% "+ch);
    Thread.sleep(100);
  }
  System.out.println("\nDone");
 }
}

The key in both the example here is the use of “\r” (carriage return character). What it does is that it moves the cursor to the front of the current-line without moving it down (like “\n”).

Although, this is not something awesome but still something that might help you make your command-line tool or application look pretty.

If you have done some nice effect in your text-based console app, I would like to have a look at it. Send me an email or leave a reply here.

Competition, Collaboration and Software.

If you happen to be a guy who has spent some time in online forums for software developers, you might be aware of the flame wars that go on between different software such as vim and emacs or netbeans and eclipse, or between different operating systems. I happen to be the guy who just hates these kind of discussions. The problem with these flame wars is that they start as simple comparisons or discussions and evolve into pure blasphemy.

Obviously there is a reason to this madness. It is usually the incapability/inflexibility of a particular piece of software to achieve what someone might want. One thing that I have learnt about software in terms of functionality is that it is a very bad idea to develop software that has features to satisfy the needs of every user in a given domain. What happens very often is that people start copying their rival product which can lead to bad things happening. You might copy some product that already exists and you won’t have a selling point and eventually you will have to sell your product at a lower price (potentially a series of unpleasant decisions). Just look at the products that try to copy Photoshop, per se. Now, I am not talking about products that were created to provide free alternatives because they have achieved their goals.

I see a potential misunderstanding that might arise of what I just said. When I say a potential risk in copying features of a product, I do not mean that an image editing software should not have an image crop feature because Photoshop has it. What I mean is that one should try to copy the “selling points” of a software. Rather, try to have your unique selling points or improve on the features that are already provided by existing software. To give a more concrete example, have a look at ormr which does not sell itself by copying existing image editors, but brings something that others do not have.

Now, this is to some extent the perspective or requirement of a category of users (which is much more in numbers as one might think) who need a difference in the products they use.

On the  other hand of the spectrum is research in both academia and industry. On one hand where software needs more competition to create a market of unique products, research needs a community of collaborators. To allow, commercial vendors to provide some new and outstanding functionality that will drop our jaws, research should constantly feed the market with new results and technology.

Now, it might sound easy and you might think that the research community is to blame. And I would simply say, “I do not agree”. Here is what generally happens. A graduate student starts with some idea in mind, explores related research and then half way through realizes that, just to get his idea going, he needs to get results from completely different field of study than computer science and also needs software components that are mentioned in some research but are not available as implementations. Now, by the time, he finishes coding all the pre-requisites, he does not have enough time to spend on his original idea. He would eventually code his idea (half-baked a lot of times) and present it to the community. Another student at some other place who wants to continue his research in the same area as our former student, needs to go through all of the work that our former student has already done.

Although, this approach works, the problem is that the incremental results of this approach are too small and take a very long time before they reach the market as part of some software. To overcome this sluggish nature of the beast, what the research community desperately needs is a directory of research (not just researchers) and related software components which are easily accessible to other researchers and graduate students which will allow them to work more on their idea and not on the pre-requisite components.

I know some people who are already there working on something similar. I am fortunate enough to be a part of the project and also the fact that someone else too experiences the same limitations as I do. I would also ask you to let me know if you are interested in helping us build such a research directly. At the same time, I would also like to hear from you, if you happen to have any other ideas, opinion or comments.