rubyvis 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -1
- data/Manifest.txt +421 -1
- data/README.txt +12 -10
- data/examples/first.rb +2 -2
- data/examples/second.rb +6 -3
- data/lib/rubyvis.rb +18 -3
- data/lib/rubyvis/mark.rb +101 -83
- data/lib/rubyvis/mark/anchor.rb +5 -7
- data/lib/rubyvis/mark/area.rb +19 -17
- data/lib/rubyvis/mark/bar.rb +3 -10
- data/lib/rubyvis/mark/label.rb +3 -4
- data/lib/rubyvis/mark/line.rb +20 -4
- data/lib/rubyvis/mark/panel.rb +31 -6
- data/lib/rubyvis/mark/rule.rb +8 -4
- data/lib/rubyvis/property.rb +11 -0
- data/lib/rubyvis/scene/svg_label.rb +1 -1
- data/lib/rubyvis/scene/svg_scene.rb +2 -1
- data/lib/rubyvis/sceneelement.rb +2 -0
- data/spec/bar_spec.rb +50 -0
- data/spec/label_spec.rb +41 -0
- data/spec/mark_spec.rb +16 -0
- data/spec/panel_spec.rb +22 -4
- data/spec/spec_helper.rb +1 -0
- data/vendor/FUTURE +62 -0
- data/vendor/Makefile +138 -0
- data/vendor/TODO +22 -0
- data/vendor/examples/antibiotics/antibiotics-scatter.html +113 -0
- data/vendor/examples/antibiotics/antibiotics.html +140 -0
- data/vendor/examples/antibiotics/antibiotics.js +20 -0
- data/vendor/examples/barley/barley.html +102 -0
- data/vendor/examples/barley/barley.js +122 -0
- data/vendor/examples/cars/cars.html +90 -0
- data/vendor/examples/cars/cars.js +408 -0
- data/vendor/examples/clock/clock.html +91 -0
- data/vendor/examples/crimea/crimea-grouped-bar.html +65 -0
- data/vendor/examples/crimea/crimea-line.html +61 -0
- data/vendor/examples/crimea/crimea-stacked-area.html +61 -0
- data/vendor/examples/crimea/crimea-stacked-bar.html +60 -0
- data/vendor/examples/crimea/crimea.html +100 -0
- data/vendor/examples/crimea/crimea.js +33 -0
- data/vendor/examples/downloadify/LICENSE.txt +22 -0
- data/vendor/examples/downloadify/download.png +0 -0
- data/vendor/examples/downloadify/downloadify.html +57 -0
- data/vendor/examples/downloadify/downloadify.min.js +3 -0
- data/vendor/examples/downloadify/downloadify.swf +0 -0
- data/vendor/examples/downloadify/swfobject.js +4 -0
- data/vendor/examples/ex.css +17 -0
- data/vendor/examples/eyes/eyes.html +53 -0
- data/vendor/examples/eyes/matrix.html +44 -0
- data/vendor/examples/flowers/flowers.html +109 -0
- data/vendor/examples/flowers/flowers.js +154 -0
- data/vendor/examples/group-stack/group-stack.html +79 -0
- data/vendor/examples/group-stack/headcount.js +23 -0
- data/vendor/examples/hotel/hotel.html +76 -0
- data/vendor/examples/hotel/hotel.js +245 -0
- data/vendor/examples/jobs/jobs.html +71 -0
- data/vendor/examples/jobs/jobs.js +1024 -0
- data/vendor/examples/jquery-1.4.2.min.js +154 -0
- data/vendor/examples/nba/nba.html +83 -0
- data/vendor/examples/nba/nba.js +53 -0
- data/vendor/examples/nba/nba2.html +82 -0
- data/vendor/examples/sankey/gdp2009.js +184 -0
- data/vendor/examples/sankey/sankey.html +77 -0
- data/vendor/examples/slider/cell.html +112 -0
- data/vendor/examples/slider/cell.js +31 -0
- data/vendor/examples/slider/horizon.html +85 -0
- data/vendor/examples/slider/jquery-ui-1.8rc3.custom.min.js +71 -0
- data/vendor/examples/slider/slider.html +50 -0
- data/vendor/examples/slider/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/vendor/examples/slider/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/vendor/examples/slider/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/vendor/examples/slider/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/vendor/examples/slider/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/vendor/examples/slider/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/vendor/examples/slider/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/vendor/examples/slider/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/vendor/examples/slider/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/vendor/examples/slider/ui-lightness/images/ui-icons_222222_256x240.png +2 -0
- data/vendor/examples/slider/ui-lightness/images/ui-icons_228ef1_256x240.png +2 -0
- data/vendor/examples/slider/ui-lightness/images/ui-icons_ef8c08_256x240.png +2 -0
- data/vendor/examples/slider/ui-lightness/images/ui-icons_ffd27a_256x240.png +2 -0
- data/vendor/examples/slider/ui-lightness/images/ui-icons_ffffff_256x240.png +2 -0
- data/vendor/examples/slider/ui-lightness/jquery-ui-1.8rc3.custom.css +302 -0
- data/vendor/examples/tipsy/jquery.tipsy.js +198 -0
- data/vendor/examples/tipsy/tipsy-bar.html +65 -0
- data/vendor/examples/tipsy/tipsy-line.html +67 -0
- data/vendor/examples/tipsy/tipsy.css +12 -0
- data/vendor/examples/tipsy/tipsy.gif +0 -0
- data/vendor/examples/tipsy/tipsy.js +66 -0
- data/vendor/examples/weather/weather.html +86 -0
- data/vendor/examples/weather/weather.js +42 -0
- data/vendor/examples/wheat/wheat.html +130 -0
- data/vendor/examples/wheat/wheat.js +70 -0
- data/vendor/lib/google-compiler/COPYING +202 -0
- data/vendor/lib/google-compiler/README +224 -0
- data/vendor/lib/google-compiler/compiler-20100201.jar +0 -0
- data/vendor/protovis-d3.3.js +15726 -0
- data/vendor/protovis-r3.3.js +287 -0
- data/vendor/src/behavior/Behavior.js +32 -0
- data/vendor/src/behavior/Drag.js +112 -0
- data/vendor/src/behavior/Pan.js +110 -0
- data/vendor/src/behavior/Point.js +157 -0
- data/vendor/src/behavior/Resize.js +104 -0
- data/vendor/src/behavior/Select.js +100 -0
- data/vendor/src/behavior/Zoom.js +85 -0
- data/vendor/src/color/Color.js +598 -0
- data/vendor/src/color/Colors.js +135 -0
- data/vendor/src/color/Ramp.js +17 -0
- data/vendor/src/data/Arrays.js +277 -0
- data/vendor/src/data/Dom.js +380 -0
- data/vendor/src/data/Flatten.js +146 -0
- data/vendor/src/data/Histogram.js +120 -0
- data/vendor/src/data/LinearScale.js +54 -0
- data/vendor/src/data/LogScale.js +142 -0
- data/vendor/src/data/Nest.js +257 -0
- data/vendor/src/data/Numbers.js +313 -0
- data/vendor/src/data/Objects.js +78 -0
- data/vendor/src/data/OrdinalScale.js +267 -0
- data/vendor/src/data/QuantileScale.js +180 -0
- data/vendor/src/data/QuantitativeScale.js +440 -0
- data/vendor/src/data/RootScale.js +55 -0
- data/vendor/src/data/Scale.js +86 -0
- data/vendor/src/data/Transform.js +109 -0
- data/vendor/src/data/Tree.js +124 -0
- data/vendor/src/data/Vector.js +118 -0
- data/vendor/src/geo/Geo.js +5 -0
- data/vendor/src/geo/GeoScale.js +307 -0
- data/vendor/src/geo/LatLng.js +23 -0
- data/vendor/src/geo/Projection.js +43 -0
- data/vendor/src/geo/Projections.js +117 -0
- data/vendor/src/lang/Array.js +112 -0
- data/vendor/src/lang/init.js +26 -0
- data/vendor/src/layout/Arc.js +178 -0
- data/vendor/src/layout/Bullet.js +164 -0
- data/vendor/src/layout/Cluster.js +205 -0
- data/vendor/src/layout/Force.js +309 -0
- data/vendor/src/layout/Grid.js +119 -0
- data/vendor/src/layout/Hierarchy.js +249 -0
- data/vendor/src/layout/Horizon.js +159 -0
- data/vendor/src/layout/Indent.js +83 -0
- data/vendor/src/layout/Layout.js +56 -0
- data/vendor/src/layout/Matrix.js +177 -0
- data/vendor/src/layout/Network.js +302 -0
- data/vendor/src/layout/Pack.js +323 -0
- data/vendor/src/layout/Partition.js +203 -0
- data/vendor/src/layout/Rollup.js +203 -0
- data/vendor/src/layout/Stack.js +391 -0
- data/vendor/src/layout/Tree.js +282 -0
- data/vendor/src/layout/Treemap.js +347 -0
- data/vendor/src/mark/Anchor.js +81 -0
- data/vendor/src/mark/Area.js +268 -0
- data/vendor/src/mark/Bar.js +93 -0
- data/vendor/src/mark/Dot.js +212 -0
- data/vendor/src/mark/Ease.js +150 -0
- data/vendor/src/mark/Image.js +154 -0
- data/vendor/src/mark/Label.js +155 -0
- data/vendor/src/mark/Line.js +195 -0
- data/vendor/src/mark/Mark.js +1237 -0
- data/vendor/src/mark/Panel.js +273 -0
- data/vendor/src/mark/Rule.js +143 -0
- data/vendor/src/mark/Transient.js +7 -0
- data/vendor/src/mark/Transition.js +195 -0
- data/vendor/src/mark/Wedge.js +244 -0
- data/vendor/src/physics/BoundConstraint.js +75 -0
- data/vendor/src/physics/ChargeForce.js +184 -0
- data/vendor/src/physics/CollisionConstraint.js +113 -0
- data/vendor/src/physics/Constraint.js +26 -0
- data/vendor/src/physics/DragForce.js +49 -0
- data/vendor/src/physics/Force.js +25 -0
- data/vendor/src/physics/Particle.js +81 -0
- data/vendor/src/physics/PositionConstraint.js +72 -0
- data/vendor/src/physics/Quadtree.js +195 -0
- data/vendor/src/physics/Simulation.js +159 -0
- data/vendor/src/physics/SpringForce.js +141 -0
- data/vendor/src/pv-internals.js +154 -0
- data/vendor/src/pv.js +95 -0
- data/vendor/src/scene/SvgArea.js +172 -0
- data/vendor/src/scene/SvgBar.js +28 -0
- data/vendor/src/scene/SvgCurve.js +354 -0
- data/vendor/src/scene/SvgDot.js +81 -0
- data/vendor/src/scene/SvgImage.js +45 -0
- data/vendor/src/scene/SvgLabel.js +46 -0
- data/vendor/src/scene/SvgLine.js +159 -0
- data/vendor/src/scene/SvgPanel.js +126 -0
- data/vendor/src/scene/SvgRule.js +26 -0
- data/vendor/src/scene/SvgScene.js +185 -0
- data/vendor/src/scene/SvgWedge.js +66 -0
- data/vendor/src/text/DateFormat.js +262 -0
- data/vendor/src/text/Format.js +78 -0
- data/vendor/src/text/NumberFormat.js +227 -0
- data/vendor/src/text/TimeFormat.js +115 -0
- data/vendor/test1.html +30 -0
- data/vendor/tests/behavior/drag-events.html +47 -0
- data/vendor/tests/behavior/drag.html +32 -0
- data/vendor/tests/behavior/drag2.html +33 -0
- data/vendor/tests/behavior/point-area-stacked.html +73 -0
- data/vendor/tests/behavior/point-area-stacked2.html +70 -0
- data/vendor/tests/behavior/point-area.html +67 -0
- data/vendor/tests/behavior/point-bar.html +62 -0
- data/vendor/tests/behavior/point-dot.html +60 -0
- data/vendor/tests/behavior/point-line.html +62 -0
- data/vendor/tests/behavior/point-lines-grid.html +65 -0
- data/vendor/tests/behavior/point-lines.html +61 -0
- data/vendor/tests/behavior/point-wedge.html +43 -0
- data/vendor/tests/behavior/resize.html +69 -0
- data/vendor/tests/behavior/select.html +37 -0
- data/vendor/tests/bzr.js +62 -0
- data/vendor/tests/center.js +13 -0
- data/vendor/tests/data/deviation.html +54 -0
- data/vendor/tests/data/histogram-discrete.html +50 -0
- data/vendor/tests/data/histogram.html +56 -0
- data/vendor/tests/data/log-adjusted.html +48 -0
- data/vendor/tests/data/log-ceil.html +48 -0
- data/vendor/tests/data/log-floor.html +48 -0
- data/vendor/tests/data/log-symmetric.html +48 -0
- data/vendor/tests/data/log.html +48 -0
- data/vendor/tests/data/max-index.html +36 -0
- data/vendor/tests/data/max.html +36 -0
- data/vendor/tests/data/min-index.html +36 -0
- data/vendor/tests/data/min.html +36 -0
- data/vendor/tests/data/ordinal-split-banded.html +45 -0
- data/vendor/tests/data/ordinal-split-banded2.html +45 -0
- data/vendor/tests/data/ordinal-split-flush.html +51 -0
- data/vendor/tests/data/ordinal-split.html +51 -0
- data/vendor/tests/data/range.html +105 -0
- data/vendor/tests/data/scale-date.html +46 -0
- data/vendor/tests/data/scale-date2.html +38 -0
- data/vendor/tests/data/scale-date3.html +38 -0
- data/vendor/tests/data/scale-date4.html +38 -0
- data/vendor/tests/data/scale-degenerate.html +143 -0
- data/vendor/tests/data/scale-linear.html +59 -0
- data/vendor/tests/data/scale-log.html +60 -0
- data/vendor/tests/data/scale-log2.html +60 -0
- data/vendor/tests/data/scale-log3.html +60 -0
- data/vendor/tests/data/scale-log4.html +60 -0
- data/vendor/tests/data/scale-log5.html +60 -0
- data/vendor/tests/data/scale-log6.html +60 -0
- data/vendor/tests/data/scale-quantile.html +47 -0
- data/vendor/tests/data/scale-quantile2.html +50 -0
- data/vendor/tests/data/scale-quantile3.html +48 -0
- data/vendor/tests/data/scale-root.html +60 -0
- data/vendor/tests/data/scale-root2.html +39 -0
- data/vendor/tests/data/scale-tick-format.html +54 -0
- data/vendor/tests/data/scale-ticks.html +45 -0
- data/vendor/tests/data/sum.html +42 -0
- data/vendor/tests/data/variance.html +42 -0
- data/vendor/tests/diamond.js +40 -0
- data/vendor/tests/flare-imports.js +222 -0
- data/vendor/tests/flare.js +284 -0
- data/vendor/tests/geo/countries-hires.js +257 -0
- data/vendor/tests/geo/countries-lores.js +197 -0
- data/vendor/tests/geo/population.js +250 -0
- data/vendor/tests/geo/scale-aitoff.html +58 -0
- data/vendor/tests/geo/scale-gall-peters.html +56 -0
- data/vendor/tests/geo/scale-hammer.html +58 -0
- data/vendor/tests/geo/scale-identity.html +56 -0
- data/vendor/tests/geo/scale-mercator.html +56 -0
- data/vendor/tests/geo/scale-sinusoidal.html +57 -0
- data/vendor/tests/geo/scale-smart-domain.html +58 -0
- data/vendor/tests/geo/scale.html +55 -0
- data/vendor/tests/geo/scale2.html +40 -0
- data/vendor/tests/geo/us-states.js +61 -0
- data/vendor/tests/heatmap.js +63 -0
- data/vendor/tests/lang/globals.html +41 -0
- data/vendor/tests/lang/init.html +31 -0
- data/vendor/tests/layers.js +28 -0
- data/vendor/tests/layout/arc-directed.html +33 -0
- data/vendor/tests/layout/arc-radial.html +36 -0
- data/vendor/tests/layout/arc-undirected.html +32 -0
- data/vendor/tests/layout/arc.html +33 -0
- data/vendor/tests/layout/arc2.html +32 -0
- data/vendor/tests/layout/bullet-multiples.html +60 -0
- data/vendor/tests/layout/bullet.html +45 -0
- data/vendor/tests/layout/bullets.js +37 -0
- data/vendor/tests/layout/cluster-fill-group.html +24 -0
- data/vendor/tests/layout/cluster-fill.html +28 -0
- data/vendor/tests/layout/cluster-partition-radial-fill.html +43 -0
- data/vendor/tests/layout/cluster-radial-fill-radius.html +26 -0
- data/vendor/tests/layout/cluster-radial-fill.html +29 -0
- data/vendor/tests/layout/cluster-radial-group-fill.html +30 -0
- data/vendor/tests/layout/cluster-radial-radius.html +30 -0
- data/vendor/tests/layout/cluster-radial.html +28 -0
- data/vendor/tests/layout/cluster-radial2.html +33 -0
- data/vendor/tests/layout/cluster.html +34 -0
- data/vendor/tests/layout/cluster2.html +32 -0
- data/vendor/tests/layout/force-toggle.html +46 -0
- data/vendor/tests/layout/force.html +45 -0
- data/vendor/tests/layout/force2.html +58 -0
- data/vendor/tests/layout/force3.html +41 -0
- data/vendor/tests/layout/force4.html +45 -0
- data/vendor/tests/layout/force5.html +53 -0
- data/vendor/tests/layout/grid-cols.html +31 -0
- data/vendor/tests/layout/grid-heatmap.html +25 -0
- data/vendor/tests/layout/grid-rows.html +31 -0
- data/vendor/tests/layout/grid.html +34 -0
- data/vendor/tests/layout/horizon-color.html +31 -0
- data/vendor/tests/layout/horizon.html +31 -0
- data/vendor/tests/layout/indent-toggle.html +62 -0
- data/vendor/tests/layout/indent.html +25 -0
- data/vendor/tests/layout/indent2.html +33 -0
- data/vendor/tests/layout/matrix-sort.html +28 -0
- data/vendor/tests/layout/matrix.html +35 -0
- data/vendor/tests/layout/network.html +43 -0
- data/vendor/tests/layout/pack-bubble.html +45 -0
- data/vendor/tests/layout/pack.html +26 -0
- data/vendor/tests/layout/pack2.html +32 -0
- data/vendor/tests/layout/partition-fill.html +27 -0
- data/vendor/tests/layout/partition-fill2.html +22 -0
- data/vendor/tests/layout/partition-fill3.html +27 -0
- data/vendor/tests/layout/partition-radial-fill-radius.html +25 -0
- data/vendor/tests/layout/partition-radial-fill.html +26 -0
- data/vendor/tests/layout/partition-radial-fill2.html +23 -0
- data/vendor/tests/layout/partition-radial-fill3.html +29 -0
- data/vendor/tests/layout/partition-radial-radius.html +29 -0
- data/vendor/tests/layout/partition-radial.html +30 -0
- data/vendor/tests/layout/partition-radial2.html +33 -0
- data/vendor/tests/layout/partition.html +33 -0
- data/vendor/tests/layout/partition2.html +32 -0
- data/vendor/tests/layout/rollup.html +50 -0
- data/vendor/tests/layout/stack-empty.html +27 -0
- data/vendor/tests/layout/stack-expand.html +41 -0
- data/vendor/tests/layout/stack-reverse.html +42 -0
- data/vendor/tests/layout/stack-right.html +42 -0
- data/vendor/tests/layout/stack-rule.html +61 -0
- data/vendor/tests/layout/stack-visible.html +43 -0
- data/vendor/tests/layout/stack.html +53 -0
- data/vendor/tests/layout/tree-radial.html +31 -0
- data/vendor/tests/layout/tree-radial2.html +34 -0
- data/vendor/tests/layout/tree-toggle.html +36 -0
- data/vendor/tests/layout/tree.html +31 -0
- data/vendor/tests/layout/tree2.html +35 -0
- data/vendor/tests/layout/treemap-hierarchy.html +40 -0
- data/vendor/tests/layout/treemap-margin.html +26 -0
- data/vendor/tests/layout/treemap-round.html +40 -0
- data/vendor/tests/layout/treemap-slice.html +34 -0
- data/vendor/tests/layout/treemap.html +37 -0
- data/vendor/tests/life.js +212 -0
- data/vendor/tests/mark/anchor.html +25 -0
- data/vendor/tests/mark/area-anchor-chain.html +42 -0
- data/vendor/tests/mark/area-anchor-line.html +57 -0
- data/vendor/tests/mark/area-anchor-stack.html +35 -0
- data/vendor/tests/mark/area-anchor.html +43 -0
- data/vendor/tests/mark/area-anchor2.html +33 -0
- data/vendor/tests/mark/area-cardinal.html +57 -0
- data/vendor/tests/mark/area-monotone.html +57 -0
- data/vendor/tests/mark/area-segmented-basis.html +30 -0
- data/vendor/tests/mark/area-segmented-cardinal.html +30 -0
- data/vendor/tests/mark/area-segmented-monotone.html +30 -0
- data/vendor/tests/mark/area-segmented-step.html +44 -0
- data/vendor/tests/mark/area-segmented.html +29 -0
- data/vendor/tests/mark/area-stacked-cardinal.html +54 -0
- data/vendor/tests/mark/area-stacked-monotone.html +54 -0
- data/vendor/tests/mark/area-stacked.html +53 -0
- data/vendor/tests/mark/area-step.html +43 -0
- data/vendor/tests/mark/area-zero.html +32 -0
- data/vendor/tests/mark/area.html +57 -0
- data/vendor/tests/mark/bar-anchor-stack.html +51 -0
- data/vendor/tests/mark/bar-anchor.html +44 -0
- data/vendor/tests/mark/bar-column-grouped.html +63 -0
- data/vendor/tests/mark/bar-column-stacked.html +56 -0
- data/vendor/tests/mark/bar-column.html +54 -0
- data/vendor/tests/mark/bar-grouped.html +63 -0
- data/vendor/tests/mark/bar-stacked.html +57 -0
- data/vendor/tests/mark/bar.html +54 -0
- data/vendor/tests/mark/cursor.html +41 -0
- data/vendor/tests/mark/def-type.html +23 -0
- data/vendor/tests/mark/dot-anchor.html +33 -0
- data/vendor/tests/mark/dot-radius.html +22 -0
- data/vendor/tests/mark/dot-stroke.html +43 -0
- data/vendor/tests/mark/dot.html +52 -0
- data/vendor/tests/mark/dot2.html +61 -0
- data/vendor/tests/mark/ease.html +90 -0
- data/vendor/tests/mark/event-dblclick.html +30 -0
- data/vendor/tests/mark/event-prototype.html +45 -0
- data/vendor/tests/mark/event-render.html +45 -0
- data/vendor/tests/mark/event.html +24 -0
- data/vendor/tests/mark/image-color-inherit.html +33 -0
- data/vendor/tests/mark/image-color.html +35 -0
- data/vendor/tests/mark/image-color2.html +35 -0
- data/vendor/tests/mark/image-heatmap.html +29 -0
- data/vendor/tests/mark/image.html +32 -0
- data/vendor/tests/mark/label-break.html +54 -0
- data/vendor/tests/mark/label-decoration.html +22 -0
- data/vendor/tests/mark/label-events.html +32 -0
- data/vendor/tests/mark/line-anchor.html +42 -0
- data/vendor/tests/mark/line-basis.html +54 -0
- data/vendor/tests/mark/line-brownian.html +57 -0
- data/vendor/tests/mark/line-cardinal.html +77 -0
- data/vendor/tests/mark/line-catmull-rom.html +78 -0
- data/vendor/tests/mark/line-curve.html +65 -0
- data/vendor/tests/mark/line-eccentricity.html +39 -0
- data/vendor/tests/mark/line-fill.html +24 -0
- data/vendor/tests/mark/line-join.html +51 -0
- data/vendor/tests/mark/line-monotone-non-monotone.html +53 -0
- data/vendor/tests/mark/line-monotone-two-way.html +61 -0
- data/vendor/tests/mark/line-monotone.html +53 -0
- data/vendor/tests/mark/line-polar.html +36 -0
- data/vendor/tests/mark/line-segmented-basis.html +57 -0
- data/vendor/tests/mark/line-segmented-cardinal.html +80 -0
- data/vendor/tests/mark/line-segmented-join.html +52 -0
- data/vendor/tests/mark/line-segmented-monotone.html +56 -0
- data/vendor/tests/mark/line-segmented-polar.html +30 -0
- data/vendor/tests/mark/line-segmented-step.html +41 -0
- data/vendor/tests/mark/line-segmented-step2.html +32 -0
- data/vendor/tests/mark/line-segmented.html +30 -0
- data/vendor/tests/mark/line-step.html +39 -0
- data/vendor/tests/mark/line-tension.html +59 -0
- data/vendor/tests/mark/line.html +51 -0
- data/vendor/tests/mark/panel-anchor.html +37 -0
- data/vendor/tests/mark/panel-anchor2.html +31 -0
- data/vendor/tests/mark/panel-anchor3.html +22 -0
- data/vendor/tests/mark/panel-anchor4.html +28 -0
- data/vendor/tests/mark/panel-anchor5.html +28 -0
- data/vendor/tests/mark/panel-append.html +29 -0
- data/vendor/tests/mark/panel-canvas.html +107 -0
- data/vendor/tests/mark/panel-fill.html +50 -0
- data/vendor/tests/mark/panel-mouse.html +53 -0
- data/vendor/tests/mark/panel-transform.html +67 -0
- data/vendor/tests/mark/property-cast.html +24 -0
- data/vendor/tests/mark/render-partial.html +42 -0
- data/vendor/tests/mark/rule-anchor.html +29 -0
- data/vendor/tests/mark/title.html +41 -0
- data/vendor/tests/mark/transition-anchor.html +47 -0
- data/vendor/tests/mark/transition-wedge.html +47 -0
- data/vendor/tests/mark/transition.html +106 -0
- data/vendor/tests/mark/wedge-donut.html +35 -0
- data/vendor/tests/mark/wedge-implied.html +42 -0
- data/vendor/tests/mark/wedge-pie.html +37 -0
- data/vendor/tests/mark/wedge-ring.html +27 -0
- data/vendor/tests/miserables.js +348 -0
- data/vendor/tests/physics/dorling.html +70 -0
- data/vendor/tests/physics/simulation.html +56 -0
- data/vendor/tests/social.js +28 -0
- data/vendor/tests/stanford.png +0 -0
- data/vendor/tests/style.css +5 -0
- data/vendor/tests/testify.css +29 -0
- data/vendor/tests/testify.js +16 -0
- data/vendor/tests/text/format-number.html +75 -0
- data/web/first.svg +1 -0
- data/web/index.html +48 -0
- metadata +434 -31
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -2
@@ -0,0 +1,257 @@
|
|
1
|
+
/**
|
2
|
+
* Returns a {@link pv.Nest} operator for the specified array. This is a
|
3
|
+
* convenience factory method, equivalent to <tt>new pv.Nest(array)</tt>.
|
4
|
+
*
|
5
|
+
* @see pv.Nest
|
6
|
+
* @param {array} array an array of elements to nest.
|
7
|
+
* @returns {pv.Nest} a nest operator for the specified array.
|
8
|
+
*/
|
9
|
+
pv.nest = function(array) {
|
10
|
+
return new pv.Nest(array);
|
11
|
+
};
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Constructs a nest operator for the specified array. This constructor should
|
15
|
+
* not be invoked directly; use {@link pv.nest} instead.
|
16
|
+
*
|
17
|
+
* @class Represents a {@link Nest} operator for the specified array. Nesting
|
18
|
+
* allows elements in an array to be grouped into a hierarchical tree
|
19
|
+
* structure. The levels in the tree are specified by <i>key</i> functions. The
|
20
|
+
* leaf nodes of the tree can be sorted by value, while the internal nodes can
|
21
|
+
* be sorted by key. Finally, the tree can be returned either has a
|
22
|
+
* multidimensional array via {@link #entries}, or as a hierarchical map via
|
23
|
+
* {@link #map}. The {@link #rollup} routine similarly returns a map, collapsing
|
24
|
+
* the elements in each leaf node using a summary function.
|
25
|
+
*
|
26
|
+
* <p>For example, consider the following tabular data structure of Barley
|
27
|
+
* yields, from various sites in Minnesota during 1931-2:
|
28
|
+
*
|
29
|
+
* <pre>{ yield: 27.00, variety: "Manchuria", year: 1931, site: "University Farm" },
|
30
|
+
* { yield: 48.87, variety: "Manchuria", year: 1931, site: "Waseca" },
|
31
|
+
* { yield: 27.43, variety: "Manchuria", year: 1931, site: "Morris" }, ...</pre>
|
32
|
+
*
|
33
|
+
* To facilitate visualization, it may be useful to nest the elements first by
|
34
|
+
* year, and then by variety, as follows:
|
35
|
+
*
|
36
|
+
* <pre>var nest = pv.nest(yields)
|
37
|
+
* .key(function(d) d.year)
|
38
|
+
* .key(function(d) d.variety)
|
39
|
+
* .entries();</pre>
|
40
|
+
*
|
41
|
+
* This returns a nested array. Each element of the outer array is a key-values
|
42
|
+
* pair, listing the values for each distinct key:
|
43
|
+
*
|
44
|
+
* <pre>{ key: 1931, values: [
|
45
|
+
* { key: "Manchuria", values: [
|
46
|
+
* { yield: 27.00, variety: "Manchuria", year: 1931, site: "University Farm" },
|
47
|
+
* { yield: 48.87, variety: "Manchuria", year: 1931, site: "Waseca" },
|
48
|
+
* { yield: 27.43, variety: "Manchuria", year: 1931, site: "Morris" },
|
49
|
+
* ...
|
50
|
+
* ] },
|
51
|
+
* { key: "Glabron", values: [
|
52
|
+
* { yield: 43.07, variety: "Glabron", year: 1931, site: "University Farm" },
|
53
|
+
* { yield: 55.20, variety: "Glabron", year: 1931, site: "Waseca" },
|
54
|
+
* ...
|
55
|
+
* ] },
|
56
|
+
* ] },
|
57
|
+
* { key: 1932, values: ... }</pre>
|
58
|
+
*
|
59
|
+
* Further details, including sorting and rollup, is provided below on the
|
60
|
+
* corresponding methods.
|
61
|
+
*
|
62
|
+
* @param {array} array an array of elements to nest.
|
63
|
+
*/
|
64
|
+
pv.Nest = function(array) {
|
65
|
+
this.array = array;
|
66
|
+
this.keys = [];
|
67
|
+
};
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Nests using the specified key function. Multiple keys may be added to the
|
71
|
+
* nest; the array elements will be nested in the order keys are specified.
|
72
|
+
*
|
73
|
+
* @param {function} key a key function; must return a string or suitable map
|
74
|
+
* key.
|
75
|
+
* @returns {pv.Nest} this.
|
76
|
+
*/
|
77
|
+
pv.Nest.prototype.key = function(key) {
|
78
|
+
this.keys.push(key);
|
79
|
+
return this;
|
80
|
+
};
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Sorts the previously-added keys. The natural sort order is used by default
|
84
|
+
* (see {@link pv.naturalOrder}); if an alternative order is desired,
|
85
|
+
* <tt>order</tt> should be a comparator function. If this method is not called
|
86
|
+
* (i.e., keys are <i>unsorted</i>), keys will appear in the order they appear
|
87
|
+
* in the underlying elements array. For example,
|
88
|
+
*
|
89
|
+
* <pre>pv.nest(yields)
|
90
|
+
* .key(function(d) d.year)
|
91
|
+
* .key(function(d) d.variety)
|
92
|
+
* .sortKeys()
|
93
|
+
* .entries()</pre>
|
94
|
+
*
|
95
|
+
* groups yield data by year, then variety, and sorts the variety groups
|
96
|
+
* lexicographically (since the variety attribute is a string).
|
97
|
+
*
|
98
|
+
* <p>Key sort order is only used in conjunction with {@link #entries}, which
|
99
|
+
* returns an array of key-values pairs. If the nest is used to construct a
|
100
|
+
* {@link #map} instead, keys are unsorted.
|
101
|
+
*
|
102
|
+
* @param {function} [order] an optional comparator function.
|
103
|
+
* @returns {pv.Nest} this.
|
104
|
+
*/
|
105
|
+
pv.Nest.prototype.sortKeys = function(order) {
|
106
|
+
this.keys[this.keys.length - 1].order = order || pv.naturalOrder;
|
107
|
+
return this;
|
108
|
+
};
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Sorts the leaf values. The natural sort order is used by default (see
|
112
|
+
* {@link pv.naturalOrder}); if an alternative order is desired, <tt>order</tt>
|
113
|
+
* should be a comparator function. If this method is not called (i.e., values
|
114
|
+
* are <i>unsorted</i>), values will appear in the order they appear in the
|
115
|
+
* underlying elements array. For example,
|
116
|
+
*
|
117
|
+
* <pre>pv.nest(yields)
|
118
|
+
* .key(function(d) d.year)
|
119
|
+
* .key(function(d) d.variety)
|
120
|
+
* .sortValues(function(a, b) a.yield - b.yield)
|
121
|
+
* .entries()</pre>
|
122
|
+
*
|
123
|
+
* groups yield data by year, then variety, and sorts the values for each
|
124
|
+
* variety group by yield.
|
125
|
+
*
|
126
|
+
* <p>Value sort order, unlike keys, applies to both {@link #entries} and
|
127
|
+
* {@link #map}. It has no effect on {@link #rollup}.
|
128
|
+
*
|
129
|
+
* @param {function} [order] an optional comparator function.
|
130
|
+
* @returns {pv.Nest} this.
|
131
|
+
*/
|
132
|
+
pv.Nest.prototype.sortValues = function(order) {
|
133
|
+
this.order = order || pv.naturalOrder;
|
134
|
+
return this;
|
135
|
+
};
|
136
|
+
|
137
|
+
/**
|
138
|
+
* Returns a hierarchical map of values. Each key adds one level to the
|
139
|
+
* hierarchy. With only a single key, the returned map will have a key for each
|
140
|
+
* distinct value of the key function; the correspond value with be an array of
|
141
|
+
* elements with that key value. If a second key is added, this will be a nested
|
142
|
+
* map. For example:
|
143
|
+
*
|
144
|
+
* <pre>pv.nest(yields)
|
145
|
+
* .key(function(d) d.variety)
|
146
|
+
* .key(function(d) d.site)
|
147
|
+
* .map()</pre>
|
148
|
+
*
|
149
|
+
* returns a map <tt>m</tt> such that <tt>m[variety][site]</tt> is an array, a subset of
|
150
|
+
* <tt>yields</tt>, with each element having the given variety and site.
|
151
|
+
*
|
152
|
+
* @returns a hierarchical map of values.
|
153
|
+
*/
|
154
|
+
pv.Nest.prototype.map = function() {
|
155
|
+
var map = {}, values = [];
|
156
|
+
|
157
|
+
/* Build the map. */
|
158
|
+
for (var i, j = 0; j < this.array.length; j++) {
|
159
|
+
var x = this.array[j];
|
160
|
+
var m = map;
|
161
|
+
for (i = 0; i < this.keys.length - 1; i++) {
|
162
|
+
var k = this.keys[i](x);
|
163
|
+
if (!m[k]) m[k] = {};
|
164
|
+
m = m[k];
|
165
|
+
}
|
166
|
+
k = this.keys[i](x);
|
167
|
+
if (!m[k]) {
|
168
|
+
var a = [];
|
169
|
+
values.push(a);
|
170
|
+
m[k] = a;
|
171
|
+
}
|
172
|
+
m[k].push(x);
|
173
|
+
}
|
174
|
+
|
175
|
+
/* Sort each leaf array. */
|
176
|
+
if (this.order) {
|
177
|
+
for (var i = 0; i < values.length; i++) {
|
178
|
+
values[i].sort(this.order);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
return map;
|
183
|
+
};
|
184
|
+
|
185
|
+
/**
|
186
|
+
* Returns a hierarchical nested array. This method is similar to
|
187
|
+
* {@link pv.entries}, but works recursively on the entire hierarchy. Rather
|
188
|
+
* than returning a map like {@link #map}, this method returns a nested
|
189
|
+
* array. Each element of the array has a <tt>key</tt> and <tt>values</tt>
|
190
|
+
* field. For leaf nodes, the <tt>values</tt> array will be a subset of the
|
191
|
+
* underlying elements array; for non-leaf nodes, the <tt>values</tt> array will
|
192
|
+
* contain more key-values pairs.
|
193
|
+
*
|
194
|
+
* <p>For an example usage, see the {@link Nest} constructor.
|
195
|
+
*
|
196
|
+
* @returns a hierarchical nested array.
|
197
|
+
*/
|
198
|
+
pv.Nest.prototype.entries = function() {
|
199
|
+
|
200
|
+
/** Recursively extracts the entries for the given map. */
|
201
|
+
function entries(map) {
|
202
|
+
var array = [];
|
203
|
+
for (var k in map) {
|
204
|
+
var v = map[k];
|
205
|
+
array.push({ key: k, values: (v instanceof Array) ? v : entries(v) });
|
206
|
+
};
|
207
|
+
return array;
|
208
|
+
}
|
209
|
+
|
210
|
+
/** Recursively sorts the values for the given key-values array. */
|
211
|
+
function sort(array, i) {
|
212
|
+
var o = this.keys[i].order;
|
213
|
+
if (o) array.sort(function(a, b) { return o(a.key, b.key); });
|
214
|
+
if (++i < this.keys.length) {
|
215
|
+
for (var j = 0; j < array.length; j++) {
|
216
|
+
sort.call(this, array[j].values, i);
|
217
|
+
}
|
218
|
+
}
|
219
|
+
return array;
|
220
|
+
}
|
221
|
+
|
222
|
+
return sort.call(this, entries(this.map()), 0);
|
223
|
+
};
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Returns a rollup map. The behavior of this method is the same as
|
227
|
+
* {@link #map}, except that the leaf values are replaced with the return value
|
228
|
+
* of the specified rollup function <tt>f</tt>. For example,
|
229
|
+
*
|
230
|
+
* <pre>pv.nest(yields)
|
231
|
+
* .key(function(d) d.site)
|
232
|
+
* .rollup(function(v) pv.median(v, function(d) d.yield))</pre>
|
233
|
+
*
|
234
|
+
* first groups yield data by site, and then returns a map from site to median
|
235
|
+
* yield for the given site.
|
236
|
+
*
|
237
|
+
* @see #map
|
238
|
+
* @param {function} f a rollup function.
|
239
|
+
* @returns a hierarchical map, with the leaf values computed by <tt>f</tt>.
|
240
|
+
*/
|
241
|
+
pv.Nest.prototype.rollup = function(f) {
|
242
|
+
|
243
|
+
/** Recursively descends to the leaf nodes (arrays) and does rollup. */
|
244
|
+
function rollup(map) {
|
245
|
+
for (var key in map) {
|
246
|
+
var value = map[key];
|
247
|
+
if (value instanceof Array) {
|
248
|
+
map[key] = f(value);
|
249
|
+
} else {
|
250
|
+
rollup(value);
|
251
|
+
}
|
252
|
+
}
|
253
|
+
return map;
|
254
|
+
}
|
255
|
+
|
256
|
+
return rollup(this.map());
|
257
|
+
};
|
@@ -0,0 +1,313 @@
|
|
1
|
+
/**
|
2
|
+
* Returns an array of numbers, starting at <tt>start</tt>, incrementing by
|
3
|
+
* <tt>step</tt>, until <tt>stop</tt> is reached. The stop value is
|
4
|
+
* exclusive. If only a single argument is specified, this value is interpeted
|
5
|
+
* as the <i>stop</i> value, with the <i>start</i> value as zero. If only two
|
6
|
+
* arguments are specified, the step value is implied to be one.
|
7
|
+
*
|
8
|
+
* <p>The method is modeled after the built-in <tt>range</tt> method from
|
9
|
+
* Python. See the Python documentation for more details.
|
10
|
+
*
|
11
|
+
* @see <a href="http://docs.python.org/library/functions.html#range">Python range</a>
|
12
|
+
* @param {number} [start] the start value.
|
13
|
+
* @param {number} stop the stop value.
|
14
|
+
* @param {number} [step] the step value.
|
15
|
+
* @returns {number[]} an array of numbers.
|
16
|
+
*/
|
17
|
+
pv.range = function(start, stop, step) {
|
18
|
+
if (arguments.length == 1) {
|
19
|
+
stop = start;
|
20
|
+
start = 0;
|
21
|
+
}
|
22
|
+
if (step == undefined) step = 1;
|
23
|
+
if ((stop - start) / step == Infinity) throw new Error("range must be finite");
|
24
|
+
var array = [], i = 0, j;
|
25
|
+
stop -= (stop - start) * 1e-10; // floating point precision!
|
26
|
+
if (step < 0) {
|
27
|
+
while ((j = start + step * i++) > stop) {
|
28
|
+
array.push(j);
|
29
|
+
}
|
30
|
+
} else {
|
31
|
+
while ((j = start + step * i++) < stop) {
|
32
|
+
array.push(j);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return array;
|
36
|
+
};
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Returns a random number in the range [<tt>start</tt>, <tt>stop</tt>) that is
|
40
|
+
* a multiple of <tt>step</tt>. More specifically, the returned number is of the
|
41
|
+
* form <tt>start</tt> + <i>n</i> * <tt>step</tt>, where <i>n</i> is a
|
42
|
+
* nonnegative integer. If <tt>step</tt> is not specified, it defaults to 1,
|
43
|
+
* returning a random integer if <tt>start</tt> is also an integer.
|
44
|
+
*
|
45
|
+
* @param {number} [start] the start value value.
|
46
|
+
* @param {number} stop the stop value.
|
47
|
+
* @param {number} [step] the step value.
|
48
|
+
* @returns {number} a random number between <i>start</i> and <i>stop</i>.
|
49
|
+
*/
|
50
|
+
pv.random = function(start, stop, step) {
|
51
|
+
if (arguments.length == 1) {
|
52
|
+
stop = start;
|
53
|
+
start = 0;
|
54
|
+
}
|
55
|
+
if (step == undefined) step = 1;
|
56
|
+
return step
|
57
|
+
? (Math.floor(Math.random() * (stop - start) / step) * step + start)
|
58
|
+
: (Math.random() * (stop - start) + start);
|
59
|
+
};
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Returns the sum of the specified array. If the specified array is not an
|
63
|
+
* array of numbers, an optional accessor function <tt>f</tt> can be specified
|
64
|
+
* to map the elements to numbers. See {@link #normalize} for an example.
|
65
|
+
* Accessor functions can refer to <tt>this.index</tt>.
|
66
|
+
*
|
67
|
+
* @param {array} array an array of objects, or numbers.
|
68
|
+
* @param {function} [f] an optional accessor function.
|
69
|
+
* @returns {number} the sum of the specified array.
|
70
|
+
*/
|
71
|
+
pv.sum = function(array, f) {
|
72
|
+
var o = {};
|
73
|
+
return array.reduce(f
|
74
|
+
? function(p, d, i) { o.index = i; return p + f.call(o, d); }
|
75
|
+
: function(p, d) { return p + d; }, 0);
|
76
|
+
};
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Returns the maximum value of the specified array. If the specified array is
|
80
|
+
* not an array of numbers, an optional accessor function <tt>f</tt> can be
|
81
|
+
* specified to map the elements to numbers. See {@link #normalize} for an
|
82
|
+
* example. Accessor functions can refer to <tt>this.index</tt>.
|
83
|
+
*
|
84
|
+
* @param {array} array an array of objects, or numbers.
|
85
|
+
* @param {function} [f] an optional accessor function.
|
86
|
+
* @returns {number} the maximum value of the specified array.
|
87
|
+
*/
|
88
|
+
pv.max = function(array, f) {
|
89
|
+
if (f == pv.index) return array.length - 1;
|
90
|
+
return Math.max.apply(null, f ? pv.map(array, f) : array);
|
91
|
+
};
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Returns the index of the maximum value of the specified array. If the
|
95
|
+
* specified array is not an array of numbers, an optional accessor function
|
96
|
+
* <tt>f</tt> can be specified to map the elements to numbers. See
|
97
|
+
* {@link #normalize} for an example. Accessor functions can refer to
|
98
|
+
* <tt>this.index</tt>.
|
99
|
+
*
|
100
|
+
* @param {array} array an array of objects, or numbers.
|
101
|
+
* @param {function} [f] an optional accessor function.
|
102
|
+
* @returns {number} the index of the maximum value of the specified array.
|
103
|
+
*/
|
104
|
+
pv.max.index = function(array, f) {
|
105
|
+
if (!array.length) return -1;
|
106
|
+
if (f == pv.index) return array.length - 1;
|
107
|
+
if (!f) f = pv.identity;
|
108
|
+
var maxi = 0, maxx = -Infinity, o = {};
|
109
|
+
for (var i = 0; i < array.length; i++) {
|
110
|
+
o.index = i;
|
111
|
+
var x = f.call(o, array[i]);
|
112
|
+
if (x > maxx) {
|
113
|
+
maxx = x;
|
114
|
+
maxi = i;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
return maxi;
|
118
|
+
}
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Returns the minimum value of the specified array of numbers. If the specified
|
122
|
+
* array is not an array of numbers, an optional accessor function <tt>f</tt>
|
123
|
+
* can be specified to map the elements to numbers. See {@link #normalize} for
|
124
|
+
* an example. Accessor functions can refer to <tt>this.index</tt>.
|
125
|
+
*
|
126
|
+
* @param {array} array an array of objects, or numbers.
|
127
|
+
* @param {function} [f] an optional accessor function.
|
128
|
+
* @returns {number} the minimum value of the specified array.
|
129
|
+
*/
|
130
|
+
pv.min = function(array, f) {
|
131
|
+
if (f == pv.index) return 0;
|
132
|
+
return Math.min.apply(null, f ? pv.map(array, f) : array);
|
133
|
+
};
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Returns the index of the minimum value of the specified array. If the
|
137
|
+
* specified array is not an array of numbers, an optional accessor function
|
138
|
+
* <tt>f</tt> can be specified to map the elements to numbers. See
|
139
|
+
* {@link #normalize} for an example. Accessor functions can refer to
|
140
|
+
* <tt>this.index</tt>.
|
141
|
+
*
|
142
|
+
* @param {array} array an array of objects, or numbers.
|
143
|
+
* @param {function} [f] an optional accessor function.
|
144
|
+
* @returns {number} the index of the minimum value of the specified array.
|
145
|
+
*/
|
146
|
+
pv.min.index = function(array, f) {
|
147
|
+
if (!array.length) return -1;
|
148
|
+
if (f == pv.index) return 0;
|
149
|
+
if (!f) f = pv.identity;
|
150
|
+
var mini = 0, minx = Infinity, o = {};
|
151
|
+
for (var i = 0; i < array.length; i++) {
|
152
|
+
o.index = i;
|
153
|
+
var x = f.call(o, array[i]);
|
154
|
+
if (x < minx) {
|
155
|
+
minx = x;
|
156
|
+
mini = i;
|
157
|
+
}
|
158
|
+
}
|
159
|
+
return mini;
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Returns the arithmetic mean, or average, of the specified array. If the
|
164
|
+
* specified array is not an array of numbers, an optional accessor function
|
165
|
+
* <tt>f</tt> can be specified to map the elements to numbers. See
|
166
|
+
* {@link #normalize} for an example. Accessor functions can refer to
|
167
|
+
* <tt>this.index</tt>.
|
168
|
+
*
|
169
|
+
* @param {array} array an array of objects, or numbers.
|
170
|
+
* @param {function} [f] an optional accessor function.
|
171
|
+
* @returns {number} the mean of the specified array.
|
172
|
+
*/
|
173
|
+
pv.mean = function(array, f) {
|
174
|
+
return pv.sum(array, f) / array.length;
|
175
|
+
};
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Returns the median of the specified array. If the specified array is not an
|
179
|
+
* array of numbers, an optional accessor function <tt>f</tt> can be specified
|
180
|
+
* to map the elements to numbers. See {@link #normalize} for an example.
|
181
|
+
* Accessor functions can refer to <tt>this.index</tt>.
|
182
|
+
*
|
183
|
+
* @param {array} array an array of objects, or numbers.
|
184
|
+
* @param {function} [f] an optional accessor function.
|
185
|
+
* @returns {number} the median of the specified array.
|
186
|
+
*/
|
187
|
+
pv.median = function(array, f) {
|
188
|
+
if (f == pv.index) return (array.length - 1) / 2;
|
189
|
+
array = pv.map(array, f).sort(pv.naturalOrder);
|
190
|
+
if (array.length % 2) return array[Math.floor(array.length / 2)];
|
191
|
+
var i = array.length / 2;
|
192
|
+
return (array[i - 1] + array[i]) / 2;
|
193
|
+
};
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Returns the unweighted variance of the specified array. If the specified
|
197
|
+
* array is not an array of numbers, an optional accessor function <tt>f</tt>
|
198
|
+
* can be specified to map the elements to numbers. See {@link #normalize} for
|
199
|
+
* an example. Accessor functions can refer to <tt>this.index</tt>.
|
200
|
+
*
|
201
|
+
* @param {array} array an array of objects, or numbers.
|
202
|
+
* @param {function} [f] an optional accessor function.
|
203
|
+
* @returns {number} the variance of the specified array.
|
204
|
+
*/
|
205
|
+
pv.variance = function(array, f) {
|
206
|
+
if (array.length < 1) return NaN;
|
207
|
+
if (array.length == 1) return 0;
|
208
|
+
var mean = pv.mean(array, f), sum = 0, o = {};
|
209
|
+
if (!f) f = pv.identity;
|
210
|
+
for (var i = 0; i < array.length; i++) {
|
211
|
+
o.index = i;
|
212
|
+
var d = f.call(o, array[i]) - mean;
|
213
|
+
sum += d * d;
|
214
|
+
}
|
215
|
+
return sum;
|
216
|
+
};
|
217
|
+
|
218
|
+
/**
|
219
|
+
* Returns an unbiased estimation of the standard deviation of a population,
|
220
|
+
* given the specified random sample. If the specified array is not an array of
|
221
|
+
* numbers, an optional accessor function <tt>f</tt> can be specified to map the
|
222
|
+
* elements to numbers. See {@link #normalize} for an example. Accessor
|
223
|
+
* functions can refer to <tt>this.index</tt>.
|
224
|
+
*
|
225
|
+
* @param {array} array an array of objects, or numbers.
|
226
|
+
* @param {function} [f] an optional accessor function.
|
227
|
+
* @returns {number} the standard deviation of the specified array.
|
228
|
+
*/
|
229
|
+
pv.deviation = function(array, f) {
|
230
|
+
return Math.sqrt(pv.variance(array, f) / (array.length - 1));
|
231
|
+
};
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Returns the logarithm with a given base value.
|
235
|
+
*
|
236
|
+
* @param {number} x the number for which to compute the logarithm.
|
237
|
+
* @param {number} b the base of the logarithm.
|
238
|
+
* @returns {number} the logarithm value.
|
239
|
+
*/
|
240
|
+
pv.log = function(x, b) {
|
241
|
+
return Math.log(x) / Math.log(b);
|
242
|
+
};
|
243
|
+
|
244
|
+
/**
|
245
|
+
* Computes a zero-symmetric logarithm. Computes the logarithm of the absolute
|
246
|
+
* value of the input, and determines the sign of the output according to the
|
247
|
+
* sign of the input value.
|
248
|
+
*
|
249
|
+
* @param {number} x the number for which to compute the logarithm.
|
250
|
+
* @param {number} b the base of the logarithm.
|
251
|
+
* @returns {number} the symmetric log value.
|
252
|
+
*/
|
253
|
+
pv.logSymmetric = function(x, b) {
|
254
|
+
return (x == 0) ? 0 : ((x < 0) ? -pv.log(-x, b) : pv.log(x, b));
|
255
|
+
};
|
256
|
+
|
257
|
+
/**
|
258
|
+
* Computes a zero-symmetric logarithm, with adjustment to values between zero
|
259
|
+
* and the logarithm base. This adjustment introduces distortion for values less
|
260
|
+
* than the base number, but enables simultaneous plotting of log-transformed
|
261
|
+
* data involving both positive and negative numbers.
|
262
|
+
*
|
263
|
+
* @param {number} x the number for which to compute the logarithm.
|
264
|
+
* @param {number} b the base of the logarithm.
|
265
|
+
* @returns {number} the adjusted, symmetric log value.
|
266
|
+
*/
|
267
|
+
pv.logAdjusted = function(x, b) {
|
268
|
+
if (!isFinite(x)) return x;
|
269
|
+
var negative = x < 0;
|
270
|
+
if (x < b) x += (b - x) / b;
|
271
|
+
return negative ? -pv.log(x, b) : pv.log(x, b);
|
272
|
+
};
|
273
|
+
|
274
|
+
/**
|
275
|
+
* Rounds an input value down according to its logarithm. The method takes the
|
276
|
+
* floor of the logarithm of the value and then uses the resulting value as an
|
277
|
+
* exponent for the base value.
|
278
|
+
*
|
279
|
+
* @param {number} x the number for which to compute the logarithm floor.
|
280
|
+
* @param {number} b the base of the logarithm.
|
281
|
+
* @returns {number} the rounded-by-logarithm value.
|
282
|
+
*/
|
283
|
+
pv.logFloor = function(x, b) {
|
284
|
+
return (x > 0)
|
285
|
+
? Math.pow(b, Math.floor(pv.log(x, b)))
|
286
|
+
: -Math.pow(b, -Math.floor(-pv.log(-x, b)));
|
287
|
+
};
|
288
|
+
|
289
|
+
/**
|
290
|
+
* Rounds an input value up according to its logarithm. The method takes the
|
291
|
+
* ceiling of the logarithm of the value and then uses the resulting value as an
|
292
|
+
* exponent for the base value.
|
293
|
+
*
|
294
|
+
* @param {number} x the number for which to compute the logarithm ceiling.
|
295
|
+
* @param {number} b the base of the logarithm.
|
296
|
+
* @returns {number} the rounded-by-logarithm value.
|
297
|
+
*/
|
298
|
+
pv.logCeil = function(x, b) {
|
299
|
+
return (x > 0)
|
300
|
+
? Math.pow(b, Math.ceil(pv.log(x, b)))
|
301
|
+
: -Math.pow(b, -Math.ceil(-pv.log(-x, b)));
|
302
|
+
};
|
303
|
+
|
304
|
+
(function() {
|
305
|
+
var radians = Math.PI / 180,
|
306
|
+
degrees = 180 / Math.PI;
|
307
|
+
|
308
|
+
/** Returns the number of radians corresponding to the specified degrees. */
|
309
|
+
pv.radians = function(degrees) { return radians * degrees; };
|
310
|
+
|
311
|
+
/** Returns the number of degrees corresponding to the specified radians. */
|
312
|
+
pv.degrees = function(radians) { return degrees * radians; };
|
313
|
+
})();
|