[Commits] r2371 - in core/trunk/geoext: lib/GeoExt/widgets tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Tue Sep 21 01:51:53 CEST 2010
Author: tschaub
Date: 2010-09-21 01:51:53 +0200 (Tue, 21 Sep 2010)
New Revision: 2371
Modified:
core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js
core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html
Log:
Displaying a number next to untitled rule text that represents the rule index in the rules collection. r=ahocevar (closes #262)
Modified: core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js 2010-09-20 20:11:27 UTC (rev 2370)
+++ core/trunk/geoext/lib/GeoExt/widgets/VectorLegend.js 2010-09-20 23:51:53 UTC (rev 2371)
@@ -69,7 +69,7 @@
* ``String``
* The prefix to use as a title for rules with no title or
* name. Default is ``"Untitled "``. Prefix will be appended with a
- * number.
+ * number that corresponds to the index of the rule (1 for first rule).
*/
untitledPrefix: "Untitled ",
@@ -133,12 +133,6 @@
*/
currentScaleDenominator: null,
- /** private: property[untitledCount]
- * ``Number``
- * Last number used for untitled rule.
- */
- untitledCount: 0,
-
/** private: method[initComponent]
* Initializes the Vector legend.
*/
@@ -631,7 +625,11 @@
* Get a rule title given a rule.
*/
getRuleTitle: function(rule) {
- return rule.title || rule.name || (this.untitledPrefix + (++this.untitledCount));
+ var title = rule.title || rule.name || "";
+ if (!title && this.untitledPrefix) {
+ title = this.untitledPrefix + (this.rules.indexOf(rule) + 1);
+ }
+ return title;
},
/** private: method[beforeDestroy]
Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html 2010-09-20 20:11:27 UTC (rev 2370)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/VectorLegend.html 2010-09-20 23:51:53 UTC (rev 2371)
@@ -159,7 +159,75 @@
t.eq(pointRenderer.symbolType, "Point", "got point renderer");
}
+
+ function test_getRuleTitle(t) {
+ t.plan(9);
+ var legend;
+ var rules = [
+ new OpenLayers.Rule({
+ title: "Rule 0 Title",
+ name: "Rule 0 Name",
+ symbolizers: [
+ new OpenLayers.Symbolizer.Point({
+ pointRadius: 6,
+ fillColor: "red"
+ })
+ ]
+ }),
+ new OpenLayers.Rule({
+ name: "Rule 1 Name",
+ symbolizers: [
+ new OpenLayers.Symbolizer.Point({
+ pointRadius: 8,
+ fillColor: "red"
+ })
+ ]
+ }),
+ new OpenLayers.Rule({
+ symbolizers: [
+ new OpenLayers.Symbolizer.Point({
+ pointRadius: 10,
+ fillColor: "red"
+ })
+ ]
+ })
+ ];
+
+ // [a] test legend with default config
+ legend = new GeoExt.VectorLegend({
+ renderTo: "legendpanel",
+ rules: rules
+ });
+ t.eq(legend.getRuleTitle(rules[0]), "Rule 0 Title", "[a] rule.title used when present");
+ t.eq(legend.getRuleTitle(rules[1]), "Rule 1 Name", "[a] rule.name used if rule.title not present");
+ t.eq(legend.getRuleTitle(rules[2]), "Untitled 3", "[a] Untitled X (where x is index + 1) used when no rule.title or rule.name");
+ legend.destroy();
+
+ // [b] test legend with custom untitledPrefix
+ legend = new GeoExt.VectorLegend({
+ renderTo: "legendpanel",
+ rules: rules,
+ untitledPrefix: "foo "
+ });
+ t.eq(legend.getRuleTitle(rules[0]), "Rule 0 Title", "[b] rule.title used when present");
+ t.eq(legend.getRuleTitle(rules[1]), "Rule 1 Name", "[b] rule.name used if rule.title not present");
+ t.eq(legend.getRuleTitle(rules[2]), "foo 3", "[b] foo X (where x is index + 1) used when no rule.title or rule.name");
+ legend.destroy();
+
+ // [c] test legend with null untitledPrefix
+ legend = new GeoExt.VectorLegend({
+ renderTo: "legendpanel",
+ rules: rules,
+ untitledPrefix: null
+ });
+ t.eq(legend.getRuleTitle(rules[0]), "Rule 0 Title", "[c] rule.title used when present");
+ t.eq(legend.getRuleTitle(rules[1]), "Rule 1 Name", "[c] rule.name used if rule.title not present");
+ t.eq(legend.getRuleTitle(rules[2]), "", "[c] empty string used when no rule.title or rule.name");
+ legend.destroy();
+
+ }
+
</script>
</head><body>
<div id="legendpanel"></div>
More information about the Commits
mailing list