Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #38 from looker/jim/v1_common_files
Browse files Browse the repository at this point in the history
Add the v1 common files into a single entry point
  • Loading branch information
JimRottinger authored Aug 15, 2018
2 parents a2be649 + 3466ade commit a64be99
Show file tree
Hide file tree
Showing 13 changed files with 621 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/chord.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/collapsible_tree.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/hello_world.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/liquid_fill_gauge.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sankey.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/subtotal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sunburst.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/treemap.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/v1_common.js

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions src/common/common-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
function formatType(valueFormat) {
if (typeof valueFormat != "string") {
return function (x) {return x}
}
let format = ""
switch (valueFormat.charAt(0)) {
case '$':
format += '$'; break
case '£':
format += '£'; break
case '€':
format += '€'; break
}
if (valueFormat.indexOf(',') > -1) {
format += ','
}
splitValueFormat = valueFormat.split(".")
format += '.'
format += splitValueFormat.length > 1 ? splitValueFormat[1].length : 0

switch(valueFormat.slice(-1)) {
case '%':
format += '%'; break
case '0':
format += 'f'; break
}
return d3.format(format)
}

function handleErrors(vis, resp, options) {
function messageFromLimits(min, max, field) {
let message = "You need " + min
if (max) {
message += " to " + max
}
message += " " + field
return message
}

if ((resp.fields.pivots.length < options.min_pivots) ||
(resp.fields.pivots.length > options.max_pivots)) {
let message
vis.addError({
group: "pivot-req",
title: "Incompatible Pivot Data",
message: messageFromLimits(options.min_pivots, options.max_pivots, "pivots"),
});
return false;
} else {
vis.clearErrors("pivot-req");
}

if ((resp.fields.dimensions.length < options.min_dimensions) ||
(resp.fields.dimensions.length > options.max_dimensions)) {
vis.addError({
group: "dim-req",
title: "Incompatible Dimension Data",
message: messageFromLimits(options.min_dimensions, options.max_dimensions, "dimensions"),
});
return false;
} else {
vis.clearErrors("dim-req");
}

if ((resp.fields.measure_like.length < options.min_measures) ||
(resp.fields.measure_like.length > options.max_measures)) {
vis.addError({
group: "mes-req",
title: "Incompatible Measure Data",
message: messageFromLimits(options.min_measures, options.max_measures, "measures"),
});
return false;
} else {
vis.clearErrors("mes-req");
}
return true;
}

global.d3v4 = require('./d3.v4')
global.Highcharts = require('./highcharts')
global.formatType = formatType
global.handleErrors = handleErrors
2 changes: 2 additions & 0 deletions src/common/d3.v4.js

Large diffs are not rendered by default.

Loading

0 comments on commit a64be99

Please sign in to comment.