提交 734abf2a 编写于 作者: K kohsuke

Labels for nodes are shown in a tag cloud style. Compared to the patch, the...

Labels for nodes are shown in a tag cloud style. Compared to the patch, the following changes are made:

- fixed a divide-by-0 problem if every weight is 0.
- Stapler prefers a typed data structure over bare Map, so TagCloudFactory is changed to TagCloud.
- There are different tag cloud rendering for the same model, so the weight assignment is pushed outside the item. For example, labels can be made into a tag cloud via # of slave / # of tied jobs, etc.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@21086 71c3de6d-444a-0410-be80-ed276b4c234a
上级 ab9ad519
......@@ -38,6 +38,8 @@ import hudson.slaves.NodePropertyDescriptor;
import hudson.util.ClockDifference;
import hudson.util.DescribableList;
import hudson.util.EnumConverter;
import hudson.util.TagCloud;
import hudson.util.TagCloud.WeightFunction;
import java.io.IOException;
import java.util.Set;
......@@ -161,6 +163,16 @@ public abstract class Node extends AbstractModelObject implements Describable<No
*/
protected abstract Computer createComputer();
/**
* Return the possibly empty tag cloud for the labels of this node.
*/
public TagCloud<Label> getLabelCloud() {
return new TagCloud<Label>(getAssignedLabels(),new WeightFunction<Label>() {
public float weight(Label item) {
return item.getTiedJobs().size();
}
});
}
/**
* Returns the possibly empty set of labels that are assigned to this node,
* including the automatic {@link #getSelfLabel() self label}.
......
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.util;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
/**
* Represents an order-preserving tag cloud (http://en.wikipedia.org/wiki/Tag_cloud)
* where each keyword gets a weight and displayed according to their weight.
*
* TODO: define a view on its own.
*
* @since 1.322
*/
public class TagCloud<T> extends AbstractList<TagCloud<T>.Entry> {
public final class Entry {
public final T item;
public final float weight;
public Entry(T item, float weight) {
this.item = item;
this.weight = weight;
}
public float scale() {
// TODO: it's not obvious if linear scaling is the right approach or not.
return weight*9/max;
}
public String getClassName() {
return "tag"+((int)scale());
}
}
public interface WeightFunction<T> {
float weight(T item);
}
private final List<Entry> entries = new ArrayList<Entry>();
private float max = 1;
/**
* Creates a tag cloud.
*
* @param f
* Assigns weight to each item.
*/
public TagCloud(Iterable<? extends T> inputs, WeightFunction<T> f) {
for (T input : inputs) {
float w = Math.abs(f.weight(input));
max = Math.max(w,max);
entries.add(new Entry(input, w));
}
}
public Entry get(int index) {
return entries.get(index);
}
public int size() {
return entries.size();
}
}
......@@ -65,9 +65,10 @@ THE SOFTWARE.
<j:if test="${it.node.assignedLabels.size() gt 1}">
<div>
${%Labels:}
<j:forEach var="l" items="${it.node.assignedLabels}">
<j:if test="${l!=it.node.selfLabel}">
<a href="${rootURL}/label/${l.name}">${l.name}</a>
<j:forEach var="entry" items="${it.node.labelCloud}">
<!-- Skip the label for this node -->
<j:if test="${entry.item!=it.node.selfLabel}">
<a class="${entry.className}" href="${rootURL}/label/${entry.item.name}">${entry.item.name}</a>
<st:nbsp/>
</j:if>
</j:forEach>
......
......@@ -873,3 +873,15 @@ table.progress-bar.red td.progress-bar-done {
margin: 0 !important;
}
/* ========================= tags/labels ================== */
/* tag0 is the least important tag in a tag cloud */
.tag0 { font-size: 1.00em; }
.tag1 { font-size: 1.10em; }
.tag2 { font-size: 1.20em; }
.tag3 { font-size: 1.30em; }
.tag4 { font-size: 1.40em; }
.tag5 { font-size: 1.50em; }
.tag6 { font-size: 1.60em; }
.tag7 { font-size: 1.70em; }
.tag8 { font-size: 1.80em; }
.tag9 { font-size: 1.90em; }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册