Skip to content

Instantly share code, notes, and snippets.

@ashenfad
Last active August 29, 2015 14:05
Show Gist options
  • Save ashenfad/044e84c77250ab57e8cf to your computer and use it in GitHub Desktop.
Save ashenfad/044e84c77250ab57e8cf to your computer and use it in GitHub Desktop.
Dynamic Scatterplot - Autos

Dynamic scatterplot of the 1985 automobiles dataset.

Controls:

  • Left click to choose X-axis.
  • Right click to choose Y-axis.
  • Alt + right click to choose color axis.
  • Repeat click (left, right, or alt) for log scale.
  • Hover over a point to see all field values.
  • Click a multi-point (larger circle) to cycle through values.
  • Drag box to zoom in.
  • Click on empty area to zoom out.
  • Choose plot granularity with keys 1-9 (1 is the default).
{"fields":[{"id":"000000","preferred":true,"summary":{"missing_count":0,"categories":[["toyota",32],["nissan",18],["mazda",16],["honda",13],["mitsubishi",13],["subaru",12],["volkswagen",12],["peugot",11],["volvo",11],["bmw",8],["dodge",8],["mercedes-benz",8],["plymouth",7],["audi",6],["saab",6],["porsche",4],["alfa-romero",3],["chevrolet",3],["jaguar",3],["isuzu",2],["mercury",1]]},"datatype":"string","order":0,"term_analysis":{"enabled":true},"optype":"categorical","name":"Make","column_number":0},{"id":"000001","preferred":true,"summary":{"missing_count":0,"categories":[["gas",178],["diesel",19]]},"datatype":"string","order":1,"term_analysis":{"enabled":true},"optype":"categorical","name":"Fuel","column_number":1},{"id":"000002","order":2,"optype":"categorical","name":"Doors","column_number":2,"preferred":true,"summary":{"missing_count":0,"categories":[["2-door",85],["4-door",112]]}},{"id":"000003","preferred":true,"summary":{"missing_count":0,"categories":[["sedan",92],["hatchback",67],["wagon",24],["hardtop",8],["convertible",6]]},"datatype":"string","order":3,"term_analysis":{"enabled":true},"optype":"categorical","name":"Body","column_number":3},{"id":"000004","preferred":true,"summary":{"missing_count":0,"categories":[["fwd",114],["rwd",75],["4wd",8]]},"datatype":"string","order":4,"term_analysis":{"enabled":true},"optype":"categorical","name":"Drive","column_number":4},{"id":"000005","preferred":true,"summary":{"splits":[154.30374,157.23856,157.41626,158.43808,159.20315,165.28012,166.04861,166.66088,168.16145,168.86008,169.01938,170.16922,171.48348,171.87215,172.33567,173.10704,173.43281,174.7625,175.53445,176.11141,176.70208,177.68275,179.83511,183.9125,186.61492,186.76667,188.14365,188.81646,189.50469,193.21615,199.0778],"mean":174.21827,"sum_squares":6009353.9,"bins":[[141.1,1],[144.6,2],[150,3],[155.9,1],[157.3,17],[158.9375,8],[162.4,1],[163.4,1],[165.3875,8],[166.41111,9],[167.4,4],[168.87333,15],[170.31111,9],[172.00588,17],[173.30769,13],[175.28333,12],[176.46667,12],[177.9,8],[180.23333,3],[181.7,1],[183.36667,3],[184.6,2],[186.65385,13],[187.7,3],[188.83077,13],[191.16667,3],[192.7,3],[193.8,1],[197,1],[199.14286,7],[202.6,2],[208.1,1]],"maximum":208.1,"missing_count":0,"variance":153.10466,"median":173.10704,"population":197,"minimum":141.1,"standard_deviation":12.37355,"sum":34321},"datatype":"double","order":5,"optype":"numeric","name":"Length","column_number":5},{"id":"000006","preferred":true,"summary":{"splits":[1877.03628,1913.77699,1944.96875,1972.75,2008.5625,2031.9375,2115.53125,2148.10011,2211.71875,2264.0625,2289.19896,2302.75,2337.04706,2380.44862,2396.375,2413,2467.34375,2535.4589,2570.5,2689,2747.21718,2807.5,2844.28125,2939.25,3017.625,3057.8125,3092.46875,3149.58359,3246.84375,3486.875,3743.4375],"mean":2558.45685,"sum_squares":1342865464,"bins":[[1488,1],[1713,1],[1828,2],[1897.54545,11],[1962.92857,14],[2023.36364,11],[2087.5,2],[2134,9],[2212.875,8],[2282.3125,16],[2330.14286,7],[2395.05,20],[2482.14286,7],[2548.33333,9],[2684.4,10],[2757.83333,6],[2823.11111,9],[2920.8,5],[2964.25,4],[3016,3],[3066.07692,13],[3141.16667,6],[3229.66667,6],[3290.5,2],[3380,1],[3430,1],[3500,4],[3700,2],[3753.33333,3],[3900,1],[3950,1],[4066,2]],"maximum":4066,"missing_count":0,"variance":272256.50451,"median":2413,"population":197,"minimum":1488,"standard_deviation":521.78205,"sum":504016},"datatype":"int16","order":6,"optype":"numeric","name":"Weight","column_number":6},{"id":"000007","preferred":true,"summary":{"counts":[[2,4],[3,1],[4,153],[5,10],[6,24],[8,4],[12,1]],"mean":4.37056,"sum_squares":3987,"maximum":12,"missing_count":0,"variance":1.1426,"median":4.11757,"population":197,"minimum":2,"standard_deviation":1.06892,"sum":861},"datatype":"int8","order":7,"optype":"numeric","name":"Cylinders","column_number":7},{"id":"000008","preferred":true,"summary":{"splits":[82.86606,90.13586,90.99377,91.7145,92.76431,94.86731,97.0067,97.45378,97.91614,100.54499,106.79661,108.27406,108.88317,109.56783,110.1184,119,120.31513,121.25778,121.84834,124.67709,130.37229,135.97491,140.6943,145.17417,149.36609,153.41682,159.99653,171.65479,181.5342,191.14439,232.0836],"mean":126.99492,"sum_squares":3521474,"bins":[[61,1],[70,3],[79.5,2],[90.33333,15],[92,15],[97.48148,27],[103,1],[108.38095,21],[110.07692,13],[119.875,8],[121.7,20],[130.2,5],[134,2],[136,5],[140.77778,9],[145.85714,7],[151,1],[152,6],[156,5],[161,1],[164,3],[171,3],[173,1],[181,6],[183,4],[194,3],[209,3],[234,2],[258,2],[304,1],[308,1],[326,1]],"maximum":326,"missing_count":0,"variance":1756.70916,"median":119,"population":197,"minimum":61,"standard_deviation":41.91311,"sum":25018},"datatype":"int16","order":8,"optype":"numeric","name":"Engine size","column_number":8},{"id":"000009","preferred":true,"summary":{"splits":[57.40192,63.09572,66.2332,68.06007,68.42626,68.8984,69.52305,70.42997,73.82975,78.22474,83.2875,85.1225,87.3033,89.80152,93.42609,95.2918,97.75,100.96842,103.07762,110.01569,111.07159,113.80624,115.60921,117.80742,122.43303,141.125,147.59929,155.1875,160.22089,175.1726,183.84669],"mean":103.60406,"sum_squares":2392234,"bins":[[48,1],[52,2],[55.66667,3],[59,2],[62,6],[68.73684,38],[72.75,4],[76.33333,6],[82,5],[84.91667,12],[88.66667,9],[92,4],[94.77778,9],[97,5],[101.16667,12],[106,1],[110.57143,14],[115.1875,16],[120.75,4],[123,4],[134.5,2],[140,1],[142.5,2],[145,5],[152,3],[155.2,5],[160.66667,9],[175.66667,3],[182.8,5],[200,1],[207,3],[262,1]],"maximum":262,"missing_count":0,"variance":1416.70978,"median":95.2918,"population":197,"minimum":48,"standard_deviation":37.63921,"sum":20410},"datatype":"int16","order":9,"optype":"numeric","name":"Horsepower","column_number":9},{"id":"00000a","preferred":true,"summary":{"counts":[[4150,5],[4200,5],[4250,3],[4350,4],[4400,3],[4500,7],[4750,4],[4800,36],[4900,1],[5000,27],[5100,3],[5200,23],[5250,7],[5300,1],[5400,11],[5500,35],[5600,1],[5800,7],[5900,3],[6000,9],[6600,2]],"mean":5118.0203,"sum_squares":5205597500,"maximum":6600,"missing_count":0,"variance":231395.55061,"median":5132.16991,"population":197,"minimum":4150,"standard_deviation":481.03591,"sum":1008250},"datatype":"int16","order":10,"optype":"numeric","name":"Peak RPM","column_number":10},{"id":"00000b","preferred":true,"summary":{"counts":[[16,2],[17,1],[18,2],[19,2],[20,2],[22,7],[23,7],[24,17],[25,19],[26,3],[27,5],[28,12],[29,10],[30,15],[31,6],[32,16],[33,9],[34,14],[36,2],[37,13],[38,17],[39,2],[41,3],[42,2],[43,2],[46,2],[47,2],[50,1],[53,1],[54,1]],"mean":30.62944,"sum_squares":193978,"maximum":54,"missing_count":0,"variance":46.73443,"median":30.13914,"population":197,"minimum":16,"standard_deviation":6.83626,"sum":6034},"datatype":"int8","order":11,"optype":"numeric","name":"Highway MPG","column_number":11},{"id":"00000c","preferred":true,"summary":{"splits":[5464.625,6239.75026,6527.71875,6706.25,6952.34375,7233.82272,7484.375,7759.50214,7909.98438,8015.8125,8377.90625,8840.74494,9168.3125,9524.5625,9986.75,10345,11206.1875,11741.1875,12528.59375,13259.375,13801.25,15029.3125,15772.03125,16506,16910.15625,17845,18414.09375,20811.125,23896.5625,31721.875,35704.6875],"mean":13279.64467,"sum_squares":47317174666,"bins":[[5360.33333,9],[6580.3913,23],[7223.8,10],[7971.96667,30],[9168.82353,17],[10095.4,10],[11015,9],[11738.83333,6],[12642.75,8],[13570.3,10],[14809.4,5],[15736.85714,7],[16713.46154,13],[17609.66667,3],[18289.125,8],[18971.66667,3],[19699,1],[21186.66667,3],[22371,3],[23875,1],[24565,1],[25552,1],[28212,2],[30760,1],[31600,1],[32389,2],[34106,2],[35056,1],[35775,2],[36954,2],[41137.5,2],[45400,1]],"maximum":45400,"missing_count":0,"variance":6.416545429146E7,"median":10345,"population":197,"minimum":5118,"standard_deviation":8010.33422,"sum":2616090},"datatype":"int32","order":12,"optype":"numeric","name":"Price","column_number":12}],"rows":[["mercedes-benz","diesel","4-door","sedan","rwd",202.6,3770.0,5.0,183.0,123.0,4350.0,25.0,31600.0],["mercedes-benz","gas","2-door","hardtop","rwd",199.2,3715.0,8.0,304.0,184.0,4500.0,16.0,45400.0],["nissan","diesel","2-door","sedan","fwd",165.3,2017.0,4.0,103.0,55.0,4800.0,50.0,7099.0],["bmw","gas","2-door","sedan","rwd",193.8,3380.0,6.0,209.0,182.0,5400.0,22.0,41315.0],["honda","gas","2-door","hatchback","fwd",144.6,1713.0,4.0,92.0,58.0,4800.0,54.0,6479.0],["mercedes-benz","diesel","2-door","hardtop","rwd",187.5,3495.0,5.0,183.0,123.0,4350.0,25.0,28176.0],["chevrolet","gas","2-door","hatchback","fwd",141.1,1488.0,3.0,61.0,48.0,5100.0,53.0,5151.0],["mercedes-benz","gas","4-door","sedan","rwd",208.1,3900.0,8.0,308.0,184.0,4500.0,16.0,40960.0],["jaguar","gas","2-door","sedan","rwd",191.7,3950.0,12.0,326.0,262.0,5000.0,17.0,36000.0],["mercedes-benz","gas","2-door","convertible","rwd",180.3,3685.0,8.0,234.0,155.0,4750.0,18.0,35056.0],["nissan","gas","2-door","sedan","fwd",165.3,1951.0,4.0,97.0,69.0,5200.0,37.0,7299.0],["alfa-romero","gas","2-door","convertible","rwd",168.8,2548.0,4.0,130.0,111.0,5000.0,27.0,16500.0],["audi","gas","4-door","wagon","fwd",192.7,2954.0,5.0,136.0,110.0,5500.0,25.0,18920.0],["nissan","gas","4-door","sedan","fwd",173.4,2302.0,4.0,120.0,97.0,5200.0,34.0,9549.0],["toyota","gas","4-door","wagon","fwd",169.7,2280.0,4.0,92.0,62.0,4800.0,37.0,6918.0],["nissan","gas","2-door","hardtop","fwd",162.4,2008.0,4.0,97.0,69.0,5200.0,37.0,8249.0],["toyota","gas","4-door","hatchback","fwd",175.6,2414.0,4.0,122.0,92.0,4200.0,32.0,9988.0],["mitsubishi","gas","2-door","hatchback","fwd",173.2,2921.0,4.0,156.0,145.0,5000.0,24.0,14869.0],["toyota","gas","4-door","wagon","4wd",169.7,3110.0,4.0,92.0,62.0,4800.0,32.0,8778.0],["toyota","gas","2-door","sedan","rwd",168.7,2169.0,4.0,98.0,70.0,4800.0,34.0,8058.0],["dodge","gas","4-door","sedan","fwd",157.3,1989.0,4.0,90.0,68.0,5500.0,38.0,6692.0],["toyota","gas","4-door","hatchback","fwd",175.6,2458.0,4.0,122.0,92.0,4200.0,32.0,11248.0],["peugot","diesel","4-door","sedan","rwd",186.7,3252.0,4.0,152.0,95.0,4150.0,33.0,16900.0],["mazda","gas","2-door","hatchback","rwd",169.0,2385.0,2.0,70.0,101.0,6000.0,23.0,13645.0],["volvo","diesel","4-door","sedan","rwd",188.8,3217.0,6.0,145.0,106.0,4800.0,27.0,22470.0],["mercedes-benz","diesel","4-door","sedan","rwd",190.9,3515.0,5.0,183.0,123.0,4350.0,25.0,25552.0],["subaru","gas","4-door","wagon","4wd",173.6,2420.0,4.0,108.0,82.0,4800.0,29.0,8013.0],["volvo","gas","4-door","sedan","rwd",188.8,3045.0,4.0,130.0,162.0,5100.0,22.0,18420.0],["saab","gas","4-door","sedan","fwd",186.6,2695.0,4.0,121.0,110.0,5250.0,28.0,12170.0],["nissan","gas","4-door","sedan","fwd",181.7,3095.0,6.0,181.0,152.0,5200.0,22.0,13499.0],["subaru","gas","4-door","wagon","fwd",173.5,2455.0,4.0,108.0,94.0,5200.0,31.0,10198.0],["volvo","gas","4-door","sedan","rwd",188.8,3049.0,4.0,141.0,160.0,5300.0,25.0,19045.0],["dodge","gas","4-door","hatchback","fwd",157.3,1967.0,4.0,90.0,68.0,5500.0,38.0,6229.0],["subaru","gas","4-door","sedan","4wd",172.0,2510.0,4.0,108.0,111.0,4800.0,29.0,11259.0],["peugot","gas","4-door","wagon","rwd",198.9,3285.0,4.0,120.0,95.0,5000.0,24.0,16695.0],["honda","gas","2-door","hatchback","fwd",150.0,1837.0,4.0,79.0,60.0,5500.0,42.0,5399.0],["honda","gas","4-door","wagon","fwd",157.1,2024.0,4.0,92.0,76.0,6000.0,34.0,7295.0],["nissan","gas","4-door","wagon","fwd",184.6,3296.0,6.0,181.0,152.0,5200.0,22.0,14399.0],["audi","gas","2-door","sedan","fwd",177.3,2507.0,5.0,136.0,110.0,5500.0,25.0,15250.0],["mazda","gas","4-door","sedan","rwd",175.0,2670.0,4.0,140.0,120.0,5000.0,27.0,18280.0],["nissan","gas","4-door","hatchback","fwd",173.4,2324.0,4.0,120.0,97.0,5200.0,34.0,8949.0],["mitsubishi","gas","2-door","hatchback","fwd",173.2,2833.0,4.0,156.0,145.0,5000.0,24.0,12629.0],["volkswagen","diesel","4-door","sedan","fwd",180.2,2579.0,4.0,97.0,68.0,4500.0,38.0,13845.0],["nissan","gas","2-door","sedan","fwd",165.3,1918.0,4.0,97.0,69.0,5200.0,37.0,6649.0],["toyota","gas","4-door","wagon","4wd",169.7,2290.0,4.0,92.0,62.0,4800.0,32.0,7898.0],["saab","gas","2-door","hatchback","fwd",186.6,2808.0,4.0,121.0,160.0,5500.0,26.0,18150.0],["mazda","gas","2-door","hatchback","fwd",177.8,2385.0,4.0,122.0,84.0,4800.0,32.0,8845.0],["volkswagen","gas","4-door","sedan","fwd",171.7,2275.0,4.0,109.0,85.0,5250.0,34.0,8495.0],["volkswagen","gas","4-door","sedan","fwd",171.7,2212.0,4.0,109.0,85.0,5250.0,34.0,8195.0],["volkswagen","gas","4-door","sedan","fwd",171.7,2300.0,4.0,109.0,100.0,5500.0,32.0,9995.0],["peugot","diesel","4-door","wagon","rwd",198.9,3485.0,4.0,152.0,95.0,4150.0,25.0,17075.0],["audi","gas","4-door","sedan","4wd",176.6,2824.0,5.0,136.0,115.0,5500.0,22.0,17450.0],["toyota","gas","2-door","hatchback","rwd",168.7,2300.0,4.0,98.0,112.0,6600.0,29.0,9538.0],["bmw","gas","4-door","sedan","rwd",176.8,2395.0,4.0,108.0,101.0,5800.0,29.0,16925.0],["toyota","gas","4-door","hatchback","fwd",158.7,2015.0,4.0,92.0,62.0,4800.0,38.0,6488.0],["volvo","gas","4-door","wagon","rwd",188.8,3042.0,4.0,141.0,114.0,5400.0,28.0,16515.0],["volkswagen","gas","2-door","sedan","fwd",171.7,2209.0,4.0,109.0,85.0,5250.0,34.0,7975.0],["mazda","gas","2-door","hatchback","rwd",169.0,2380.0,2.0,70.0,101.0,6000.0,23.0,11845.0],["nissan","gas","2-door","sedan","fwd",165.3,1889.0,4.0,97.0,69.0,5200.0,37.0,5499.0],["honda","gas","2-door","sedan","fwd",169.1,2293.0,4.0,110.0,100.0,5500.0,31.0,10345.0],["toyota","diesel","4-door","hatchback","fwd",166.3,2275.0,4.0,110.0,56.0,4500.0,47.0,7788.0],["honda","gas","2-door","hatchback","fwd",167.5,2289.0,4.0,110.0,86.0,5800.0,33.0,9095.0],["plymouth","gas","4-door","hatchback","fwd",157.3,1967.0,4.0,90.0,68.0,5500.0,38.0,6229.0],["mitsubishi","gas","4-door","sedan","fwd",172.4,2405.0,4.0,122.0,88.0,5000.0,32.0,8189.0],["nissan","gas","2-door","hatchback","fwd",165.6,2028.0,4.0,97.0,69.0,5200.0,37.0,7799.0],["toyota","gas","4-door","sedan","fwd",175.6,2326.0,4.0,122.0,92.0,4200.0,34.0,8948.0],["volkswagen","gas","2-door","hatchback","fwd",165.7,2221.0,4.0,109.0,90.0,5500.0,29.0,9980.0],["subaru","gas","2-door","hatchback","4wd",157.3,2240.0,4.0,108.0,73.0,4400.0,31.0,7603.0],["mazda","gas","2-door","hatchback","fwd",177.8,2385.0,4.0,122.0,84.0,4800.0,32.0,10595.0],["chevrolet","gas","2-door","hatchback","fwd",155.9,1874.0,4.0,90.0,70.0,5400.0,43.0,6295.0],["audi","gas","4-door","sedan","fwd",192.7,3086.0,5.0,131.0,140.0,5500.0,20.0,23875.0],["porsche","gas","2-door","hardtop","rwd",168.9,2756.0,6.0,194.0,207.0,5900.0,25.0,32528.0],["bmw","gas","2-door","sedan","rwd",176.8,2710.0,6.0,164.0,121.0,4250.0,28.0,20970.0],["mazda","gas","4-door","sedan","fwd",177.8,2410.0,4.0,122.0,84.0,4800.0,32.0,8495.0],["toyota","gas","2-door","hardtop","rwd",176.2,2540.0,4.0,146.0,116.0,4800.0,30.0,8449.0],["volkswagen","diesel","4-door","sedan","fwd",171.7,2319.0,4.0,97.0,68.0,4500.0,42.0,9495.0],["subaru","gas","4-door","sedan","fwd",172.0,2145.0,4.0,108.0,82.0,4800.0,37.0,7126.0],["plymouth","gas","2-door","hatchback","fwd",157.3,2128.0,4.0,98.0,102.0,5500.0,30.0,7957.0],["toyota","gas","2-door","convertible","rwd",176.2,2975.0,4.0,146.0,116.0,4800.0,30.0,17669.0],["nissan","gas","4-door","sedan","fwd",184.6,3060.0,6.0,181.0,152.0,5200.0,25.0,13499.0],["toyota","diesel","4-door","sedan","fwd",166.3,2275.0,4.0,110.0,56.0,4500.0,36.0,7898.0],["nissan","gas","4-door","sedan","fwd",165.3,1938.0,4.0,97.0,69.0,5200.0,37.0,6849.0],["chevrolet","gas","4-door","sedan","fwd",158.8,1909.0,4.0,90.0,70.0,5400.0,43.0,6575.0],["volvo","gas","4-door","sedan","rwd",188.8,3062.0,4.0,141.0,114.0,5400.0,25.0,22625.0],["mercedes-benz","gas","4-door","sedan","rwd",202.6,3740.0,8.0,234.0,155.0,4750.0,18.0,34184.0],["mazda","gas","4-door","sedan","fwd",166.8,1945.0,4.0,91.0,68.0,5000.0,38.0,6695.0],["plymouth","gas","2-door","hatchback","fwd",157.3,1918.0,4.0,90.0,68.0,5500.0,41.0,5572.0],["dodge","gas","2-door","hatchback","fwd",173.2,2811.0,4.0,156.0,145.0,5000.0,24.0,12964.0],["volvo","gas","4-door","wagon","rwd",188.8,3034.0,4.0,141.0,114.0,5400.0,28.0,13415.0],["honda","gas","4-door","sedan","fwd",175.4,2465.0,4.0,110.0,101.0,5800.0,28.0,12945.0],["isuzu","gas","2-door","hatchback","rwd",172.6,2734.0,4.0,119.0,90.0,5000.0,29.0,11048.0],["peugot","gas","4-door","wagon","rwd",198.9,3230.0,4.0,120.0,97.0,5000.0,24.0,12440.0],["nissan","gas","4-door","sedan","fwd",165.3,1971.0,4.0,97.0,69.0,5200.0,37.0,7499.0],["mitsubishi","gas","2-door","hatchback","fwd",157.3,2004.0,4.0,92.0,68.0,5500.0,38.0,6669.0],["peugot","diesel","4-door","wagon","rwd",198.9,3430.0,4.0,152.0,95.0,4150.0,25.0,13860.0],["jaguar","gas","4-door","sedan","rwd",199.6,4066.0,6.0,258.0,176.0,4750.0,19.0,32250.0],["subaru","gas","2-door","hatchback","fwd",157.9,2120.0,4.0,108.0,73.0,4400.0,31.0,7053.0],["peugot","gas","4-door","sedan","rwd",186.7,3075.0,4.0,120.0,97.0,5000.0,24.0,16630.0],["mitsubishi","gas","2-door","hatchback","fwd",157.3,1918.0,4.0,92.0,68.0,5500.0,41.0,5389.0],["toyota","gas","2-door","hatchback","rwd",176.2,2714.0,4.0,146.0,116.0,4800.0,30.0,11549.0],["plymouth","gas","4-door","sedan","fwd",167.3,1989.0,4.0,90.0,68.0,5500.0,38.0,6692.0],["toyota","gas","4-door","hatchback","fwd",166.3,2109.0,4.0,98.0,70.0,4800.0,37.0,7198.0],["peugot","gas","4-door","sedan","rwd",186.7,3075.0,4.0,120.0,95.0,5000.0,24.0,15580.0],["bmw","gas","2-door","sedan","rwd",176.8,2395.0,4.0,108.0,101.0,5800.0,29.0,16430.0],["volvo","gas","4-door","sedan","rwd",188.8,3012.0,6.0,173.0,134.0,5500.0,23.0,21485.0],["toyota","gas","2-door","hardtop","rwd",176.2,2536.0,4.0,146.0,116.0,4800.0,30.0,9639.0],["porsche","gas","2-door","hatchback","rwd",168.9,2778.0,4.0,151.0,143.0,5500.0,27.0,22018.0],["mazda","gas","2-door","hatchback","fwd",159.1,1900.0,4.0,91.0,68.0,5000.0,38.0,6095.0],["subaru","gas","4-door","wagon","fwd",173.5,2290.0,4.0,108.0,82.0,4800.0,32.0,7463.0],["honda","gas","2-door","hatchback","fwd",150.0,1940.0,4.0,92.0,76.0,6000.0,34.0,6529.0],["plymouth","gas","2-door","hatchback","rwd",173.2,2818.0,4.0,156.0,145.0,5000.0,24.0,12764.0],["jaguar","gas","4-door","sedan","rwd",199.6,4066.0,6.0,258.0,176.0,4750.0,19.0,35550.0],["toyota","gas","4-door","sedan","fwd",166.3,2140.0,4.0,98.0,70.0,4800.0,34.0,9258.0],["mazda","gas","2-door","hatchback","rwd",169.0,2380.0,2.0,70.0,101.0,6000.0,23.0,10945.0],["subaru","gas","4-door","sedan","fwd",172.0,2340.0,4.0,108.0,94.0,5200.0,32.0,9960.0],["bmw","gas","4-door","sedan","rwd",176.8,2765.0,6.0,164.0,121.0,4250.0,28.0,21105.0],["mitsubishi","gas","4-door","sedan","fwd",172.4,2403.0,4.0,110.0,116.0,5500.0,30.0,9279.0],["honda","gas","4-door","sedan","fwd",163.4,2010.0,4.0,92.0,76.0,6000.0,34.0,7295.0],["dodge","gas","2-door","hatchback","fwd",157.3,2128.0,4.0,98.0,102.0,5500.0,30.0,7957.0],["volkswagen","diesel","4-door","sedan","fwd",171.7,2264.0,4.0,97.0,52.0,4800.0,46.0,7995.0],["volkswagen","gas","4-door","wagon","fwd",183.1,2563.0,4.0,109.0,88.0,5500.0,31.0,12290.0],["honda","gas","4-door","sedan","fwd",175.4,2372.0,4.0,110.0,86.0,5800.0,33.0,10295.0],["mercury","gas","2-door","hatchback","rwd",178.4,2910.0,4.0,140.0,175.0,5000.0,24.0,16503.0],["porsche","gas","2-door","hardtop","rwd",168.9,2756.0,6.0,194.0,207.0,5900.0,25.0,34028.0],["saab","gas","4-door","sedan","fwd",186.6,2847.0,4.0,121.0,160.0,5500.0,26.0,18620.0],["mitsubishi","gas","4-door","sedan","fwd",172.4,2403.0,4.0,110.0,116.0,5500.0,30.0,9279.0],["plymouth","gas","4-door","wagon","fwd",174.6,2535.0,4.0,122.0,88.0,5000.0,30.0,8921.0],["mazda","diesel","4-door","sedan","rwd",175.0,2700.0,4.0,134.0,72.0,4200.0,39.0,18344.0],["toyota","gas","2-door","hatchback","rwd",183.5,3016.0,6.0,171.0,161.0,5200.0,24.0,15998.0],["nissan","gas","2-door","hatchback","rwd",170.7,3139.0,6.0,181.0,200.0,5200.0,23.0,19699.0],["saab","gas","2-door","hatchback","fwd",186.6,2707.0,4.0,121.0,110.0,5250.0,28.0,15040.0],["volkswagen","gas","2-door","convertible","fwd",159.3,2254.0,4.0,109.0,90.0,5500.0,29.0,11595.0],["toyota","gas","2-door","hatchback","rwd",183.5,2976.0,6.0,171.0,161.0,5200.0,24.0,16558.0],["volvo","gas","4-door","wagon","rwd",188.8,3157.0,4.0,130.0,162.0,5100.0,22.0,18950.0],["toyota","gas","4-door","wagon","rwd",187.8,3151.0,6.0,161.0,156.0,5200.0,24.0,15750.0],["peugot","gas","4-door","sedan","rwd",186.7,3130.0,4.0,134.0,142.0,5600.0,24.0,18150.0],["subaru","gas","2-door","hatchback","fwd",156.9,2050.0,4.0,97.0,69.0,4900.0,36.0,5118.0],["mitsubishi","gas","2-door","hatchback","fwd",173.0,2370.0,4.0,110.0,116.0,5500.0,30.0,9959.0],["toyota","gas","4-door","sedan","rwd",187.8,3131.0,6.0,171.0,156.0,5200.0,24.0,15690.0],["mercedes-benz","diesel","4-door","wagon","rwd",190.9,3750.0,5.0,183.0,123.0,4350.0,25.0,28248.0],["subaru","gas","4-door","sedan","4wd",172.0,2385.0,4.0,108.0,82.0,4800.0,25.0,9233.0],["toyota","gas","4-door","sedan","fwd",166.3,2081.0,4.0,98.0,70.0,4800.0,37.0,6938.0],["mitsubishi","gas","4-door","sedan","fwd",172.4,2365.0,4.0,122.0,88.0,5000.0,32.0,6989.0],["subaru","gas","4-door","wagon","4wd",173.6,2650.0,4.0,108.0,111.0,4800.0,23.0,11694.0],["honda","gas","2-door","hatchback","fwd",167.5,2236.0,4.0,110.0,86.0,5800.0,33.0,7895.0],["saab","gas","4-door","sedan","fwd",186.6,2758.0,4.0,121.0,110.0,5250.0,28.0,15510.0],["volvo","gas","4-door","sedan","rwd",188.8,2935.0,4.0,141.0,114.0,5400.0,28.0,15985.0],["volvo","gas","4-door","sedan","rwd",188.8,2912.0,4.0,141.0,114.0,5400.0,28.0,12940.0],["porsche","gas","2-door","convertible","rwd",168.9,2800.0,6.0,194.0,207.0,5900.0,25.0,37028.0],["mitsubishi","gas","2-door","hatchback","fwd",173.0,2328.0,4.0,122.0,88.0,5000.0,32.0,8499.0],["mazda","gas","2-door","hatchback","fwd",159.1,1890.0,4.0,91.0,68.0,5000.0,31.0,5195.0],["peugot","diesel","4-door","sedan","rwd",186.7,3252.0,4.0,152.0,95.0,4150.0,33.0,17950.0],["dodge","gas","4-door","sedan","fwd",157.3,1989.0,4.0,90.0,68.0,5500.0,38.0,7609.0],["toyota","gas","2-door","hatchback","rwd",176.2,2551.0,4.0,146.0,116.0,4800.0,30.0,9989.0],["nissan","gas","4-door","wagon","fwd",170.2,2037.0,4.0,97.0,69.0,5200.0,37.0,7999.0],["mitsubishi","gas","2-door","hatchback","fwd",157.3,1944.0,4.0,92.0,68.0,5500.0,38.0,6189.0],["peugot","gas","4-door","sedan","rwd",186.7,3020.0,4.0,120.0,97.0,5000.0,24.0,11900.0],["alfa-romero","gas","2-door","hatchback","rwd",171.2,2823.0,6.0,152.0,154.0,5000.0,26.0,16500.0],["toyota","gas","2-door","sedan","rwd",168.7,2265.0,4.0,98.0,112.0,6600.0,29.0,9298.0],["toyota","gas","4-door","hatchback","fwd",166.3,2122.0,4.0,98.0,70.0,4800.0,34.0,8358.0],["mazda","gas","2-door","hatchback","fwd",159.1,1905.0,4.0,91.0,68.0,5000.0,38.0,6795.0],["isuzu","gas","4-door","sedan","rwd",170.7,2337.0,4.0,111.0,78.0,4800.0,29.0,6785.0],["saab","gas","2-door","hatchback","fwd",186.6,2658.0,4.0,121.0,110.0,5250.0,28.0,11850.0],["mazda","gas","4-door","sedan","fwd",166.8,1950.0,4.0,91.0,68.0,5000.0,38.0,7395.0],["volkswagen","gas","4-door","sedan","fwd",180.2,2661.0,5.0,136.0,110.0,5500.0,24.0,13295.0],["dodge","gas","2-door","hatchback","fwd",157.3,1876.0,4.0,90.0,68.0,5500.0,41.0,5572.0],["toyota","diesel","4-door","sedan","fwd",175.6,2480.0,4.0,110.0,73.0,4500.0,33.0,10698.0],["volvo","gas","4-door","sedan","rwd",188.8,2952.0,4.0,141.0,114.0,5400.0,28.0,16845.0],["dodge","gas","2-door","hatchback","fwd",157.3,1876.0,4.0,90.0,68.0,5500.0,38.0,6377.0],["toyota","gas","4-door","sedan","fwd",175.6,2414.0,4.0,122.0,92.0,4200.0,32.0,10898.0],["mazda","gas","4-door","hatchback","fwd",177.8,2425.0,4.0,122.0,84.0,4800.0,32.0,11245.0],["toyota","gas","2-door","hardtop","rwd",176.2,2679.0,4.0,146.0,116.0,4800.0,30.0,11199.0],["dodge","gas","4-door","wagon","fwd",174.6,2535.0,4.0,122.0,88.0,5000.0,30.0,8921.0],["honda","gas","2-door","hatchback","fwd",144.6,1819.0,4.0,92.0,76.0,6000.0,38.0,6855.0],["audi","gas","4-door","sedan","fwd",192.7,2844.0,5.0,136.0,110.0,5500.0,25.0,17710.0],["toyota","gas","4-door","sedan","fwd",166.3,2094.0,4.0,98.0,70.0,4800.0,47.0,7738.0],["plymouth","gas","4-door","sedan","fwd",167.3,2191.0,4.0,98.0,68.0,5500.0,38.0,7609.0],["toyota","gas","2-door","hatchback","fwd",158.7,1985.0,4.0,92.0,62.0,4800.0,39.0,5348.0],["honda","gas","2-door","hatchback","fwd",150.0,1956.0,4.0,92.0,76.0,6000.0,34.0,7129.0],["subaru","gas","4-door","sedan","fwd",172.0,2190.0,4.0,108.0,82.0,4400.0,33.0,7775.0],["bmw","gas","4-door","sedan","rwd",189.0,3230.0,6.0,209.0,182.0,5400.0,22.0,30760.0],["nissan","gas","2-door","hatchback","rwd",178.5,3139.0,6.0,181.0,160.0,5200.0,25.0,18399.0],["mitsubishi","gas","2-door","hatchback","fwd",157.3,2145.0,4.0,98.0,102.0,5500.0,30.0,7689.0],["mazda","gas","2-door","hatchback","rwd",169.0,2500.0,2.0,80.0,135.0,6000.0,23.0,15645.0],["peugot","diesel","4-door","sedan","rwd",186.7,3197.0,4.0,152.0,95.0,4150.0,33.0,13200.0],["mitsubishi","gas","2-door","hatchback","fwd",173.2,2926.0,4.0,156.0,145.0,5000.0,24.0,14489.0],["bmw","gas","4-door","sedan","rwd",189.0,3055.0,6.0,164.0,121.0,4250.0,25.0,24565.0],["bmw","gas","4-door","sedan","rwd",197.0,3505.0,6.0,209.0,182.0,5400.0,20.0,36880.0],["volkswagen","diesel","2-door","sedan","fwd",171.7,2261.0,4.0,97.0,52.0,4800.0,46.0,7775.0],["audi","gas","4-door","sedan","fwd",176.6,2337.0,4.0,109.0,102.0,5500.0,30.0,13950.0],["nissan","gas","2-door","hatchback","rwd",170.7,3071.0,6.0,181.0,160.0,5200.0,25.0,17199.0],["mazda","gas","4-door","sedan","fwd",177.8,2410.0,4.0,122.0,84.0,4800.0,32.0,10245.0],["toyota","gas","2-door","hatchback","fwd",158.7,2040.0,4.0,92.0,62.0,4800.0,38.0,6338.0],["alfa-romero","gas","2-door","convertible","rwd",168.8,2548.0,4.0,130.0,111.0,5000.0,27.0,13495.0],["honda","gas","4-door","sedan","fwd",175.4,2304.0,4.0,110.0,86.0,5800.0,33.0,8845.0],["nissan","gas","4-door","wagon","fwd",170.2,2024.0,4.0,97.0,69.0,5200.0,37.0,7349.0],["toyota","gas","2-door","hatchback","rwd",168.7,2204.0,4.0,98.0,70.0,4800.0,34.0,8238.0]]}
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.domain {
stroke: #ddd;
stoke-width: 1px;
fill: none;
}
.tick line {
stroke: #ddd;
stroke-dasharray: 3,3;
}
.field {
cursor: pointer;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
.brush .extent {
stroke: #fff;
fill-opacity: .125;
shape-rendering: crispEdges;
}
svg {
-webkit-user-select: none; /* webkit (safari, chrome) browsers */
-moz-user-select: none; /* mozilla browsers */
-khtml-user-select: none; /* webkit (konqueror) browsers */
-ms-user-select: none; /* IE10+ */
}
.field-marker {
}
</style>
<body oncontextmenu="return false;">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
function getParam(key) {
if(key=(new RegExp('[?&]'+encodeURIComponent(key)+'=([^&]*)'))
.exec(location.search))
return decodeURIComponent(key[1]);
}
function setParam(key, value) {
key = encodeURI(key); value = encodeURI(value);
var s = document.location.search;
var kvp = key+"="+value;
var r = new RegExp("(&|\\?)"+key+"=[^\&]*");
s = s.replace(r,"$1"+kvp);
if(!RegExp.$1) {s += (s.length>0 ? '&' : '?') + kvp;};
window.history.replaceState({}, "", s);
}
function removeParam(key) {
var sourceURL = document.location.search;
var rtn = sourceURL.split("?")[0],
param,
params_arr = [],
queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";
if (queryString !== "") {
params_arr = queryString.split("&");
for (var i = params_arr.length - 1; i >= 0; i -= 1) {
param = params_arr[i].split("=")[0];
if (param === key) {
params_arr.splice(i, 1);
}
}
rtn = rtn + "?" + params_arr.join("&");
}
window.history.replaceState({}, "", rtn);
}
var margin = {top: 20, right: 20, bottom: 20, left: 20},
width = 1000 - margin.left - margin.right,
height = 640 - margin.bottom - margin.top;
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 + ")");
d3.json("autos.json", function(error, data) {
var fields = data.fields;
var rows = data.rows;
var shows;
var buffer = width / 20;
var field_size = width / 4;
var right_fields = 250;
var plotWidth = width - 2 * buffer - right_fields;
var plotHeight = 0.75 * height;
resetConstraints();
function resetConstraints() {
for (var i = 0; i < fields.length; i++) {
fields[i].constraint = false;
}
shows = [];
for (var i = 0; i < rows.length; i++) {
shows.push(true);
}
evalConstraints();
}
function evalConstraints() {
var visiblePoints = 0;
for (var i = 0; i < rows.length; i++) {
var show = true;
for (var j = 0; j < fields.length && show; j++) {
var field = fields[j];
if (field.constraint) {
var val = rows[i][j];
if ((field.optype == "numeric" &&
(val < field.minConstraint || val > field.maxConstraint)) ||
(field.optype == "categorical" && !(val in field.catConstraint))) {
show = false;
}
}
}
if (show) visiblePoints += 1;
shows[i] = show;
}
if (visiblePoints == 0) {
resetConstraints();
} else {
r = Math.pow((6 * Math.min(plotWidth, plotHeight)) / Math.min(visiblePoints, 1024), 0.5);
}
}
var brushX = d3.scale.identity().domain([buffer, plotWidth]),
brushY = d3.scale.identity().domain([0, plotHeight]);
var brushExtent;
var brush = d3.svg.brush()
.x(brushX)
.y(brushY)
.on("brush", brushed)
.on("brushend", brushended);
svg.append("g")
.attr("class", "brush")
.call(brush)
.call(brush.event);
function brushed() {
brushExtent = brush.extent();
}
function brushended() {
var validConstraint = true;
if (!d3.event.sourceEvent) return; // only transition after input
if (fields[x].optype == "numeric") {
fields[x].minConstraint = xScale.invert(brushExtent[0][0]);
fields[x].maxConstraint = xScale.invert(brushExtent[1][0]);
} else {
var cats = fields[x].cats;
var selected = {};
for (var i = 0; i < cats.length; i++) {
var val = xScale(cats[i]);
if (val >= brushExtent[0][0] && val <= brushExtent[1][0]) {
selected[cats[i]] = true;
}
}
if (Object.keys(selected).length == 0) {
validConstraint = false;
}
fields[x].catConstraint = selected;
}
if (fields[y].optype == "numeric") {
fields[y].minConstraint = yScale.invert(brushExtent[1][1]);
fields[y].maxConstraint = yScale.invert(brushExtent[0][1]);
} else {
var cats = fields[y].cats;
var selected = {};
for (var i = 0; i < cats.length; i++) {
var val = yScale(cats[i]);
if (val >= brushExtent[0][1] && val <= brushExtent[1][1]) {
selected[cats[i]] = true;
}
}
if (Object.keys(selected).length == 0) {
validConstraint = false;
}
fields[y].catConstraint = selected;
}
d3.select(this).call(brush.extent([[0, 0], [0, 0]]));
if (validConstraint) {
fields[x].constraint = true;
fields[y].constraint = true;
evalConstraints();
} else {
resetConstraints();
}
updateForClick();
}
var maxNameChars = 0;
for (var i = 0; i < fields.length; i++) {
maxNameChars = Math.max(maxNameChars, fields[i].name.length);
}
var valueOffset = 9 * maxNameChars;
for (var i = 0; i < fields.length; i++) {
fields[i].constraint = false;
makeField(fields[i], i);
calcRange(i);
}
var hintY = i * 28;
var hintX = width - right_fields - buffer;
hint = svg.append("g").attr("class", "hint").style("font-size","12px");
hint.append("text")
.attr("transform", "translate(" + hintX + "," + (hintY + 20) + ")")
.text("Left click --> Set X Axis");
hint.append("text")
.attr("transform", "translate(" + hintX + "," + (hintY + 35) + ")")
.text("Right click --> Set Y Axis");
hint.append("text")
.attr("transform", "translate(" + hintX + "," + (hintY + 50) + ")")
.text("Alt + left click --> Set Color");
var fcX = width - right_fields - buffer + valueOffset;
var fcY = -5;
svg.append("g").attr("class", "field-counter").append("text")
.attr("transform", "translate(" + fcX + "," + fcY + ")");
var gx, gy;
var xAxis, yAxis;
var xScale;
var yScale;
var uniqueMap;
var xMap;
var yMap;
var colorMap;
var colorFn;
var currentRow = null;
var currentIds;
var x = getParam("x");
var y = getParam("y");
var c = getParam("c");
if (x == null) x = 9;
if (y == null) y = 11;
if (c == null) c = fields.length - 1;
setParam("x", x);
setParam("y", y);
setParam("c", c);
var xLogMode = getParam("xLog");
var yLogMode = getParam("yLog");
var cLogMode = getParam("cLog");
if (xLogMode == null) xLogMode = false;
if (yLogMode == null) yLogMode = false;
if (cLogMode == null) cLogMode = false;
var granularity = getParam("g");
if (granularity == null) granularity = 1;
var pointIndex = 0;
var r;
makeAxis();
makePoints();
updateForClick();
function genKey(row) {
var xVal, yVal;
var g = 1 + ((granularity - 1) * 5);
if (fields[x].optype == "numeric") {
xVal = Math.round(xScale(row[x]) / g) * g;
} else {
xVal = row[x];
}
if (fields[y].optype == "numeric") {
yVal = Math.round(yScale(row[y]) / g) * g;
} else {
yVal = row[y];
}
return xVal.toString() + "," + yVal.toString();
}
d3.select("body").on("keydown", keydown);
function keydown() {
var needUpdate = true;
var lastKeyDown = d3.event.keyCode;
if (lastKeyDown >= 49 && lastKeyDown <= 57) {
granularity = lastKeyDown - 48;
if (granularity == 1) {
removeParam("g");
} else {
setParam("g", granularity);
}
updateForClick();
}
}
function updateForClick() {
updateScales();
updateUniqueMap();
updateColorFn();
updatePoints();
updateFieldMarkers();
updateAxis();
}
function makeField(field, index) {
var x_loc = width - right_fields - buffer;
var y_loc = 20 + index * 28;
var field_text = svg.append("g")
.attr("class", "field");
field_text.append("text")
.attr("class", "field")
.attr("transform", "translate(" + x_loc + "," + y_loc + ")")
.on("click", function() {
if (d3.event.altKey) {
if (c == index && fields[c].optype == "numeric") {
cLogMode = !cLogMode;
} else {
cLogMode = false;
}
if (cLogMode == true) {
setParam("cLog", true);
} else {
removeParam("cLog");
}
c = index;
setParam("c", index);
} else {
if (x == index && fields[x].optype == "numeric") {
xLogMode = !xLogMode;
} else {
xLogMode = false;
}
if (xLogMode == true) {
setParam("xLog", true);
} else {
removeParam("xLog");
}
x = index;
setParam("x", index);
}
updateForClick();
})
.on("contextmenu", function() {
if (y == index && fields[y].optype == "numeric") {
yLogMode = !yLogMode;
} else {
yLogMode = false;
}
if (yLogMode == true) {
setParam("yLog", true);
} else {
removeParam("yLog");
}
y = index;
setParam("y", index);
updateForClick();
})
.text(field.name);
svg.append("g")
.append("text")
.attr("class", "field-value")
.attr("transform", "translate(" + (valueOffset + x_loc) + "," + y_loc + ")");
svg.append("g")
.append("text")
.attr("class", "field-marker")
.attr("transform", "translate(" + (-6 + x_loc) + "," + y_loc + ")")
.style("text-anchor", "end")
.text("");
}
function makeAxis() {
gy = svg.append("g")
.attr("class", "y-axis")
.attr("transform", "translate(" + buffer + "," + 0 + ")");
gx = svg.append("g")
.attr("class", "x-axis")
.attr("transform", "translate(" + 0 + "," + plotHeight + ")");
}
function updateAxis() {
var currentY = gy.transition()
.duration(700)
.call(yAxis);
if (fields[y].optype == "categorical") {
currentY.selectAll("text")
.attr("y", 10)
.attr("x", 2)
.style("fill", "#999")
.style("font-size", "13")
.style("text-anchor", "start");
}
var currentX = gx.transition()
.duration(700)
.call(xAxis);
if (fields[x].optype == "categorical") { // && fields[x].cats.length > 4) {
currentX.selectAll("text")
.attr("y", 5)
.attr("x", 2)
.attr("transform", "rotate(-90)")
.style("fill", "#999")
.style("font-size", "13")
.style("text-anchor", "start");
}
}
function updateFieldMarkers() {
var ids = Array.apply(null, Array(fields.length)).map(function (_, i) {return i;});
svg.selectAll(".field-marker")
.data(ids)
.text(function(d) {
var marker = "";
if (d == x) {
if (xLogMode) {
marker += "x";
} else {
marker += "X";
}
}
if (d == y) {
if (yLogMode) {
marker += "y";
} else {
marker += "Y";
}
}
if (d == c) {
if (cLogMode) {
marker += "c";
} else {
marker += "C";
}
}
if (marker != "") { marker += ":"};
return marker;
})
}
function updateFieldValues() {
var ids = Array.apply(null, Array(fields.length)).map(function (_, i) {return i;});
var currentRow;
if (currentIds != null) {
currentRow = rows[currentIds[pointIndex % currentIds.length]];
}
svg.selectAll(".field-value")
.data(ids)
.text(function(d) {
var val = "";
if (currentRow != null) {
val += currentRow[d].toString();
}
return val;
});
svg.select(".field-counter").select("text")
.text(function(d) {
var str = "";
if (currentIds != null && currentIds.length > 1) {
str += (1 + pointIndex % currentIds.length) + " of " + currentIds.length;
}
return str;
});
}
function updateUniqueMap() {
uniqueMap = {};
for (var i = 0; i < rows.length; i++) {
if (shows[i]) {
var key = genKey(rows[i]);
if (key in uniqueMap) {
uniqueMap[key].push(i);
} else {
uniqueMap[key] = [i];
}
}
}
colorMap = {};
xMap = {};
yMap = {};
for (var key in uniqueMap) {
var ids = uniqueMap[key];
if (ids.length > 1) {
if (fields[x].optype == "numeric") {
var sum = 0;
for (var j = 0; j < ids.length; j++) {
sum += rows[ids[j]][x];
}
xMap[key] = sum / ids.length;
} else {
xMap[key] = rows[ids[0]][x];
}
if (fields[y].optype == "numeric") {
var sum = 0;
for (var j = 0; j < ids.length; j++) {
sum += rows[ids[j]][y];
}
yMap[key] = sum / ids.length;
} else {
yMap[key] = rows[ids[0]][y];
}
if (fields[c].optype == "numeric") {
var sum = 0;
for (var j = 0; j < ids.length; j++) {
sum += rows[ids[j]][c];
}
colorMap[key] = sum / ids.length;
} else {
var cat_counts = {};
for (var j = 0; j < ids.length; j++) {
var cat = rows[ids[j]][c];
if (cat in cat_counts) {
cat_counts[cat] = cat_counts[cat] + 1;
} else {
cat_counts[cat] = 1;
}
}
var max_count = 0;
var max_cat;
for (cat in cat_counts) {
if (cat_counts[cat] > max_count) {
max_count = cat_counts[cat];
max_cat = cat;
}
}
colorMap[key] = max_cat;
if (rows[ids[0]][c] != max_cat) {
for (var j = 0; j < ids.length; j++) {
if (rows[ids[j]][c] == max_cat) {
var temp = ids[0];
ids[0] = ids[j];
ids[j] = temp;
break;
}
}
}
}
} else {
colorMap[key] = rows[ids[0]][c];
xMap[key] = rows[ids[0]][x];
yMap[key] = rows[ids[0]][y];
}
}
}
function updateColorFn() {
if (fields[c].optype == "numeric") {
if (cLogMode && fields[c].min > 0) {
colorFn = d3.scale.log()
.domain([fields[c].min, fields[c].max])
.range(["#3f3", "#f55"])
} else {
if (cLogMode) removeParam("cLog");
colorFn = d3.scale.linear()
.domain([fields[c].min, fields[c].max])
.range(["#3f3", "#f55"])
}
} else {
if (fields[c].cats.length <= 10) {
colorFn = d3.scale.category10().domain(fields[c].cats);
} else {
colorFn = d3.scale.category20().domain(fields[c].cats);
}
}
}
function calcRange(col) {
if (fields[col].optype == "numeric") {
var min = rows[0][col];
var max = rows[0][col];
for (var i = 0; i < rows.length; i++) {
min = Math.min(min, rows[i][col]);
max = Math.max(max, rows[i][col]);
}
fields[col].min = min;
fields[col].max = max;
} else {
var categories = {};
for (var i = 0; i < rows.length; i++) {
var val = rows[i][col];
if (val == null || val == "") {
val = "?";
rows[i][col] = val;
}
categories[val] = true;
}
var finalCats = [];
for (var cat in categories) {
finalCats.push(cat);
}
fields[col].cats = finalCats.sort();
}
}
function updateScale(col, rangeMin, rangeMax, isX) {
if (fields[col].optype == "numeric") {
var firstIndex;
for (firstIndex = 0; firstIndex < shows.length; firstIndex++) {
if (shows[firstIndex]) {
break;
}
}
var min = rows[firstIndex][col];
var max = rows[firstIndex][col];
var uniques = {};
var uniqueCount = 0;
for (var i = 0; i < rows.length; i++) {
if (shows[i]) {
var key = rows[i][col].toString();
if (!(key in uniques)) {
uniques[key] = true;
uniqueCount += 1;
}
min = Math.min(min, rows[i][col]);
max = Math.max(max, rows[i][col]);
}
}
if (min == max) {
var buf = (fields[col].max - fields[col].min) / 100;
if (buf == 0) {
buf = 0.1;
}
min -= buf;
max += buf;
}
if (min > 0 && ((col == x && xLogMode && isX) || (col == y && yLogMode && !isX))) {
return d3.scale.log()
.range([rangeMin, rangeMax])
.domain([min, max]);
} else {
if (min <= 0 && ((col == x && xLogMode && isX) || (col == y && yLogMode && !isX))) {
if (isX) {
xLogMode = false;
removeParam("xLog");
} else {
yLogMode = false;
removeParam("yLog");
}
}
var diff = max - min;
if (uniqueCount > 4) {
max += diff / 30;
min -= diff / 30;
} else {
max += diff / 5;
min -= diff / 5;
}
return d3.scale.linear()
.range([rangeMin, rangeMax])
.domain([min, max]);
}
} else {
if (isX) {
xLogMode = false;
} else {
yLogMode = false;
}
var categories = {};
for (var i = 0; i < rows.length; i++) {
if (shows[i]) {
categories[rows[i][col]] = true;
}
}
var finalCats = [];
for (var cat in categories) {
if (!fields[col].constraint || cat in fields[col].catConstraint) {
finalCats.push(cat);
}
}
return d3.scale.ordinal()
.domain(finalCats.sort())
.rangePoints([rangeMin, rangeMax], 1);
}
}
function updateScales () {
xScale = updateScale(x, buffer, plotWidth, true);
yScale = updateScale(y, plotHeight, 0, false);
xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.tickPadding(10)
.tickSize(-plotHeight);
yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.tickPadding(10)
.tickSize(-plotWidth + buffer);
}
function point_size(index) {
if (shows[index]) {
return r * Math.pow(uniqueMap[genKey(rows[index])].length, 0.5);
} else {
return r;
}
}
function makePoints() {
svg.selectAll(".data")
.data(Array.apply(null, Array(rows.length)).map(function (_, i) {return i;}))
.enter()
.append("g")
.attr("class", "data")
.style("opacity", "0")
.style("fill", "#fff")
.style("stroke", "#fff")
.style("stroke-width", "1.5")
.append("circle")
.attr("class", "point")
.on("click", function(d) {
pointIndex += 1;
updateFieldValues();
})
.on("mouseover", function(d) {
d3.select(this)
.attr("r", point_size(d) + Math.pow(point_size(d), 0.15) + 1);
currentIds = uniqueMap[genKey(rows[d])];
updateFieldValues();
})
.on("mouseout", function(d) {
d3.select(this)
.attr("r", (point_size(d)));
currentIds = null;
pointIndex = 0;
updateFieldValues();
});
}
function updatePoints() {
var transitions = 0;
svg.selectAll(".data")
.style("cursor", function (d) {
if (shows[d] && uniqueMap[genKey(rows[d])].length > 1) {
return "pointer";
} else {
return "auto";
}
})
.sort(function (a, b) {
var pa = point_size(a);
var pb = point_size(b);
if (pa == pb) {
if (a > b) {
return -1;
} else {
return 1;
}
}
if (pa > pb) {
return -1;
} else {
return 1;
}
})
.transition()
.duration(700)
.style("opacity", function (d) {
if (shows[d] && uniqueMap[genKey(rows[d])][0] == d) {
return "0.9";
} else {
return "0";
}
})
.style("fill", function(d) {
if (shows[d]) {
return colorFn(colorMap[genKey(rows[d])]);
} else {
return "#999";
}
})
.style("stroke", function(d) {
if (shows[d]) {
return d3.rgb(colorFn(colorMap[genKey(rows[d])])).darker(0.3);
} else {
return "#999";
}
})
.select(".point")
.attr("display", function (d) {
if (shows[d]) {
return "inherit";
} else {
return "none";
}
})
.attr("r", function(d) {
return point_size(d);
})
.attr("cx", function(d) {
var key = genKey(rows[d]);
if (key in xMap) {
return xScale(xMap[key]);
} else {
if (fields[x].optype == "numeric") {
return Math.round(xScale(rows[d][x]));
} else {
return xScale(rows[d][x]);
}
}
})
.attr("cy", function(d) {
var key = genKey(rows[d]);
if (key in yMap) {
return yScale(yMap[key]);
} else {
if (fields[y].optype == "numeric") {
return Math.round(yScale(rows[d][y]));
} else {
return yScale(rows[d][y]);
}
}
})
.transition()
.attr("display", function (d) {
if (shows[d] && uniqueMap[genKey(rows[d])][0] == d) {
return "inherit";
} else {
return "none";
}
});
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment