D3.js json structure question

237 views
Skip to first unread message

Innocentpixel

unread,
Nov 12, 2012, 7:59:21 PM11/12/12
to d3...@googlegroups.com
I'm doing some charts with analytics regarding a game. Here is the basic assumptions.


There are three possible actions a player can make.Player can attack
Player can deffend
Player can run ( in 2 directions forwards and backwards)


Each action can happen in one of the three battlegrounds (bg a, bg b, bg c)


A player can be human or alien. Each player regarding of race can have a level.


Each player executes a particular action at a particular time.


Now i need to chart these things.


Piechart of the players race
Piechart of where the actions took place(in which of the 3 battlegrounds)
A barchart of the players level
A line chart for attacks based on time
A line chart for defends based on time
A linechart for runs( oneline for each diection of running) based on time


Each chart needs to be connected to the other ones (kondof the crossfilter flight charts are) . So for example if i click on the piechart with the player race and chose human the other charts update accordingly to reflect levels, and battlegrounds and actions pertaining just to that race.


Bottom line is i am having a hard time structuring my json input. Can any experts give me some hints?
Thank you for your time.

Ian Johnson

unread,
Nov 12, 2012, 8:21:11 PM11/12/12
to d3...@googlegroups.com
My suggestion would be to work backwards from the charts. You can come up with sample data for each chart based on what you will need to plot. You can then look at how you would get that data from your real data source. some of it will be by filtering, some will be by aggregation or groupings (.group() in crossfilter).

Once you have that laid out it may become clearer how to structure your data to feed into your app. I'd say this is a pretty common but realistic problem, figuring out where to do your data processing and when your data is actually ready for visualization.

My guess is that getting your data formatted nicely for crossfilter will take you pretty far, but the way I would definitely figure out all the requirements first and see if you can come up with the appropriate crossfilter filters/groups to get what you need.
--
Ian Johnson

Innocentpixel

unread,
Nov 12, 2012, 8:26:08 PM11/12/12
to d3...@googlegroups.com
So bottom line is i can have for example 2 entrie for the same player with two separate actions and then group them together is that what you are saying? This is a new field to me so if you can give me any sample be it as simple as possible would get me a long way. Cheers

Kai Chang

unread,
Nov 12, 2012, 8:35:30 PM11/12/12
to d3...@googlegroups.com
Check out Ralph Kimball's writings on dimensional modelling.

http://www.kimballgroup.com/1997/08/02/a-dimensional-modeling-manifesto/

You can accomplish that with a collection of csvs, and load them with d3.csv.

I would have at least three tables:

Players - Level, race, id
Actions - Attacker (player id), defender(player id), location, time
Movement - Player id, direction, time

In the future you could easily add other tables, such as a Weapons
table. Then include the weapon id in the Actions table to capture that
new dimension.

On Mon, Nov 12, 2012 at 4:59 PM, Innocentpixel <mi...@pocorschi.com> wrote:

Ian Johnson

unread,
Nov 12, 2012, 8:36:01 PM11/12/12
to d3...@googlegroups.com
Well you could start by just making charts for all data (no filtering) and start with a small subset of your data.
So plot the line charts of actions over time, or bar charts of players level.

Grouping is when you want to group by (usually count by) a certain property. So if you wanted to group attacks by player you would need to do a group on all the attack events. So you may find you need to do an extra calculation step to get the data for some of the charts (the ones you couldn't make just by plotting your recorded data).

Once you can draw the things you want to draw, you can start dealing with the interaction between them and get more complex behavior.



On Mon, Nov 12, 2012 at 5:26 PM, Innocentpixel <mi...@pocorschi.com> wrote:
So bottom line is i can have for example 2 entrie for the same player with two separate actions and then group them together is that what you are saying? This is a new field to me so if you can give me any sample be it as simple as possible would get me a long way. Cheers



Innocentpixel

unread,
Nov 12, 2012, 8:40:15 PM11/12/12
to d3...@googlegroups.com, kai.s...@gmail.com
holy f$#^ I might be over my head on this one.

Kai Chang

unread,
Nov 12, 2012, 8:44:45 PM11/12/12
to d3...@googlegroups.com
Here are some example tables. Units of time completely made up.

player,id,race,level
Garrk,1,orc,2
Yvette,2,human,3
Pozar,3,human,2

location,id
Mystic Forest,1
Plains of Hell,2

attacker_id,defender_id,location_id,time
1,2,2,24323
1,3,2,24325

mover_id,direction,location_id,x,y,time
3,N,1,30,45,24876
3,N,1,30,46,24877

Kai Chang

unread,
Nov 12, 2012, 8:46:03 PM11/12/12
to d3...@googlegroups.com
The attacker table describes Garrk attacking Yvette and Pozar in the
Plains of Hell.

The movement table describes Pozar taking two step North through the
Mystic Forest.

Innocentpixel

unread,
Nov 12, 2012, 8:52:42 PM11/12/12
to d3...@googlegroups.com, kai.s...@gmail.com
Ok first of all. lol. Can I give you a +1 for awesome taxonomy? :P
Second I think i get it but how would I then connect them together? 
Reply all
Reply to author
Forward
0 new messages