Skip to content

Commit

Permalink
Merge pull request #242 from ejabx/blp_dev
Browse files Browse the repository at this point in the history
News Profile: Color Color Ramp and Export AVMM Size
  • Loading branch information
tylerparsons authored Jan 30, 2018
2 parents 7165235 + 49534ff commit 05b7ecc
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
12 changes: 10 additions & 2 deletions lib/assets/javascripts/cartodb/models/carto.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,16 @@ function choropleth_generator(table, props, changed, callback) {

var fn = carto_functionMap[props['qfunction'] || DEFAULT_QFUNCTION];
var prop = props['property'];
var nquartiles = methodMap[props['method']];
var ramp = cdb.admin.color_ramps[props['color_ramp']][nquartiles];
var ramp, nquartiles;
var user = new cdb.admin.User(user_data);
var customColorRamps = user.profileAttributes.get('customColorRamps');
if (customColorRamps) {
ramp = customColorRamps[props['color_ramp']];
nquartiles = ramp.length;
} else {
nquartiles = methodMap[props['method']];
ramp = cdb.admin.color_ramps[props['color_ramp']][nquartiles];
}

if(!ramp) {
cdb.log.error("no color ramp defined for " + nquartiles + " quartiles");
Expand Down
14 changes: 14 additions & 0 deletions lib/assets/javascripts/cartodb/table/mapview.js
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,18 @@ cdb.admin.MapTab = cdb.core.View.extend({
this.export_form_data[0].form.destination.value = 'Local';
this.export_form_data[0].form.destination.extra.splice(0, 1);
}
if(this.user.profileAttributes.get('customExportSizes')) {
var customExportSizes = this.user.profileAttributes.get('customExportSizes');
this.export_sizes = customExportSizes.exportSizes.sizes;
this.default_export_size = this.export_size = this.last_export_size = Object.keys(customExportSizes.exportSizes.sizes)[customExportSizes.exportSizes.defaultIndex];
this.export_form_data[1].form.size.extra = customExportSizes.exportSizesMenu.sizes;
this.export_form_data[1].form.size.value = customExportSizes.exportSizesMenu.sizes[customExportSizes.exportSizesMenu.defaultIndex];
this.customSizeMapping = {}
var that = this;
Object.keys(customExportSizes.exportSizesMenu.sizes).forEach(function (key, i) {
that.customSizeMapping[customExportSizes.exportSizesMenu.sizes[key]] = Object.keys(customExportSizes.exportSizes.sizes)[key];
});
}
},

_addBindings: function() {
Expand Down Expand Up @@ -2177,6 +2189,8 @@ cdb.admin.MapTab = cdb.core.View.extend({
selectedSize = 'medium';
} else if (selection.indexOf('Large') > -1) {
selectedSize = 'large';
} else if (this.customSizeMapping.hasOwnProperty(selection)) {
selectedSize = this.customSizeMapping[selection];
} else {
console.error('unrecognized size selection ' + selection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,17 @@ var color_ramp_point = {
}
};

var user = new cdb.admin.User(user_data);
var customColorRamps = user.profileAttributes.get('customColorRamps');
if (customColorRamps) {
var ramps = Object.keys(customColorRamps);
var colorRampForm = { 'type': 'select', value: ramps[0], extra: ramps };

color_ramp_polyline.form.color_ramp = colorRampForm;
color_ramp_polygon.form.color_ramp = colorRampForm;
color_ramp_point.form.color_ramp = colorRampForm;
}

var bubble_form = [
column_numeric, // Select column
QuantifyFn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ cdb.admin.mod.ChoroplethLegend = cdb.admin.mod.CustomLegend.extend({
'7 Buckets': 7
};

var nquartiles = methodMap[this.wizardProperties.get('method')];
var ramp = cdb.admin.color_ramps[this.wizardProperties.get('color_ramp')][nquartiles];

var nquartiles, ramp;
var user = new cdb.admin.User(user_data);
var customColorRamps = user.profileAttributes.get('customColorRamps');
if (customColorRamps) {
ramp = customColorRamps[this.wizardProperties.get('color_ramp')];
nquartiles = ramp.length;
} else {
nquartiles = methodMap[this.wizardProperties.get('method')];
ramp = cdb.admin.color_ramps[this.wizardProperties.get('color_ramp')][nquartiles];
}

/* Left label */
// If a custom label was previously set, we don't change it
Expand Down
24 changes: 20 additions & 4 deletions vendor/assets/javascripts/select2.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,15 @@ the specific language governing permissions and limitations under the Apache Lic
var color = $(this.container).find(".select2-choice").text().replace(/ /g,"")
, bucket = $(this.container).attr("class").match(/(\d)_buckets/)[1]
, html = "<ul>"
, colors = cdb.admin.color_ramps[color][bucket];
, colors;

var user = new cdb.admin.User(user_data);
var customColorRamps = user.profileAttributes.get('customColorRamps');
if (customColorRamps) {
colors = customColorRamps[color];
} else {
colors = cdb.admin.color_ramps[color][bucket];
}

for (var j=0, c_l = colors.length; j<c_l; j++) {
var color = colors[j];
Expand All @@ -689,7 +697,7 @@ the specific language governing permissions and limitations under the Apache Lic

$(this.container).find('.select2-choice').append(html);
} catch(e) {
cdb.log.info("Failing Select plugin when tries to generate a color ramp dropdown");
cdb.log.info("Failing Select plugin when tries to generate a color ramp dropdown: " + e.toString());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -794,7 +802,15 @@ the specific language governing permissions and limitations under the Apache Lic
var color = result.text
, bucket = $(container.prevObject).attr("class").match(/(\d)_buckets/)[1]
, html = "<table><tr>"
, colors = cdb.admin.color_ramps[color][bucket];
, colors;

var user = new cdb.admin.User(user_data);
var customColorRamps = user.profileAttributes.get('customColorRamps');
if (customColorRamps) {
colors = customColorRamps[color];
} else {
colors = cdb.admin.color_ramps[color][bucket];
}

for (var j=0, c_l = colors.length; j<c_l; j++) {
var color = colors[j];
Expand All @@ -805,7 +821,7 @@ the specific language governing permissions and limitations under the Apache Lic

label.append(html);
} catch(e) {
cdb.log.info("Failing Select plugin when tries to generate a color ramp dropdown");
cdb.log.info("Failing Select plugin when tries to generate a color ramp dropdown: " + e.toString());
}
}
//////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 05b7ecc

Please sign in to comment.