Skip to content

Instantly share code, notes, and snippets.

@jesseh
Created November 29, 2012 13:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jesseh/4168921 to your computer and use it in GitHub Desktop.
Pair Contribution and Selection

This is a data set of the cost of repairing damage done to shipping containers. Each repair involves a type of damage done to a part of a container. And each repair has an associated cost.

The question is how much does a set of damage-part pairs contribute to the total cost of repairs? And, if an intervention were made to address some types of damage and/or some part how much savings would result?

This chart shows the damage types (left side) and the part types (right side). The height of each block indicates the blocks contribution to the total repair costs.

The bands between the two sides show the cost contribution of each damage/part pair. Dark gray bands are selected for the total percentage number, while light gray bands are not.

Putting your mouse over a block label will show what contributes to the repair costs associated with that block.

You can change which damage/part pairs are selected by clicking on the blocks. Within each block. Only damage/part pairs where both the damage and part are addressable by the intervention are included in the total. Clicking on a block cycles through these states:

  • + indicates that the block is addressed by the intervention (labels in bold)
  • x indicates that the block is not addressed by the intervention
  • o that it may be addressable if the other part of the pair is definitely addressable — (o,+) is selected while (o,-) and (o,x) are not

By clicking blocks on, off and in between you can explore the value of interventions that address alternate sets of damage types and parts.

The data in this chart is randomly generated.

{
"total_cost": 213368763.24923909,
"rights": [
{
"perc": 0.20928050971527695,
"y0": 0,
"y1": 0.20928050971527695,
"name": "Other"
},
{
"perc": 0.01474334908635762,
"y0": 0.20928050971527454,
"y1": 0.22402385880163217,
"name": "Container Interior"
},
{
"perc": 0.015736600580996622,
"y0": 0.224023858801632,
"y1": 0.23976045938262863,
"name": "Hinge Blade"
},
{
"perc": 0.02040020552925697,
"y0": 0.23976045938262844,
"y1": 0.2601606649118854,
"name": "Markings"
},
{
"perc": 0.020629068400847647,
"y0": 0.26016066491188516,
"y1": 0.2807897333127328,
"name": "CAM"
},
{
"perc": 0.021433845964944083,
"y0": 0.28078973331273255,
"y1": 0.3022235792776766,
"name": "Gasket Assembly (with strip)"
},
{
"perc": 0.027845447548656154,
"y0": 0.3022235792776764,
"y1": 0.33006902682633255,
"name": "Handle"
},
{
"perc": 0.02826715043107081,
"y0": 0.33006902682633227,
"y1": 0.3583361772574031,
"name": "Gasket"
},
{
"perc": 0.028758792513170543,
"y0": 0.35833617725740274,
"y1": 0.3870949697705733,
"name": "Handle Retainer"
},
{
"perc": 0.035940737435951275,
"y0": 0.38709496977057295,
"y1": 0.4230357072065242,
"name": "Locking Bar Tube/Rod"
},
{
"perc": 0.04956535674643772,
"y0": 0.4230357072065238,
"y1": 0.47260106395296153,
"name": "Rails - Top and Bottom"
},
{
"perc": 0.06039760904090695,
"y0": 0.47260106395296086,
"y1": 0.5329986729938678,
"name": "Floor - Plywood"
},
{
"perc": 0.06285774771083429,
"y0": 0.532998672993867,
"y1": 0.5958564207047014,
"name": "Interior"
},
{
"perc": 0.08084526896890998,
"y0": 0.5958564207047008,
"y1": 0.6767016896736108,
"name": "Wood Floor Assembly"
},
{
"perc": 0.15774000004020503,
"y0": 0.67670168967361,
"y1": 0.834441689713815,
"name": "Panel"
},
{
"perc": 0.16555831028617732,
"y0": 0.8344416897138136,
"y1": 0.9999999999999909,
"name": "Steel Corrugation"
}
],
"links": [
{
"perc": 1.4483839378416313e-06,
"right": "Interior",
"yb0": 0.532998672993867,
"yb1": 0.533000121377805,
"ya1": 0.5089473154128683,
"ya0": 0.5089458670289304,
"left": "Broken/Split"
},
{
"perc": 5.631585866993288e-06,
"right": "Container Interior",
"yb0": 0.20928050971527454,
"yb1": 0.20928614130114154,
"ya1": 0.17721279223841896,
"ya0": 0.17720716065255196,
"left": "Foreign Marking(s)"
},
{
"perc": 9.68783818905686e-06,
"right": "Other",
"yb0": 0,
"yb1": 9.68783818905686e-06,
"ya1": 0.09383266261241903,
"ya0": 0.09382297477422998,
"left": "Not in Place"
},
{
"perc": 1.137368420369311e-05,
"right": "Handle",
"yb0": 0.3022235792776764,
"yb1": 0.3022349529618801,
"ya1": 0.4344160171747526,
"ya0": 0.4344046434905489,
"left": "Cut"
},
{
"perc": 1.40868439916907e-05,
"right": "Steel Corrugation",
"yb0": 0.8344416897138136,
"yb1": 0.8344557765578053,
"ya1": 0.3603177365292035,
"ya0": 0.36030364968521184,
"left": "Dirty"
},
{
"perc": 1.808929110915915e-05,
"right": "Other",
"yb0": 9.68783818905686e-06,
"yb1": 2.777712929821601e-05,
"ya1": 0.36033582582031265,
"ya0": 0.3603177365292035,
"left": "Dirty"
},
{
"perc": 1.9313148805037936e-05,
"right": "Interior",
"yb0": 0.533000121377805,
"yb1": 0.5330194345266099,
"ya1": 0.1524569762571929,
"ya0": 0.15243766310838786,
"left": "Damaged"
},
{
"perc": 2.0217132497781572e-05,
"right": "Floor - Plywood",
"yb0": 0.47260106395296086,
"yb1": 0.47262128108545864,
"ya1": 0.12939323695362812,
"ya0": 0.12937301982113034,
"left": "Not ISO"
},
{
"perc": 2.329174155691997e-05,
"right": "Wood Floor Assembly",
"yb0": 0.5958564207047008,
"yb1": 0.5958797124462577,
"ya1": 0.5089706071544252,
"ya0": 0.5089473154128683,
"left": "Broken/Split"
},
{
"perc": 2.4771369317957486e-05,
"right": "CAM",
"yb0": 0.26016066491188516,
"yb1": 0.2601854362812031,
"ya1": 0.2540110213735163,
"ya0": 0.25398625000419833,
"left": "Loose Component"
},
{
"perc": 3.368951012099066e-05,
"right": "Interior",
"yb0": 0.5330194345266099,
"yb1": 0.5330531240367309,
"ya1": 0.20764082366916864,
"ya0": 0.20760713415904763,
"left": "Corroded/Rusted"
},
{
"perc": 3.3716872060870836e-05,
"right": "Panel",
"yb0": 0.67670168967361,
"yb1": 0.6767354065456709,
"ya1": 0.25404473824557716,
"ya0": 0.2540110213735163,
"left": "Loose Component"
},
{
"perc": 3.550334796801289e-05,
"right": "Markings",
"yb0": 0.23976045938262844,
"yb1": 0.23979596273059645,
"ya1": 0.30107890839625717,
"ya0": 0.30104340504828914,
"left": "Debris/Dunage"
},
{
"perc": 3.602333837451539e-05,
"right": "Hinge Blade",
"yb0": 0.224023858801632,
"yb1": 0.22405988214000652,
"ya1": 0.07301820869121525,
"ya0": 0.07298218535284073,
"left": "Missing/Lost Component"
},
{
"perc": 3.681391311538485e-05,
"right": "Handle Retainer",
"yb0": 0.35833617725740274,
"yb1": 0.35837299117051813,
"ya1": 0.08343715287422972,
"ya0": 0.08340033896111433,
"left": "Holed"
},
{
"perc": 3.9534534102425045e-05,
"right": "Wood Floor Assembly",
"yb0": 0.5958797124462577,
"yb1": 0.5959192469803601,
"ya1": 0.7887403044962255,
"ya0": 0.788700769962123,
"left": "Bent"
},
{
"perc": 4.0298441530867904e-05,
"right": "Markings",
"yb0": 0.23979596273059645,
"yb1": 0.2398362611721273,
"ya1": 0.3603761242618435,
"ya0": 0.36033582582031265,
"left": "Dirty"
},
{
"perc": 4.313908114868047e-05,
"right": "Locking Bar Tube/Rod",
"yb0": 0.38709496977057295,
"yb1": 0.3871381088517216,
"ya1": 0.07306134777236394,
"ya0": 0.07301820869121525,
"left": "Missing/Lost Component"
},
{
"perc": 4.6281515934175516e-05,
"right": "Floor - Plywood",
"yb0": 0.47262128108545864,
"yb1": 0.4726675626013928,
"ya1": 0.07310762928829811,
"ya0": 0.07306134777236394,
"left": "Missing/Lost Component"
},
{
"perc": 4.8057492184634565e-05,
"right": "Gasket Assembly (with strip)",
"yb0": 0.28078973331273255,
"yb1": 0.28083779080491716,
"ya1": 0.5953563897837261,
"ya0": 0.5953083322915415,
"left": "Dent"
},
{
"perc": 5.0047372874683296e-05,
"right": "Handle Retainer",
"yb0": 0.35837299117051813,
"yb1": 0.3584230385433928,
"ya1": 0.0731576766611728,
"ya0": 0.07310762928829811,
"left": "Missing/Lost Component"
},
{
"perc": 5.343340338776286e-05,
"right": "Markings",
"yb0": 0.2398362611721273,
"yb1": 0.23988969457551507,
"ya1": 0.509024040557813,
"ya0": 0.5089706071544252,
"left": "Broken/Split"
},
{
"perc": 5.5968533237141004e-05,
"right": "Panel",
"yb0": 0.6767354065456709,
"yb1": 0.6767913750789081,
"ya1": 0.12944920548686525,
"ya0": 0.12939323695362812,
"left": "Not ISO"
},
{
"perc": 5.7420059279835004e-05,
"right": "Gasket",
"yb0": 0.33006902682633227,
"yb1": 0.3301264468856121,
"ya1": 0.07321509672045264,
"ya0": 0.0731576766611728,
"left": "Missing/Lost Component"
},
{
"perc": 5.915246701541114e-05,
"right": "Markings",
"yb0": 0.23988969457551507,
"yb1": 0.23994884704253047,
"ya1": 5.915246701541114e-05,
"ya0": 0,
"left": "Other"
},
{
"perc": 6.457680373071505e-05,
"right": "Locking Bar Tube/Rod",
"yb0": 0.3871381088517216,
"yb1": 0.38720268565545235,
"ya1": 0.4344805939784833,
"ya0": 0.4344160171747526,
"left": "Cut"
},
{
"perc": 6.728989459888953e-05,
"right": "Panel",
"yb0": 0.6767913750789081,
"yb1": 0.676858664973507,
"ya1": 0.30114619829085604,
"ya0": 0.30107890839625717,
"left": "Debris/Dunage"
},
{
"perc": 6.82477134936012e-05,
"right": "Gasket Assembly (with strip)",
"yb0": 0.28083779080491716,
"yb1": 0.2809060385184108,
"ya1": 0.07328334443394624,
"ya0": 0.07321509672045264,
"left": "Missing/Lost Component"
},
{
"perc": 8.009791095412743e-05,
"right": "Hinge Blade",
"yb0": 0.22405988214000652,
"yb1": 0.22413998005096064,
"ya1": 0.43456069188943747,
"ya0": 0.4344805939784833,
"left": "Cut"
},
{
"perc": 8.025772663319074e-05,
"right": "Gasket Assembly (with strip)",
"yb0": 0.2809060385184108,
"yb1": 0.28098629624504395,
"ya1": 0.7888205622228587,
"ya0": 0.7887403044962255,
"left": "Bent"
},
{
"perc": 9.540428357746748e-05,
"right": "Handle",
"yb0": 0.3022349529618801,
"yb1": 0.30233035724545754,
"ya1": 0.00015455675059287862,
"ya0": 5.915246701541114e-05,
"left": "Other"
},
{
"perc": 9.594278240555794e-05,
"right": "Gasket",
"yb0": 0.3301264468856121,
"yb1": 0.33022238966801765,
"ya1": 0.5954523325661316,
"ya0": 0.5953563897837261,
"left": "Dent"
},
{
"perc": 9.72787032706739e-05,
"right": "Handle",
"yb0": 0.30233035724545754,
"yb1": 0.30242763594872824,
"ya1": 0.30124347699412674,
"ya0": 0.30114619829085604,
"left": "Debris/Dunage"
},
{
"perc": 0.00010763866165761028,
"right": "CAM",
"yb0": 0.2601854362812031,
"yb1": 0.2602930749428607,
"ya1": 0.07339098309560385,
"ya0": 0.07328334443394624,
"left": "Missing/Lost Component"
},
{
"perc": 0.00011614115199968982,
"right": "Gasket Assembly (with strip)",
"yb0": 0.28098629624504395,
"yb1": 0.28110243739704366,
"ya1": 0.0002706979025925685,
"ya0": 0.00015455675059287862,
"left": "Other"
},
{
"perc": 0.00011999815534024021,
"right": "Interior",
"yb0": 0.5330531240367309,
"yb1": 0.5331731221920711,
"ya1": 0.10773625103695464,
"ya0": 0.1076162528816144,
"left": "Nails In Floor"
},
{
"perc": 0.0001230541839720918,
"right": "Steel Corrugation",
"yb0": 0.8344557765578053,
"yb1": 0.8345788307417774,
"ya1": 0.25416779242954923,
"ya0": 0.25404473824557716,
"left": "Loose Component"
},
{
"perc": 0.0001231698147733709,
"right": "Rails - Top and Bottom",
"yb0": 0.4230357072065238,
"yb1": 0.4231588770212972,
"ya1": 0.2542909622443226,
"ya0": 0.25416779242954923,
"left": "Loose Component"
},
{
"perc": 0.00012391926571779803,
"right": "Floor - Plywood",
"yb0": 0.4726675626013928,
"yb1": 0.4727914818671106,
"ya1": 0.20776474293488645,
"ya0": 0.20764082366916864,
"left": "Corroded/Rusted"
},
{
"perc": 0.00012633699277612935,
"right": "Other",
"yb0": 2.777712929821601e-05,
"yb1": 0.00015411412207434535,
"ya1": 0.10786258802973077,
"ya0": 0.10773625103695464,
"left": "Nails In Floor"
},
{
"perc": 0.00012917882068844253,
"right": "Handle Retainer",
"yb0": 0.3584230385433928,
"yb1": 0.35855221736408127,
"ya1": 0.000399876723281011,
"ya0": 0.0002706979025925685,
"left": "Other"
},
{
"perc": 0.00014675224140824522,
"right": "CAM",
"yb0": 0.2602930749428607,
"yb1": 0.26043982718426895,
"ya1": 0.15260372849860115,
"ya0": 0.1524569762571929,
"left": "Damaged"
},
{
"perc": 0.00015585550580244747,
"right": "Gasket",
"yb0": 0.33022238966801765,
"yb1": 0.3303782451738201,
"ya1": 0.0005557322290834584,
"ya0": 0.000399876723281011,
"left": "Other"
},
{
"perc": 0.0001657136781059084,
"right": "Interior",
"yb0": 0.5331731221920711,
"yb1": 0.533338835870177,
"ya1": 0.12961491916497117,
"ya0": 0.12944920548686525,
"left": "Not ISO"
},
{
"perc": 0.00018711508096243783,
"right": "Gasket",
"yb0": 0.3303782451738201,
"yb1": 0.3305653602547825,
"ya1": 0.5092111556387755,
"ya0": 0.509024040557813,
"left": "Broken/Split"
},
{
"perc": 0.00018942463717695095,
"right": "Steel Corrugation",
"yb0": 0.8345788307417774,
"yb1": 0.8347682553789544,
"ya1": 0.1774022168755959,
"ya0": 0.17721279223841896,
"left": "Foreign Marking(s)"
},
{
"perc": 0.00019721435034734865,
"right": "Handle",
"yb0": 0.30242763594872824,
"yb1": 0.3026248502990756,
"ya1": 0.25448817659467,
"ya0": 0.2542909622443226,
"left": "Loose Component"
},
{
"perc": 0.00021216563705946437,
"right": "Locking Bar Tube/Rod",
"yb0": 0.38720268565545235,
"yb1": 0.3874148512925118,
"ya1": 0.15281589413566063,
"ya0": 0.15260372849860115,
"left": "Damaged"
},
{
"perc": 0.00022057172785066564,
"right": "Handle",
"yb0": 0.3026248502990756,
"yb1": 0.30284542202692627,
"ya1": 0.1530364658635113,
"ya0": 0.15281589413566063,
"left": "Damaged"
},
{
"perc": 0.00022224084152893731,
"right": "Wood Floor Assembly",
"yb0": 0.5959192469803601,
"yb1": 0.596141487821889,
"ya1": 0.08365939371575866,
"ya0": 0.08343715287422972,
"left": "Holed"
},
{
"perc": 0.00023503843502852416,
"right": "Container Interior",
"yb0": 0.20928614130114154,
"yb1": 0.20952117973617007,
"ya1": 0.10809762646475929,
"ya0": 0.10786258802973077,
"left": "Nails In Floor"
},
{
"perc": 0.0002996462225166671,
"right": "Floor - Plywood",
"yb0": 0.4727914818671106,
"yb1": 0.4730911280896273,
"ya1": 0.08395903993827533,
"ya0": 0.08365939371575866,
"left": "Holed"
},
{
"perc": 0.00030947256681772013,
"right": "Floor - Plywood",
"yb0": 0.4730911280896273,
"yb1": 0.473400600656445,
"ya1": 0.153345938430329,
"ya0": 0.1530364658635113,
"left": "Damaged"
},
{
"perc": 0.00033741758340281923,
"right": "Other",
"yb0": 0.00015411412207434535,
"yb1": 0.0004915317054771646,
"ya1": 0.129952336748374,
"ya0": 0.12961491916497117,
"left": "Not ISO"
},
{
"perc": 0.0003967264779880504,
"right": "Rails - Top and Bottom",
"yb0": 0.4231588770212972,
"yb1": 0.4235556034992852,
"ya1": 0.15374266490831706,
"ya0": 0.153345938430329,
"left": "Damaged"
},
{
"perc": 0.0004388031900146265,
"right": "Locking Bar Tube/Rod",
"yb0": 0.3874148512925118,
"yb1": 0.3878536544825264,
"ya1": 0.5096499588287902,
"ya0": 0.5092111556387755,
"left": "Broken/Split"
},
{
"perc": 0.0004476608616408669,
"right": "Handle Retainer",
"yb0": 0.35855221736408127,
"yb1": 0.35899987822572216,
"ya1": 0.2549358374563109,
"ya0": 0.25448817659467,
"left": "Loose Component"
},
{
"perc": 0.00044823299565859416,
"right": "Gasket Assembly (with strip)",
"yb0": 0.28110243739704366,
"yb1": 0.28155067039270226,
"ya1": 0.20821297593054505,
"ya0": 0.20776474293488645,
"left": "Corroded/Rusted"
},
{
"perc": 0.0005857438264810383,
"right": "Handle Retainer",
"yb0": 0.35899987822572216,
"yb1": 0.3595856220522032,
"ya1": 0.4351464357159185,
"ya0": 0.43456069188943747,
"left": "Cut"
},
{
"perc": 0.0006174017189747675,
"right": "Panel",
"yb0": 0.676858664973507,
"yb1": 0.6774760666924817,
"ya1": 0.17801961859457066,
"ya0": 0.1774022168755959,
"left": "Foreign Marking(s)"
},
{
"perc": 0.0006604922031458149,
"right": "Handle",
"yb0": 0.30284542202692627,
"yb1": 0.30350591423007206,
"ya1": 0.07405147529874967,
"ya0": 0.07339098309560385,
"left": "Missing/Lost Component"
},
{
"perc": 0.0007210726697058806,
"right": "Hinge Blade",
"yb0": 0.22413998005096064,
"yb1": 0.22486105272066653,
"ya1": 0.510371031498496,
"ya0": 0.5096499588287902,
"left": "Broken/Split"
},
{
"perc": 0.0007222042782756242,
"right": "Locking Bar Tube/Rod",
"yb0": 0.3878536544825264,
"yb1": 0.38857585876080203,
"ya1": 0.0012779365073590826,
"ya0": 0.0005557322290834584,
"left": "Other"
},
{
"perc": 0.000924200358074025,
"right": "Rails - Top and Bottom",
"yb0": 0.4235556034992852,
"yb1": 0.42447980385735923,
"ya1": 0.0022021368654331075,
"ya0": 0.0012779365073590826,
"left": "Other"
},
{
"perc": 0.0011213247165728552,
"right": "Container Interior",
"yb0": 0.20952117973617007,
"yb1": 0.21064250445274293,
"ya1": 0.0033234615820059627,
"ya0": 0.0022021368654331075,
"left": "Other"
},
{
"perc": 0.0013821649722746427,
"right": "Markings",
"yb0": 0.23994884704253047,
"yb1": 0.2413310120148051,
"ya1": 0.07543364027102431,
"ya0": 0.07405147529874967,
"left": "Missing/Lost Component"
},
{
"perc": 0.0014151658365088836,
"right": "Floor - Plywood",
"yb0": 0.473400600656445,
"yb1": 0.4748157664929539,
"ya1": 0.7902357280593676,
"ya0": 0.7888205622228587,
"left": "Bent"
},
{
"perc": 0.001429752982884511,
"right": "Gasket",
"yb0": 0.3305653602547825,
"yb1": 0.331995113237667,
"ya1": 0.20964272891342955,
"ya0": 0.20821297593054505,
"left": "Corroded/Rusted"
},
{
"perc": 0.0014303485996656363,
"right": "Floor - Plywood",
"yb0": 0.4748157664929539,
"yb1": 0.4762461150926195,
"ya1": 0.5968826811657972,
"ya0": 0.5954523325661316,
"left": "Dent"
},
{
"perc": 0.0015275582250257296,
"right": "Hinge Blade",
"yb0": 0.22486105272066653,
"yb1": 0.22638861094569226,
"ya1": 0.5984102393908229,
"ya0": 0.5968826811657972,
"left": "Dent"
},
{
"perc": 0.0015945014597279266,
"right": "Hinge Blade",
"yb0": 0.22638861094569226,
"yb1": 0.22798311240542019,
"ya1": 0.00491796304173389,
"ya0": 0.0033234615820059627,
"left": "Other"
},
{
"perc": 0.0016313327903426718,
"right": "Panel",
"yb0": 0.6774760666924817,
"yb1": 0.6791073994828244,
"ya1": 0.085590372728618,
"ya0": 0.08395903993827533,
"left": "Holed"
},
{
"perc": 0.0016614033942797372,
"right": "Rails - Top and Bottom",
"yb0": 0.42447980385735923,
"yb1": 0.42614120725163895,
"ya1": 0.13161374014265373,
"ya0": 0.129952336748374,
"left": "Not ISO"
},
{
"perc": 0.0016906033017689273,
"right": "Steel Corrugation",
"yb0": 0.8347682553789544,
"yb1": 0.8364588586807233,
"ya1": 0.08728097603038693,
"ya0": 0.085590372728618,
"left": "Holed"
},
{
"perc": 0.001876463192097246,
"right": "Rails - Top and Bottom",
"yb0": 0.42614120725163895,
"yb1": 0.4280176704437362,
"ya1": 0.08915743922248417,
"ya0": 0.08728097603038693,
"left": "Holed"
},
{
"perc": 0.0019234455562885603,
"right": "Gasket",
"yb0": 0.331995113237667,
"yb1": 0.33391855879395554,
"ya1": 0.09108088477877274,
"ya0": 0.08915743922248417,
"left": "Holed"
},
{
"perc": 0.002030400383399529,
"right": "CAM",
"yb0": 0.26043982718426895,
"yb1": 0.26247022756766847,
"ya1": 0.5124014318818956,
"ya0": 0.510371031498496,
"left": "Broken/Split"
},
{
"perc": 0.0020405613292058134,
"right": "Panel",
"yb0": 0.6791073994828244,
"yb1": 0.6811479608120302,
"ya1": 0.5144419932111014,
"ya0": 0.5124014318818956,
"left": "Broken/Split"
},
{
"perc": 0.0020851454626233373,
"right": "Handle",
"yb0": 0.30350591423007206,
"yb1": 0.3055910596926954,
"ya1": 0.5165271386737247,
"ya0": 0.5144419932111014,
"left": "Broken/Split"
},
{
"perc": 0.0021656658498090025,
"right": "Handle",
"yb0": 0.3055910596926954,
"yb1": 0.3077567255425044,
"ya1": 0.600575905240632,
"ya0": 0.5984102393908229,
"left": "Dent"
},
{
"perc": 0.002196941748790924,
"right": "Handle Retainer",
"yb0": 0.3595856220522032,
"yb1": 0.3617825638009941,
"ya1": 0.6027728469894229,
"ya0": 0.600575905240632,
"left": "Dent"
},
{
"perc": 0.002404716514183434,
"right": "Hinge Blade",
"yb0": 0.22798311240542019,
"yb1": 0.23038782891960363,
"ya1": 0.212047445427613,
"ya0": 0.20964272891342955,
"left": "Corroded/Rusted"
},
{
"perc": 0.002417427630034053,
"right": "Gasket Assembly (with strip)",
"yb0": 0.28155067039270226,
"yb1": 0.2839680980227363,
"ya1": 0.43756386334595254,
"ya0": 0.4351464357159185,
"left": "Cut"
},
{
"perc": 0.002428285501389956,
"right": "Rails - Top and Bottom",
"yb0": 0.4280176704437362,
"yb1": 0.43044595594512614,
"ya1": 0.21447573092900296,
"ya0": 0.212047445427613,
"left": "Corroded/Rusted"
},
{
"perc": 0.002609488890596254,
"right": "Gasket",
"yb0": 0.33391855879395554,
"yb1": 0.3365280476845518,
"ya1": 0.15635215379891332,
"ya0": 0.15374266490831706,
"left": "Damaged"
},
{
"perc": 0.002624541157332247,
"right": "Steel Corrugation",
"yb0": 0.8364588586807233,
"yb1": 0.8390833998380556,
"ya1": 0.007542504199066137,
"ya0": 0.00491796304173389,
"left": "Other"
},
{
"perc": 0.002742089995457234,
"right": "Other",
"yb0": 0.0004915317054771646,
"yb1": 0.0032336217009343985,
"ya1": 0.09382297477422998,
"ya0": 0.09108088477877274,
"left": "Holed"
},
{
"perc": 0.003020750338112149,
"right": "Panel",
"yb0": 0.6811479608120302,
"yb1": 0.6841687111501423,
"ya1": 0.15937290413702546,
"ya0": 0.15635215379891332,
"left": "Damaged"
},
{
"perc": 0.0037312954738292817,
"right": "Panel",
"yb0": 0.6841687111501423,
"yb1": 0.6879000066239717,
"ya1": 0.21820702640283224,
"ya0": 0.21447573092900296,
"left": "Corroded/Rusted"
},
{
"perc": 0.003823670147034227,
"right": "CAM",
"yb0": 0.26247022756766847,
"yb1": 0.2662938977147027,
"ya1": 0.6065965171364571,
"ya0": 0.6027728469894229,
"left": "Dent"
},
{
"perc": 0.0038825745765492864,
"right": "Steel Corrugation",
"yb0": 0.8390833998380556,
"yb1": 0.8429659744146049,
"ya1": 0.520409713250274,
"ya0": 0.5165271386737247,
"left": "Broken/Split"
},
{
"perc": 0.0040906582270224335,
"right": "Interior",
"yb0": 0.533338835870177,
"yb1": 0.5374294940971995,
"ya1": 0.1821102768215931,
"ya0": 0.17801961859457066,
"left": "Foreign Marking(s)"
},
{
"perc": 0.004233476395822439,
"right": "Handle Retainer",
"yb0": 0.3617825638009941,
"yb1": 0.36601604019681655,
"ya1": 0.5246431896460964,
"ya0": 0.520409713250274,
"left": "Broken/Split"
},
{
"perc": 0.004601755560459205,
"right": "Gasket Assembly (with strip)",
"yb0": 0.2839680980227363,
"yb1": 0.28856985358319553,
"ya1": 0.2595375930167701,
"ya0": 0.2549358374563109,
"left": "Loose Component"
},
{
"perc": 0.004931805285523159,
"right": "Steel Corrugation",
"yb0": 0.8429659744146049,
"yb1": 0.847897779700128,
"ya1": 0.1365455454281769,
"ya0": 0.13161374014265373,
"left": "Not ISO"
},
{
"perc": 0.004972843789234376,
"right": "Container Interior",
"yb0": 0.21064250445274293,
"yb1": 0.2156153482419773,
"ya1": 0.3062163207833611,
"ya0": 0.30124347699412674,
"left": "Debris/Dunage"
},
{
"perc": 0.005476750096426393,
"right": "Floor - Plywood",
"yb0": 0.4762461150926195,
"yb1": 0.4817228651890459,
"ya1": 0.01301925429549253,
"ya0": 0.007542504199066137,
"left": "Other"
},
{
"perc": 0.005638046791036366,
"right": "Floor - Plywood",
"yb0": 0.4817228651890459,
"yb1": 0.48736091198008225,
"ya1": 0.31185436757439744,
"ya0": 0.3062163207833611,
"left": "Debris/Dunage"
},
{
"perc": 0.005727392979562471,
"right": "Gasket Assembly (with strip)",
"yb0": 0.28856985358319553,
"yb1": 0.294297246562758,
"ya1": 0.5303705826256588,
"ya0": 0.5246431896460964,
"left": "Broken/Split"
},
{
"perc": 0.005857257554276964,
"right": "Floor - Plywood",
"yb0": 0.48736091198008225,
"yb1": 0.4932181695343592,
"ya1": 0.09968992016669599,
"ya0": 0.09383266261241903,
"left": "Not in Place"
},
{
"perc": 0.006214399133868298,
"right": "Other",
"yb0": 0.0032336217009343985,
"yb1": 0.009448020834802697,
"ya1": 0.3180687667082657,
"ya0": 0.31185436757439744,
"left": "Debris/Dunage"
},
{
"perc": 0.006860399956789846,
"right": "Wood Floor Assembly",
"yb0": 0.596141487821889,
"yb1": 0.6030018877786789,
"ya1": 0.2663979929735599,
"ya0": 0.2595375930167701,
"left": "Loose Component"
},
{
"perc": 0.0068862800996895065,
"right": "Handle",
"yb0": 0.3077567255425044,
"yb1": 0.3146430056421939,
"ya1": 0.1434318255278664,
"ya0": 0.1365455454281769,
"left": "Not ISO"
},
{
"perc": 0.0070654020135550505,
"right": "Floor - Plywood",
"yb0": 0.4932181695343592,
"yb1": 0.5002835715479143,
"ya1": 0.36744152627539856,
"ya0": 0.3603761242618435,
"left": "Dirty"
},
{
"perc": 0.007490339358433697,
"right": "Interior",
"yb0": 0.5374294940971995,
"yb1": 0.5449198334556332,
"ya1": 0.02050959365392623,
"ya0": 0.01301925429549253,
"left": "Other"
},
{
"perc": 0.007681996929718802,
"right": "Rails - Top and Bottom",
"yb0": 0.43044595594512614,
"yb1": 0.43812795287484496,
"ya1": 0.44524586027567137,
"ya0": 0.43756386334595254,
"left": "Cut"
},
{
"perc": 0.007820049553512072,
"right": "Floor - Plywood",
"yb0": 0.5002835715479143,
"yb1": 0.5081036211014264,
"ya1": 0.538190632179171,
"ya0": 0.5303705826256588,
"left": "Broken/Split"
},
{
"perc": 0.007926332714918407,
"right": "Gasket Assembly (with strip)",
"yb0": 0.294297246562758,
"yb1": 0.3022235792776764,
"ya1": 0.1076162528816144,
"ya0": 0.09968992016669599,
"left": "Not in Place"
},
{
"perc": 0.007966698690090018,
"right": "Other",
"yb0": 0.009448020834802697,
"yb1": 0.017414719524892715,
"ya1": 0.08340033896111433,
"ya0": 0.07543364027102431,
"left": "Missing/Lost Component"
},
{
"perc": 0.008141681917193468,
"right": "Markings",
"yb0": 0.2413310120148051,
"yb1": 0.24947269393199858,
"ya1": 0.16751458605421893,
"ya0": 0.15937290413702546,
"left": "Damaged"
},
{
"perc": 0.00819642118719035,
"right": "Rails - Top and Bottom",
"yb0": 0.43812795287484496,
"yb1": 0.4463243740620353,
"ya1": 0.7984321492465579,
"ya0": 0.7902357280593676,
"left": "Bent"
},
{
"perc": 0.008408510559654699,
"right": "Container Interior",
"yb0": 0.2156153482419773,
"yb1": 0.224023858801632,
"ya1": 0.37585003683505325,
"ya0": 0.36744152627539856,
"left": "Dirty"
},
{
"perc": 0.008896710768855917,
"right": "Other",
"yb0": 0.017414719524892715,
"yb1": 0.026311430293748633,
"ya1": 0.45414257104452727,
"ya0": 0.44524586027567137,
"left": "Cut"
},
{
"perc": 0.009005837580521451,
"right": "Handle Retainer",
"yb0": 0.36601604019681655,
"yb1": 0.375021877777338,
"ya1": 0.15243766310838786,
"ya0": 0.1434318255278664,
"left": "Not ISO"
},
{
"perc": 0.009250967079543319,
"right": "Other",
"yb0": 0.026311430293748633,
"yb1": 0.03556239737329195,
"ya1": 0.27564896005310324,
"ya0": 0.2663979929735599,
"left": "Loose Component"
},
{
"perc": 0.009372630463024818,
"right": "Hinge Blade",
"yb0": 0.23038782891960363,
"yb1": 0.23976045938262844,
"ya1": 0.8078047797095828,
"ya0": 0.7984321492465579,
"left": "Bent"
},
{
"perc": 0.009614531673498386,
"right": "Rails - Top and Bottom",
"yb0": 0.4463243740620353,
"yb1": 0.4559389057355337,
"ya1": 0.6162110488099555,
"ya0": 0.6065965171364571,
"left": "Dent"
},
{
"perc": 0.00969257459833303,
"right": "Other",
"yb0": 0.03556239737329195,
"yb1": 0.04525497197162498,
"ya1": 0.17720716065255196,
"ya0": 0.16751458605421893,
"left": "Damaged"
},
{
"perc": 0.010209861853363346,
"right": "Interior",
"yb0": 0.5449198334556332,
"yb1": 0.5551296953089966,
"ya1": 0.3282786285616291,
"ya0": 0.3180687667082657,
"left": "Debris/Dunage"
},
{
"perc": 0.010633551018917314,
"right": "Wood Floor Assembly",
"yb0": 0.6030018877786789,
"yb1": 0.6136354387975962,
"ya1": 0.1187311774836766,
"ya0": 0.10809762646475929,
"left": "Nails In Floor"
},
{
"perc": 0.010641842337453732,
"right": "Floor - Plywood",
"yb0": 0.5081036211014264,
"yb1": 0.5187454634388801,
"ya1": 0.12937301982113034,
"ya0": 0.1187311774836766,
"left": "Nails In Floor"
},
{
"perc": 0.01066689413265204,
"right": "Gasket",
"yb0": 0.3365280476845518,
"yb1": 0.34719494181720384,
"ya1": 0.4648094651771793,
"ya0": 0.45414257104452727,
"left": "Cut"
},
{
"perc": 0.010687970979886571,
"right": "Markings",
"yb0": 0.24947269393199858,
"yb1": 0.26016066491188516,
"ya1": 0.19279824780147967,
"ya0": 0.1821102768215931,
"left": "Foreign Marking(s)"
},
{
"perc": 0.010863349899480092,
"right": "Locking Bar Tube/Rod",
"yb0": 0.38857585876080203,
"yb1": 0.3994392086602821,
"ya1": 0.6270743987094356,
"ya0": 0.6162110488099555,
"left": "Dent"
},
{
"perc": 0.011141235440198894,
"right": "Gasket",
"yb0": 0.34719494181720384,
"yb1": 0.35833617725740274,
"ya1": 0.28679019549330215,
"ya0": 0.27564896005310324,
"left": "Loose Component"
},
{
"perc": 0.012073091993234976,
"right": "Handle Retainer",
"yb0": 0.375021877777338,
"yb1": 0.38709496977057295,
"ya1": 0.8198778717028178,
"ya0": 0.8078047797095828,
"left": "Bent"
},
{
"perc": 0.012178389247731318,
"right": "Panel",
"yb0": 0.6879000066239717,
"yb1": 0.700078395871703,
"ya1": 0.032687982901657545,
"ya0": 0.02050959365392623,
"left": "Other"
},
{
"perc": 0.012560200580547656,
"right": "Steel Corrugation",
"yb0": 0.847897779700128,
"yb1": 0.8604579802806757,
"ya1": 0.8324380722833654,
"ya0": 0.8198778717028178,
"left": "Bent"
},
{
"perc": 0.013213348492639512,
"right": "Wood Floor Assembly",
"yb0": 0.6136354387975962,
"yb1": 0.6268487872902357,
"ya1": 0.04590133139429706,
"ya0": 0.032687982901657545,
"left": "Other"
},
{
"perc": 0.014253209554986981,
"right": "Floor - Plywood",
"yb0": 0.5187454634388801,
"yb1": 0.532998672993867,
"ya1": 0.30104340504828914,
"ya0": 0.28679019549330215,
"left": "Loose Component"
},
{
"perc": 0.01449583559802986,
"right": "CAM",
"yb0": 0.2662938977147027,
"yb1": 0.28078973331273255,
"ya1": 0.8469339078813953,
"ya0": 0.8324380722833654,
"left": "Bent"
},
{
"perc": 0.014808886357567955,
"right": "Other",
"yb0": 0.04525497197162498,
"yb1": 0.060063858329192935,
"ya1": 0.20760713415904763,
"ya0": 0.19279824780147967,
"left": "Foreign Marking(s)"
},
{
"perc": 0.01542602118413836,
"right": "Handle",
"yb0": 0.3146430056421939,
"yb1": 0.33006902682633227,
"ya1": 0.8623599290655337,
"ya0": 0.8469339078813953,
"left": "Bent"
},
{
"perc": 0.015536705177116887,
"right": "Steel Corrugation",
"yb0": 0.8604579802806757,
"yb1": 0.8759946854577926,
"ya1": 0.23374373157994913,
"ya0": 0.21820702640283224,
"left": "Corroded/Rusted"
},
{
"perc": 0.016662158217427166,
"right": "Rails - Top and Bottom",
"yb0": 0.4559389057355337,
"yb1": 0.47260106395296086,
"ya1": 0.5548527903965981,
"ya0": 0.538190632179171,
"left": "Broken/Split"
},
{
"perc": 0.017827881259791515,
"right": "Wood Floor Assembly",
"yb0": 0.6268487872902357,
"yb1": 0.6446766685500273,
"ya1": 0.39367791809484476,
"ya0": 0.37585003683505325,
"left": "Dirty"
},
{
"perc": 0.01796264549336942,
"right": "Steel Corrugation",
"yb0": 0.8759946854577926,
"yb1": 0.893957330951162,
"ya1": 0.4827721106705487,
"ya0": 0.4648094651771793,
"left": "Cut"
},
{
"perc": 0.020242518424249192,
"right": "Other",
"yb0": 0.060063858329192935,
"yb1": 0.08030637675344213,
"ya1": 0.25398625000419833,
"ya0": 0.23374373157994913,
"left": "Corroded/Rusted"
},
{
"perc": 0.023596498546241663,
"right": "Locking Bar Tube/Rod",
"yb0": 0.3994392086602821,
"yb1": 0.4230357072065238,
"ya1": 0.8859564276117754,
"ya0": 0.8623599290655337,
"left": "Bent"
},
{
"perc": 0.026173756358381758,
"right": "Panel",
"yb0": 0.700078395871703,
"yb1": 0.7262521522300847,
"ya1": 0.5089458670289304,
"ya0": 0.4827721106705487,
"left": "Cut"
},
{
"perc": 0.027080853958543673,
"right": "Other",
"yb0": 0.08030637675344213,
"yb1": 0.1073872307119858,
"ya1": 0.07298218535284073,
"ya0": 0.04590133139429706,
"left": "Other"
},
{
"perc": 0.02713479781442289,
"right": "Other",
"yb0": 0.1073872307119858,
"yb1": 0.13452202852640868,
"ya1": 0.6542091965238584,
"ya0": 0.6270743987094356,
"left": "Dent"
},
{
"perc": 0.028448904389437847,
"right": "Panel",
"yb0": 0.7262521522300847,
"yb1": 0.7547010566195225,
"ya1": 0.6826581009132963,
"ya0": 0.6542091965238584,
"left": "Dent"
},
{
"perc": 0.03202502112358272,
"right": "Wood Floor Assembly",
"yb0": 0.6446766685500273,
"yb1": 0.67670168967361,
"ya1": 0.36030364968521184,
"ya0": 0.3282786285616291,
"left": "Debris/Dunage"
},
{
"perc": 0.034302939293922474,
"right": "Other",
"yb0": 0.13452202852640868,
"yb1": 0.16882496782033116,
"ya1": 0.9202593669056979,
"ya0": 0.8859564276117754,
"left": "Bent"
},
{
"perc": 0.04045554189494338,
"right": "Other",
"yb0": 0.16882496782033116,
"yb1": 0.20928050971527454,
"ya1": 0.5953083322915415,
"ya0": 0.5548527903965981,
"left": "Broken/Split"
},
{
"perc": 0.040726725395704176,
"right": "Interior",
"yb0": 0.5551296953089966,
"yb1": 0.5958564207047008,
"ya1": 0.4344046434905489,
"ya0": 0.39367791809484476,
"left": "Dirty"
},
{
"perc": 0.07974063309429118,
"right": "Panel",
"yb0": 0.7547010566195225,
"yb1": 0.8344416897138136,
"ya1": 0.999999999999989,
"ya0": 0.9202593669056979,
"left": "Bent"
},
{
"perc": 0.10604266904882678,
"right": "Steel Corrugation",
"yb0": 0.893957330951162,
"yb1": 0.9999999999999888,
"ya1": 0.788700769962123,
"ya0": 0.6826581009132963,
"left": "Dent"
}
],
"lefts": [
{
"perc": 0.07298218535284151,
"y0": 0,
"y1": 0.07298218535284151,
"name": "Other"
},
{
"perc": 0.010418153608273695,
"y0": 0.07298218535284073,
"y1": 0.08340033896111443,
"name": "Missing/Lost Component"
},
{
"perc": 0.010422635813115741,
"y0": 0.08340033896111433,
"y1": 0.09382297477423007,
"name": "Holed"
},
{
"perc": 0.013793278107384588,
"y0": 0.09382297477422998,
"y1": 0.10761625288161457,
"name": "Not in Place"
},
{
"perc": 0.021756766939516173,
"y0": 0.1076162528816144,
"y1": 0.12937301982113059,
"name": "Nails In Floor"
},
{
"perc": 0.023064643287257745,
"y0": 0.12937301982113034,
"y1": 0.15243766310838808,
"name": "Not ISO"
},
{
"perc": 0.02476949754416433,
"y0": 0.15243766310838786,
"y1": 0.17720716065255218,
"name": "Damaged"
},
{
"perc": 0.030399973506496,
"y0": 0.17720716065255196,
"y1": 0.20760713415904797,
"name": "Foreign Marking(s)"
},
{
"perc": 0.046379115845151135,
"y0": 0.20760713415904763,
"y1": 0.2539862500041988,
"name": "Corroded/Rusted"
},
{
"perc": 0.0470571550440913,
"y0": 0.25398625000419833,
"y1": 0.30104340504828964,
"name": "Loose Component"
},
{
"perc": 0.0592602446369233,
"y0": 0.30104340504828914,
"y1": 0.36030364968521245,
"name": "Debris/Dunage"
},
{
"perc": 0.0741009938053378,
"y0": 0.36030364968521184,
"y1": 0.43440464349054964,
"name": "Dirty"
},
{
"perc": 0.07454122353838231,
"y0": 0.4344046434905489,
"y1": 0.5089458670289312,
"name": "Cut"
},
{
"perc": 0.08636246526261193,
"y0": 0.5089458670289304,
"y1": 0.5953083322915423,
"name": "Broken/Split"
},
{
"perc": 0.19339243767058464,
"y0": 0.5953083322915415,
"y1": 0.7887007699621261,
"name": "Dent"
},
{
"perc": 0.21129923003786782,
"y0": 0.788700769962123,
"y1": 0.9999999999999909,
"name": "Bent"
}
]
}
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<body>
<p><strong><i>The data in this chart is randomly generated.</i></strong></p>
<h3>Percent of repair costs associated with the selected damage types and parts: &nbsp;&nbsp;<span id="summary"></span></h3>
<script src="http://d3js.org/d3.v3.js"></script>
<script src="http://underscorejs.org/underscore.js"></script>
<script>
// Set a list of prechosen bars.
var prechosen = {
"Bent": 2,
"Broken/Split": 2,
"CAM": 0,
"Corner Post Assembly": 0,
"Corroded/Rusted": 0,
"Cross Member Assembly": 1,
"Cut": 2,
"Damaged": 2,
"Debris/Dunage": 1,
"Delaminated": 0,
"Dent": 2,
"Dirty": 0,
"Floor - Plywood": 0,
"Gasket": 0,
"Header (extension) Plate - Front, Rear": 2,
"Header Reinforce Gusset": 0,
"Hinge Blade": 0,
"Holed": 0,
"Improper Repair": 0,
"Interior": 2,
"Locking Bar Tube/Rod": 0,
"Loose Component": 0,
"Not ISO": 0,
"Other": 1,
"Panel": 2,
"Rails - Top and Bottom": 0,
"Rusted & Holed": 2,
"Steel Corrugation": 2,
"Stiffener - Bottom edge": 1,
"Wear and Tear": 0,
"Wood Floor Assembly": 0
}
var margin = {top: 20, right: 100, bottom: 30, left: 200},
width = 960 - margin.left - margin.right,
height = 750 - margin.top - margin.bottom;
//var x = d3.scale.ordinal()
// .rangeRoundBands([0, width], .1);
var y = d3.scale.linear()
.rangeRound([height, 0]);
var line = d3.svg.line()
.x(function (d) { return d[0]; })
.y(function (d) { return y(d[1]); });
var as_perc = d3.format(".0%")
var as_num = d3.format(",.0f")
var chosen_states = {0: 'x', 1: 'o', 2: '+'};
function tip_text(d) {
return d.left.name + " :: " + d.right.name + " (" + as_perc(d.perc) + ")";
}
var x0 = 10,
x1 = 300,
bar_width = 30,
text_margin = 10;
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
.attr("class", "chart");
var summary = d3.select("#summary");
// Returns the path for a given data point.
function link(d) {
var link_x0 = x0 + bar_width,
link_x1 = x1;
var points = [[link_x0, d.ya0], [link_x1, d.yb0], [link_x1, d.yb1], [link_x0, d.ya1]]
return line(points);
}
sum_stats = [{perc_sum: 20}];
function draw(data) {
var lefts = data['lefts'],
rights = data['rights'],
links = data['links'],
total_cost = data['total_cost'];
// The domain is 0, 1 for a 100% bar.
y.domain([0, 1]);
// The left stack
var bars = svg.append("g")
bars.selectAll(".left .bar")
.data(lefts)
.enter().append("rect")
.attr("class", "left bar")
.attr("x", x0)
.attr("width", bar_width)
.attr("y", function(d) { return y(d.y1); })
.attr("height", function(d) { return y(d.y0) - y(d.y1); })
.attr("rx", 3)
.attr("ry", 3)
.attr("stroke", "#444")
.on("mouseup", toggle_left_chosen);
chosen_left = bars.selectAll(".left chosen")
.data(lefts)
.enter().append("text")
.text(function (d) { return chosen_states[d.chosen]; })
//.attr("text-anchor", "end")
.attr("x", x0 + bar_width / 2)
.attr("y", function (d) { return y((d.y1 + d.y0) / 2); })
.on("mouseup", toggle_left_chosen);
chosen_left_label = bars.selectAll(".left text")
.data(lefts)
.enter().append("text")
.text(function(d) { return d.name + " (" + as_perc(d.perc) + ")"; })
.attr("text-anchor", "end")
.attr("x", x0 - text_margin)
.attr("y", function (d) { return y((d.y1 + d.y0) / 2); })
.on("mouseover", set_left_focus)
.on("mouseout", reset_focus);
// The right stack
bars.selectAll(".right .bar")
.data(rights)
.enter().append("rect")
.attr("class", "right bar")
.attr("x", x1)
.attr("width", bar_width)
.attr("y", function(d) { return y(d.y1); })
.attr("height", function(d) { return y(d.y0) - y(d.y1); })
.attr("rx", 3)
.attr("ry", 3)
.attr("stroke", "#444")
.on("mouseup", toggle_right_chosen);
chosen_right = bars.selectAll(".right chosen")
.data(rights)
.enter().append("text")
.text(function (d) { return chosen_states[d.chosen]; })
//.attr("text-anchor", "end")
.attr("x", x1 + bar_width / 2)
.attr("y", function (d) { return y((d.y1 + d.y0) / 2); })
.on("mouseup", toggle_right_chosen);
chosen_right_label = bars.selectAll(".right text")
.data(rights)
.enter().append("text")
.text(function(d) { return d.name + " (" + as_perc(d.perc) + ")"; })
.attr("text-anchor", "start")
.attr("x", x1 + text_margin + bar_width)
.attr("y", function (d) { return y((d.y1 + d.y0) / 2); })
.on("mouseover", set_right_focus)
.on("mouseout", reset_focus);
// The links
// Add grey background lines for context.
svg.append("g")
.attr("class", "background")
.selectAll("path")
.data(links)
.enter().append("path")
.attr("d", link);
// Add darker foreground lines for focus.
foreground = svg.append("g")
.attr("class", "foreground")
.selectAll("path")
.data(links)
.enter().append("path")
.attr("d", link);
// Add tool tips
foreground.append("svg:title")
.text(tip_text);
// Initialize the view in the reset focus mode.
reset_focus();
}
// Toggling the display of foreground lines.
function set_focus(ths, side) {
var name = d3.select(ths).datum().name;
foreground.style("display", function(d) {
if (d[side]['name'] === name) {
return null;
} else {
return 'none';
}
});
}
function set_left_focus() { set_focus(this, 'left'); }
function set_right_focus() { set_focus(this, 'right'); }
function reset_focus() {
var total_perc = 0
foreground.style("display", function(d) {
if (d.left.chosen === 2) {
ret_val = d.right.chosen > 0 ? null : 'none';
} else if (d.right.chosen == 2) {
ret_val = d.left.chosen > 0 ? null : 'none';
} else {
ret_val = 'none';
}
if (ret_val === null) {
total_perc += d['perc'];
}
return ret_val;
});
chosen_right.text(function (d) { return chosen_states[d.chosen]; })
chosen_left.text(function (d) { return chosen_states[d.chosen]; })
chosen_right_label.style("font-weight", function (d) {
return d.chosen == 2 ? "bold" : "normal";
})
chosen_left_label.style("font-weight", function (d) {
return d.chosen == 2 ? "bold" : "normal";
})
summary.text(as_perc(total_perc));
}
function toggle_chosen(ths, side) {
var d = d3.select(ths).datum();
d.chosen = (d.chosen + 1) % 3;
reset_focus();
}
function toggle_left_chosen() { return toggle_chosen(this, 'left'); }
function toggle_right_chosen() { return toggle_chosen(this, 'right'); }
/*
* Connect the links to the left and right side objects.
*/
function connect_sides(data) {
var lefts = data['lefts'],
rights = data['rights'],
links = data['links'];
_.each(links, function (l) {
l.left = _.find(lefts, function (f) { return f.name === l.left; });
l.right = _.find(rights, function (f) { return f.name === l.right; });
});
}
/**
* Initialize the chosen settings.
* Uses global prechosen as a hash of names and chosen values (0, 1, 2)
**/
function set_chosen(data) {
var both_sides = data.lefts.concat(data.rights);
_.each(both_sides, function (l) {
l['chosen'] = l.name in prechosen ? prechosen[l.name] : 1;
});
}
function main(error, data) {
if (error) {
console.log(error);
} else {
connect_sides(data);
set_chosen(data);
draw(data);
}
}
d3.json("data.js", main);
</script>
body {
font: 14px sans-serif;
}
.chart {
font: 12px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.bar {
fill: steelblue;
}
.x.axis path {
display: none;
}
.legend line {
stroke: #000;
shape-rendering: crispEdges;
}
div.bar {
display: inline-block;
width: 20px;
height: 75px; /* We'll override this later */
background-color: teal;
}
.background path {
fill: #ccc;
stroke: #bbb;
stroke-opacity: .4;
fill-opacity: .4;
shape-rendering: crispEdges;
}
.foreground path {
fill: #666;
stroke: #555;
stroke-opacity: .7;
fill-opacity: .7;
}
#summary {
font-size: 30px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment