Example usage for org.w3c.dom Element setAttributeNS

List of usage examples for org.w3c.dom Element setAttributeNS

Introduction

In this page you can find the example usage for org.w3c.dom Element setAttributeNS.

Prototype

public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException;

Source Link

Document

Adds a new attribute.

Usage

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Returns a chart title element containing the input text.
 * /*from  w  ww .  ja va2s .com*/
 * @param chartTitle
 * @return chartTitleElement
 */
private Element getChartTitle(String chartTitle) {

    Text chartTitleText = doc.createTextNode(chartTitle);
    Integer chartTitleFontSize = App.prefs.getIntPref(PrefKey.CHART_TITLE_FONT_SIZE, 20);

    Element chartTitleElement = doc.createElementNS(svgNS, "text");
    chartTitleElement.setAttributeNS(null, "x", "0");
    chartTitleElement.setAttributeNS(null, "y", "0");
    chartTitleElement.setAttributeNS(null, "font-family",
            App.prefs.getPref(PrefKey.CHART_FONT_FAMILY, "Verdana"));
    chartTitleElement.setAttributeNS(null, "font-size", chartTitleFontSize.toString());
    chartTitleElement.appendChild(chartTitleText);

    return chartTitleElement;
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Gets the index plot as an element.//from ww  w  .j  av  a  2 s.  c  o m
 * 
 * @return indexPlot
 */
private Element getIndexPlot() {

    int indexPlotOffsetAmount = 0;

    if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_CHART_TITLE, true)) {
        indexPlotOffsetAmount = App.prefs.getIntPref(PrefKey.CHART_TITLE_FONT_SIZE, 20) + 10;
    }

    Element indexPlot = doc.createElementNS(svgNS, "g");
    indexPlot.setAttribute("id", "indexplot");
    indexPlot.setAttributeNS(null, "transform", "translate(0," + indexPlotOffsetAmount + ")");
    indexPlot.appendChild(getSampleOrRecorderDepthsPlot(
            App.prefs.getBooleanPref(PrefKey.CHART_SHOW_SAMPLE_DEPTH, false),
            App.prefs.getEventTypePref(PrefKey.CHART_COMPOSITE_EVENT_TYPE, EventTypeToProcess.FIRE_EVENT)));
    indexPlot.appendChild(getPercentScarredPlot());

    return indexPlot;
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Gets the chronology plot as an element.
 * //  w  w  w . j a v a  2 s .  co m
 * @return chronologyPlot
 */
private Element getChronologyPlot() {

    Element chronologyPlot = doc.createElementNS(svgNS, "g");
    chronologyPlot.setAttributeNS(null, "id", "chronology_plot");
    chronologyPlot.setAttributeNS(null, "display", "inline");

    // Build all of the series
    ArrayList<Boolean> series_visible = new ArrayList<Boolean>();

    this.showPith = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_PITH_SYMBOL, true);
    this.showBark = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_BARK_SYMBOL, true);
    this.showFires = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_FIRE_EVENT_SYMBOL, true);
    this.showInjuries = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_INJURY_SYMBOL, true);
    this.showInnerRing = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_INNER_RING_SYMBOL, true);
    this.showOuterRing = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_OUTER_RING_SYMBOL, true);
    int fontSize = App.prefs.getIntPref(PrefKey.CHART_CHRONOLOGY_PLOT_LABEL_FONT_SIZE, 8);

    String longestLabel = "A";
    for (int i = 0; i < seriesSVGList.size(); i++) {
        FHSeries series = seriesSVGList.get(i);
        if (series.getTitle().length() > longestLabel.length())
            longestLabel = series.getTitle();
    }

    widestChronologyLabelSize = FireChartUtil.getStringWidth(Font.PLAIN,
            App.prefs.getIntPref(PrefKey.CHART_CHRONOLOGY_PLOT_LABEL_FONT_SIZE, 10), longestLabel);

    // Define a string for keeping track of the category groups
    ArrayList<String> categoryGroupsProcessed = new ArrayList<String>();

    for (int i = 0; i < seriesSVGList.size(); i++) {
        if (lastTypeSortedBy == SeriesSortType.CATEGORY
                && App.prefs.getBooleanPref(PrefKey.CHART_SHOW_CATEGORY_GROUPS, true)) {
            String currentCategoryGroup = seriesSVGList.get(i).getCategoryEntries().get(0).getContent();

            // Keep track of which category groups have already been processed
            if (!categoryGroupsProcessed.contains(currentCategoryGroup)) {
                categoryGroupsProcessed.add(currentCategoryGroup);
            }

            // Apply the series coloring as necessary
            if (App.prefs.getBooleanPref(PrefKey.CHART_AUTOMATICALLY_COLORIZE_SERIES, false)) {
                seriesSVGList.get(i)
                        .setLabelColor(FireChartUtil.pickColorFromInteger(categoryGroupsProcessed.size()));
                seriesSVGList.get(i)
                        .setLineColor(FireChartUtil.pickColorFromInteger(categoryGroupsProcessed.size()));
            } else {
                seriesSVGList.get(i).setLabelColor(Color.BLACK);
                seriesSVGList.get(i).setLineColor(Color.BLACK);
            }
        }

        FHSeriesSVG seriesSVG = seriesSVGList.get(i);
        series_visible.add(true);

        Element series_group = doc.createElementNS(svgNS, "g");
        series_group.setAttributeNS(null, "id", "series_group_" + seriesSVG.getTitle());

        // Add in the series group, which has the lines and ticks
        Element series_line = buildSingleSeriesLine(seriesSVG);
        series_line.setAttributeNS(null, "id", "series_line_" + seriesSVG.getTitle());
        int x_offset = applyBCYearOffset(seriesSVG.getFirstYear()) - getFirstChartYear();
        String translate_string = "translate(" + Integer.toString(x_offset) + ",0)";
        String scale_string = "scale("
                + FireChartUtil.yearsToPixels(chartWidth, getFirstChartYear(), getLastChartYear()) + ",1)";
        series_line.setAttributeNS(null, "transform", scale_string + " " + translate_string);

        // Add in the label for the series
        Element series_name = seriesEB.getSeriesNameTextElement(seriesSVG, fontSize);

        // Add in the up button
        Element up_button_g = doc.createElementNS(svgNS, "g");
        up_button_g.setAttributeNS(null, "id", "up_button" + i);
        up_button_g.setAttributeNS(null, "class", "no_export");
        up_button_g.setAttributeNS(null, "transform",
                "translate(" + Double.toString(chartWidth + 15 + widestChronologyLabelSize) + ",-2)");
        up_button_g.setAttributeNS(null, "onclick", "FireChartSVG.getChart(chart_num).moveSeriesUp(\""
                + seriesSVG.getTitle() + "\"); evt.target.setAttribute('opacity', '0.2');");
        up_button_g.setAttributeNS(null, "onmouseover", "evt.target.setAttribute('opacity', '1');");
        up_button_g.setAttributeNS(null, "onmouseout", "evt.target.setAttribute('opacity', '0.2');");
        up_button_g.appendChild(seriesEB.getUpButton());

        // Add in the down button
        Element down_button_g = doc.createElementNS(svgNS, "g");
        down_button_g.setAttributeNS(null, "id", "down_button" + i);
        down_button_g.setAttributeNS(null, "class", "no_export");
        down_button_g.setAttributeNS(null, "transform",
                "translate(" + Double.toString(chartWidth + 10 + widestChronologyLabelSize + 15) + ",-2)");
        down_button_g.setAttributeNS(null, "onclick", "FireChartSVG.getChart(chart_num).moveSeriesDown(\""
                + seriesSVG.getTitle() + "\"); evt.target.setAttribute('opacity', '0.2');");
        down_button_g.setAttributeNS(null, "onmouseover", "evt.target.setAttribute('opacity', '1');");
        down_button_g.setAttributeNS(null, "onmouseout", "evt.target.setAttribute('opacity', '0.2');");
        down_button_g.appendChild(seriesEB.getDownButton());

        // Determine whether to draw the chronology plot labels
        if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_CHRONOLOGY_PLOT_LABELS, true)) {
            if (lastTypeSortedBy == SeriesSortType.CATEGORY
                    && App.prefs.getBooleanPref(PrefKey.CHART_SHOW_CATEGORY_GROUPS, true)) {
                // Do not show the up/down buttons if grouping series by category
                up_button_g.setAttributeNS(null, "display", "none");
                down_button_g.setAttributeNS(null, "display", "none");
            } else {
                series_name.setAttributeNS(null, "display", "inline");
                up_button_g.setAttributeNS(null, "display", "inline");
                down_button_g.setAttributeNS(null, "display", "inline");
            }
        } else {
            series_name.setAttributeNS(null, "display", "none");
            up_button_g.setAttributeNS(null, "display", "none");
            down_button_g.setAttributeNS(null, "display", "none");
        }

        series_group.appendChild(series_line);
        series_group.appendChild(series_name);
        series_group.appendChild(up_button_g);
        series_group.appendChild(down_button_g);
        chronologyPlot.appendChild(series_group);
    }

    if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_CHRONOLOGY_PLOT, true)) {
        chronologyPlot.setAttributeNS(null, "display", "inline");
    } else {
        chronologyPlot.setAttributeNS(null, "display", "none");
    }

    return chronologyPlot;
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Get the composite plot as an element.
 * /*from w w  w .jav  a  2s .  c om*/
 * @return compositePlot
 */
private Element getCompositePlot() {

    boolean useAbbreviatedYears = App.prefs.getBooleanPref(PrefKey.CHART_COMPOSITE_YEAR_LABELS_TWO_DIGIT,
            false);

    String textStr = "2099";

    if (useAbbreviatedYears) {
        textStr = "'99";
    }

    int compositeYearLabelFontSize = App.prefs.getIntPref(PrefKey.CHART_COMPOSITE_YEAR_LABEL_FONT_SIZE, 8);
    int rotateLabelsAngle = App.prefs
            .getLabelOrientationPref(PrefKey.CHART_COMPOSITE_LABEL_ALIGNMENT, LabelOrientation.HORIZONTAL)
            .getAngle();
    int stringbuffer = App.prefs.getIntPref(PrefKey.CHART_COMPOSITE_YEAR_LABEL_BUFFER, 5);

    int compositeYearLabelMaxWidth = 0;
    int compositeYearLabelHeight = 0;

    if (rotateLabelsAngle == 0) {
        compositeYearLabelMaxWidth = FireChartUtil.getStringWidth(Font.PLAIN, compositeYearLabelFontSize,
                textStr) + stringbuffer;
        compositeYearLabelHeight = FireChartUtil.getStringHeight(Font.PLAIN, compositeYearLabelFontSize,
                textStr);
    } else if (rotateLabelsAngle == 315) {
        int width = FireChartUtil.getStringWidth(Font.PLAIN, compositeYearLabelFontSize, textStr);

        double widthsq = width * width;
        double hyp = Math.sqrt(widthsq + widthsq);

        compositeYearLabelMaxWidth = (int) ((hyp + stringbuffer)) / 2;
        compositeYearLabelHeight = (int) hyp;
    } else {
        compositeYearLabelMaxWidth = FireChartUtil.getStringHeight(Font.PLAIN, compositeYearLabelFontSize,
                textStr);
        compositeYearLabelHeight = FireChartUtil.getStringWidth(Font.PLAIN, compositeYearLabelFontSize, textStr)
                + stringbuffer;
    }

    // compositePlot is centered off of the year 0 A.D.
    Element compositePlot = doc.createElementNS(svgNS, "g");
    compositePlot.setAttributeNS(null, "id", "comp_plot");
    compositePlot.setAttributeNS(null, "transform",
            "scale(" + FireChartUtil.yearsToPixels(chartWidth, getFirstChartYear(), getLastChartYear()) + ","
                    + 1 + ") translate(-" + getFirstChartYear() + ",0) ");

    // draw the vertical lines for fire years
    ArrayList<Integer> composite_years = reader.getCompositeFireYears(
            App.prefs.getEventTypePref(PrefKey.CHART_COMPOSITE_EVENT_TYPE, EventTypeToProcess.FIRE_EVENT),
            App.prefs.getFireFilterTypePref(PrefKey.CHART_COMPOSITE_FILTER_TYPE,
                    FireFilterType.NUMBER_OF_EVENTS),
            App.prefs.getIntPref(PrefKey.CHART_COMPOSITE_FILTER_VALUE, 1),
            App.prefs.getIntPref(PrefKey.CHART_COMPOSITE_MIN_NUM_SAMPLES, 1),
            App.prefs.getSampleDepthFilterTypePref(PrefKey.CHART_COMPOSITE_SAMPLE_DEPTH_TYPE,
                    SampleDepthFilterType.MIN_NUM_SAMPLES));

    // Remove out-of-range years if necessary
    if (!App.prefs.getBooleanPref(PrefKey.CHART_AXIS_X_AUTO_RANGE, true)) {
        ArrayList<Integer> composite_years2 = new ArrayList<Integer>();
        for (Integer v : composite_years) {
            if (v > this.getLastChartYear() || v < this.getFirstChartYear())
                continue;

            composite_years2.add(v);
        }

        composite_years = composite_years2;
    }

    int overlap_margin = (compositeYearLabelMaxWidth);
    int cur_offset_level = 0;
    int prev_i = 0;
    int max_offset_level = 0;

    // run through the array once to see how many layers we need to keep year labels from overlapping
    boolean showLabels = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_COMPOSITE_YEAR_LABELS, true);
    if (showLabels) {
        for (int i : composite_years) {
            double pixelsBetweenLabels = FireChartUtil.yearsToPixels(i, chartWidth, getFirstChartYear(),
                    getLastChartYear())
                    - FireChartUtil.yearsToPixels(prev_i, chartWidth, getFirstChartYear(), getLastChartYear());

            if (pixelsBetweenLabels < overlap_margin) {
                cur_offset_level = cur_offset_level + 1;
                if (cur_offset_level > max_offset_level) {
                    max_offset_level = cur_offset_level;
                }
            } else {
                cur_offset_level = 0;
                prev_i = i;
            }
        }
    } else {
        cur_offset_level = 0;
    }

    int num_layers = max_offset_level + 1;
    // int num_layers = (max_offset_level > 0) ? max_offset_level : 1; // number of layers for putting the offset year labels
    double chart_height = App.prefs.getIntPref(PrefKey.CHART_COMPOSITE_HEIGHT, 70);

    if (num_layers > (chart_height / compositeYearLabelFontSize)) {
        // ensure height is non-negative
        num_layers = (int) Math.floor(chart_height / compositeYearLabelHeight);
    }

    if (showLabels) {
        if (rotateLabelsAngle == 315) {
            chart_height = chart_height - (num_layers * (compositeYearLabelHeight / 3));
        } else {
            // height of the composite plot minus the year labels
            chart_height = chart_height - (num_layers * compositeYearLabelHeight);
        }
    }

    cur_offset_level = 0;
    prev_i = 0;
    for (int i : composite_years) {
        compositePlot.appendChild(compositePlotEB.getEventLine(i, chart_height));

        // calculate the offsets for the labels
        if (FireChartUtil.yearsToPixels(i - prev_i, chartWidth, getFirstChartYear(),
                getLastChartYear()) < overlap_margin) {
            cur_offset_level = (cur_offset_level + 1) % num_layers;
        } else {
            cur_offset_level = 0;
        }

        Element text_g = doc.createElementNS(svgNS, "g");
        String scale_str = "scale("
                + FireChartUtil.pixelsToYears(chartWidth, getFirstChartYear(), getLastChartYear()) + ", 1)";

        if (rotateLabelsAngle == 270) {
            double offset = chart_height + (cur_offset_level * compositeYearLabelHeight)
                    + compositeYearLabelHeight;
            String translate_str = "translate("
                    + (Double.toString(i + (FireChartUtil.pixelsToYears(compositeYearLabelMaxWidth / 2,
                            chartWidth, getFirstChartYear(), getLastChartYear()))))
                    + "," + offset + ")";
            text_g.setAttributeNS(null, "transform",
                    translate_str + scale_str + " rotate(" + rotateLabelsAngle + ")");
        } else if (rotateLabelsAngle == 315) {
            double offset = chart_height + (cur_offset_level * (compositeYearLabelHeight / 3))
                    + compositeYearLabelHeight / 1.3;
            String translate_str = "translate("
                    + (Double.toString(i - (FireChartUtil.pixelsToYears(compositeYearLabelMaxWidth / 2,
                            chartWidth, getFirstChartYear(), getLastChartYear()))))
                    + "," + offset + ")";
            text_g.setAttributeNS(null, "transform",
                    translate_str + scale_str + " rotate(" + rotateLabelsAngle + ")");
        } else {
            double offset = chart_height + (cur_offset_level * compositeYearLabelHeight)
                    + compositeYearLabelHeight;
            String translate_str = "translate("
                    + (Double.toString(i - (FireChartUtil.pixelsToYears(compositeYearLabelMaxWidth / 2,
                            chartWidth, getFirstChartYear(), getLastChartYear()))))
                    + "," + offset + ")";
            text_g.setAttributeNS(null, "transform", translate_str + scale_str);
        }

        // Grab label string depending on style
        String year_str = "";
        if (useAbbreviatedYears) {
            year_str = "'";
            if (i % 100 < 10) {
                year_str += "0";
            }
            year_str += Integer.toString(i % 100);
        } else {
            year_str = Integer.toString(i);
        }

        Text year_text_t = doc.createTextNode(year_str);
        Element year_text = doc.createElementNS(svgNS, "text");
        // year_text.setAttributeNS(null, "x", Integer.toString(i));
        // year_text.setAttributeNS(null, "x", "0");
        // year_text.setAttributeNS(null, "y", "0");
        year_text.setAttributeNS(null, "font-family", App.prefs.getPref(PrefKey.CHART_FONT_FAMILY, "Verdana"));
        year_text.setAttributeNS(null, "font-size", Integer.toString(compositeYearLabelFontSize));

        if (showLabels) {
            year_text.appendChild(year_text_t);
            text_g.appendChild(year_text);
        }

        compositePlot.appendChild(text_g);
        prev_i = i;
    }

    // Draw a rectangle around it
    // Needs to be 4 lines to cope with stroke width in different coord sys in x and y
    compositePlot.appendChild(compositePlotEB.getBorderLine1());
    compositePlot.appendChild(compositePlotEB.getBorderLine2(chart_height));
    compositePlot.appendChild(compositePlotEB.getBorderLine3(chart_height));
    compositePlot.appendChild(compositePlotEB.getBorderLine4(chart_height));

    // add the label
    String translate_string = "translate("
            + Double.toString(getLastChartYear()
                    + FireChartUtil.pixelsToYears(10, chartWidth, getFirstChartYear(), getLastChartYear()))
            + ", "
            + ((chart_height / 2) + (FireChartUtil.getStringHeight(Font.PLAIN,
                    App.prefs.getIntPref(PrefKey.CHART_COMPOSITE_PLOT_LABEL_FONT_SIZE, 10),
                    App.prefs.getPref(PrefKey.CHART_COMPOSITE_LABEL_TEXT, "Composite"))) / 2)
            + ")";
    String scale_string = "scale("
            + FireChartUtil.pixelsToYears(chartWidth, getFirstChartYear(), getLastChartYear()) + ", 1)";

    Element comp_name_text_g = doc.createElementNS(svgNS, "g");
    comp_name_text_g.setAttributeNS(null, "transform", translate_string + scale_string);
    comp_name_text_g.appendChild(compositePlotEB.getCompositeLabelTextElement());
    compositePlot.appendChild(comp_name_text_g);

    if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_COMPOSITE_PLOT, true)) {
        compositePlot.setAttributeNS(null, "display", "inline");
    } else {
        compositePlot.setAttributeNS(null, "display", "none");
    }

    return compositePlot;
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * This function creates a legend dynamically, based on the current event(s) displayed on the canvas (Fire, Injury, or Fire and Injury).
 * /*from  w w w  .ja v  a 2s.c o m*/
 * @return legend
 */
private Element getLegend() {

    int labelWidth = FireChartUtil.getStringWidth(Font.PLAIN, 8, "Outer year without bark") + 40;
    int labelHeight = FireChartUtil.getStringHeight(Font.PLAIN, 8, "Outer year without bark");
    int currentY = 0; // to help position symbols
    int moveValue = 20;
    int leftJustified = 20;

    Element legend = doc.createElementNS(svgNS, "g");
    legend.setAttributeNS(null, "id", "legend");
    // legend.setAttributeNS(null, "transform", "translate(" + chart_width + ", " + 200 + ")");

    // make a "g" for each element, and append to that, so each element is
    // in a group. then append groups to legend. This is so when the legend moves,
    // you wont have to manually move all the other elements again.

    // Get current symbols on canvas and append to legend

    // RECORDER YEAR
    Element recorder_g = doc.createElementNS(svgNS, "g");
    recorder_g.setAttributeNS(null, "id", "recorder");
    recorder_g.appendChild(legendEB.getRecorderYearExample());
    Element recorder_desc = legendEB.getDescriptionTextElement("Recorder year", leftJustified,
            currentY + (labelHeight / 2));
    recorder_g.appendChild(recorder_desc);
    legend.appendChild(recorder_g);

    // NON-RECORDER YEAR
    currentY += moveValue;
    Element nonrecorder_g = doc.createElementNS(svgNS, "g");
    nonrecorder_g.appendChild(legendEB.getNonRecorderYearExample(currentY));
    Element nonrecorder_desc = legendEB.getDescriptionTextElement("Non-recorder year", leftJustified,
            currentY + (labelHeight / 2));
    nonrecorder_g.appendChild(nonrecorder_desc);
    legend.appendChild(nonrecorder_g);

    // currentY += moveValue * 2; // so next symbol is at spot y = 100

    if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_FIRE_EVENT_SYMBOL, true)) {
        // FIRE EVENT MARKER
        currentY += moveValue;
        Element fireMarker_g = doc.createElementNS(svgNS, "g");
        Element fireMarker = seriesEB.getFireYearMarker(Color.BLACK);
        fireMarker.setAttributeNS(null, "width", "2");
        fireMarker_g.appendChild(fireMarker);
        fireMarker_g.setAttributeNS(null, "transform", "translate(0, " + currentY + ")");
        Element fireMarker_desc = legendEB.getDescriptionTextElement("Fire event", leftJustified,
                (labelHeight / 2));
        fireMarker_g.appendChild(fireMarker_desc);
        legend.appendChild(fireMarker_g);
    }

    if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_INJURY_SYMBOL, true)) {
        // INJURY EVENT MARKER
        currentY += moveValue;
        Element injuryMarker_g = doc.createElementNS(svgNS, "g");
        injuryMarker_g.appendChild(seriesEB.getInjuryYearMarker(3, Color.BLACK));
        injuryMarker_g.setAttributeNS(null, "transform", "translate(0, " + Integer.toString(currentY) + ")");
        Element injuryMarker_desc = legendEB.getDescriptionTextElement("Injury event", leftJustified,
                (labelHeight / 2));
        injuryMarker_g.appendChild(injuryMarker_desc);
        legend.appendChild(injuryMarker_g);
    }

    // PITH WITH NON-RECORDER LINE
    currentY += moveValue;
    Element innerPith_g = doc.createElementNS(svgNS, "g");
    Element innerPith = seriesEB.getInnerYearPithMarker(true, 5, Color.BLACK);
    innerPith_g.appendChild(innerPith);
    innerPith_g.setAttributeNS(null, "transform", "translate(0, " + Integer.toString(currentY) + ")");
    Element pithNonrecorder_g = doc.createElementNS(svgNS, "g");
    pithNonrecorder_g.appendChild(legendEB.getPithWithNonRecorderLineExample());
    innerPith_g.appendChild(pithNonrecorder_g);
    Element pithNonrecorder_desc = legendEB.getDescriptionTextElement("Inner year with pith", leftJustified,
            (labelHeight / 2));
    innerPith_g.appendChild(pithNonrecorder_desc);
    legend.appendChild(innerPith_g);

    // NO PITH WITH NON-RECORDER LINE
    currentY += moveValue;
    Element withoutPith_g = doc.createElementNS(svgNS, "g");
    Element withoutPith = seriesEB.getInnerYearPithMarker(false, SERIES_HEIGHT, Color.BLACK);
    withoutPith_g.appendChild(withoutPith);
    withoutPith_g.setAttributeNS(null, "transform", "translate(0, " + Integer.toString(currentY) + ")");
    Element withoutPithNonrecorder_g = doc.createElementNS(svgNS, "g");
    withoutPithNonrecorder_g.appendChild(legendEB.getNoPithWithNonRecorderLineExample());
    withoutPith_g.appendChild(withoutPithNonrecorder_g);
    Element withoutPithNonrecorder_desc = legendEB.getDescriptionTextElement("Inner year without pith",
            leftJustified, (labelHeight / 2));
    withoutPith_g.appendChild(withoutPithNonrecorder_desc);
    legend.appendChild(withoutPith_g);

    // BARK WITH RECORDER LINE
    currentY += moveValue;
    Element withBark_g = doc.createElementNS(svgNS, "g");
    Element withBark = seriesEB.getOuterYearBarkMarker(true, 5, Color.BLACK);
    withBark_g.appendChild(withBark);
    withBark_g.setAttributeNS(null, "transform", "translate(5, " + Integer.toString(currentY) + ")");
    Element barkRecorder_g = doc.createElementNS(svgNS, "g");
    barkRecorder_g.appendChild(legendEB.getBarkWithRecorderLineExample());
    withBark_g.appendChild(barkRecorder_g);
    Element barkRecorder_desc = legendEB.getDescriptionTextElement("Outer year with bark", leftJustified - 5,
            (labelHeight / 2));
    withBark_g.appendChild(barkRecorder_desc);
    legend.appendChild(withBark_g);

    // NO BARK WITH RECORDER LINE
    currentY += moveValue;
    Element withoutBark_g = doc.createElementNS(svgNS, "g");
    Element withoutBark = seriesEB.getOuterYearBarkMarker(false, SERIES_HEIGHT, Color.BLACK);
    withoutBark_g.appendChild(withoutBark);
    withoutBark_g.setAttributeNS(null, "transform", "translate(5, " + Integer.toString(currentY) + ")");
    Element withoutBarkRecorder_g = doc.createElementNS(svgNS, "g");
    withoutBarkRecorder_g.appendChild(legendEB.getNoBarkWithRecorderLineExample());
    withoutBark_g.appendChild(withoutBarkRecorder_g);
    Element withoutBarkRecorder_desc = legendEB.getDescriptionTextElement("Outer year without bark",
            leftJustified - 5, (labelHeight / 2));
    withoutBark_g.appendChild(withoutBarkRecorder_desc);
    legend.appendChild(withoutBark_g);

    // ADD FILTER DETAILS
    if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_FILTER_IN_LEGEND, false)) {
        String s = "";
        String longestLabel = s;
        if (App.prefs.getEventTypePref(PrefKey.CHART_COMPOSITE_EVENT_TYPE, EventTypeToProcess.FIRE_EVENT)
                .equals(EventTypeToProcess.FIRE_EVENT)) {
            currentY += moveValue + (labelHeight * 1.3);
            s = StringUtils.capitalize("Composite based on " + App.prefs
                    .getEventTypePref(PrefKey.CHART_COMPOSITE_EVENT_TYPE, EventTypeToProcess.FIRE_EVENT)
                    .toString().toLowerCase() + " and filtered by:");
            Element filterType = legendEB.getDescriptionTextElement(s, leftJustified, (labelHeight / 2));
            filterType.setAttributeNS(null, "transform", "translate(-25, " + Integer.toString(currentY) + ")");
            legend.appendChild(filterType);
            longestLabel = s;
        } else if (App.prefs
                .getEventTypePref(PrefKey.CHART_COMPOSITE_EVENT_TYPE, EventTypeToProcess.FIRE_AND_INJURY_EVENT)
                .equals(EventTypeToProcess.FIRE_AND_INJURY_EVENT)) {
            currentY += moveValue + (labelHeight * 1.3);
            s = StringUtils.capitalize("Composite based on " + App.prefs
                    .getEventTypePref(PrefKey.CHART_COMPOSITE_EVENT_TYPE, EventTypeToProcess.FIRE_EVENT)
                    .toString().toLowerCase());
            Element filterType = legendEB.getDescriptionTextElement(s, leftJustified, (labelHeight / 2));
            filterType.setAttributeNS(null, "transform", "translate(-25, " + Integer.toString(currentY) + ")");
            legend.appendChild(filterType);

            currentY += labelHeight * 1.3;
            filterType = legendEB.getDescriptionTextElement("and filtered by:", leftJustified,
                    (labelHeight / 2));
            filterType.setAttributeNS(null, "transform", "translate(-25, " + Integer.toString(currentY) + ")");
            legend.appendChild(filterType);

            longestLabel = s;
        } else if (App.prefs
                .getEventTypePref(PrefKey.CHART_COMPOSITE_EVENT_TYPE, EventTypeToProcess.INJURY_EVENT)
                .equals(EventTypeToProcess.INJURY_EVENT)) {
            currentY += moveValue + (labelHeight * 1.3);
            s = StringUtils.capitalize("Composite based on " + App.prefs
                    .getEventTypePref(PrefKey.CHART_COMPOSITE_EVENT_TYPE, EventTypeToProcess.FIRE_EVENT)
                    .toString().toLowerCase() + " and filtered by:");
            Element filterType = legendEB.getDescriptionTextElement(s, leftJustified, (labelHeight / 2));
            filterType.setAttributeNS(null, "transform", "translate(-25, " + Integer.toString(currentY) + ")");
            legend.appendChild(filterType);
            longestLabel = s;
        }

        currentY += labelHeight * 1.3;
        s = " - " + StringUtils.capitalize(App.prefs
                .getFireFilterTypePref(PrefKey.CHART_COMPOSITE_FILTER_TYPE, FireFilterType.NUMBER_OF_EVENTS)
                .toString().toLowerCase() + " >= "
                + App.prefs.getIntPref(PrefKey.CHART_COMPOSITE_FILTER_VALUE, 1));
        Element filterType = legendEB.getDescriptionTextElement(s, leftJustified, (labelHeight / 2));
        filterType.setAttributeNS(null, "transform", "translate(-25, " + Integer.toString(currentY) + ")");
        legend.appendChild(filterType);
        if (s.length() > longestLabel.length())
            longestLabel = s;

        currentY += labelHeight * 1.3;
        s = " - " + StringUtils
                .capitalize(App.prefs.getSampleDepthFilterTypePref(PrefKey.CHART_COMPOSITE_SAMPLE_DEPTH_TYPE,
                        SampleDepthFilterType.MIN_NUM_SAMPLES).toString().toLowerCase() + " >= "
                        + App.prefs.getIntPref(PrefKey.CHART_COMPOSITE_MIN_NUM_SAMPLES, 1));
        filterType = legendEB.getDescriptionTextElement(s, leftJustified, (labelHeight / 2));
        filterType.setAttributeNS(null, "transform", "translate(-25, " + Integer.toString(currentY) + ")");
        legend.appendChild(filterType);

        labelWidth = FireChartUtil.getStringWidth(Font.PLAIN, 8, longestLabel) + 10;
    }

    // Add rectangle around legend and append
    legend.setAttributeNS(null, "transform", "scale(1.0)");
    legend.appendChild(legendEB.getChartRectangle(labelWidth, currentY));

    // Only show the chart if the preference has been set to do so
    if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_LEGEND, true)) {
        legend.setAttributeNS(null, "display", "inline");
    } else {
        legend.setAttributeNS(null, "display", "none");
    }

    return legend;
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Get the time axis including the guide and highlight lines.
 * /*from w  w w.j a v a2 s  . c o  m*/
 * @param height
 * @return
 */
private Element getTimeAxis(int height) {

    // Time axis is centered off of the first year in the reader
    Element timeAxis = doc.createElementNS(svgNS, "g");
    String scale = "scale(" + FireChartUtil.yearsToPixels(chartWidth, getFirstChartYear(), getLastChartYear())
            + ",1)";
    timeAxis.setAttributeNS(null, "transform", scale + " translate(-" + this.getFirstChartYear() + ",0)");
    int majorTickInterval = App.prefs.getIntPref(PrefKey.CHART_XAXIS_MAJOR_TICK_SPACING, 50);
    int minorTickInterval = App.prefs.getIntPref(PrefKey.CHART_XAXIS_MINOR_TICK_SPACING, 10);
    boolean majorTicks = App.prefs.getBooleanPref(PrefKey.CHART_XAXIS_MAJOR_TICKS, true);
    boolean minorTicks = App.prefs.getBooleanPref(PrefKey.CHART_XAXIS_MINOR_TICKS, true);
    boolean vertGuides = App.prefs.getBooleanPref(PrefKey.CHART_VERTICAL_GUIDES, true);
    ArrayList<Integer> years = App.prefs.getIntegerArrayPref(PrefKey.CHART_HIGHLIGHT_YEARS_ARRAY, null);

    // Add highlight lines
    if (years != null && App.prefs.getBooleanPref(PrefKey.CHART_HIGHLIGHT_YEARS, false)) {
        for (Integer i : years) {
            // Don't plot out of range years
            if (i > this.getLastChartYear() || i < this.getFirstChartYear())
                continue;

            timeAxis.appendChild(timeAxisEB.getHighlightLine(i, height));
        }
    }

    for (int i = getFirstChartYear(); i < getLastChartYear(); i++) {
        if (i % majorTickInterval == 0) { // year is a multiple of tickInterval
            if (vertGuides) {
                int vertGuidesOffsetAmount = 0;

                if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_CHART_TITLE, true)) {
                    vertGuidesOffsetAmount = App.prefs.getIntPref(PrefKey.CHART_TITLE_FONT_SIZE, 20) + 10;
                }

                timeAxis.appendChild(timeAxisEB.getVerticalGuide(i, vertGuidesOffsetAmount, height));
            }

            if (majorTicks) {
                timeAxis.appendChild(timeAxisEB.getMajorTick(i, height));
            }

            Element year_text_g = doc.createElementNS(svgNS, "g");

            year_text_g.setAttributeNS(null, "transform", "translate(" + i + "," + height + ") scale("
                    + FireChartUtil.pixelsToYears(chartWidth, getFirstChartYear(), getLastChartYear()) + ",1)");

            year_text_g.appendChild(timeAxisEB.getYearTextElement(removeBCYearOffset(i)));

            timeAxis.appendChild(year_text_g);
        }

        if (minorTicks && i % minorTickInterval == 0) // && i % tickInterval != 0)
        {
            timeAxis.appendChild(timeAxisEB.getMinorTick(i, height));
        }
    }

    timeAxis.appendChild(timeAxisEB.getTimeAxis(height));

    return timeAxis;
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Get the percent scarred plot including bounding box and y2 axis.
 * //from www . j  a va  2  s  .  c  om
 * @return
 */
private Element getPercentScarredPlot() {

    // determine y scaling
    double scale_y = -1 * ((double) App.prefs.getIntPref(PrefKey.CHART_INDEX_PLOT_HEIGHT, 100)) / (100);
    double unscale_y = 1 / scale_y;

    Element scarred_g = doc.createElementNS(svgNS, "g");
    scarred_g.setAttributeNS(null, "id", "scarred");
    scarred_g.setAttributeNS(null, "transform", "translate(0,"
            + App.prefs.getIntPref(PrefKey.CHART_INDEX_PLOT_HEIGHT, 100) + ") scale(1," + scale_y + ")");

    // only x-scale the drawn part -- not the labels
    Element scarred_scale_g = doc.createElementNS(svgNS, "g");
    scarred_scale_g.setAttributeNS(null, "transform", "scale("
            + FireChartUtil.yearsToPixels(chartWidth, getFirstChartYear(), getLastChartYear()) + ",1)");
    scarred_g.appendChild(scarred_scale_g);

    // draw in vertical bars
    double[] percent_arr = reader.getPercentOfRecordingScarred(
            App.prefs.getEventTypePref(PrefKey.CHART_COMPOSITE_EVENT_TYPE, EventTypeToProcess.FIRE_EVENT));

    // Limit to specified years if necessary
    if (!App.prefs.getBooleanPref(PrefKey.CHART_AXIS_X_AUTO_RANGE, true)) {
        int startindex_file = this.getFirstChartYear() - applyBCYearOffset(reader.getFirstYear());
        double[] percent_file = percent_arr.clone();
        percent_arr = new double[(this.getLastChartYear() - this.getFirstChartYear()) + 1];

        int ind_in_file = startindex_file;
        for (int ind_in_newarr = 0; ind_in_newarr < percent_arr.length; ind_in_newarr++) {

            if (ind_in_file > percent_file.length - 1) {
                // Reached end of data we are extracting
                break;
            }

            if (ind_in_file < 0) {
                // Before data we are extracting so keep going
                ind_in_file++;
                continue;
            }

            percent_arr[ind_in_newarr] = percent_file[ind_in_file];
            ind_in_file++;
        }
    }

    for (int i = 0; i < percent_arr.length; i++) {
        if (percent_arr[i] != 0) {
            double percent = percent_arr[i];
            percent = (percent > 100) ? 100 : percent; // don't allow values over 100%
            scarred_scale_g.appendChild(percentScarredPlotEB.getVerticalLine(i, percent));
        }
    }

    // draw a rectangle around it
    // Needs to be 4 lines to cope with stroke width in different coord sys in x and y
    scarred_scale_g.appendChild(percentScarredPlotEB.getBorderLine1());
    scarred_scale_g.appendChild(percentScarredPlotEB.getBorderLine2(unscale_y));
    scarred_scale_g.appendChild(percentScarredPlotEB.getBorderLine3());
    scarred_scale_g.appendChild(percentScarredPlotEB.getBorderLine4(unscale_y));

    // draw in the labels
    int yAxisFontSize = App.prefs.getIntPref(PrefKey.CHART_AXIS_Y2_FONT_SIZE, 10);
    int labelHeight = FireChartUtil.getStringHeight(Font.PLAIN, yAxisFontSize, "100");
    int labelY = labelHeight / 2;

    for (int i = 0; i <= 100; i += 25) {
        Element unscale_g = doc.createElementNS(svgNS, "g");
        String x = Double.toString(chartWidth);
        String y = Integer.toString(i);
        unscale_g.setAttributeNS(null, "transform",
                "translate(" + x + "," + y + ") scale(1," + unscale_y + ")");
        unscale_g.appendChild(percentScarredPlotEB.getPercentScarredTextElement(labelY, i, yAxisFontSize));
        unscale_g.appendChild(percentScarredPlotEB.getHorizontalTick(unscale_y));
        scarred_g.appendChild(unscale_g);
    }

    // add in the label that says "% Scarred"
    Element unscale_g = doc.createElementNS(svgNS, "g");
    unscale_g.setAttributeNS(null, "transform", "scale(1," + unscale_y + ")");

    Element rotate_g = doc.createElementNS(svgNS, "g");
    String x = Double
            .toString(chartWidth + 5 + 10 + FireChartUtil.getStringWidth(Font.PLAIN, yAxisFontSize, "100"));
    String y = Double.toString(scale_y * 100);
    rotate_g.setAttributeNS(null, "transform", "translate(" + x + "," + y + ") rotate(90)");

    Text label_t = doc.createTextNode(App.prefs.getPref(PrefKey.CHART_AXIS_Y2_LABEL, "% Scarred"));
    Element label = doc.createElementNS(svgNS, "text");
    label.setAttributeNS(null, "font-family", App.prefs.getPref(PrefKey.CHART_FONT_FAMILY, "Verdana"));
    label.setAttributeNS(null, "font-size", App.prefs.getIntPref(PrefKey.CHART_AXIS_Y2_FONT_SIZE, 10) + "");

    label.appendChild(label_t);
    rotate_g.appendChild(label);
    unscale_g.appendChild(rotate_g);
    scarred_g.appendChild(unscale_g);

    if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_INDEX_PLOT, true)
            && App.prefs.getBooleanPref(PrefKey.CHART_SHOW_PERCENT_SCARRED, true)) {
        scarred_g.setAttributeNS(null, "display", "inline");
    } else {
        scarred_g.setAttributeNS(null, "display", "none");
    }

    return scarred_g;
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Get the sample or recorder depth plot.
 * /*  www  . j a  v a  2 s . co m*/
 * @param plotSampleNorRecordingDepth
 * @return
 */
private Element getSampleOrRecorderDepthsPlot(boolean plotSampleNorRecordingDepth,
        EventTypeToProcess eventTypeToProcess) {

    Element sample_g = doc.createElementNS(svgNS, "g");
    Element sample_g_chart = doc.createElementNS(svgNS, "g"); // scales the years on the x direction

    sample_g.setAttributeNS(null, "id", "depths");

    int[] sample_depths;
    if (plotSampleNorRecordingDepth)
        sample_depths = reader.getSampleDepths();
    else
        sample_depths = reader.getRecordingDepths(eventTypeToProcess);

    // Limit to specified years if necessary
    if (!App.prefs.getBooleanPref(PrefKey.CHART_AXIS_X_AUTO_RANGE, true)) {
        int startindex_file = this.getFirstChartYear() - applyBCYearOffset(reader.getFirstYear());
        int[] sample_depths_file = sample_depths.clone();
        sample_depths = new int[(this.getLastChartYear() - this.getFirstChartYear()) + 1];

        int ind_in_file = startindex_file;
        for (int ind_in_newarr = 0; ind_in_newarr < sample_depths.length; ind_in_newarr++) {

            if (ind_in_file > sample_depths_file.length - 1) {
                // Reached end of data we are extracting
                break;
            }

            if (ind_in_file < 0) {
                // Before data we are extracting so keep going
                ind_in_file++;
                continue;
            }

            sample_depths[ind_in_newarr] = sample_depths_file[ind_in_file];
            ind_in_file++;
        }
    }

    int[] sample_depths_sorted = sample_depths.clone(); // sort to find the max.
    Arrays.sort(sample_depths_sorted);
    int largest_sample_depth = sample_depths_sorted[sample_depths_sorted.length - 1];

    // Make the max value 110% of the actually max value so there is a bit of breathing room at top of the chart
    if (largest_sample_depth > 0) {
        largest_sample_depth = (int) Math.ceil(largest_sample_depth * 1.1);
    } else {
        largest_sample_depth = 1;
    }

    // the trend line is constructed as if the first year is 0 A.D.
    String translation = "translate(0," + App.prefs.getIntPref(PrefKey.CHART_INDEX_PLOT_HEIGHT, 100) + ")";
    double scale_y = -1 * ((double) App.prefs.getIntPref(PrefKey.CHART_INDEX_PLOT_HEIGHT, 100))
            / (largest_sample_depth);
    double unscale_y = 1 / scale_y;

    // String scale = "scale("+yearsToPixels()+"," + scale_y + ")";
    String t = translation + "scale(1," + scale_y + ")";
    sample_g.setAttributeNS(null, "transform", t);
    sample_g_chart.setAttributeNS(null, "transform", "scale("
            + FireChartUtil.yearsToPixels(chartWidth, getFirstChartYear(), getLastChartYear()) + ",1)");

    // error check
    if (sample_depths.length == 0) {
        return sample_g;
    }

    // build the trend line
    int begin_index = 0;
    String lineColor = FireChartUtil
            .colorToHexString(App.prefs.getColorPref(PrefKey.CHART_SAMPLE_OR_RECORDER_DEPTH_COLOR, Color.BLUE));
    for (int i = 1; i < sample_depths.length; i++) {
        if (sample_depths[i] != sample_depths[begin_index]) {
            sample_g_chart.appendChild(sampleRecorderPlotEB.getVerticalTrendLinePart(lineColor, i,
                    sample_depths[begin_index], sample_depths[i]));

            sample_g_chart.appendChild(sampleRecorderPlotEB.getHorizontalTrendLinePart(lineColor, scale_y,
                    begin_index, i, sample_depths[begin_index]));

            begin_index = i;
        }

        // draw in the final line
        if (i + 1 == sample_depths.length) {
            sample_g_chart.appendChild(sampleRecorderPlotEB.getHorizontalTrendLinePart(lineColor, scale_y,
                    begin_index, i, sample_depths[begin_index]));
        }
    }

    // add the threshold depth
    sample_g_chart.appendChild(sampleRecorderPlotEB.getThresholdLine(scale_y, largest_sample_depth));

    // add in the tick lines
    int num_ticks = FireChartUtil.calculateNumSampleDepthTicks(largest_sample_depth);
    int tick_spacing = (int) Math.ceil((double) largest_sample_depth / (double) num_ticks);
    int yAxisFontSize = App.prefs.getIntPref(PrefKey.CHART_AXIS_Y1_FONT_SIZE, 10);
    int labelHeight = FireChartUtil.getStringHeight(Font.PLAIN, yAxisFontSize, "9");
    int labelY = labelHeight / 2;

    for (int i = 0; i < num_ticks; i++) {
        sample_g.appendChild(sampleRecorderPlotEB.getHorizontalTick(unscale_y, i, tick_spacing));

        Element unscale_g = doc.createElementNS(svgNS, "g");
        unscale_g.setAttributeNS(null, "transform",
                "translate(-5," + (i * tick_spacing) + ") scale(1," + (1.0 / scale_y) + ")");
        unscale_g.appendChild(
                sampleRecorderPlotEB.getDepthCountTextElement(labelY, yAxisFontSize, i, tick_spacing));

        sample_g.appendChild(unscale_g);
    }

    // add in label that says "Sample Depth"
    int labelWidth = FireChartUtil.getStringWidth(Font.PLAIN, yAxisFontSize, num_ticks * tick_spacing + "");

    Element unscale_g = doc.createElementNS(svgNS, "g");
    unscale_g.setAttributeNS(null, "transform",
            "translate(" + (-5 - labelWidth - 10) + "," + 0 + ") scale(1," + (1.0 / scale_y) + ") rotate(270)");

    unscale_g.appendChild(sampleRecorderPlotEB.getSampleDepthTextElement());
    sample_g.appendChild(unscale_g);
    sample_g.appendChild(sample_g_chart);

    if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_INDEX_PLOT, true)) {
        sample_g.setAttributeNS(null, "display", "inline");
    } else {
        sample_g.setAttributeNS(null, "display", "none");
    }

    return sample_g;
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Set the visibility of the index plot based on the preferences.
 *///w ww .ja  va  2s .  co m
public void setIndexPlotVisibility() {

    boolean isVisible = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_INDEX_PLOT, true);

    Element plot_grouper1 = doc.getElementById("scarred");
    Element plot_grouper2 = doc.getElementById("depths");

    if (!isVisible) {
        plot_grouper1.setAttributeNS(null, "display", "none");
        plot_grouper2.setAttributeNS(null, "display", "none");
    } else {
        plot_grouper1.setAttributeNS(null, "display", "inline");
        plot_grouper2.setAttributeNS(null, "display", "inline");
    }

    positionChartGroupersAndDrawTimeAxis();
}

From source file:org.fhaes.neofhchart.svg.FireChartSVG.java

/**
 * Set the visibility of the chronology plot based on the preferences.
 *///  w  ww.j a  va2 s  .com
public void setChronologyPlotVisibility() {

    boolean isVisible = App.prefs.getBooleanPref(PrefKey.CHART_SHOW_CHRONOLOGY_PLOT, true);
    Element plot_grouper = doc.getElementById("chronology_plot");

    if (!isVisible) {
        plot_grouper.setAttributeNS(null, "display", "none");
    } else {
        plot_grouper.setAttributeNS(null, "display", "inline");
    }

    positionChartGroupersAndDrawTimeAxis();
}