提交 12e3edd4 编写于 作者: M Mathieu Bastian

Overhaul of the function discovery and refresh in Appearance

上级 bea78741
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.appearance;
import org.gephi.appearance.api.AttributeFunction;
import org.gephi.appearance.api.Partition;
import org.gephi.appearance.api.PartitionFunction;
import org.gephi.appearance.api.Ranking;
import org.gephi.appearance.api.RankingFunction;
import org.gephi.appearance.spi.Transformer;
import org.gephi.appearance.spi.TransformerUI;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Graph;
/**
*
* @author mbastian
*/
public class AttributeFunctionImpl extends FunctionImpl implements RankingFunction, PartitionFunction, AttributeFunction {
public AttributeFunctionImpl(String id, Graph graph, Column column, Transformer transformer, TransformerUI transformerUI, RankingImpl ranking) {
super(id, null, graph, column, transformer, transformerUI, null, ranking);
}
public AttributeFunctionImpl(String id, Graph graph, Column column, Transformer transformer, TransformerUI transformerUI, PartitionImpl partition) {
super(id, null, graph, column, transformer, transformerUI, partition, null);
}
@Override
public Column getColumn() {
return column;
}
@Override
public Partition getPartition() {
return partition;
}
@Override
public Ranking getRanking() {
return ranking;
}
@Override
public String toString() {
return column.getTitle();
}
}
/*
Copyright 2008-2013 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2013 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2013 Gephi Consortium.
*/
package org.gephi.appearance;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.Index;
/**
*
* @author mbastian
*/
public class AttributePartitionImpl extends PartitionImpl {
protected final Index index;
protected final Column column;
public AttributePartitionImpl(Column column, Index index) {
super();
this.column = column;
this.index = index;
}
@Override
public Object getValue(Element element) {
return element.getAttribute(column);
}
@Override
public Iterable getValues() {
return index.values(column);
}
@Override
public int getElementCount() {
return index.countElements(column);
}
@Override
public int count(Object value) {
return index.count(column, value);
}
@Override
public float percentage(Object value) {
int count = index.count(column, value);
return (float) count / index.countElements(column);
}
@Override
public int size() {
return index.countValues(column);
}
@Override
public Column getColumn() {
return column;
}
@Override
public int hashCode() {
int hash = 3;
hash = 23 * hash + (this.column != null ? this.column.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final AttributePartitionImpl other = (AttributePartitionImpl) obj;
if (this.column != other.column && (this.column == null || !this.column.equals(other.column))) {
return false;
}
return true;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.appearance;
import org.gephi.appearance.api.Interpolator;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.Index;
/**
*
* @author mbastian
*/
public class AttributeRankingImpl extends RankingImpl {
protected final Index index;
protected final Column column;
public AttributeRankingImpl(Column column, Index index, Interpolator interpolator) {
super(interpolator);
this.column = column;
this.index = index;
}
@Override
protected void refresh() {
min = index.getMinValue(column);
max = index.getMaxValue(column);
}
@Override
public Number getValue(Element element) {
return (Number) element.getAttribute(column);
}
@Override
public int hashCode() {
int hash = 3;
hash = 67 * hash + (this.column != null ? this.column.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final AttributeRankingImpl other = (AttributeRankingImpl) obj;
if (this.column != other.column && (this.column == null || !this.column.equals(other.column))) {
return false;
}
return true;
}
}
/*
Copyright 2008-2013 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2013 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2013 Gephi Consortium.
*/
package org.gephi.appearance;
import org.gephi.appearance.api.Interpolator;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.Node;
/**
*
* @author mbastian
*/
public class DegreeRankingImpl extends RankingImpl {
private final Graph graph;
public DegreeRankingImpl(Graph graph, Interpolator interpolator) {
super(interpolator);
this.graph = graph;
}
@Override
public Number getValue(Element element) {
return graph.getDegree((Node) element);
}
@Override
protected void refresh() {
if (graph.getNodeCount() > 0) {
int minV = Integer.MAX_VALUE;
int maxV = Integer.MIN_VALUE;
for (Node n : graph.getNodes()) {
int degree = graph.getDegree(n);
minV = Math.min(degree, minV);
maxV = Math.max(degree, maxV);
}
min = minV;
max = maxV;
}
}
}
/*
Copyright 2008-2013 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2013 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2013 Gephi Consortium.
*/
package org.gephi.appearance;
import java.util.Arrays;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphModel;
/**
*
* @author mbastian
*/
public class EdgeTypePartitionImpl extends PartitionImpl {
protected final Graph graph;
protected final GraphModel model;
public EdgeTypePartitionImpl(Graph graph) {
super();
this.graph = graph;
this.model = graph.getModel();
}
@Override
public Iterable getValues() {
return Arrays.asList(model.getEdgeTypeLabels());
}
@Override
public Object getValue(Element element) {
return ((Edge) element).getTypeLabel();
}
@Override
public int getElementCount() {
return graph.getEdgeCount();
}
@Override
public int count(Object value) {
return graph.getEdgeCount(model.getEdgeType(value));
}
@Override
public float percentage(Object value) {
int count = count(value);
return (float) count / graph.getEdgeCount();
}
@Override
public int size() {
return model.getEdgeTypeCount();
}
@Override
public Column getColumn() {
return null;
}
}
/*
Copyright 2008-2013 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2013 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2013 Gephi Consortium.
*/
package org.gephi.appearance;
import org.gephi.appearance.api.Interpolator;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.Graph;
/**
*
* @author mbastian
*/
public class EdgeWeightRankingImpl extends RankingImpl {
private final Graph graph;
public EdgeWeightRankingImpl(Graph graph, Interpolator interpolator) {
super(interpolator);
this.graph = graph;
}
@Override
public Number getValue(Element element) {
return ((Edge) element).getWeight();
}
@Override
protected void refresh() {
if (graph.getEdgeCount() > 0) {
double minV = Double.MAX_VALUE;
double maxV = Double.MIN_VALUE;
for (Edge e : graph.getEdges()) {
double weight = e.getWeight();
minV = Math.min(weight, minV);
maxV = Math.max(weight, maxV);
}
min = minV;
max = maxV;
}
}
}
......@@ -41,11 +41,7 @@
*/
package org.gephi.appearance;
import org.gephi.appearance.api.Partition;
import org.gephi.appearance.api.PartitionFunction;
import org.gephi.appearance.api.Ranking;
import org.gephi.appearance.api.RankingFunction;
import org.gephi.appearance.api.SimpleFunction;
import org.gephi.appearance.api.Function;
import org.gephi.appearance.spi.PartitionTransformer;
import org.gephi.appearance.spi.RankingTransformer;
import org.gephi.appearance.spi.SimpleTransformer;
......@@ -53,35 +49,31 @@ import org.gephi.appearance.spi.Transformer;
import org.gephi.appearance.spi.TransformerUI;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.Graph;
/**
*
* @author mbastian
*/
public class FunctionImpl implements RankingFunction, PartitionFunction, SimpleFunction {
public abstract class FunctionImpl implements Function {
protected final AppearanceModelImpl model;
protected final String id;
protected final String name;
protected final Graph graph;
protected final Column column;
protected final Transformer transformer;
protected final TransformerUI transformerUI;
protected final PartitionImpl partition;
protected final RankingImpl ranking;
public FunctionImpl(AppearanceModelImpl model, Column column, Transformer transformer, TransformerUI transformerUI) {
this(model, column, transformer, transformerUI, null, null);
}
public FunctionImpl(AppearanceModelImpl model, Column column, Transformer transformer, TransformerUI transformerUI, RankingImpl ranking) {
this(model, column, transformer, transformerUI, null, ranking);
}
public FunctionImpl(AppearanceModelImpl model, Column column, Transformer transformer, TransformerUI transformerUI, PartitionImpl partition) {
this(model, column, transformer, transformerUI, partition, null);
}
public FunctionImpl(AppearanceModelImpl model, Column column, Transformer transformer, TransformerUI transformerUI, PartitionImpl partition, RankingImpl ranking) {
this.model = model;
protected FunctionImpl(String id, String name, Graph graph, Column column, Transformer transformer, TransformerUI transformerUI, PartitionImpl partition, RankingImpl ranking) {
if (id == null) {
throw new NullPointerException("The id can't be null");
}
this.id = id;
this.name = name;
this.column = column;
this.graph = graph;
try {
this.transformer = transformer.getClass().newInstance();
} catch (Exception ex) {
......@@ -97,23 +89,14 @@ public class FunctionImpl implements RankingFunction, PartitionFunction, SimpleF
if (isSimple()) {
((SimpleTransformer) transformer).transform(element);
} else if (isRanking()) {
Number val = (Number) element.getAttribute(column);
Number val = ranking.getValue(element);
((RankingTransformer) transformer).transform(element, ranking, val);
} else if (isPartition()) {
Object val = element.getAttribute(column);
Object val = partition.getValue(element);
((PartitionTransformer) transformer).transform(element, partition, val);
}
}
@Override
public Column getColumn() {
return column;
}
public AppearanceModelImpl getModel() {
return model;
}
@Override
public Transformer getTransformer() {
return transformer;
......@@ -126,7 +109,7 @@ public class FunctionImpl implements RankingFunction, PartitionFunction, SimpleF
@Override
public boolean isSimple() {
return column == null;
return ranking == null && partition == null;
}
@Override
......@@ -145,39 +128,30 @@ public class FunctionImpl implements RankingFunction, PartitionFunction, SimpleF
}
@Override
public Partition getPartition() {
return partition;
}
@Override
public Ranking getRanking() {
return ranking;
public Graph getGraph() {
return graph;
}
@Override
public String toString() {
if (column != null) {
if (column.getTitle() != null) {
return column.getTitle();
} else {
return column.getId();
}
if (name != null) {
return name;
}
return super.toString();
return id;
}
@Override
public int hashCode() {
int hash = 5;
hash = 47 * hash + (this.column != null ? this.column.hashCode() : 0);
hash = 47 * hash + (this.transformer != null ? this.transformer.hashCode() : 0);
hash = 47 * hash + (this.partition != null ? this.partition.hashCode() : 0);
hash = 47 * hash + (this.ranking != null ? this.ranking.hashCode() : 0);
hash = 97 * hash + (this.id != null ? this.id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
......@@ -185,16 +159,7 @@ public class FunctionImpl implements RankingFunction, PartitionFunction, SimpleF
return false;
}
final FunctionImpl other = (FunctionImpl) obj;
if (this.column != other.column && (this.column == null || !this.column.equals(other.column))) {
return false;
}
if (this.transformer != other.transformer && (this.transformer == null || !this.transformer.equals(other.transformer))) {
return false;
}
if (this.partition != other.partition && (this.partition == null || !this.partition.equals(other.partition))) {
return false;
}
if (this.ranking != other.ranking && (this.ranking == null || !this.ranking.equals(other.ranking))) {
if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) {
return false;
}
return true;
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.appearance;
import org.gephi.appearance.api.GraphFunction;
import org.gephi.appearance.api.Partition;
import org.gephi.appearance.api.PartitionFunction;
import org.gephi.appearance.api.Ranking;
import org.gephi.appearance.api.RankingFunction;
import org.gephi.appearance.spi.Transformer;
import org.gephi.appearance.spi.TransformerUI;
import org.gephi.graph.api.Graph;
/**
*
* @author mbastian
*/
public class GraphFunctionImpl extends FunctionImpl implements GraphFunction, RankingFunction, PartitionFunction {
public GraphFunctionImpl(String id, String name, Graph graph, Transformer transformer, TransformerUI transformerUI, RankingImpl ranking) {
super(id, name, graph, null, transformer, transformerUI, null, ranking);
}
public GraphFunctionImpl(String id, String name, Graph graph, Transformer transformer, TransformerUI transformerUI, PartitionImpl partition) {
super(id, name, graph, null, transformer, transformerUI, partition, null);
}
@Override
public PartitionImpl getPartition() {
return partition;
}
@Override
public RankingImpl getRanking() {
return ranking;
}
}
/*
Copyright 2008-2013 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2013 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2013 Gephi Consortium.
*/
package org.gephi.appearance;
import org.gephi.appearance.api.Interpolator;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.Node;
/**
*
* @author mbastian
*/
public class InDegreeRankingImpl extends RankingImpl {
private final DirectedGraph graph;
public InDegreeRankingImpl(DirectedGraph graph, Interpolator interpolator) {
super(interpolator);
this.graph = graph;
}
@Override
public Number getValue(Element element) {
return graph.getInDegree((Node) element);
}
@Override
protected void refresh() {
if (graph.getNodeCount() > 0) {
int minV = Integer.MAX_VALUE;
int maxV = Integer.MIN_VALUE;
for (Node n : graph.getNodes()) {
int degree = graph.getInDegree(n);
minV = Math.min(degree, minV);
maxV = Math.max(degree, maxV);
}
min = minV;
max = maxV;
}
}
}
/*
Copyright 2008-2013 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2013 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2013 Gephi Consortium.
*/
package org.gephi.appearance;
import org.gephi.appearance.api.Interpolator;
import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.Node;
/**
*
* @author mbastian
*/
public class OutDegreeRankingImpl extends RankingImpl {
private final DirectedGraph graph;
public OutDegreeRankingImpl(DirectedGraph graph, Interpolator interpolator) {
super(interpolator);
this.graph = graph;
}
@Override
public Number getValue(Element element) {
return graph.getOutDegree((Node) element);
}
@Override
protected void refresh() {
if (graph.getNodeCount() > 0) {
int minV = Integer.MAX_VALUE;
int maxV = Integer.MIN_VALUE;
for (Node n : graph.getNodes()) {
int degree = graph.getOutDegree(n);
minV = Math.min(degree, minV);
maxV = Math.max(degree, maxV);
}
min = minV;
max = maxV;
}
}
}
......@@ -45,40 +45,19 @@ import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
import org.gephi.appearance.api.Partition;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Index;
/**
*
* @author mbastian
*/
public class PartitionImpl implements Partition {
public abstract class PartitionImpl implements Partition {
private final Index index;
private final Column column;
private final Map<Object, Color> colorMap;
protected final Map<Object, Color> colorMap;
public PartitionImpl(Column column, Index index) {
this.column = column;
this.index = index;
protected PartitionImpl() {
this.colorMap = new HashMap<Object, Color>();
}
@Override
public Iterable getValues() {
return index.values(column);
}
@Override
public int getElementCount() {
return index.countElements(column);
}
@Override
public int count(Object value) {
return index.count(column, value);
}
@Override
public Color getColor(Object value) {
return colorMap.get(value);
......@@ -89,41 +68,4 @@ public class PartitionImpl implements Partition {
colorMap.put(value, color);
}
@Override
public float percentage(Object value) {
int count = index.count(column, value);
return (float) count / index.countElements(column);
}
@Override
public int size() {
return index.countValues(column);
}
@Override
public Column getColumn() {
return column;
}
@Override
public int hashCode() {
int hash = 3;
hash = 23 * hash + (this.column != null ? this.column.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PartitionImpl other = (PartitionImpl) obj;
if (this.column != other.column && (this.column == null || !this.column.equals(other.column))) {
return false;
}
return true;
}
}
......@@ -43,33 +43,31 @@ package org.gephi.appearance;
import org.gephi.appearance.api.Interpolator;
import org.gephi.appearance.api.Ranking;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Index;
/**
*
* @author mbastian
*/
public class RankingImpl implements Ranking {
public abstract class RankingImpl implements Ranking {
private final Index index;
private final Column column;
private Interpolator interpolator;
protected Interpolator interpolator;
protected Number min;
protected Number max;
public RankingImpl(Column column, Index index, Interpolator interpolator) {
this.column = column;
this.index = index;
protected RankingImpl(Interpolator interpolator) {
this.interpolator = interpolator;
}
protected abstract void refresh();
@Override
public Number getMinValue() {
return index.getMinValue(column);
return min;
}
@Override
public Number getMaxValue() {
return index.getMaxValue(column);
return max;
}
@Override
......@@ -84,29 +82,7 @@ public class RankingImpl implements Ranking {
@Override
public float normalize(Number value) {
float normalizedValue = (float) (value.doubleValue() - getMinValue().doubleValue()) / (float) (getMaxValue().doubleValue() - getMinValue().doubleValue());
float normalizedValue = (float) (value.doubleValue() - min.doubleValue()) / (float) (max.doubleValue() - min.doubleValue());
return interpolator.interpolate(normalizedValue);
}
@Override
public int hashCode() {
int hash = 3;
hash = 67 * hash + (this.column != null ? this.column.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final RankingImpl other = (RankingImpl) obj;
if (this.column != other.column && (this.column == null || !this.column.equals(other.column))) {
return false;
}
return true;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.gephi.appearance;
import org.gephi.appearance.api.SimpleFunction;
import org.gephi.appearance.spi.Transformer;
import org.gephi.appearance.spi.TransformerUI;
import org.gephi.graph.api.Graph;
/**
*
* @author mbastian
*/
public class SimpleFunctionImpl extends FunctionImpl implements SimpleFunction {
public SimpleFunctionImpl(String id, Graph graph, Transformer transformer, TransformerUI transformerUI) {
super(id, null, graph, null, transformer, transformerUI, null, null);
}
}
......@@ -41,6 +41,7 @@
*/
package org.gephi.appearance.api;
import org.gephi.graph.api.Graph;
import org.gephi.project.api.Workspace;
/**
......@@ -57,18 +58,16 @@ public interface AppearanceModel {
public Workspace getWorkspace();
/**
* Returns
* <code>true</code> if rankings are using the currently visible graph as a
* scale. If
* <code>false</code> the complete graph is used to determine minimum and
* maximum values, the ranking scale.
* Returns <code>true</code> if rankings are using the currently visible
* graph as a scale. If <code>false</code> the complete graph is used to
* determine minimum and maximum values, the ranking scale.
*
* @return <code>true</code> if using a local scale, <code>false</code> if
* global scale
*/
public boolean isLocalScale();
public Function[] getNodeFunctions();
public Function[] getNodeFunctions(Graph graph);
public Function[] getEdgeFunctions();
public Function[] getEdgeFunctions(Graph graph);
}
......@@ -44,6 +44,7 @@ package org.gephi.appearance.api;
import org.gephi.appearance.spi.Transformer;
import org.gephi.appearance.spi.TransformerUI;
import org.gephi.graph.api.Element;
import org.gephi.graph.api.Graph;
/**
*
......@@ -64,4 +65,6 @@ public interface Function {
public boolean isRanking();
public boolean isPartition();
public Graph getGraph();
}
/*
Copyright 2008-2013 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2013 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2013 Gephi Consortium.
*/
package org.gephi.appearance.api;
/**
*
* @author mbastian
*/
public interface GraphFunction extends Function {
}
......@@ -52,9 +52,7 @@ import java.awt.geom.Point2D;
public abstract class Interpolator {
/**
* Linear interpolation
* <code>x = interpolate(x)
* <code>
* Linear interpolation <code>x = interpolate(x)</code>
*/
public static final Interpolator LINEAR = new Interpolator() {
@Override
......
......@@ -43,6 +43,7 @@ package org.gephi.appearance.api;
import java.awt.Color;
import org.gephi.graph.api.Column;
import org.gephi.graph.api.Element;
/**
*
......@@ -56,6 +57,8 @@ public interface Partition {
public int count(Object value);
public Object getValue(Element element);
public Color getColor(Object value);
public void setColor(Object value, Color color);
......
......@@ -45,7 +45,7 @@ package org.gephi.appearance.api;
*
* @author mbastian
*/
public interface PartitionFunction extends AttributeFunction {
public interface PartitionFunction extends Function {
public Partition getPartition();
}
......@@ -41,6 +41,8 @@
*/
package org.gephi.appearance.api;
import org.gephi.graph.api.Element;
/**
*
* @author mbastian
......@@ -55,5 +57,7 @@ public interface Ranking {
public void setInterpolator(Interpolator interpolator);
public Number getValue(Element element);
public float normalize(Number value);
}
......@@ -45,7 +45,7 @@ package org.gephi.appearance.api;
*
* @author mbastian
*/
public interface RankingFunction extends AttributeFunction {
public interface RankingFunction extends Function {
public Ranking getRanking();
}
NodeGraphFunction.Degree.name = Degree
NodeGraphFunction.InDegree.name = In-Degree
NodeGraphFunction.OutDegree.name = Out-Degree
EdgeGraphFunction.Weight.name = Weight
EdgeGraphFunction.Type.name = Type
......@@ -56,6 +56,9 @@ import org.gephi.appearance.spi.Transformer;
import org.gephi.appearance.spi.TransformerCategory;
import org.gephi.appearance.spi.TransformerUI;
import static org.gephi.desktop.appearance.AppearanceUIController.ELEMENT_CLASSES;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.openide.util.Lookup;
/**
*
......@@ -65,6 +68,7 @@ public class AppearanceUIModel {
protected final AppearanceUIController controller;
protected final AppearanceModel appearanceModel;
protected final GraphController graphController;
protected final Map<String, Map<TransformerCategory, TransformerUI>> selectedTransformerUI;
protected final Map<String, Map<TransformerUI, Function>> selectedFunction;
protected final Map<String, TransformerCategory> selectedCategory;
......@@ -75,6 +79,7 @@ public class AppearanceUIModel {
public AppearanceUIModel(AppearanceUIController controller, AppearanceModel model) {
this.controller = controller;
this.appearanceModel = model;
this.graphController = Lookup.getDefault().lookup(GraphController.class);
//Init maps
selectedCategory = new HashMap<String, TransformerCategory>();
......@@ -90,8 +95,9 @@ public class AppearanceUIModel {
}
private void initSelectedTransformerUIs(String elementClass) {
Graph graph = graphController.getGraphModel(appearanceModel.getWorkspace()).getGraph();
Map<TransformerCategory, TransformerUI> newMap = new HashMap<TransformerCategory, TransformerUI>();
for (Function func : elementClass.equals(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions() : appearanceModel.getEdgeFunctions()) {
for (Function func : elementClass.equals(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions(graph) : appearanceModel.getEdgeFunctions(graph)) {
TransformerUI ui = func.getUI();
if (ui != null) {
TransformerCategory cat = ui.getCategory();
......@@ -111,7 +117,8 @@ public class AppearanceUIModel {
private void refreshSelectedFunctions(String elementClass) {
Set<Function> functionSet = new HashSet<Function>();
for (Function func : elementClass.equals(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions() : appearanceModel.getEdgeFunctions()) {
Graph graph = graphController.getGraphModel(appearanceModel.getWorkspace()).getGraph();
for (Function func : elementClass.equals(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions(graph) : appearanceModel.getEdgeFunctions(graph)) {
TransformerUI ui = func.getUI();
if (ui != null) {
functionSet.add(func);
......@@ -127,9 +134,10 @@ public class AppearanceUIModel {
}
public boolean refreshSelectedFunction() {
Graph graph = graphController.getGraphModel(appearanceModel.getWorkspace()).getGraph();
Function sFunction = getSelectedFunction();
if (sFunction != null && sFunction.isAttribute()) {
for (Function func : getSelectedElementClass().equals(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions() : appearanceModel.getEdgeFunctions()) {
for (Function func : getSelectedElementClass().equals(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions(graph) : appearanceModel.getEdgeFunctions(graph)) {
if (func.equals(sFunction)) {
return false;
}
......@@ -170,8 +178,9 @@ public class AppearanceUIModel {
}
public Collection<Function> getFunctions() {
Graph graph = graphController.getGraphModel(appearanceModel.getWorkspace()).getGraph();
List<Function> functions = new ArrayList<Function>();
for (Function func : selectedElementClass.equalsIgnoreCase(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions() : appearanceModel.getEdgeFunctions()) {
for (Function func : selectedElementClass.equalsIgnoreCase(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions(graph) : appearanceModel.getEdgeFunctions(graph)) {
TransformerUI ui = func.getUI();
if (ui != null && ui.getDisplayName().equals(getSelectedTransformerUI().getDisplayName())) {
if (ui.getCategory().equals(selectedCategory.get(selectedElementClass))) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册