This repository has been archived by the owner on Apr 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from looker/jim/v1_common_files
Add the v1 common files into a single entry point
- Loading branch information
Showing
13 changed files
with
621 additions
and
10 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.