From: lempinen Date: Thu, 1 Dec 2011 12:48:05 +0000 (+0000) Subject: Axis and series label rules for ChartAxisAndVariablesTab X-Git-Tag: simantics-1.6~82 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=314f8f64742e7bf82b0f9da8055cbbfb9a78ca6c;p=simantics%2Fsysdyn.git Axis and series label rules for ChartAxisAndVariablesTab git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23385 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 613fa022..4dbbefac 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/ChartAxisAndVariablesViewpoint.pgraph b/org.simantics.sysdyn.ontology/graph/ChartAxisAndVariablesViewpoint.pgraph index 4d6f3fab..e5c72a0c 100644 --- a/org.simantics.sysdyn.ontology/graph/ChartAxisAndVariablesViewpoint.pgraph +++ b/org.simantics.sysdyn.ontology/graph/ChartAxisAndVariablesViewpoint.pgraph @@ -13,6 +13,8 @@ CAC = SYSDYN.ChartAxisAndVariablesActionContext : VP.BrowseContext CBC.AxisChildRule : VP.ChildRule CBC.VariableChildRule : VP.ChildRule +CBC.SeriesLabelRule : VP.LabelRule +CBC.AxisLabelRule : VP.LabelRule CBC @VP.customChildRule JFREE.Chart CBC.AxisChildRule @@ -21,8 +23,8 @@ CBC JFREE.Series : VP.ResourceNodeType CBC - @VP.customLabelRule JFREE.Axis VP.ResourceLabelLabelRule - @VP.customLabelRule JFREE.Series VP.ResourceLabelLabelRule + @VP.customLabelRule JFREE.Axis CBC.AxisLabelRule + @VP.customLabelRule JFREE.Series CBC.SeriesLabelRule CBC @VP.dropActionContribution JFREE.Axis ACTIONS.DropAction 1.0 diff --git a/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java b/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java index 3cb6e09a..bcebfbec 100644 --- a/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java +++ b/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java @@ -51,6 +51,8 @@ public class SysdynResource { public final Resource ChartAxisAndVariablesActionContext_Actions_DropAction; public final Resource ChartAxisAndVariablesBrowseContext; public final Resource ChartAxisAndVariablesBrowseContext_AxisChildRule; + public final Resource ChartAxisAndVariablesBrowseContext_AxisLabelRule; + public final Resource ChartAxisAndVariablesBrowseContext_SeriesLabelRule; public final Resource ChartAxisAndVariablesBrowseContext_VariableChildRule; public final Resource Cloud; public final Resource CloudSymbol; @@ -320,6 +322,8 @@ public class SysdynResource { public static final String ChartAxisAndVariablesActionContext_Actions_DropAction = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesActionContext/Actions/DropAction"; public static final String ChartAxisAndVariablesBrowseContext = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext"; public static final String ChartAxisAndVariablesBrowseContext_AxisChildRule = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext/AxisChildRule"; + public static final String ChartAxisAndVariablesBrowseContext_AxisLabelRule = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext/AxisLabelRule"; + public static final String ChartAxisAndVariablesBrowseContext_SeriesLabelRule = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext/SeriesLabelRule"; public static final String ChartAxisAndVariablesBrowseContext_VariableChildRule = "http://www.simantics.org/Sysdyn-1.1/ChartAxisAndVariablesBrowseContext/VariableChildRule"; public static final String Cloud = "http://www.simantics.org/Sysdyn-1.1/Cloud"; public static final String CloudSymbol = "http://www.simantics.org/Sysdyn-1.1/CloudSymbol"; @@ -599,6 +603,8 @@ public class SysdynResource { ChartAxisAndVariablesActionContext_Actions_DropAction = getResourceOrNull(graph, URIs.ChartAxisAndVariablesActionContext_Actions_DropAction); ChartAxisAndVariablesBrowseContext = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext); ChartAxisAndVariablesBrowseContext_AxisChildRule = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext_AxisChildRule); + ChartAxisAndVariablesBrowseContext_AxisLabelRule = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext_AxisLabelRule); + ChartAxisAndVariablesBrowseContext_SeriesLabelRule = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext_SeriesLabelRule); ChartAxisAndVariablesBrowseContext_VariableChildRule = getResourceOrNull(graph, URIs.ChartAxisAndVariablesBrowseContext_VariableChildRule); Cloud = getResourceOrNull(graph, URIs.Cloud); CloudSymbol = getResourceOrNull(graph, URIs.CloudSymbol); diff --git a/org.simantics.sysdyn.ui/adapters.xml b/org.simantics.sysdyn.ui/adapters.xml index cd26fb0a..bde90b08 100644 --- a/org.simantics.sysdyn.ui/adapters.xml +++ b/org.simantics.sysdyn.ui/adapters.xml @@ -10,5 +10,5 @@ VTT Technical Research Centre of Finland - initial API and implementation --> - none 0 fill 1 + none 0 fill 1 \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java index 73f08545..6aa3ac6f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java @@ -37,7 +37,7 @@ public class ChartUtils { // Create range axis axis = GraphUtils.create2(graph, jfree.NumberAxis, l0.HasName, "NumberAxis" + UUID.randomUUID().toString(), - l0.HasLabel, NameUtils.findFreshLabel(graph, "range", plot), + l0.HasLabel, NameUtils.findFreshLabel(graph, "Range", plot), jfree.Plot_rangeAxis_Inverse, plot, l0.PartOf, plot); @@ -98,7 +98,7 @@ public class ChartUtils { // Create series Resource series = GraphUtils.create2(graph, jfree.Series, l0.HasName, "Series" + UUID.randomUUID().toString(), - jfree.variableRVI, rvi == null ? " " : rvi, + jfree.variableRVI, rvi == null ? " Set variable" : rvi, l0.PartOf, dataset); // Add series to the dataset's series list diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisLabelRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisLabelRule.java new file mode 100644 index 00000000..ee3d3636 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisLabelRule.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.graphexplorer; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.labels.LabelRule; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Label rule for range axis label + * @author Teemu Lempinen + * + */ +public class AxisLabelRule implements LabelRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + /** + * Range axis label + * + * Options: + * 1. Label + * 2. Default + */ + @Override + public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource resource = (Resource)content; + String label = graph.getPossibleRelatedValue(resource, l0.HasLabel, Bindings.STRING); + if(label == null || label.isEmpty()) { + label = "Range"; + Resource plot = graph.getPossibleObject(resource, l0.PartOf); + if(plot != null) { + Resource axisListResource = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); + if(axisListResource != null) { + List axisList = ListUtils.toList(graph, axisListResource); + if(axisList.contains(resource)) + label = label + " " + (axisList.indexOf(resource) + 1); + } + } + } + return Collections.singletonMap(ColumnKeys.SINGLE, label); + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelRule.java new file mode 100644 index 00000000..d334765a --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelRule.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart.graphexplorer; + +import java.util.Collections; +import java.util.Map; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.labels.LabelRule; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; + +/** + * Label rule for dataset series + * @author Teemu Lempinen + * + */ +public class SeriesLabelRule implements LabelRule { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + /** + * Options: + * 1. Label + * 2. Variable rvi + * 3. Default + */ + @Override + public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + Resource resource = (Resource)content; + String label = graph.getPossibleRelatedValue(resource, l0.HasLabel, Bindings.STRING); + if(label == null || label.isEmpty()) { + label = graph.getPossibleRelatedValue(resource, jfree.variableRVI); + if(label != null && !label.isEmpty() && label.length() > 1) + label = label.substring(1).replace('/', '.'); + else + label = "Set variable"; + } + return Collections.singletonMap(ColumnKeys.SINGLE, label); + } + +}