diff --git a/.eslintrc.js b/.eslintrc.js index a407a46c90755..59ae8c43e1d11 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -70,6 +70,7 @@ module.exports = { 'packages/kbn-test/**/*', 'packages/kbn-eslint-import-resolver-kibana/**/*', 'x-pack/plugins/apm/**/*', + 'x-pack/plugins/canvas/**/*', ], plugins: ['prettier'], rules: Object.assign( @@ -366,43 +367,30 @@ module.exports = { */ { files: ['x-pack/plugins/canvas/**/*'], - plugins: ['prettier'], rules: { - // preferences - 'comma-dangle': [2, 'always-multiline'], - 'no-multiple-empty-lines': [2, { max: 1, maxEOF: 1 }], - 'no-multi-spaces': 2, - radix: 2, - curly: [2, 'multi-or-nest', 'consistent'], - - // annoying rules that conflict with prettier - 'space-before-function-paren': 0, - indent: 0, - 'wrap-iife': 0, - 'max-len': 0, + radix: 'error', + curly: ['error', 'all'], // module importing 'import/order': [ - 2, - { groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'] }, + 'error', + { + groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'], + }, ], - 'import/extensions': [2, 'never', { json: 'always', less: 'always', svg: 'always' }], - - // prettier - 'prettier/prettier': 2, + 'import/extensions': ['error', 'never', { json: 'always', less: 'always', svg: 'always' }], // react - 'jsx-quotes': 2, - 'react/no-did-mount-set-state': 2, - 'react/no-did-update-set-state': 2, - 'react/no-multi-comp': [2, { ignoreStateless: true }], - 'react/self-closing-comp': 2, - 'react/sort-comp': 2, - 'react/jsx-boolean-value': 2, - 'react/jsx-wrap-multilines': 2, - 'react/no-unescaped-entities': [2, { forbid: ['>', '}'] }], + 'react/no-did-mount-set-state': 'error', + 'react/no-did-update-set-state': 'error', + 'react/no-multi-comp': ['error', { ignoreStateless: true }], + 'react/self-closing-comp': 'error', + 'react/sort-comp': 'error', + 'react/jsx-boolean-value': 'error', + 'react/jsx-wrap-multilines': 'error', + 'react/no-unescaped-entities': ['error', { forbid: ['>', '}'] }], 'react/forbid-elements': [ - 2, + 'error', { forbid: [ { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/sort.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/sort.js index 3cfaf7d46ae18..9940be856ec91 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/sort.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/sort.js @@ -13,7 +13,9 @@ describe('sort', () => { const fn = functionWrapper(sort); const isSorted = (rows, column, reverse) => { - if (reverse) return !rows.some((row, i) => rows[i + 1] && row[column] < rows[i + 1][column]); + if (reverse) { + return !rows.some((row, i) => rows[i + 1] && row[column] < rows[i + 1][column]); + } return !rows.some((row, i) => rows[i + 1] && row[column] > rows[i + 1][column]); }; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.js index c4e465b76c812..0c706e4d562bb 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.js @@ -32,18 +32,25 @@ export const alterColumn = () => ({ }, }, fn: (context, args) => { - if (!args.column || (!args.type && !args.name)) return context; + if (!args.column || (!args.type && !args.name)) { + return context; + } const column = context.columns.find(col => col.name === args.column); - if (!column) throw new Error(`Column not found: '${args.column}'`); + if (!column) { + throw new Error(`Column not found: '${args.column}'`); + } const name = args.name || column.name; const type = args.type || column.type; const columns = context.columns.reduce((all, col) => { if (col.name !== args.name) { - if (col.name !== column.name) all.push(col); - else all.push({ name, type }); + if (col.name !== column.name) { + all.push(col); + } else { + all.push({ name, type }); + } } return all; }, []); @@ -54,7 +61,9 @@ export const alterColumn = () => ({ handler = (function getHandler() { switch (type) { case 'string': - if (column.type === 'date') return v => new Date(v).toISOString(); + if (column.type === 'date') { + return v => new Date(v).toISOString(); + } return String; case 'number': return Number; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axisConfig.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axisConfig.js index 0d37c3b32c45f..a89f2206023ae 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axisConfig.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axisConfig.js @@ -42,7 +42,9 @@ export const axisConfig = () => ({ }, fn: (context, args) => { const positions = ['top', 'bottom', 'left', 'right', '']; - if (!positions.includes(args.position)) throw new Error(`Invalid position ${args.position}`); + if (!positions.includes(args.position)) { + throw new Error(`Invalid position ${args.position}`); + } const min = typeof args.min === 'string' ? moment.utc(args.min).valueOf() : args.min; const max = typeof args.max === 'string' ? moment.utc(args.max).valueOf() : args.max; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.js index b4579c414afce..026614cee2331 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.js @@ -33,12 +33,18 @@ export const caseFn = () => ({ }); async function doesMatch(context, args) { - if (typeof args.if !== 'undefined') return args.if; - if (typeof args.when !== 'undefined') return (await args.when()) === context; + if (typeof args.if !== 'undefined') { + return args.if; + } + if (typeof args.when !== 'undefined') { + return (await args.when()) === context; + } return true; } async function getResult(context, args) { - if (typeof args.then !== 'undefined') return await args.then(); + if (typeof args.then !== 'undefined') { + return await args.then(); + } return context; } diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.js index 1dba45a459471..a022ac707eb4a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.js @@ -46,7 +46,9 @@ export const columns = () => ({ const columns = []; fields.forEach(field => { const column = find(result.columns, { name: field }); - if (column) columns.push(column); + if (column) { + columns.push(column); + } }); const rows = columns.length > 0 ? result.rows.map(row => pick(row, fields)) : []; result = { ...result, rows, columns }; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.js index c9dd2245b8696..a0c117af7dd8d 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.js @@ -41,16 +41,24 @@ export const compare = () => ({ case 'ne': return a !== b; case 'lt': - if (typesMatch) return a < b; + if (typesMatch) { + return a < b; + } return false; case 'lte': - if (typesMatch) return a <= b; + if (typesMatch) { + return a <= b; + } return false; case 'gt': - if (typesMatch) return a > b; + if (typesMatch) { + return a > b; + } return false; case 'gte': - if (typesMatch) return a >= b; + if (typesMatch) { + return a >= b; + } return false; default: throw new Error('Invalid compare operator. Use eq, ne, lt, gt, lte, or gte.'); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.js index a5e71e3143e16..8ff58b539d6d9 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.js @@ -67,8 +67,9 @@ export const containerStyle = () => ({ }; if (backgroundImage) { - if (!isValidUrl(backgroundImage)) + if (!isValidUrl(backgroundImage)) { throw new Error('Invalid backgroundImage. Please provide an asset or a URL.'); + } style.backgroundImage = `url(${backgroundImage})`; style.backgroundSize = backgroundSize; style.backgroundRepeat = backgroundRepeat; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.js index 4a02b901786c8..63df4fc6d06d6 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.js @@ -41,8 +41,12 @@ export const csv = () => ({ }, }; - if (delimiter != null) config.delimiter = delimiter; - if (newline != null) config.newline = newline; + if (delimiter != null) { + config.delimiter = delimiter; + } + if (newline != null) { + config.newline = newline; + } // TODO: handle errors, check output.errors const output = Papa.parse(csvString, config); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.js index 23b2631325763..ff17cf25518d1 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.js @@ -8,7 +8,9 @@ import moment from 'moment'; const getInputDate = input => { // return current date if no input - if (!input) return new Date(); + if (!input) { + return new Date(); + } // return the input return input; @@ -40,7 +42,9 @@ export const date = () => ({ const useMoment = date && format; const outputDate = useMoment ? moment.utc(date, format).toDate() : new Date(getInputDate(date)); - if (isNaN(outputDate.getTime())) throw new Error(`Invalid date input: ${date}`); + if (isNaN(outputDate.getTime())) { + throw new Error(`Invalid date input: ${date}`); + } return outputDate.valueOf(); }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdownControl.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdownControl.js index ebb94cde8fb68..dddec18e5a809 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdownControl.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdownControl.js @@ -26,8 +26,9 @@ export const dropdownControl = () => ({ }, fn: (context, { valueColumn, filterColumn }) => { let choices = []; - if (context.rows[0][valueColumn]) + if (context.rows[0][valueColumn]) { choices = uniq(context.rows.map(row => row[valueColumn])).sort(); + } const column = filterColumn || valueColumn; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/font.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/font.js index c8b0141d2ef24..ec99f19d8d598 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/font.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/font.js @@ -79,8 +79,12 @@ export const font = () => ({ }, }, fn: (context, args) => { - if (!weights.includes(args.weight)) throw new Error(`Invalid font weight: ${args.weight}`); - if (!alignments.includes(args.align)) throw new Error(`Invalid text alignment: ${args.align}`); + if (!weights.includes(args.weight)) { + throw new Error(`Invalid font weight: ${args.weight}`); + } + if (!alignments.includes(args.align)) { + throw new Error(`Invalid text alignment: ${args.align}`); + } // the line height shouldn't ever be lower than the size const lineHeight = args.lHeight ? `${args.lHeight}px` : 1; @@ -96,7 +100,9 @@ export const font = () => ({ }; // conditionally apply styles based on input - if (args.color) spec.color = args.color; + if (args.color) { + spec.color = args.color; + } return { type: 'style', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.js index 489317928e035..5a33e750d5065 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.js @@ -20,7 +20,9 @@ export const formatdate = () => ({ }, }, fn: (context, args) => { - if (!args.format) return moment.utc(new Date(context)).toISOString(); + if (!args.format) { + return moment.utc(new Date(context)).toISOString(); + } return moment.utc(new Date(context)).format(args.format); }, }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.js index ff3cd5f243d46..a2f8546068f0f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.js @@ -21,7 +21,9 @@ export const formatnumber = () => ({ }, }, fn: (context, args) => { - if (!args.format) return String(context); + if (!args.format) { + return String(context); + } return numeral(context).format(args.format); }, }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.js index 625db0a434a4d..e978c6d64c9f8 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.js @@ -25,12 +25,16 @@ export const getCell = () => ({ }, fn: (context, args) => { const row = context.rows[args.row]; - if (!row) throw new Error(`Row not found: ${args.row}`); + if (!row) { + throw new Error(`Row not found: ${args.row}`); + } const { column = context.columns[0].name } = args; const value = row[column]; - if (typeof value === 'undefined') throw new Error(`Column not found: ${column}`); + if (typeof value === 'undefined') { + throw new Error(`Column not found: ${column}`); + } return value; }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.js index ccde455f20cba..5bde46008b43a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.js @@ -17,7 +17,9 @@ export const gt = () => ({ }, }, fn: (context, args) => { - if (typeof context !== typeof args.value) return false; + if (typeof context !== typeof args.value) { + return false; + } return context > args.value; }, }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.js index 691deae146c05..e368560988eaf 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.js @@ -17,7 +17,9 @@ export const gte = () => ({ }, }, fn: (context, args) => { - if (typeof context !== typeof args.value) return false; + if (typeof context !== typeof args.value) { + return false; + } return context >= args.value; }, }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.js index fa54a14b0998a..1d67e6425851f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.js @@ -27,10 +27,14 @@ export const ifFn = () => ({ }, fn: async (context, args) => { if (args.condition) { - if (typeof args.then === 'undefined') return context; + if (typeof args.then === 'undefined') { + return context; + } return await args.then(); } else { - if (typeof args.else === 'undefined') return context; + if (typeof args.else === 'undefined') { + return context; + } return await args.else(); } }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.js index 5bf6c429331f7..577580eb3f41a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.js @@ -36,7 +36,9 @@ export const image = () => ({ }, }, fn: (context, { dataurl, mode }) => { - if (!modes.includes(mode)) throw '"mode" must be "contain", "cover", or "stretch"'; + if (!modes.includes(mode)) { + throw '"mode" must be "contain", "cover", or "stretch"'; + } const modeStyle = mode === 'stretch' ? '100% 100%' : mode; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.js index f2d90639fc995..a7c87657deb4f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.js @@ -17,7 +17,9 @@ export const lt = () => ({ }, }, fn: (context, args) => { - if (typeof context !== typeof args.value) return false; + if (typeof context !== typeof args.value) { + return false; + } return context < args.value; }, }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.js index ed9a413a71ede..98822ed2235e8 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.js @@ -17,7 +17,9 @@ export const lte = () => ({ }, }, fn: (context, args) => { - if (typeof context !== typeof args.value) return false; + if (typeof context !== typeof args.value) { + return false; + } return context <= args.value; }, }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.js index 825744858527f..a909aca0bda2f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.js @@ -49,8 +49,11 @@ export const mapColumn = () => ({ const existingColumnIndex = columns.findIndex(({ name }) => name === args.name); const type = getType(rows[0][args.name]); const newColumn = { name: args.name, type }; - if (existingColumnIndex === -1) columns.push(newColumn); - else columns[existingColumnIndex] = newColumn; + if (existingColumnIndex === -1) { + columns.push(newColumn); + } else { + columns[existingColumnIndex] = newColumn; + } return { type: 'datatable', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/math.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/math.js index ded8500ffbb09..132e35be043d3 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/math.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/math.js @@ -25,7 +25,9 @@ export const math = () => ({ }, }, fn: (context, args) => { - if (!args.expression || args.expression.trim() === '') throw new Error('Empty expression'); + if (!args.expression || args.expression.trim() === '') { + throw new Error('Empty expression'); + } const isDatatable = context && context.type === 'datatable'; const mathContext = isDatatable @@ -34,17 +36,23 @@ export const math = () => ({ try { const result = evaluate(args.expression, mathContext); if (Array.isArray(result)) { - if (result.length === 1) return result[0]; + if (result.length === 1) { + return result[0]; + } throw new Error( 'Expressions must return a single number. Try wrapping your expression in mean() or sum()' ); } - if (isNaN(result)) + if (isNaN(result)) { throw new Error('Failed to execute math expression. Check your column names'); + } return result; } catch (e) { - if (context.rows.length === 0) throw new Error('Empty datatable'); - else throw e; + if (context.rows.length === 0) { + throw new Error('Empty datatable'); + } else { + throw e; + } } }, }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/pie.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/pie.js index 2cc0fbaeb30c0..bc206e3fb0c2b 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/pie.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/pie.js @@ -79,7 +79,9 @@ export const pie = () => ({ const seriesStyle = seriesStyles[label]; // append series style, if there is a match - if (seriesStyle) item.color = get(seriesStyle, 'color'); + if (seriesStyle) { + item.color = get(seriesStyle, 'color'); + } return item; }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_flot_axis_config.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_flot_axis_config.js index 6391b01c3ded6..ea426abff8e5b 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_flot_axis_config.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_flot_axis_config.js @@ -8,7 +8,9 @@ import { get, map } from 'lodash'; import { getType } from '@kbn/interpreter/common'; export const getFlotAxisConfig = (axis, argValue, { columns, ticks, font } = {}) => { - if (!argValue || argValue.show === false) return { show: false }; + if (!argValue || argValue.show === false) { + return { show: false }; + } const config = { show: true }; const axisType = get(columns, `${axis}.type`); @@ -21,19 +23,30 @@ export const getFlotAxisConfig = (axis, argValue, { columns, ticks, font } = {}) config.position = acceptedPositions.includes(position) ? position : acceptedPositions[0]; if (axisType === 'number' || axisType === 'date') { - if (min) config.min = min; - if (max) config.max = max; + if (min) { + config.min = min; + } + if (max) { + config.max = max; + } } - if (tickSize && axisType === 'number') config.tickSize = tickSize; + if (tickSize && axisType === 'number') { + config.tickSize = tickSize; + } } - if (axisType === 'string') + if (axisType === 'string') { config.ticks = map(ticks[axis].hash, (position, name) => [position, name]); + } - if (axisType === 'date') config.mode = 'time'; + if (axisType === 'date') { + config.mode = 'time'; + } - if (typeof font === 'object') config.font = font; + if (typeof font === 'object') { + config.font = font; + } return config; }; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_font_spec.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_font_spec.js index 1d9242833b646..7532a6ac840f9 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_font_spec.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_font_spec.js @@ -17,7 +17,9 @@ export const defaultSpec = { }; export const getFontSpec = argFont => { - if (!argFont || !argFont.spec) return defaultSpec; + if (!argFont || !argFont.spec) { + return defaultSpec; + } const { fontSize, lineHeight, fontStyle, fontWeight, fontFamily, color } = argFont.spec; const size = fontSize && Number(fontSize.replace('px', '')); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_tick_hash.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_tick_hash.js index 6ca670b881303..0e7f8306e48e3 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_tick_hash.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_tick_hash.js @@ -20,7 +20,9 @@ export const getTickHash = (columns, rows) => { if (get(columns, 'x.type') === 'string') { sortBy(rows, ['x']).forEach(row => { - if (!ticks.x.hash[row.x]) ticks.x.hash[row.x] = ticks.x.counter++; + if (!ticks.x.hash[row.x]) { + ticks.x.hash[row.x] = ticks.x.counter++; + } }); } @@ -28,7 +30,9 @@ export const getTickHash = (columns, rows) => { sortBy(rows, ['y']) .reverse() .forEach(row => { - if (!ticks.y.hash[row.y]) ticks.y.hash[row.y] = ticks.y.counter++; + if (!ticks.y.hash[row.y]) { + ticks.y.hash[row.y] = ticks.y.counter++; + } }); } diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/index.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/index.js index c76a7d658da09..4b00d4c399323 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/index.js @@ -88,7 +88,9 @@ export const plot = () => ({ set(flotStyle, 'bubbles.size.min', seriesStyle.points); } - if (point.text != null) attrs.text = point.text; + if (point.text != null) { + attrs.text = point.text; + } return [x, y, attrs]; }), diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/series_style_to_flot.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/series_style_to_flot.js index 644487e4ac71e..1b187c8e44ca6 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/series_style_to_flot.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/series_style_to_flot.js @@ -7,7 +7,9 @@ import { get } from 'lodash'; export const seriesStyleToFlot = seriesStyle => { - if (!seriesStyle) return {}; + if (!seriesStyle) { + return {}; + } const lines = get(seriesStyle, 'lines'); const bars = get(seriesStyle, 'bars'); @@ -42,8 +44,12 @@ export const seriesStyleToFlot = seriesStyle => { }, }; - if (stack) flotStyle.stack = stack; - if (color) flotStyle.color = color; + if (stack) { + flotStyle.stack = stack; + } + if (color) { + flotStyle.color = color; + } return flotStyle; }; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.js index f3f167275949f..c082c5c4c988d 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.js @@ -10,8 +10,11 @@ function combineColumns(arrayOfColumnsArrays) { return arrayOfColumnsArrays.reduce((resultingColumns, columns) => { if (columns) { columns.forEach(column => { - if (resultingColumns.find(resultingColumn => resultingColumn.name === column.name)) return; - else resultingColumns.push(column); + if (resultingColumns.find(resultingColumn => resultingColumn.name === column.name)) { + return; + } else { + resultingColumns.push(column); + } }); } @@ -27,8 +30,9 @@ function combineAcross(datatableArray) { // Sanity check datatableArray.forEach(datatable => { - if (datatable.rows.length !== targetRowLength) + if (datatable.rows.length !== targetRowLength) { throw new Error('All expressions must return the same number of rows'); + } }); // Merge columns and rows. @@ -81,14 +85,18 @@ export const ply = () => ({ // The way the function below is written you can add as many arbitrary named args as you want. }, fn: (context, args) => { - if (!args) return context; + if (!args) { + return context; + } let byColumns; let originalDatatables; if (args.by) { byColumns = args.by.map(by => { const column = context.columns.find(column => column.name === by); - if (!column) throw new Error(`No such column: ${by}`); + if (!column) { + throw new Error(`No such column: ${by}`); + } return column; }); const keyedDatatables = groupBy(context.rows, row => JSON.stringify(pick(row, args.by))); @@ -103,9 +111,11 @@ export const ply = () => ({ const datatablePromises = originalDatatables.map(originalDatatable => { let expressionResultPromises = []; - if (args.expression) + if (args.expression) { expressionResultPromises = args.expression.map(expression => expression(originalDatatable)); - else expressionResultPromises.push(Promise.resolve(originalDatatable)); + } else { + expressionResultPromises.push(Promise.resolve(originalDatatable)); + } return Promise.all(expressionResultPromises).then(combineAcross); }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.js index 453730b3f861a..863e606984f74 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.js @@ -71,11 +71,17 @@ export const progress = () => ({ }, }, fn: (value, args) => { - if (args.max <= 0) throw new Error(`'max' must be greater than 0`); - if (value > args.max || value < 0) throw new Error(`Context must be between 0 and ${args.max}`); + if (args.max <= 0) { + throw new Error(`'max' must be greater than 0`); + } + if (value > args.max || value < 0) { + throw new Error(`Context must be between 0 and ${args.max}`); + } let label = ''; - if (args.label) label = typeof args.label === 'string' ? args.label : `${value}`; + if (args.label) { + label = typeof args.label === 'string' ? args.label : `${value}`; + } let font = {}; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/revealImage.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/revealImage.js index 9d54dc9363b95..888f0899978da 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/revealImage.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/revealImage.js @@ -34,7 +34,9 @@ export const revealImage = () => ({ }, }, fn: (percent, args) => { - if (percent > 1 || percent < 0) throw new Error('input must be between 0 and 1'); + if (percent > 1 || percent < 0) { + throw new Error('input must be between 0 and 1'); + } return { type: 'render', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.js index 1eeccd1b19432..e5b95d881878c 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.js @@ -22,7 +22,9 @@ export const rounddate = () => ({ }, }, fn: (context, args) => { - if (!args.format) return context; + if (!args.format) { + return context; + } return moment.utc(moment.utc(context).format(args.format), args.format).valueOf(); }, }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.js index 4a5d06ac8c170..648d6860e04b8 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.js @@ -34,8 +34,11 @@ export const staticColumn = () => ({ const existingColumnIndex = columns.findIndex(({ name }) => name === args.name); const newColumn = { name: args.name, type }; - if (existingColumnIndex > -1) columns[existingColumnIndex] = newColumn; - else columns.push(newColumn); + if (existingColumnIndex > -1) { + columns[existingColumnIndex] = newColumn; + } else { + columns.push(newColumn); + } return { type: 'datatable', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.js index 3cb3577cf74c8..1e3ef069c8c6b 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.js @@ -25,9 +25,13 @@ export const switchFn = () => ({ const cases = args.case || []; for (let i = 0; i < cases.length; i++) { const { matches, result } = await cases[i](); - if (matches) return result; + if (matches) { + return result; + } + } + if (typeof args.default !== 'undefined') { + return await args.default(); } - if (typeof args.default !== 'undefined') return await args.default(); return context; }, }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.js index 42463bf374e65..f9a8b12497ac1 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.js @@ -33,7 +33,9 @@ export const timefilter = () => ({ }, }, fn: (context, args) => { - if (!args.from && !args.to) return context; + if (!args.from && !args.to) { + return context; + } const { from, to, column } = args; const filter = { @@ -42,16 +44,24 @@ export const timefilter = () => ({ }; function parseAndValidate(str) { - if (!str) return; + if (!str) { + return; + } const moment = dateMath.parse(str); - if (!moment || !moment.isValid()) throw new Error(`Invalid date/time string ${str}`); + if (!moment || !moment.isValid()) { + throw new Error(`Invalid date/time string ${str}`); + } return moment.toISOString(); } - if (to != null) filter.to = parseAndValidate(to); + if (to != null) { + filter.to = parseAndValidate(to); + } - if (from != null) filter.from = parseAndValidate(from); + if (from != null) { + filter.from = parseAndValidate(from); + } return { ...context, and: [...context.and, filter] }; }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/demodata/get_demo_rows.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/demodata/get_demo_rows.js index 16077d9b69efa..78bb441e242cb 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/demodata/get_demo_rows.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/demodata/get_demo_rows.js @@ -9,7 +9,11 @@ import ci from './ci.json'; import shirts from './shirts.json'; export function getDemoRows(arg) { - if (arg === 'ci') return cloneDeep(ci); - if (arg === 'shirts') return cloneDeep(shirts); + if (arg === 'ci') { + return cloneDeep(ci); + } + if (arg === 'shirts') { + return cloneDeep(shirts); + } throw new Error(`Invalid data set: ${arg}, use 'ci' or 'shirts'.`); } diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/esdocs.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/esdocs.js index a70d0361907ba..8ef3d517227e7 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/esdocs.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/esdocs.js @@ -70,7 +70,9 @@ export const esdocs = () => ({ if (args.sort) { const [sortField, sortOrder] = args.sort.split(',').map(str => str.trim()); - if (sortField) query.order(`"${sortField}"`, sortOrder.toLowerCase() === 'asc'); + if (sortField) { + query.order(`"${sortField}"`, sortOrder.toLowerCase() === 'asc'); + } } return queryEsSQL(handlers.elasticsearchClient, { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/index.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/index.js index 02fc450f32eca..02f927f8f7902 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/index.js @@ -56,7 +56,9 @@ export const pointseries = () => ({ const columnNames = context.columns.map(col => col.name); const mathScope = pivotObjectArray(context.rows, columnNames); const autoQuoteColumn = col => { - if (!columnNames.includes(col)) return col; + if (!columnNames.includes(col)) { + return col; + } return col.match(/\s/) ? `'${col}'` : col; }; @@ -78,7 +80,9 @@ export const pointseries = () => ({ if (isColumnReference(mathExp)) { // TODO: Do something better if the column does not exist - if (!columnExists(columnNames, mathExp)) return; + if (!columnExists(columnNames, mathExp)) { + return; + } dimensions.push({ name: arg, @@ -147,8 +151,9 @@ export const pointseries = () => ({ const measureValues = measureNames.map(measure => { try { const ev = evaluate(args[measure], subScope); - if (Array.isArray(ev)) + if (Array.isArray(ev)) { throw new Error('Expressions must be wrapped in a function such as sum()'); + } return ev; } catch (e) { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/get_expression_type.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/get_expression_type.js index 4da10af4dd11b..98b4b0ae788e7 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/get_expression_type.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/get_expression_type.js @@ -12,7 +12,9 @@ import { getFieldNames } from './get_field_names'; export function getExpressionType(columns, mathExpression) { // if isColumnReference returns true, then mathExpression is just a string // referencing a column in a datatable - if (isColumnReference(mathExpression)) return getFieldType(columns, mathExpression); + if (isColumnReference(mathExpression)) { + return getFieldType(columns, mathExpression); + } const parsedMath = parse(mathExpression); @@ -22,7 +24,9 @@ export function getExpressionType(columns, mathExpression) { if (fieldNames.length > 0) { const fieldTypes = fieldNames.reduce((types, name) => { const type = getFieldType(columns, name); - if (type !== 'null' && types.indexOf(type) === -1) return types.concat(type); + if (type !== 'null' && types.indexOf(type) === -1) { + return types.concat(type); + } return types; }, []); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/get_field_names.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/get_field_names.js index 835138477fcf7..2f47d84d6d6ee 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/get_field_names.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/get_field_names.js @@ -5,9 +5,13 @@ */ export function getFieldNames(names, arg) { - if (arg.args != null) return names.concat(arg.args.reduce(getFieldNames, [])); + if (arg.args != null) { + return names.concat(arg.args.reduce(getFieldNames, [])); + } - if (typeof arg === 'string') return names.concat(arg); + if (typeof arg === 'string') { + return names.concat(arg); + } return names; } diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/is_column_reference.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/is_column_reference.js index 3d66bd9a97c2a..3163fae377351 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/is_column_reference.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/src/pointseries/lib/is_column_reference.js @@ -7,7 +7,9 @@ import { parse } from 'tinymath'; export function isColumnReference(mathExpression) { - if (mathExpression == null) mathExpression = 'null'; + if (mathExpression == null) { + mathExpression = 'null'; + } const parsedMath = parse(mathExpression); return typeof parsedMath === 'string'; } diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/pie/index.js b/x-pack/plugins/canvas/canvas_plugin_src/renderers/pie/index.js index 7d007d70b6bab..b60d341b75552 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/pie/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/pie/index.js @@ -17,7 +17,9 @@ export const pie = () => ({ help: 'Render a pie chart from data', reuseDomNode: false, render(domNode, config, handlers) { - if (!includes($.plot.plugins, piePlugin)) $.plot.plugins.push(piePlugin); + if (!includes($.plot.plugins, piePlugin)) { + $.plot.plugins.push(piePlugin); + } config.options.legend.labelBoxBorderColor = 'transparent'; @@ -49,12 +51,17 @@ export const pie = () => ({ let plot; function draw() { - if (domNode.clientHeight < 1 || domNode.clientWidth < 1) return; + if (domNode.clientHeight < 1 || domNode.clientWidth < 1) { + return; + } try { $(domNode).empty(); - if (!config.data || !config.data.length) $(domNode).empty(); - else plot = $.plot($(domNode), config.data, config.options); + if (!config.data || !config.data.length) { + $(domNode).empty(); + } else { + plot = $.plot($(domNode), config.data, config.options); + } } catch (e) { console.log(e); // Nope @@ -62,7 +69,9 @@ export const pie = () => ({ } function destroy() { - if (plot) plot.shutdown(); + if (plot) { + plot.shutdown(); + } } handlers.onDestroy(destroy); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/pie/plugins/pie.js b/x-pack/plugins/canvas/canvas_plugin_src/renderers/pie/plugins/pie.js index 4e6616a625023..9229def146f8b 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/pie/plugins/pie.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/pie/plugins/pie.js @@ -96,46 +96,65 @@ function init(plot) { // set labels.show if (options.series.pie.label.show === 'auto') { - if (options.legend.show) options.series.pie.label.show = false; - else options.series.pie.label.show = true; + if (options.legend.show) { + options.series.pie.label.show = false; + } else { + options.series.pie.label.show = true; + } } // set radius if (options.series.pie.radius === 'auto') { - if (options.series.pie.label.show) options.series.pie.radius = 3 / 4; - else options.series.pie.radius = 1; + if (options.series.pie.label.show) { + options.series.pie.radius = 3 / 4; + } else { + options.series.pie.radius = 1; + } } // ensure sane tilt - if (options.series.pie.tilt > 1) options.series.pie.tilt = 1; - else if (options.series.pie.tilt < 0) options.series.pie.tilt = 0; + if (options.series.pie.tilt > 1) { + options.series.pie.tilt = 1; + } else if (options.series.pie.tilt < 0) { + options.series.pie.tilt = 0; + } } }); plot.hooks.bindEvents.push(function(plot, eventHolder) { const options = plot.getOptions(); if (options.series.pie.show) { - if (options.grid.hoverable) eventHolder.unbind('mousemove').mousemove(onMouseMove); + if (options.grid.hoverable) { + eventHolder.unbind('mousemove').mousemove(onMouseMove); + } - if (options.grid.clickable) eventHolder.unbind('click').click(onClick); + if (options.grid.clickable) { + eventHolder.unbind('click').click(onClick); + } } }); plot.hooks.processDatapoints.push(function(plot, series, data, datapoints) { const options = plot.getOptions(); - if (options.series.pie.show) processDatapoints(plot, series, data, datapoints); + if (options.series.pie.show) { + processDatapoints(plot, series, data, datapoints); + } }); plot.hooks.drawOverlay.push(function(plot, octx) { const options = plot.getOptions(); - if (options.series.pie.show) drawOverlay(plot, octx); + if (options.series.pie.show) { + drawOverlay(plot, octx); + } }); plot.hooks.draw.push(function(plot, newCtx) { const options = plot.getOptions(); - if (options.series.pie.show) draw(plot, newCtx); + if (options.series.pie.show) { + draw(plot, newCtx); + } }); function processDatapoints(plot) { @@ -167,12 +186,17 @@ function init(plot) { // new one; this is more efficient and preserves any extra data // that the user may have stored in higher indexes. - if (Array.isArray(value) && value.length === 1) value = value[0]; + if (Array.isArray(value) && value.length === 1) { + value = value[0]; + } if (Array.isArray(value)) { // Equivalent to $.isNumeric() but compatible with jQuery < 1.7 - if (!isNaN(parseFloat(value[1])) && isFinite(value[1])) value[1] = +value[1]; - else value[1] = 0; + if (!isNaN(parseFloat(value[1])) && isFinite(value[1])) { + value[1] = +value[1]; + } else { + value[1] = 0; + } } else if (!isNaN(parseFloat(value)) && isFinite(value)) { value = [1, +value]; } else { @@ -184,7 +208,9 @@ function init(plot) { // Sum up all the slices, so we can calculate percentages for each - for (let i = 0; i < data.length; ++i) total += data[i].data[0][1]; + for (let i = 0; i < data.length; ++i) { + total += data[i].data[0][1]; + } // Count the number of slices with percentages below the combine // threshold; if it turns out to be just one, we won't combine. @@ -194,7 +220,9 @@ function init(plot) { if (value / total <= options.series.pie.combine.threshold) { combined += value; numCombined++; - if (!color) color = data[i].color; + if (!color) { + color = data[i].color; + } } } @@ -229,7 +257,9 @@ function init(plot) { } function draw(plot, newCtx) { - if (!target) return; // if no series were passed + if (!target) { + return; + } // if no series were passed const canvasWidth = plot.getPlaceholder().width(); const canvasHeight = plot.getPlaceholder().height(); @@ -272,11 +302,17 @@ function init(plot) { centerLeft = canvasWidth / 2; if (options.series.pie.offset.left === 'auto') { - if (options.legend.position.match('w')) centerLeft += legendWidth / 2; - else centerLeft -= legendWidth / 2; + if (options.legend.position.match('w')) { + centerLeft += legendWidth / 2; + } else { + centerLeft -= legendWidth / 2; + } - if (centerLeft < maxRadius) centerLeft = maxRadius; - else if (centerLeft > canvasWidth - maxRadius) centerLeft = canvasWidth - maxRadius; + if (centerLeft < maxRadius) { + centerLeft = maxRadius; + } else if (centerLeft > canvasWidth - maxRadius) { + centerLeft = canvasWidth - maxRadius; + } } else { centerLeft += options.series.pie.offset.left; } @@ -288,11 +324,15 @@ function init(plot) { // indicating that all the labels fit, or we try too many times. do { - if (attempts > 0) maxRadius *= REDRAW_SHRINK; + if (attempts > 0) { + maxRadius *= REDRAW_SHRINK; + } attempts += 1; clear(); - if (options.series.pie.tilt <= 0.8) drawShadow(); + if (options.series.pie.tilt <= 0.8) { + drawShadow(); + } } while (!drawPie() && attempts < REDRAW_ATTEMPTS); if (attempts >= REDRAW_ATTEMPTS) { @@ -331,8 +371,9 @@ function init(plot) { radius >= canvasWidth / 2 - shadowLeft || radius * options.series.pie.tilt >= canvasHeight / 2 - shadowTop || radius <= edge - ) - return; // shadow would be outside canvas, so don't draw it + ) { + return; + } // shadow would be outside canvas, so don't draw it ctx.save(); ctx.translate(shadowLeft, shadowTop); @@ -386,8 +427,9 @@ function init(plot) { ctx.save(); ctx.lineWidth = options.series.pie.stroke.width; currentAngle = startAngle; - for (let i = 0; i < slices.length; ++i) + for (let i = 0; i < slices.length; ++i) { drawSlice(slices[i].angle, options.series.pie.stroke.color, false); + } ctx.restore(); } @@ -400,11 +442,16 @@ function init(plot) { // Draw the labels, returning true if they fit within the plot - if (options.series.pie.label.show) return drawLabels(); - else return true; + if (options.series.pie.label.show) { + return drawLabels(); + } else { + return true; + } function drawSlice(angle, color, fill) { - if (angle <= 0 || isNaN(angle)) return; + if (angle <= 0 || isNaN(angle)) { + return; + } if (fill) { ctx.fillStyle = color; @@ -414,7 +461,9 @@ function init(plot) { } ctx.beginPath(); - if (Math.abs(angle - Math.PI * 2) > 0.000000001) ctx.moveTo(0, 0); // Center of the pie + if (Math.abs(angle - Math.PI * 2) > 0.000000001) { + ctx.moveTo(0, 0); + } // Center of the pie //ctx.arc(0, 0, radius, 0, angle, false); // This doesn't work properly in Opera ctx.arc(0, 0, radius, currentAngle, currentAngle + angle / 2, false); @@ -423,8 +472,11 @@ function init(plot) { //ctx.rotate(angle); // This doesn't work properly in Opera currentAngle += angle; - if (fill) ctx.fill(); - else ctx.stroke(); + if (fill) { + ctx.fill(); + } else { + ctx.stroke(); + } } function drawLabels() { @@ -435,8 +487,11 @@ function init(plot) { : maxRadius * options.series.pie.label.radius; for (let i = 0; i < slices.length; ++i) { - if (slices[i].percent >= options.series.pie.label.threshold * 100) - if (!drawLabel(slices[i], currentAngle, i)) return false; + if (slices[i].percent >= options.series.pie.label.threshold * 100) { + if (!drawLabel(slices[i], currentAngle, i)) { + return false; + } + } currentAngle += slices[i].angle; } @@ -444,7 +499,9 @@ function init(plot) { return true; function drawLabel(slice, startAngle, index) { - if (slice.data[0][1] === 0) return true; + if (slice.data[0][1] === 0) { + return true; + } // format label text @@ -452,10 +509,15 @@ function init(plot) { let text; const plf = options.series.pie.label.formatter; - if (lf) text = lf(slice.label, slice); - else text = slice.label; + if (lf) { + text = lf(slice.label, slice); + } else { + text = slice.label; + } - if (plf) text = plf(text, slice); + if (plf) { + text = plf(text, slice); + } const halfAngle = (startAngle + slice.angle + startAngle) / 2; const x = centerLeft + Math.round(Math.cos(halfAngle) * radius); @@ -487,15 +549,18 @@ function init(plot) { 0 - labelLeft > 0 || canvasHeight - (labelTop + label.height()) < 0 || canvasWidth - (labelLeft + label.width()) < 0 - ) + ) { return false; + } if (options.series.pie.label.background.opacity !== 0) { // put in the transparent background separately to avoid blended labels and label boxes let c = options.series.pie.label.background.color; - if (c == null) c = slice.color; + if (c == null) { + c = slice.color; + } const pos = 'top:' + labelTop + 'px;left:' + labelLeft + 'px;'; $( @@ -662,13 +727,17 @@ function init(plot) { for (let i = 0; i < highlights.length; ++i) { const h = highlights[i]; - if (h.auto === eventname && !(item && h.series === item.series)) unhighlight(h.series); + if (h.auto === eventname && !(item && h.series === item.series)) { + unhighlight(h.series); + } } } // highlight the slice - if (item) highlight(item.series, eventname); + if (item) { + highlight(item.series, eventname); + } // trigger any hover bind events @@ -712,7 +781,9 @@ function init(plot) { function indexOfHighlight(s) { for (let i = 0; i < highlights.length; ++i) { const h = highlights[i]; - if (h.series === s) return i; + if (h.series === s) { + return i; + } } return -1; } @@ -729,19 +800,25 @@ function init(plot) { octx.translate(centerLeft, centerTop); octx.scale(1, options.series.pie.tilt); - for (let i = 0; i < highlights.length; ++i) drawHighlight(highlights[i].series); + for (let i = 0; i < highlights.length; ++i) { + drawHighlight(highlights[i].series); + } drawDonutHole(octx); octx.restore(); function drawHighlight(series) { - if (series.angle <= 0 || isNaN(series.angle)) return; + if (series.angle <= 0 || isNaN(series.angle)) { + return; + } //octx.fillStyle = parseColor(options.series.pie.highlight.color).scale(null, null, null, options.series.pie.highlight.opacity).toString(); octx.fillStyle = 'rgba(255, 255, 255, ' + options.series.pie.highlight.opacity + ')'; // this is temporary until we have access to parseColor octx.beginPath(); - if (Math.abs(series.angle - Math.PI * 2) > 0.000000001) octx.moveTo(0, 0); // Center of the pie + if (Math.abs(series.angle - Math.PI * 2) > 0.000000001) { + octx.moveTo(0, 0); + } // Center of the pie octx.arc(0, 0, radius, series.startAngle, series.startAngle + series.angle / 2, false); octx.arc( diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/index.js b/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/index.js index 67f26abb1c6b8..9a2d0e4a9b26d 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/index.js @@ -15,12 +15,18 @@ import './plot.scss'; const render = (domNode, config, handlers) => { // TODO: OH NOES - if (!includes($.plot.plugins, size)) $.plot.plugins.push(size); - if (!includes($.plot.plugins, text)) $.plot.plugins.push(text); + if (!includes($.plot.plugins, size)) { + $.plot.plugins.push(size); + } + if (!includes($.plot.plugins, text)) { + $.plot.plugins.push(text); + } let plot; function draw() { - if (domNode.clientHeight < 1 || domNode.clientWidth < 1) return; + if (domNode.clientHeight < 1 || domNode.clientWidth < 1) { + return; + } if (config.font) { const legendFormatter = label => { @@ -46,7 +52,9 @@ const render = (domNode, config, handlers) => { } function destroy() { - if (plot) plot.shutdown(); + if (plot) { + plot.shutdown(); + } } handlers.onDestroy(destroy); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/plugins/size.js b/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/plugins/size.js index 1f582170e8f88..adf2e7d3aed8a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/plugins/size.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/plugins/size.js @@ -53,7 +53,9 @@ const options = { function drawbubbleDefault(ctx, series, x, y, radius, c) { ctx.fillStyle = c; - if (series.bubbles.fill) ctx.globalAlpha = series.bubbles.fill; + if (series.bubbles.fill) { + ctx.globalAlpha = series.bubbles.fill; + } ctx.strokeStyle = c; ctx.lineWidth = Math.round(radius / 3); @@ -61,15 +63,20 @@ function drawbubbleDefault(ctx, series, x, y, radius, c) { ctx.arc(x, y, radius, 0, Math.PI * 2, true); ctx.closePath(); - if (series.bubbles.fill) ctx.fill(); - else ctx.stroke(); + if (series.bubbles.fill) { + ctx.fill(); + } else { + ctx.stroke(); + } } function init(plot) { plot.hooks.processOptions.push(processOptions); function processOptions(plot, options) { - if (options.series.bubbles.active) plot.hooks.drawSeries.push(drawSeries); + if (options.series.bubbles.active) { + plot.hooks.drawSeries.push(drawSeries); + } } function drawSeries(plot, ctx, series) { @@ -88,8 +95,12 @@ function init(plot) { const delta = maxPoint - minPoint; const radius = (function() { - if (size == null) return 0; // If there is no size, draw nothing - if (delta === 0) return series.bubbles.size.min; // If there is no difference between the min and the max, draw the minimum bubble. + if (size == null) { + return 0; + } // If there is no size, draw nothing + if (delta === 0) { + return series.bubbles.size.min; + } // If there is no difference between the min and the max, draw the minimum bubble. // Otherwise draw something between the min and max acceptable radius. return ( diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/plugins/text.js b/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/plugins/text.js index 7dfcd2c2f2b68..65dc7517453a1 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/plugins/text.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/plot/plugins/text.js @@ -30,7 +30,9 @@ function draw(plot, ctx) { $('.valueLabel', plot.getPlaceholder()).remove(); plot.getData().forEach(function(series) { const show = get(series.numbers, 'show'); - if (!show) return; + if (!show) { + return; + } let points = series.data; @@ -54,7 +56,9 @@ function draw(plot, ctx) { ctx.textAlign = 'center'; function writeText(text, x, y) { - if (typeof text === 'undefined') return; + if (typeof text === 'undefined') { + return; + } const textNode = $('
') .text(String(text)) .addClass('valueLabel') diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/progress/index.js b/x-pack/plugins/canvas/canvas_plugin_src/renderers/progress/index.js index d7c1885f6388c..99e5fe564196f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/progress/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/progress/index.js @@ -72,10 +72,12 @@ export const progress = () => ({ text.textContent = label; text.setAttribute('className', 'canvasProgress__label'); - if (shape === 'horizontalPill') + if (shape === 'horizontalPill') { text.setAttribute('x', parseInt(text.getAttribute('x'), 10) + offset / 2); - if (shape === 'verticalPill') + } + if (shape === 'verticalPill') { text.setAttribute('y', parseInt(text.getAttribute('y'), 10) - offset / 2); + } Object.assign(text.style, font.spec); shapeSvg.appendChild(text); @@ -101,7 +103,9 @@ export const progress = () => ({ shapeSvg.setAttribute('width', domNode.offsetWidth); shapeSvg.setAttribute('height', domNode.offsetHeight); - if (domNode.firstChild) domNode.removeChild(domNode.firstChild); + if (domNode.firstChild) { + domNode.removeChild(domNode.firstChild); + } domNode.appendChild(shapeSvg); handlers.onResize(() => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.js b/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.js index 780e5f8acbe8f..120fdeb89c207 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.js @@ -24,8 +24,11 @@ export const repeatImage = () => ({ const container = $('