⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphengine.java

📁 openfire 服务器源码下载
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                false // URLs?
        );

        chart.setBackgroundPaint(backgroundColor);
        chart.setBorderVisible(false);
        chart.setBorderPaint(null);

        XYPlot plot = (XYPlot)chart.getPlot();
        plot.setDomainGridlinesVisible(false);
        plot.setDomainCrosshairVisible(false);
        plot.setRangeCrosshairVisible(false);
        plot.setBackgroundPaint(backgroundColor);
        plot.setRangeGridlinesVisible(false);


        GraphDefinition graphDef = GraphDefinition.getDefinition(color);
        Color plotColor = graphDef.getInlineColor(0);
        plot.getRenderer().setSeriesPaint(0, plotColor);
        plot.getRenderer().setBaseItemLabelsVisible(false);
        plot.getRenderer().setBaseOutlinePaint(backgroundColor);
        plot.setOutlineStroke(null);
        plot.setDomainGridlinePaint(null);

        ValueAxis xAxis = chart.getXYPlot().getDomainAxis();

        xAxis.setLabel(null);
        xAxis.setTickLabelsVisible(true);
        xAxis.setTickMarksVisible(true);
        xAxis.setAxisLineVisible(false);
        xAxis.setNegativeArrowVisible(false);
        xAxis.setPositiveArrowVisible(false);
        xAxis.setVisible(false);

        ValueAxis yAxis = chart.getXYPlot().getRangeAxis();
        yAxis.setTickLabelsVisible(false);
        yAxis.setTickMarksVisible(false);
        yAxis.setAxisLineVisible(false);
        yAxis.setNegativeArrowVisible(false);
        yAxis.setPositiveArrowVisible(false);
        yAxis.setVisible(false);

        return chart;
    }

    /**
     * Takes a hexidecimel color value and returns its color equivelent.
     *
     * @param hexColor The hex color to be parsed
     * @return The java color object
     */
    private static Color getColor(String hexColor) {
        return new Color(Integer.valueOf(hexColor.substring(0, 2), 16),
                Integer.valueOf(hexColor.substring(2, 4), 16),
                Integer.valueOf(hexColor.substring(4, 6), 16));
    }

    /**
     * Returns a color that can be used as a background.
     * @return Color
     */
    private static Color getBackgroundColor() {
        return new Color(255,255,255);
    }

    public static long[] parseTimePeriod(String timeperiod) {

        if (null == timeperiod)
            timeperiod = "last60minutes";

        Date fromDate = null;
        Date toDate = null;
        long dataPoints = 60;

        Calendar cal = Calendar.getInstance();
        Date now = cal.getTime();
        // Reset the day fields so we're at the beginning of the day.
        cal.set(Calendar.HOUR, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        // Compute "this week" by resetting the day of the week to the first day of the week
        cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
        Date thisWeekStart = cal.getTime();
        Date thisWeekEnd = now;
        // Compute last week - start with the end boundary which is 1 millisecond before the start of this week
        cal.add(Calendar.MILLISECOND, -1);
        Date lastWeekEnd = cal.getTime();
        // Add that millisecond back, subtract 7 days for the start boundary of "last week"
        cal.add(Calendar.MILLISECOND, 1);
        cal.add(Calendar.DAY_OF_YEAR, -7);
        Date lastWeekStart = cal.getTime();
        // Reset the time
        cal.setTime(now);
        cal.set(Calendar.HOUR, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        // Reset to the 1st day of the month, make the the start boundary for "this month"
        cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DAY_OF_MONTH));
        Date thisMonthStart = cal.getTime();
        Date thisMonthEnd = now;
        // Compute last month
        cal.add(Calendar.MILLISECOND, -1);
        Date lastMonthEnd = cal.getTime();
        cal.add(Calendar.MILLISECOND, 1);
        cal.add(Calendar.MONTH, -1);
        Date lastMonthStart = cal.getTime();
        // Compute last 3 months
        cal.setTime(now);
        cal.add(Calendar.MONTH, -2);
        cal.set(Calendar.HOUR, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        Date last3MonthsStart = cal.getTime();
        Date last3MonthsEnd = now;
        // Compute last 7 days:
        cal.setTime(now);
        cal.add(Calendar.DAY_OF_YEAR, -6);
        cal.set(Calendar.HOUR, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        Date last7DaysStart = cal.getTime();
        Date last7DaysEnd = now;
        // Compute last 60 minutes;
        cal.setTime(now);
        cal.add(Calendar.MINUTE, -60);
        Date last60MinutesStart = cal.getTime();
        Date last60MinutesEnd = now;
        // Compute last 24 hours;
        cal.setTime(now);
        cal.add(Calendar.HOUR, -23);
        Date last24HoursStart = cal.getTime();
        Date last24HoursEnd = now;
        // Done, reset the cal internal date to now
        cal.setTime(now);

        if ("thisweek".equals(timeperiod)) {
            fromDate = thisWeekStart;
            toDate = thisWeekEnd;
            dataPoints = 7;
        } else if ("last7days".equals(timeperiod)) {
            fromDate = last7DaysStart;
            toDate = last7DaysEnd;
            dataPoints = 7;
        } else if ("lastweek".equals(timeperiod)) {
            fromDate = lastWeekStart;
            toDate = lastWeekEnd;
            dataPoints = 7;
        } else if ("thismonth".equals(timeperiod)) {
            fromDate = thisMonthStart;
            toDate = thisMonthEnd;
            dataPoints = 30;
        } else if ("lastmonth".equals(timeperiod)) {
            fromDate = lastMonthStart;
            toDate = lastMonthEnd;
            dataPoints = 30;
        } else if ("last3months".equals(timeperiod)) {
            fromDate = last3MonthsStart;
            toDate = last3MonthsEnd;
            dataPoints = (long)Math.ceil((toDate.getTime() - fromDate.getTime()) / WEEK);
        } else if ("last60minutes".equals(timeperiod)) {
            fromDate = last60MinutesStart;
            toDate = last60MinutesEnd;
            dataPoints = 60;
        } else if ("last24hours".equals(timeperiod)) {
            fromDate = last24HoursStart;
            toDate = last24HoursEnd;
            dataPoints = 48;
        } else {
            String[] dates = timeperiod.split("to");
            if (dates.length > 0) {
                DateFormat formDateFormatter = new SimpleDateFormat("MM/dd/yy");
                String fromDateParam = dates[0];
                String toDateParam = dates[1];
                if (fromDateParam != null) {
                    try {
                        fromDate = formDateFormatter.parse(fromDateParam);
                    }
                    catch (Exception e) {
                        // ignore formatting exception
                    }
                }
                if (toDateParam != null) {
                    try {
                        toDate = formDateFormatter.parse(toDateParam);
                        // Make this date be the end of the day (so it's the day *inclusive*, not *exclusive*)
                        Calendar adjusted = Calendar.getInstance();
                        adjusted.setTime(toDate);
                        adjusted.set(Calendar.HOUR_OF_DAY, 23);
                        adjusted.set(Calendar.MINUTE, 59);
                        adjusted.set(Calendar.SECOND, 59);
                        adjusted.set(Calendar.MILLISECOND, 999);
                        toDate = adjusted.getTime();
                    }
                    catch (Exception e) {
                        // ignore formatting exception
                    }
                }
                dataPoints = discoverDataPoints(fromDate, toDate);
            }
        }

        // default to last 60 minutes
        if (null == fromDate && null==toDate) {
            return new long[] {last60MinutesStart.getTime(), last60MinutesEnd.getTime(), dataPoints};
        } else if (null == fromDate) {
            return new long[] {0, toDate.getTime(), dataPoints};
        } else if (null == toDate) {
            return new long[] {fromDate.getTime(), now.getTime(), dataPoints};
        } else {
            return new long[] {fromDate.getTime(), toDate.getTime(), dataPoints};
        }
    }

    private static int discoverDataPoints(Date fromDate, Date toDate) {
        long delta = toDate.getTime() - fromDate.getTime();
        if(delta > YEAR) {
            return (int)(delta / MONTH);
        }
        else if (delta > 2 * MONTH) {
            return (int)(delta / WEEK);
        }
        else {
            return (int)(delta / DAY);
        }
    }

    public static class GraphDefinition {
        public static final GraphDefinition standard_light;
        public static final GraphDefinition standard_dark;
        private Color[] inlineColors;
        private Color[] outlineColors;

        static {
            standard_light = new GraphDefinition(
                    new Color[]{new Color(246, 171, 77), getColor("B1C3D9")},
                    new Color[]{new Color(217, 126, 12), getColor("17518C")}
                    );

            standard_dark = new GraphDefinition(
                    new Color[]{new Color(116, 128, 141), getColor("74808D")},
                    new Color[]{new Color(116, 128, 141), getColor("74808D")}
                    );
        }

        public static GraphDefinition getDefinition(String colorscheme) {
            GraphDefinition graphDef = GraphDefinition.standard_light;
            if (colorscheme != null && colorscheme.equalsIgnoreCase("dark")) {
                graphDef = GraphDefinition.standard_dark;
            }
            return graphDef;
        }

        public GraphDefinition(Color[] inlineColors, Color[] outlineColors) {
            this.inlineColors = inlineColors;
            this.outlineColors = outlineColors;
        }

        public Color getInlineColor(int index) {
            return inlineColors[index];
        }

        public Color[] getInlineColors() {
            return inlineColors;
        }

        public Color getOutlineColor(int index) {
            return outlineColors[index];
        }

        public Color[] getOutlineColors() {
            return outlineColors;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -