use of com.serotonin.m2m2.view.chart.ImageChartRenderer 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());
}
}
use of com.serotonin.m2m2.view.chart.ImageChartRenderer 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());
}
}
use of com.serotonin.m2m2.view.chart.ImageChartRenderer in project ma-core-public by infiniteautomation.
the class DefaultDataPointPropertiesTemplateFactory method createDefaultNumericTemplate.
protected DataPointPropertiesTemplateVO createDefaultNumericTemplate() {
DataPointPropertiesTemplateVO defaultNumericPointTemplate = new DataPointPropertiesTemplateVO();
defaultNumericPointTemplate.setXid(NUMERIC_XID);
defaultNumericPointTemplate.setName("Numeric");
defaultNumericPointTemplate.setDefaultTemplate(true);
defaultNumericPointTemplate.setDataTypeId(DataTypes.NUMERIC);
defaultNumericPointTemplate.setDefinition(new DataPointPropertiesTemplateDefinition());
defaultNumericPointTemplate.setChartColour("");
defaultNumericPointTemplate.setPlotType(PlotTypes.SPLINE);
defaultNumericPointTemplate.setLoggingType(LoggingTypes.INTERVAL);
defaultNumericPointTemplate.setIntervalLoggingPeriod(1);
defaultNumericPointTemplate.setIntervalLoggingPeriodType(TimePeriods.MINUTES);
defaultNumericPointTemplate.setIntervalLoggingType(IntervalLoggingTypes.AVERAGE);
defaultNumericPointTemplate.setDefaultCacheSize(1);
AnalogRenderer numericTextRenderer = new AnalogRenderer();
numericTextRenderer.setFormat("0.00");
defaultNumericPointTemplate.setTextRenderer(numericTextRenderer);
ImageChartRenderer numericChartRenderer = new ImageChartRenderer();
numericChartRenderer.setTimePeriod(TimePeriods.DAYS);
numericChartRenderer.setNumberOfPeriods(1);
defaultNumericPointTemplate.setChartRenderer(numericChartRenderer);
return defaultNumericPointTemplate;
}
use of com.serotonin.m2m2.view.chart.ImageChartRenderer in project ma-core-public by infiniteautomation.
the class DataPointDetailsController method handleRequest.
@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws Exception {
User user = Common.getHttpUser();
int id = -1;
if (user.getEditPoint() != null)
id = user.getEditPoint().getId();
DataPointDao dataPointDao = DataPointDao.instance;
String idStr = request.getParameter("dpid");
DataPointVO point = null;
if (StringUtils.equals(idStr, "exception"))
throw new IOException("testing");
else if (StringUtils.equals(idStr, "permission-exception"))
throw new PermissionException(new TranslatableMessage("common.default", "Testing"), user);
if (StringUtils.isBlank(idStr)) {
// Check for pedid (point event detector id)
String pedStr = request.getParameter("pedid");
if (StringUtils.isBlank(pedStr)) {
// Check if an XID was provided.
String xid = request.getParameter("dpxid");
if (!StringUtils.isBlank(xid)) {
model.put("currentXid", xid);
point = dataPointDao.getDataPoint(xid);
id = point == null ? -2 : point.getId();
}
} else {
int pedid = Integer.parseInt(pedStr);
id = EventDetectorDao.instance.getSourceId(pedid, EventType.EventTypeNames.DATA_POINT);
}
} else
id = Integer.parseInt(idStr);
// Find accessible points for the goto list
List<DataPointSummary> userPoints = ControllerUtils.addPointListDataToModel(user, id, model);
// Get the point.
if (point == null && id != -1)
point = dataPointDao.getDataPoint(id);
if (point == null && id != -2 && /* -2 means an explicit XID was provided but not found */
!userPoints.isEmpty()) {
// Load at least 1 point, there may be many points but some might not actually load if thier data source DNE anymore
for (DataPointSummary userPoint : userPoints) {
point = dataPointDao.getDataPoint(userPoint.getId());
if (point != null)
break;
}
}
if (point != null) {
// Check permissions
Permissions.ensureDataPointReadPermission(user, point);
// Put the point in the model.
model.put("point", point);
// Get the users that have access to this point.
List<User> allUsers = UserDao.instance.getUsers();
List<Map<String, Object>> users = new LinkedList<>();
Map<String, Object> userData;
int accessType;
for (User mangoUser : allUsers) {
accessType = Permissions.getDataPointAccessType(mangoUser, point);
if (accessType != Permissions.DataPointAccessTypes.NONE) {
userData = new HashMap<>();
userData.put("user", mangoUser);
userData.put("accessType", accessType);
users.add(userData);
}
}
model.put("users", users);
// Determine whether the link to edit the point should be displayed
model.put("pointEditor", Permissions.hasDataSourcePermission(user, point.getDataSourceId()));
// Put the events in the model.
model.put("events", EventDao.instance.getEventsForDataPoint(id, user.getId()));
// Put the default history table count into the model. Default to 10.
int historyLimit = 10;
if (point.getChartRenderer() instanceof TableChartRenderer)
historyLimit = ((TableChartRenderer) point.getChartRenderer()).getLimit();
else if (point.getChartRenderer() instanceof ImageFlipbookRenderer)
historyLimit = ((ImageFlipbookRenderer) point.getChartRenderer()).getLimit();
model.put("historyLimit", historyLimit);
// Determine our image chart rendering capabilities.
if (ImageChartRenderer.getDefinition().supports(point.getPointLocator().getDataTypeId())) {
// This point can render an image chart. Carry on...
int periodType = Common.TimePeriods.DAYS;
int periodCount = 1;
if (point.getChartRenderer() instanceof ImageChartRenderer) {
ImageChartRenderer r = (ImageChartRenderer) point.getChartRenderer();
periodType = r.getTimePeriod();
periodCount = r.getNumberOfPeriods();
}
model.put("periodType", periodType);
model.put("periodCount", periodCount);
}
// Determine out flipbook rendering capabilities
if (ImageFlipbookRenderer.getDefinition().supports(point.getPointLocator().getDataTypeId()))
model.put("flipbookLimit", 10);
// Set the point in the session for the dwr.
user.setEditPoint(point);
model.put("currentXid", point.getXid());
model.put("hierPath", CollectionUtils.implode(dataPointDao.getPointHierarchy(true).getPath(id), " » "));
}
return null;
}
use of com.serotonin.m2m2.view.chart.ImageChartRenderer in project ma-modules-public by infiniteautomation.
the class VirtualEditDwr method createTestSource.
/**
* Test Method for debugging system.
*/
@DwrPermission(admin = true)
public void createTestSource() {
VirtualDataSourceVO ds = new VirtualDataSourceVO();
DataSourceDefinition def = ModuleRegistry.getDataSourceDefinition("VIRTUAL");
ds = (VirtualDataSourceVO) def.baseCreateDataSourceVO();
ds.setId(Common.NEW_ID);
ds.setXid(DataSourceDao.instance.generateUniqueXid());
ds.setName("Test Virtual");
ds.setEnabled(true);
ds.setUpdatePeriods(5);
ds.setUpdatePeriodType(TimePeriods.SECONDS);
ds.setPolling(true);
ProcessResult response = new ProcessResult();
ds.validate(response);
if (!response.getHasMessages())
Common.runtimeManager.saveDataSource(ds);
else
throw new RuntimeException("Invalid data!");
DataPointDao dpDao = DataPointDao.instance;
// Create Test Points
for (int i = 0; i < 10; i++) {
VirtualPointLocatorVO pointLocator = ds.createPointLocator();
// Create a Random Points
pointLocator.setDataTypeId(DataTypes.NUMERIC);
pointLocator.setChangeTypeId(ChangeTypeVO.Types.RANDOM_ANALOG);
pointLocator.getRandomAnalogChange().setMin(0);
pointLocator.getRandomAnalogChange().setMax(100);
pointLocator.getRandomAnalogChange().setStartValue("1");
pointLocator.setSettable(true);
DataPointVO dp = new DataPointVO();
dp.setXid(dpDao.generateUniqueXid());
dp.setName("Virtual Random " + i);
dp.setDataSourceId(ds.getId());
dp.setDataSourceTypeName(ds.getDefinition().getDataSourceTypeName());
dp.setDeviceName(ds.getName());
dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
dp.defaultTextRenderer();
// Setup the Chart Renderer
ImageChartRenderer chartRenderer = new ImageChartRenderer(TimePeriods.DAYS, 5);
dp.setChartRenderer(chartRenderer);
dp.setPointLocator(pointLocator);
dp.setEnabled(true);
dp.setSettable(true);
dp.setDefaultCacheSize(0);
dp.validate(response);
if (!response.getHasMessages())
Common.runtimeManager.saveDataPoint(dp);
else
throw new RuntimeException("Invalid data!");
}
}
Aggregations