use of org.gephi.appearance.api.Partition in project gephi by gephi.
the class PartitionColorTransformerPanel method setup.
public void setup(PartitionFunction function) {
this.function = function;
NumberFormat formatter = NumberFormat.getPercentInstance();
formatter.setMaximumFractionDigits(2);
Partition partition = function.getPartition();
values = partition.getSortedValues();
List<Object> nullColors = new ArrayList<>();
Color defaultColor = Color.LIGHT_GRAY;
for (Object val : values) {
Color c = partition.getColor(val);
if (c == null) {
nullColors.add(val);
partition.setColor(val, defaultColor);
}
}
int valuesWithColors = values.size() - nullColors.size();
if (!nullColors.isEmpty() && valuesWithColors < 8) {
Color[] cls = PaletteGenerator.generatePalette(Math.min(8, values.size()), 5, new Random(42l));
int i = 0;
for (Object val : nullColors) {
int index = valuesWithColors + i++;
if (index < cls.length) {
partition.setColor(val, cls[index]);
}
}
}
//Model
String[] columnNames = new String[] { "Color", "Partition", "Percentage" };
DefaultTableModel model = new DefaultTableModel(columnNames, values.size()) {
@Override
public boolean isCellEditable(int row, int column) {
return column == 0;
}
};
table.setModel(model);
String countMsg = NbBundle.getMessage(PartitionColorTransformerPanel.class, "PartitionColorTransformerPanel.tooltip.elementsCount");
TableColumn partCol = table.getColumnModel().getColumn(1);
partCol.setCellRenderer(new TextRenderer(null));
TableColumn percCol = table.getColumnModel().getColumn(2);
percCol.setCellRenderer(new TextRenderer(countMsg));
percCol.setPreferredWidth(60);
percCol.setMaxWidth(60);
TableColumn colorCol = table.getColumnModel().getColumn(0);
colorCol.setCellEditor(new ColorChooserEditor());
colorCol.setCellRenderer(new ColorChooserRenderer());
colorCol.setPreferredWidth(16);
colorCol.setMaxWidth(16);
int j = 0;
for (Object value : values) {
String displayName = value == null ? "null" : value.getClass().isArray() ? AttributeUtils.printArray(value) : value.toString();
int count = function.getPartition().count(value);
float percentage = function.getPartition().percentage(value) / 100f;
model.setValueAt(value, j, 0);
model.setValueAt(displayName, j, 1);
String percCount = count + "_(" + formatter.format(percentage) + ")";
model.setValueAt(percCount, j, 2);
j++;
}
}
use of org.gephi.appearance.api.Partition in project gephi by gephi.
the class PartitionPanel method setup.
public void setup(final PartitionFilter filter) {
this.filter = filter;
final Partition partition = filter.getPartition();
if (partition != null) {
refresh(partition, filter.getParts());
}
}
Aggregations