Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to format the lables of a terms panel that is configured #835

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/app/panels/bettermap/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ <h6>Tooltip Field</h6>
<input type="number" class="input-small" ng-model="panel.size">
</div>
</div>
<div class="editor-row">
<div class="editor-option">
<form>
<h6>Map Tile Base URL<tip>Leave blank to use cloudemade</tip></h6>
<input type="text" class="input-xlarge" ng-model="panel.baseurl">
</form>
</div>
</div>
6 changes: 5 additions & 1 deletion src/app/panels/bettermap/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ function (angular, app, _, L, localRequire) {
* tooltip:: Which field to use for the tooltip when hovering over a marker
*/
tooltip : "_id",
/** @scratch /panels/bettermap/5
* baseurl:: Base URL to use when downloading map tiles
*/
baseurl : "https://ssl_tiles.cloudmade.com/57cbb6ca8cac418dbb1a402586df4528/22677/256/",
/** @scratch /panels/bettermap/5
* ==== Queries
* queries object:: This object describes the queries to use on this panel.
Expand Down Expand Up @@ -236,7 +240,7 @@ function (angular, app, _, L, localRequire) {
});

// This could be made configurable?
L.tileLayer('https://ssl_tiles.cloudmade.com/57cbb6ca8cac418dbb1a402586df4528/22677/256/{z}/{x}/{y}.png', {
L.tileLayer(scope.panel.baseurl+"{z}/{x}/{y}.png", {
maxZoom: 18,
minZoom: 2
}).addTo(map);
Expand Down
4 changes: 4 additions & 0 deletions src/app/panels/terms/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ <h5>View Options</h5>
<label class="small" >Legend Format</label>
<select class="input-small" ng-model="panel.arrangement" ng-options="f for f in ['horizontal','vertical']"></select></span>
</div>
<div class="editor-option" ng-show="panel.chart != 'table' && panel.tmode == 'terms_stats'">
<label class="small">Legend Value Format</label>
<select class="input-small" ng-model="panel.format" ng-options="f for f in ['number','float','money','bytes']"></select>
</div>
<div class="editor-option">
<label class="small">Missing</label><input type="checkbox" ng-model="panel.missing" ng-checked="panel.missing">
</div>
Expand Down
24 changes: 23 additions & 1 deletion src/app/panels/terms/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ function (angular, app, _, $, kbn) {
/** @scratch /panels/terms/5
* valuefield:: Terms_stats facet value field
*/
valuefield : ''
valuefield : '',
format : 'number'
};

_.defaults($scope.panel,_d);
Expand Down Expand Up @@ -263,6 +264,7 @@ function (angular, app, _, $, kbn) {
render_panel();
});


function build_results() {
var k = 0;
scope.data = [];
Expand Down Expand Up @@ -364,10 +366,30 @@ function (angular, app, _, $, kbn) {
});
}

var format = function (format, value) {
switch (format) {
case 'money':
value = numeral(value).format('$0,0.00');
break;
case 'bytes':
value = numeral(value).format('0.00b');
break;
case 'float':
value = numeral(value).format('0.00');
break;
default:
value = numeral(value).format('0,0');
}
return value;
};

// Populate legend
if(elem.is(":visible")){
setTimeout(function(){
scope.legend = plot.getData();
for(var i = 0; i < scope.legend.length; i++) {
scope.legend[i].data[0][1] = format(scope.panel.format,scope.legend[i].data[0][1]);
}
if(!scope.$$phase) {
scope.$apply();
}
Expand Down