Examples of JsDoubleFunction


Examples of org.thechiselgroup.choosel.protovis.client.jsutil.JsDoubleFunction

        PVWedge bg = vis.add(PV.Wedge)
                .data(antibiotics)
                // assumes Burtin's order
                .left(width / 2).top(height / 2).innerRadius(innerRadius)
                .outerRadius(outerRadius).angle(bigAngle)
                .startAngle(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        PVMark _this = args.getThis();
                        return _this.index() * bigAngle + bigAngle / 2
                                - Math.PI / 2;
                    }
                }).fillStyle(new JsStringFunction() {
                    public String f(JsArgs args) {
                        Antibiotics d = args.getObject(0);
                        return gramColor.get(d.gram);
                    }
                });

        /* Antibiotics. */
        bg.add(PV.Wedge).angle(smallAngle).startAngle(new JsDoubleFunction() {
            public double f(JsArgs args) {
                PVWedge _this = args.getThis();
                return _this.proto().startAngle() + smallAngle;
            }
        }).outerRadius(new JsDoubleFunction() {
            public double f(JsArgs args) {
                Antibiotics d = args.getObject();
                return radius(d.penicillin, a, b);
            }
        }).fillStyle(drugColor.get("Penicillin")).add(PV.Wedge)
                .startAngle(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        PVWedge _this = args.getThis();
                        return _this.proto().startAngle() + 2 * smallAngle;
                    }
                }).outerRadius(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        Antibiotics d = args.getObject();
                        return radius(d.streptomycin, a, b);
                    }
                }).fillStyle(drugColor.get("Streptomycin")).add(PV.Wedge)
                .outerRadius(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        Antibiotics d = args.getObject();
                        return radius(d.neomycin, a, b);
                    }
                }).fillStyle(drugColor.get("Neomycin"));

        /* Circular grid lines. */
        bg.add(PV.Dot).data(PV.range(-3, 4)).fillStyle((String) null)
                .strokeStyle("#eee").lineWidth(1).size(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        int i = args.getInt();
                        return Math.pow(radius(Math.pow(10, i), a, b), 2);
                    }
                }).anchor(TOP).add(PV.Label).visible(new JsBooleanFunction() {
                    public boolean f(JsArgs args) {
                        int i = args.getInt();
                        return i < 3;
                    }
                }).textBaseline(MIDDLE).text(new JsStringFunction() {
                    public String f(JsArgs args) {
                        int i = args.getInt();
                        return JsUtils.toFixed(Math.pow(10, i), (i > 0) ? 0
                                : -i);
                    }
                });

        /* Radial grid lines. */
        bg.add(PV.Wedge).data(PV.range(antibiotics.length + 1))
                .innerRadius(innerRadius - 10).outerRadius(outerRadius + 10)
                .fillStyle((String) null).strokeStyle("black").angle(0);

        /* Labels. */
        bg.anchor(OUTER).add(PV.Label).textAlign(CENTER)
                .text(new JsStringFunction() {
                    public String f(JsArgs args) {
                        Antibiotics d = args.getObject();
                        return d.bacteria;
                    }
                });

        /* Antibiotic legend. */
        vis.add(PV.Bar).data(drugColor.keySet()).right(width / 2 + 3)
                .top(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        PVMark _this = args.getThis();
                        return height / 2 - 28 + _this.index() * 18;
                    }
                }).fillStyle(new JsStringFunction() {
                    public String f(JsArgs args) {
                        String d = args.getObject();
                        return drugColor.get(d);
                    }
                }).width(36).height(12).anchor(RIGHT).add(PV.Label)
                .textMargin(6).textAlign(LEFT);

        /* Gram-stain legend. */
        vis.add(PV.Dot).data(gramColor.keySet()).left(width / 2 - 20)
                .bottom(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        PVMark _this = args.getThis();
                        return -60 + _this.index() * 18;
                    }
                }).fillStyle(new JsStringFunction() {
View Full Code Here

Examples of org.thechiselgroup.choosel.protovis.client.jsutil.JsDoubleFunction

                        Map.Entry<String, String> entry = args.getObject();
                        return entry.getKey();
                    }
                })
                .size(SHAPE_SIZE)
                .left(new JsDoubleFunction() {

                    private int currentWidth = 0;

                    @Override
                    public double f(JsArgs args) {
View Full Code Here

Examples of org.thechiselgroup.choosel.protovis.client.jsutil.JsDoubleFunction

                .height(regularBarLength).left(barStart).width(barWidth)
                .lineWidth(BAR_STROKE_WIDTH).cursor(POINTER).events(ALL);

        getChart().add(PV.Label).data(visualItemsJsArray)
                .left(baselineLabelStart).textAlign(PVAlignment.CENTER)
                .bottom(new JsDoubleFunction() {
                    @Override
                    public double f(JsArgs args) {
                        PVMark _this = args.getThis();
                        // TODO dynamic positioning depending on label size
                        if (chartWidth / regularValues.length > 60) {
View Full Code Here

Examples of org.thechiselgroup.choosel.protovis.client.jsutil.JsDoubleFunction

                .data(PV.sort(data, PV.reverseOrder()))
                .bottom(w / 2)
                .left(w / 2)
                .innerRadius(r - 40)
                .outerRadius(r)
                .angle(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        double d = args.getDouble(0);
                        return a.fd(d);
                    }
                })
View Full Code Here

Examples of org.thechiselgroup.choosel.protovis.client.jsutil.JsDoubleFunction

                        Map.Entry<String, String> entry = args.getObject();
                        return entry.getKey();
                    }
                })
                .size(SHAPE_SIZE)
                .left(new JsDoubleFunction() {

                    private int currentWidth = 0;

                    @Override
                    public double f(JsArgs args) {
View Full Code Here

Examples of org.thechiselgroup.choosel.protovis.client.jsutil.JsDoubleFunction

            }
        }).top(y).anchor(LEFT).add(PV.Label).text(y.tickFormat());

        /* The dot plot. */
        vis.add(PV.Panel).overflow("hidden").add(PV.Dot).data(data)
                .left(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        Pair d = args.getObject();
                        return x.fd(d.x);
                    }
                }).top(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        Pair d = args.getObject();
                        return y.fd(d.y);
                    }
                }).fillStyle(PV.rgb(121, 173, 210, .5))
                .radius(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        return 5 / args.<PVDot> getThis().scale();
                    }
                });

View Full Code Here

Examples of org.thechiselgroup.choosel.protovis.client.jsutil.JsDoubleFunction

        PVPanel vis = getPVPanel().width(200).height(250);

        /* Record range. */
        PVBar record = vis.add(PV.Bar).data(weatherRecords)
                .bottom(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        WeatherRecord d = args.getObject();
                        return d.record.low * h;
                    }
                }).height(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        WeatherRecord d = args.getObject();
                        return (d.record.high - d.record.low) * h;
                    }
                }).left(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        PVMark _this = args.getThis();
                        return _this.index() * w;
                    }
                }).width(w - 2).fillStyle("#ccc");

        /* Normal range. */
        record.add(PV.Bar).bottom(new JsDoubleFunction() {
            public double f(JsArgs args) {
                WeatherRecord d = args.getObject(0);
                return d.normal.low * h;
            }
        }).height(new JsDoubleFunction() {
            public double f(JsArgs args) {
                WeatherRecord d = args.getObject(0);
                return (d.normal.high - d.normal.low) * h;
            }
        }).fillStyle("#999");

        /* White grid lines. */
        vis.add(PV.Rule).dataInt(20, 40, 60).bottom(new JsDoubleFunction() {
            public double f(JsArgs args) {
                double d = args.getDouble();
                return d * h + 1;
            }
        }).left(0).right(20).lineWidth(2).strokeStyle("white").anchor(RIGHT)
                .add(PV.Label).text(new JsStringFunction() {
                    public String f(JsArgs args) {
                        int d = args.getInt(0);
                        return d + "\u00b0";
                    }
                });

        /* Actual and forecast range. */
        record.add(PV.Bar).visible(new JsBooleanFunction() {
            public boolean f(JsArgs args) {
                WeatherRecord d = args.getObject();
                return d.hasActual();
            }
        }).bottom(new JsDoubleFunction() {
            public double f(JsArgs args) {
                WeatherRecord d = args.getObject();
                return d.actual.low * h;
            }
        }).height(new JsDoubleFunction() {
            public double f(JsArgs args) {
                WeatherRecord d = args.getObject();
                return (d.actual.high - d.actual.low) * h;
            }
        }).left(new JsDoubleFunction() {
            public double f(JsArgs args) {
                PVMark _this = args.getThis();
                return _this.index() * w + 3;
            }
        }).width(w - 8).fillStyle("black").add(PV.Bar)
                .visible(new JsBooleanFunction() {
                    public boolean f(JsArgs args) {
                        WeatherRecord d = args.getObject();
                        return d.hasForecast();
                    }
                }).bottom(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        WeatherRecord d = args.getObject();
                        return d.forecast.highMin * h;
                    }
                }).height(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        WeatherRecord d = args.getObject();
                        return (d.forecast.highMax - d.forecast.highMin) * h;
                    }
                }).add(PV.Bar).bottom(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        WeatherRecord d = args.getObject();
                        return d.forecast.lowMin * h;
                    }
                }).height(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        WeatherRecord d = args.getObject();
                        return (d.forecast.lowMax - d.forecast.lowMin) * h;
                    }
                }).add(PV.Bar).bottom(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        WeatherRecord d = args.getObject();
                        return d.forecast.lowMin * h;
                    }
                }).height(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        WeatherRecord d = args.getObject();
                        return (d.forecast.highMax - d.forecast.lowMin) * h;
                    }
                }).left(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        PVMark _this = args.getThis();
                        return _this.index() * w + 3 + Math.floor((w - 8) / 3);
                    }
                }).width(Math.ceil((w - 8) / 3));
View Full Code Here

Examples of org.thechiselgroup.choosel.protovis.client.jsutil.JsDoubleFunction

        PVPanel vis = getPVPanel().width(w).height(h * site.size()).top(15)
                .left(90).right(20).bottom(25);

        /* A panel per site-year. */
        PVPanel cell = vis.add(PV.Panel).data(barley.entrySet()).height(h)
                .top(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        PVMark _this = args.getThis();
                        return _this.index() * h;
                    }
                }).strokeStyle("#999");

        /* Title bar. */
        cell.add(PV.Bar).height(14).fillStyle("bisque").anchor(CENTER)
                .add(PV.Label).text(new JsStringFunction() {
                    public String f(JsArgs args) {
                        Map.Entry<String, Map<String, List<Barley>>> site = args
                                .getObject();
                        return site.getKey();
                    }
                });

        /* A dot showing the yield. */
        PVDot dot = cell
                .add(PV.Panel)
                .data(new JsFunction<JsArrayGeneric<Entry<String, List<Barley>>>>() {
                    public JsArrayGeneric<Entry<String, List<Barley>>> f(
                            JsArgs args) {
                        Map.Entry<String, Map<String, List<Barley>>> site = args
                                .getObject();
                        return JsUtils.toJsArrayGeneric(site.getValue()
                                .entrySet());
                    }
                }).top(23).add(PV.Dot)
                .data(new JsFunction<JsArrayGeneric<Barley>>() {
                    public JsArrayGeneric<Barley> f(JsArgs args) {
                        Map.Entry<String, List<Barley>> year = args.getObject();
                        return JsUtils.toJsArrayGeneric(year.getValue());
                    }
                }).left(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        Barley d = args.getObject();
                        return x.fd(d.yield);
                    }
                }).top(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        PVMark _this = args.getThis();
                        return _this.index() * 11;
                    }
                }).size(12).lineWidth(2).strokeStyle(new JsFunction<PVColor>() {
                    public PVColor f(JsArgs args) {
                        Barley d = args.getObject();
                        return c.fcolor(d.year);
                    }
                });

        /* A label showing the variety. */
        dot.anchor(LEFT).add(PV.Label).visible(new JsBooleanFunction() {
            public boolean f(JsArgs args) {
                PVMark _this = args.getThis();
                return _this.parent().index() == 0;
            }
        }).left(-1).text(new JsStringFunction() {
            public String f(JsArgs args) {
                Barley d = args.getObject();
                return d.variety;
            }
        });

        /* X-ticks. */
        vis.add(PV.Rule).data(x.ticks(7)).left(x).bottom(-5).height(5)
                .strokeStyle("#999").anchor(BOTTOM).add(PV.Label);

        // /* A legend showing the year. */
        vis.add(PV.Dot).extend(dot).dataInt(1931, 1932)
                .left(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        PVMark _this = args.getThis();
                        return 170 + _this.index() * 40;
                    }
                }).top(-8).strokeStyle(new JsFunction<PVColor>() {
View Full Code Here

Examples of org.thechiselgroup.choosel.protovis.client.jsutil.JsDoubleFunction

        PVPanel vis = getPVPanel().width((size + padding) * traits.length)
                .height((size + padding) * traits.length + padding).left(10)
                .top(5);

        /* One cell per trait pair. */
        JsDoubleFunction panelPosition = new JsDoubleFunction() {
            public double f(JsArgs args) {
                PVPanel _this = args.getThis();
                return _this.index() * (size + padding) + padding / 2;
            }
        };
        final PVPanel cell = vis.add(PV.Panel).data(traits).top(panelPosition)
                .height(size).add(PV.Panel)
                .data(new JsFunction<JsArrayGeneric<TraitPair>>() {
                    public JsArrayGeneric<TraitPair> f(JsArgs args) {
                        String d = args.getObject();
                        JsArrayGeneric<TraitPair> result = JsUtils
                                .createJsArrayGeneric();
                        for (int i = 0; i < traits.length; i++) {
                            result.push(new TraitPair(traits[i], d));
                        }
                        return result;
                    }
                }).left(panelPosition).width(size);

        /* Framed dot plots not along the diagonal. */
        PVPanel plot = cell.add(PV.Panel).visible(new JsBooleanFunction() {
            public boolean f(JsArgs args) {
                TraitPair d = args.getObject(0);
                return !d.px.equals(d.py);
            }
        }).strokeStyle("#aaa");

        /* X-axis ticks. */
        PVRule xtick = plot.add(PV.Rule)
                .data(new JsFunction<JavaScriptObject>() {
                    public JavaScriptObject f(JsArgs args) {
                        TraitPair t = args.getObject();
                        return position.get(t.px).ticks(5);
                    };
                }).left(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        double d = args.getDouble();
                        TraitPair t = args.getObject(1);
                        return position.get(t.px).fd(d);
                    };
                }).strokeStyle("#eee");

        /* Bottom label. */
        xtick.anchor(BOTTOM).add(PV.Label).visible(new JsBooleanFunction() {
            public boolean f(JsArgs args) {
                return (cell.parent().index() == traits.length - 1)
                        && (cell.index() % 2 == 0);
            }
        }).text(new JsStringFunction() {
            public String f(JsArgs args) {
                double d = args.getDouble();
                TraitPair t = args.getObject(1);
                return position.get(t.px).tickFormatDouble(d);
            };
        });

        /* Top label. */
        xtick.anchor(TOP).add(PV.Label).visible(new JsBooleanFunction() {
            public boolean f(JsArgs args) {
                return (cell.parent().index() == 0) && (cell.index() % 2 == 1);
            }
        }).text(new JsStringFunction() {
            public String f(JsArgs args) {
                double d = args.getDouble(0);
                TraitPair t = args.getObject(1);
                return position.get(t.px).tickFormatDouble(d);
            };
        });

        /* Y-axis ticks. */
        PVRule ytick = plot.add(PV.Rule)
                .data(new JsFunction<JavaScriptObject>() {
                    public JavaScriptObject f(JsArgs args) {
                        TraitPair t = args.getObject(0);
                        return position.get(t.py).ticks(5);
                    };
                }).bottom(new JsDoubleFunction() {
                    public double f(JsArgs args) {
                        double d = args.getDouble(0);
                        TraitPair t = args.getObject(1);
                        return position.get(t.py).fd(d);
                    };
                }).strokeStyle("#eee");

        /* Left label. */
        ytick.anchor(LEFT).add(PV.Label).visible(new JsBooleanFunction() {
            public boolean f(JsArgs args) {
                return (cell.index() == 0) && (cell.parent().index() % 2 == 1);
            }
        }).text(new JsStringFunction() {
            public String f(JsArgs args) {
                double d = args.getDouble(0);
                TraitPair t = args.getObject(1);
                return position.get(t.py).tickFormatDouble(d);
            };
        });

        /* Right label. */
        ytick.anchor(RIGHT).add(PV.Label).visible(new JsBooleanFunction() {
            public boolean f(JsArgs args) {
                return (cell.index() == traits.length - 1)
                        && (cell.parent().index() % 2 == 0);
            }
        }).text(new JsStringFunction() {
            public String f(JsArgs args) {
                double d = args.getDouble(0);
                TraitPair t = args.getObject(1);
                return position.get(t.py).tickFormatDouble(d);
            };
        });

        /* Frame and dot plot. */
        plot.add(PV.Dot).data(flowers).left(new JsDoubleFunction() {
            public double f(JsArgs args) {
                Flower d = args.getObject(0);
                TraitPair t = args.getObject(1);
                return position.get(t.px).fd(d.getTraitValue(t.px));
            };
        }).bottom(new JsDoubleFunction() {
            public double f(JsArgs args) {
                Flower d = args.getObject(0);
                TraitPair t = args.getObject(1);
                return position.get(t.py).fd(d.getTraitValue(t.py));
            };
        }).size(10).strokeStyle((String) null)
                .fillStyle(new JsFunction<PVColor>() {
                    public PVColor f(JsArgs args) {
                        Flower d = args.getObject(0);
                        return color.fcolor(d.species);
                    }
                });

        /* Labels along the diagonal. */
        cell.anchor(CENTER).add(PV.Label).visible(new JsBooleanFunction() {
            public boolean f(JsArgs args) {
                TraitPair t = args.getObject(0);
                return t.px.equals(t.py);
            }
        }).font("bold 14px sans-serif").text(new JsStringFunction() {
            public String f(JsArgs args) {
                TraitPair t = args.getObject(0);
                return t.px;
            }
        });

        /* Legend. */
        vis.add(PV.Dot).data(species).bottom(10).left(new JsDoubleFunction() {
            public double f(JsArgs args) {
                PVMark _this = args.getThis();
                return 15 + _this.index() * 65;
            }
        }).size(8).strokeStyle((String) null)
View Full Code Here

Examples of org.thechiselgroup.choosel.protovis.client.jsutil.JsDoubleFunction

        getPVPanel().render();
    }

    private void putTraitScale(final Map<String, PVLinearScale> position,
            Flower[] flowers, final String trait, final int size) {
        position.put(trait, PV.Scale.linear(flowers, new JsDoubleFunction() {
            public double f(JsArgs args) {
                Flower d = args.getObject(0);
                return d.getTraitValue(trait);
            }
        }).range(0, size));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.