Populates script output with hacks required to give Flot featural parity with jqPlot
@param unknown_type $dataArrayJs
@param unknown_type $optionsJs
@return multitype:string
172942
public function getExtraFunctionCalls($dataArrayJs, $optionsJs)
    {
        $extraFunctionCalls = array();

        if ($this->zooming) {
            $extraFunctionCalls[] = sprintf( self::ZOOMING_FUNCTION, $dataArrayJs, $optionsJs, $dataArrayJs, $optionsJs );
        }

        if ($this->useLabels) {
            $seriesLabels = json_encode($this->pointLabels);

            $top = '';
            $left = '';
            $pixelCount = '15';

            for ( $i = 0; $i < strlen($this->labelSettings['location']); $i++ ) {
                switch ( $this->labelSettings['location'][$i] ) {
                    case 'n':
                        $top = '-'.$pixelCount;
                        break;
                    case 'e':
                        $left = '+'.$pixelCount;
                        break;
                    case 's':
                        $top = '+'.$pixelCount;
                        break;
                    case 'w':
                        $left = '-'.$pixelCount;
                }
            }

            $paddingx = '-'.(isset($this->labelSettings['xpadding']) ? $this->labelSettings['xpadding'] : '0');
            $paddingy = '-'.(isset($this->labelSettings['ypadding']) ? $this->labelSettings['ypadding'] : '0');

            $extraFunctionCalls[] = sprintf( self::LABELS_FUNCTION, $seriesLabels, $left, $paddingx, $top, $paddingy );

        }

        if ($this->highlighting) {

            $formatPoints = "x + ',' + y";

            foreach ($this->dateAxes as $axis=>$flag) {
                if ($flag) {
                    $formatPoints = str_replace($axis, "(new Date(parseInt({$axis}))).toLocaleDateString()",$formatPoints);
                }
            }

            $extraFunctionCalls[] =  sprintf( self::HIGHLIGHTING_FUNCTION, $formatPoints );

        }

        return $extraFunctionCalls;

    }
624432
protected function createTableBuilder(array $options = array(), $type = DataTableType::class)
    {
        return $this->get(DataTableFactory::class)->createBuilder($type, $options);
    }
462525
private static function getTemplateAttributeFakeJs(array $options, DOMElement $dom)
    {
        $expressionsByLine = self::getVueAttributeExpressions($options['attributePrefixes'], $dom);

        if (empty($expressionsByLine)) {
            return '';
        }

        $maxLines = max(array_keys($expressionsByLine));
        $fakeJs = '';

        for ($line = 1; $line <= $maxLines; $line++) {
            if (isset($expressionsByLine[$line])) {
                $fakeJs .= implode("; ", $expressionsByLine[$line]);
            }
            $fakeJs .= "\n";
        }

        return $fakeJs;
    }
154192
public static function render($options)
    {
        $jsExpressions = array();
        //Replace any js expression with random strings so we can switch
        //them back after json_encode the options
        $options = static::_replaceJsExpr($options, $jsExpressions);

        //TODO: Check for encoding errors
        $result = json_encode($options);

        //Replace any js expression on the json_encoded string
        foreach ($jsExpressions as $key => $expr) {
            $result = str_replace('"' . $key . '"', $expr, $result);
        }
        return $result;
    }
369348
function(dataprovider) {
            var optionDOM = "";
            var groupCounter = 0;

            $.each(dataprovider, function (index, option) {
                if ($.isArray(option.children)) {
                    groupCounter++;
                    optionDOM += '<optgroup label="' + (option.title || 'Group ' + groupCounter) + '">';

                    option.children.forEach(function(subOption) {
                        optionDOM += '<option value="' + subOption.value + '">' + (subOption.label || subOption.value) + '</option>';
                    });

                    optionDOM += '</optgroup>';
                }
                else {
                    optionDOM += '<option value="' + option.value + '">' + (option.label || option.value) + '</option>';
                }
            });

            this.$select.html(optionDOM);
            this.rebuild();
        }
359471
protected function _dataTooltip(array $options, $tooltip)
    {
        if (Arr::key('title', $options)) {
            $options['data-tooltip'] = $options['title'];
        }

        if (is_string($tooltip)) {
            $options['data-tooltip'] = $tooltip;
        }

        return $options;
    }
956115
public function renderValue($data, array $options = []) : string
    {
        $options = array_merge($this->defaultOptions, $this->fixOptions($options));
        $result = $this->getFieldValueFromData($data, $options);

        // Currently needed for blobs from the database, but might be handy later
        // for network data and such.
        // TODO: Add support for encoding (base64, et) via $options
        if (is_resource($result)) {
            $result = stream_get_contents($result);
        }

        $rendererClass = $this->config->getProvider('renderValue');
        if (!empty($options['renderAs'])) {
            $rendererClass = __NAMESPACE__ . '\\Provider\\RenderValue\\' . ucfirst($options['renderAs']) . 'Renderer';
        }

        if (!class_exists($rendererClass)) {
            throw new InvalidArgumentException("Renderer class [$rendererClass] does not exist");
        }

        $rendererClass = new $rendererClass($this->config);
        $result = (string)$rendererClass->provide($result, $options);

        return $result;
    }
67886
function(options) {
        var thead = $('<thead><tr></tr></thead><tbody></tbody>'),
            column = options.column,
            columnCount = column.length;

        this.rowSpan = 1;

        for (var i = 0; i < columnCount; i++) {
            var col = column[i];

            if (typeof col.visible !== 'undefined' && !col.visible) {
                continue;
            }

            if (!$.isArray(col.content)) {
                col.content = [col.content];
            }
            if (col.content.length > this.rowSpan) {
                this.rowSpan = col.content.length;
            }

            var th = $('<th nowrap></th>').attr({
                width: col.width,
                field: col.field
            });
            if (options.flexible) {
                th.removeAttr('nowrap width');
            }

            var title = (col.escapeTitle === false) ? col.title : escapeHTML(col.title);
            if (col.sortable) {
                var wrap = $('<div class="sortable"></div>').html(title);
                if (col.currentSort) {
                    wrap.attr(col.currentSort, '');
                }
                title = wrap.prop('outerHTML');
            }

            thead.find('tr').append(th.html(title).prop('outerHTML'));
        }

        return thead.prop('outerHTML');
    }
468389
static public function postArray($url, $data, $options=null)
    {
        $instance = new static('POST', $url, $data, $options);
        return $instance->toArray();
    }
468233
protected function _render(array $row, $widths, $options = [])
    {
        if (count($row) === 0) {
            return;
        }

        $out = '';
        foreach (array_values($row) as $i => $column) {
            $pad = $widths[$i] - $this->_cellWidth($column);
            if (!empty($options['style'])) {
                $column = $this->_addStyle($column, $options['style']);
            }
            $out .= '| ' . $column . str_repeat(' ', $pad) . ' ';
        }
        $out .= '|';
        $this->_io->out($out);
    }
55563
public function renderDataTablesFunction(DataTablesWrapperInterface $dtWrapper, array $args = []) {
        return $this->renderDataTables($dtWrapper, ArrayHelper::get($args, "class"), ArrayHelper::get($args, "thead", true), ArrayHelper::get($args, "tfoot", true));
    }
1370181
protected static function _arrayToString($data, $options)
    {
        if (empty($data)) {
            return '[]';
        }

        extract($options['array']);
        /**
         * @var string $char
         * @var int $indent
         * @var int $multiplier
         */
        $comma = false;

        $tab = str_repeat($char, $indent * $multiplier);

        $string = "[\n";

        foreach ($data as $key => $value) {
            if ($comma) {
                $string .= ",\n";
            }
            $comma = true;
            $key = filter_var($key, FILTER_VALIDATE_INT) ? $key : static::dump($key, $options['quote']);
            $string .= $tab . $key . ' => ';
            if (is_array($value)) {
                $options['array']['indent'] = $indent + 1;
                $string .= static::_arrayToString($value, $options);
            } else {
                $string .= static::toString($value, $options);
            }
        }
        $tab = str_repeat($char, ($indent - 1) * $multiplier);
        return $string . "\n" . $tab . "]";
    }
482339
protected function createFromArrayWithContext($data, $options)
    {
        $_documentClass = $this->_documentClass;

        return $_documentClass::createFromArray($data, $options);
    }
1068829
private function optionsTratament(array $options = array())
    {
        if (!isset($options['orientation']) or empty($options['orientation'])) {
            $options['orientation'] = 'LANDSCAPE';
        }
        if (!isset($options['size']) or empty($options['size'])) {
            $options['size'] = 'A4';
        }
        if (!isset($options['title']) or empty($options['title'])) {
            $options['title'] = 'Export Datagrid Cityware';
        }
        if (!isset($options['subtitle']) or empty($options['subtitle'])) {
            $options['subtitle'] = 'Export Datagrid Cityware';
        }
        if (!isset($options['footer']) or empty($options['footer'])) {
            $options['footer'] = 'Export Datagrid Cityware';
        }
        if (!isset($options['name']) or empty($options['name'])) {
            $options['name'] = date('Y_m_d_H_i_s');
        }
        if (!isset($options['noPagination']) or empty($options['noPagination'])) {
            $options['noPagination'] = 0;
        }

        $options['colors'] = array('title' => '#000000',
            'subtitle' => '#111111',
            'footer' => '#111111',
            'header' => '#AAAAAA',
            'row1' => '#EEEEEE',
            'row2' => '#FFFFFF',
            'sqlexp' => '#BBBBBB',
            'lines' => '#111111',
            'hrow' => '#E4E4F6',
            'text' => '#000000',
            'filters' => '#F9EDD2',
            'filtersBox' => '#DEDEDE');

        return $options;
    }
294094
public function getScript()
    {
        $name = $this->chart->getName();
        $dataArrayJs = '[';

        $counter = 0;
        foreach ( $this->chart->getSeries() as $title => $series ) {

            $dataArrayJs .= $counter++ > 0 ? ', ' : '';

            $dataArrayJs .= '{';

            // associate Xs with Ys in cases where we need it
            $data = $series->getData();

            $formattedData = array();
            foreach ( $data as $datum ) { 
                if (! $datum instanceof ChartDatum\ChartDatumAbstract ) {
                    throw new \UnexpectedValueException('Chart data should be an object inheriting from ChartDatumAbstract');
                }
                foreach ( $this->dateAxes as $axis => $flag ) {
                    if ( $flag ) {
                        $date = \DateTime::createFromFormat( 'm/d/Y', $datum[$axis] );
                        $datum[$axis] = $date->getTimestamp() * 1000;
                    }
                }
                        
                if ( $this->useLabels ) {
                    $dataPoints = "{$datum['x']},{$datum['y']}";
                    $this->pointLabels[$dataPoints] = $datum->getLabel();
                }
                
                $formattedData[] = $datum->getRenderData();
            }
            
            $dataArrayJs .= 'data: '.$this->makeJSArray($formattedData);
            
            if ( isset( $this->types['default'] ) && 
               ( $this->types['default'] instanceOf \Altamira\Type\Flot\Bubble
                || $this->types['default'] instanceOf \Altamira\Type\Flot\Donut ) ) {
                $dataArrayJs .= ', label: "' . str_replace('"', '\\"', $series->getTitle() ) . '"';
            }

            $this->prepOpts( $this->options['seriesStorage'][$title] );

            $opts = substr( json_encode( $this->options['seriesStorage'][$title] ), 1, -1 );

            if (strlen($opts) > 2) {
                $dataArrayJs .= ',' . $opts;
            }

            $dataArrayJs .= '}';
        }

        $dataArrayJs .= ']';

        $optionsJs = ($js = $this->getOptionsJs()) ? ", {$js}" : ', {}';

        $extraFunctionCallString = implode("\n", $this->getExtraFunctionCalls($dataArrayJs, $optionsJs));

        return sprintf( self::SCRIPT_OUTPUT, $name, $dataArrayJs, $optionsJs, $extraFunctionCallString );
    }
1275242
public function encode($data, $options = 0) {
        $json = null;

        if ($data instanceof IArrayable) {
            $json = @json_encode($data->toArray(), $options);
        } else if ($data instanceof IJsonable) {
            $json = $data->toJson($options);
        } else if (is_array($data) || is_object($data)) {
            $json =  @json_encode($data, $options);
        } else {
            throw new InvalidDataTypeException(
                s('Can not convert data of type "%s" to json.', get_type($data))
            );
        }

        if ($json === false) {
            throw new JsonEncodeException(json_last_error_msg(), $data);
        }

        return $json;
    }
1145067
public static function addDefaultCssClasses($dataArray, $rowStyles)
    {
        $count = 0;
        $ret = array();
        foreach ($dataArray as $dataItem) {
            if (!isset($dataItem['cssStyle'])) {
                $dataItem['cssClass'] = $count%2 == 0 ? 'odd' : 'even';
                $dataItem['htmlTag'] = 'td';
            } else {
                $dataItem['cssClass'] = $dataItem['cssStyle']. ' ' . ($count%2 == 0 ? 'odd' : 'even');
                $dataItem['htmlTag'] = $rowStyles[$dataItem['cssStyle']]['tag'];
            }
            for ($i = 1; $i < count($dataItem['data'])+1; $i++) {
                if (empty($dataItem['data']['column'.$i]['cssClass'])) {
                    $dataItem['data']['column'.$i]['cssClass'] .= 'col'.$i;
                } else {
                    $dataItem['data']['column'.$i]['cssClass'] .= ' col'.$i;
                }

                if ($i == 1) {
                    $dataItem['data']['column'.$i]['cssClass'] .= ' first';
                } else if ($i == count($dataItem['data'])) {
                    $dataItem['data']['column'.$i]['cssClass'] .= ' last';
                }
            }
            $ret[] = $dataItem;
            $count++;
        }
        return $ret;
    }