Search in sources :

Example 1 with StatisticsChartRenderer

use of com.serotonin.m2m2.view.chart.StatisticsChartRenderer in project ma-core-public by infiniteautomation.

the class DataPointDetailsDwr method getStatsChartData.

@DwrPermission(user = true)
public ProcessResult getStatsChartData(int periodType, int period, boolean includeSum) {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    DataPointVO pointVO = Common.getUser(request).getEditPoint();
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("point", pointVO);
    StatisticsChartRenderer r = new StatisticsChartRenderer(periodType, period, includeSum);
    r.addDataToModel(model, pointVO);
    ProcessResult response = new ProcessResult();
    response.addData("stats", generateContent(request, "statsChart.jsp", model));
    addAsof(response);
    return response;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) StatisticsChartRenderer(com.serotonin.m2m2.view.chart.StatisticsChartRenderer) HashMap(java.util.HashMap) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with StatisticsChartRenderer

use of com.serotonin.m2m2.view.chart.StatisticsChartRenderer in project ma-modules-public by infiniteautomation.

the class ChartRendererFactory method updateDataPoint.

/**
 * @param data
 * @param renderer
 */
public static void updateDataPoint(DataPointVO vo, BaseChartRendererModel<?> baseRendererModel) {
    if (baseRendererModel == null)
        // Nothing to do
        return;
    if (baseRendererModel.getType().equals(ImageChartRenderer.getDefinition().getName())) {
        ImageChartRendererModel model = (ImageChartRendererModel) baseRendererModel;
        ImageChartRenderer r = new ImageChartRenderer();
        r.setNumberOfPeriods(model.getTimePeriod().getPeriods());
        r.setTimePeriod(Common.TIME_PERIOD_CODES.getId(model.getTimePeriod().getPeriodType()));
        vo.setChartRenderer(r);
    } else if (baseRendererModel.getType().equals(ImageFlipbookRenderer.getDefinition().getName())) {
        ImageFlipbookChartRendererModel model = (ImageFlipbookChartRendererModel) baseRendererModel;
        ImageFlipbookRenderer r = new ImageFlipbookRenderer();
        r.setLimit(model.getLimit());
        vo.setChartRenderer(r);
    } else if (baseRendererModel.getType().equals(StatisticsChartRenderer.getDefinition().getName())) {
        StatisticsChartRendererModel model = (StatisticsChartRendererModel) baseRendererModel;
        StatisticsChartRenderer r = new StatisticsChartRenderer();
        r.setNumberOfPeriods(model.getTimePeriod().getPeriods());
        r.setTimePeriod(Common.TIME_PERIOD_CODES.getId(model.getTimePeriod().getPeriodType()));
        r.setIncludeSum(model.isIncludeSum());
        vo.setChartRenderer(r);
    } else if (baseRendererModel.getType().equals(TableChartRenderer.getDefinition().getName())) {
        TableChartRendererModel model = (TableChartRendererModel) baseRendererModel;
        TableChartRenderer r = new TableChartRenderer();
        r.setLimit(model.getLimit());
        vo.setChartRenderer(r);
    } else {
        throw new ShouldNeverHappenException("Unknown Chart Renderer: " + baseRendererModel.getType());
    }
}
Also used : TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer) StatisticsChartRenderer(com.serotonin.m2m2.view.chart.StatisticsChartRenderer) ImageFlipbookRenderer(com.serotonin.m2m2.view.chart.ImageFlipbookRenderer) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer)

Example 3 with StatisticsChartRenderer

use of com.serotonin.m2m2.view.chart.StatisticsChartRenderer in project ma-modules-public by infiniteautomation.

the class ChartRendererFactory method createModel.

/**
 * @param vo
 * @return
 */
public static BaseChartRendererModel<?> createModel(DataPointVO vo) {
    ChartRenderer renderer = vo.getChartRenderer();
    if (renderer == null)
        return null;
    if (renderer.getTypeName().equals(ImageChartRenderer.getDefinition().getName())) {
        ImageChartRenderer r = (ImageChartRenderer) renderer;
        TimePeriodModel tp = new TimePeriodModel(r.getNumberOfPeriods(), r.getTimePeriod());
        ImageChartRendererModel model = new ImageChartRendererModel(tp);
        return model;
    } else if (renderer.getTypeName().equals(ImageFlipbookRenderer.getDefinition().getName())) {
        ImageFlipbookRenderer r = (ImageFlipbookRenderer) renderer;
        ImageFlipbookChartRendererModel model = new ImageFlipbookChartRendererModel(r.getLimit());
        return model;
    } else if (renderer.getTypeName().equals(StatisticsChartRenderer.getDefinition().getName())) {
        StatisticsChartRenderer r = (StatisticsChartRenderer) renderer;
        TimePeriodModel tp = new TimePeriodModel(r.getNumberOfPeriods(), r.getTimePeriod());
        StatisticsChartRendererModel model = new StatisticsChartRendererModel(tp, r.isIncludeSum());
        return model;
    } else if (renderer.getTypeName().equals(TableChartRenderer.getDefinition().getName())) {
        TableChartRenderer r = (TableChartRenderer) renderer;
        TableChartRendererModel model = new TableChartRendererModel(r.getLimit());
        return model;
    } else {
        throw new ShouldNeverHappenException("Unknown Chart Renderer: " + renderer.getDef().getName());
    }
}
Also used : TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer) StatisticsChartRenderer(com.serotonin.m2m2.view.chart.StatisticsChartRenderer) ImageFlipbookRenderer(com.serotonin.m2m2.view.chart.ImageFlipbookRenderer) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer) TimePeriodModel(com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.TimePeriodModel) StatisticsChartRenderer(com.serotonin.m2m2.view.chart.StatisticsChartRenderer) ImageChartRenderer(com.serotonin.m2m2.view.chart.ImageChartRenderer) ChartRenderer(com.serotonin.m2m2.view.chart.ChartRenderer) TableChartRenderer(com.serotonin.m2m2.view.chart.TableChartRenderer)

Aggregations

StatisticsChartRenderer (com.serotonin.m2m2.view.chart.StatisticsChartRenderer)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 ImageChartRenderer (com.serotonin.m2m2.view.chart.ImageChartRenderer)2 ImageFlipbookRenderer (com.serotonin.m2m2.view.chart.ImageFlipbookRenderer)2 TableChartRenderer (com.serotonin.m2m2.view.chart.TableChartRenderer)2 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 ChartRenderer (com.serotonin.m2m2.view.chart.ChartRenderer)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)1 TimePeriodModel (com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.TimePeriodModel)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1