UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 3.23 kB
import unique from'ramda/es/uniq';import arrayHasContent from'../../../../../../fc-utils/src/type/array-has-content';import stringHasContent from'../../../../../../fc-utils/src/type/string-has-content';import isObject from'../../../../../../fc-utils/src/type/is-object';import isArray from'../../../../../../fc-utils/src/type/is-array';import isString from'../../../../../../fc-utils/src/type/is-string';const VALID_PLOT_TYPES=['column','line','step-line','smooth-line','area','step-area','smooth-area','candlestick','ohlc'];let truthFn=()=>!0,sanitisePlotType=(a='',b=!0)=>{if(VALID_PLOT_TYPES.includes(a))return a;return b?'line':void 0},objectHasContent=a=>isObject(a)&&(stringHasContent(a.plot)||arrayHasContent(a.plot)||isObject(a.plot)),stringExpando=(a,b,c={})=>{let d=[];if(stringHasContent(a)&&b(a)){const b=isObject(c.plot)?Object.assign({},c.plot):{};b.type=sanitisePlotType(b.type||c.plottype),b.value=a,b.aggregation=b.aggregation||c.aggregation||'avg',d.push(Object.assign({},c,{plot:[b]}))}return d},sanitiseObj=(a,b)=>{const c=sanitisePlotType(a.type),d='candlestick'===c||'ohlc'===c,e=a=>b(a)?a:void 0;let f,g,h,i,j,k={};if(f=isObject(a.value)?e(a.value.value):e(a.value),d?(isObject(a.value)&&(g=e(a.value.open),h=e(a.value.close),i=e(a.value.high),j=e(a.value.low)),k=g&&i&&j&&h?Object.assign({},a,{type:c,high:i,low:j,open:g,close:h,value:null}):g||i||j||h?Object.assign({},a,{type:c,high:i,low:j,open:g,close:h,value:null}):Object.assign({},a,{type:c,high:f,low:f,open:f,close:f,value:f})):k=Object.assign({},a,{type:c,value:f}),k.typeinnavigator=sanitisePlotType(k.typeinnavigator,!1),d&&(f||g||h||i||j)||f)return k},objectExpando=(a,b)=>{let c=[],d=a.plot,e=isObject(d),f=a.hasOwnProperty('plot')&&(!e||d.hasOwnProperty('value'))&&'axis',g=a=>stringHasContent(a)&&b(a);if(objectHasContent(a)){const b=[];if(c.push(Object.assign({},a,{plot:b})),(e||stringHasContent(d))&&(d=[d]),arrayHasContent(d)){const c=d.filter(a=>!!a);c.forEach(c=>{let d;if(isObject(c)){const b=c.type||a.plottype;d=sanitiseObj(Object.assign({},c,{aggregation:c.aggregation||a.aggregation||'avg',type:b}),g)}else g(c)&&(d=sanitiseObj({value:c,type:a.plottype,aggregation:a.aggregation||'avg'},g));d&&b.push(d)})}}return c[0]&&c[0].plot.length?{output:c,action:!!(isArray(d)&&d.length>c[0].plot.length)&&'plot'}:{output:[],action:f}},arrayExpando=(a,b,c)=>{let d,e=[],f=[];return a.forEach(a=>{isString(a)?e=e.concat(stringExpando(a,b,c)):isObject(a)&&(d=objectExpando(a,b),e=e.concat(d.output),d.action&&f.push(d.action))}),{output:e,actions:f}},expander=(a,b,c)=>{let d=[],e=[];if(isString(a))d=stringExpando(a,b);else if(isObject(a)){let c;({output:d,action:c}=objectExpando(a,b)),c&&e.push(c)}else isArray(a)&&({output:d,actions:e}=arrayExpando(a,b,c));return{output:d,actions:e}},expando=(a=[],b,c=!0)=>{let d=[],e=[],f=0,g=isObject(b),h=b=>0<=a.indexOf(b);if(b){({output:d,actions:e}=expander(b,h)),f=d.length;const a=e.includes('axis');g?a&&(e=['fullaxis']):isArray(b)&&f<b.length&&(f?!a&&e.push('axis'):e=['fullaxis'])}return d.length||({output:d}=expander(a,truthFn,g&&b)),c&&d.forEach(a=>{if(!isString(a.title)){const b=a.plot.map(a=>a.value);a.title=b.join(' - ')}}),{expandedAxis:d,actions:unique(e)}};export default expando;