Table::calculateColumnWidth

Calculate maximum width of each column

@return array
169932
private function calculateColumnWidth()
    {
        foreach ($this->rows as $rowIndex => $row) {
            foreach ($row as $columnIndex => $column) {
                if ( ! isset($this->columnWidths[ $columnIndex ])) {
                    $this->columnWidths[ $columnIndex ] = strlen($column);
                } else {
                    if (strlen($column) > $this->columnWidths[ $columnIndex ]) {
                        $this->columnWidths[ $columnIndex ] = strlen($column);
                    }
                }
            }
        }

        return $this->columnWidths;
    }
515727
public function getColumnNames()
    {
        $columns = array();
        foreach ($this->childs as $column) {
            $columns[] = $column->getColumnName();
        }

        return $columns;
    }
73682
protected function calculateColumnWidthPercent(array $columns)
    {
        $widthAllColumn = 0;
        foreach ($columns as $column) {
            /* @var $column \ZfcDatagrid\Column\AbstractColumn */
            $widthAllColumn += $column->getWidth();
        }

        $widthSum = 0;
        // How much 1 percent columnd width is really "one" percent...
        $relativeOnePercent = $widthAllColumn / 100;

        foreach ($columns as $column) {
            $widthSum += (($column->getWidth() / $relativeOnePercent));
            $column->setWidth(($column->getWidth() / $relativeOnePercent));
        }
    }
330220
public function getTableColumnSize()
    {
        if ($this->column_size===0 && $this->line_size===0 && $this->cell_size===0) {
            $this->_parseTableSizes();
        }
        return $this->column_size;
    }
70391
public function getWidth() : int {
        $first = $this->getStart();
        $last = $this->getEndPosition();

        return $last - $first;
    }
1212361
def compute_column_width_and_height(self):
        '''
        
        '''
        # skip tables with no row
        if not self.rows:
            return

        # determine row height
        for row in self.rows:
            max_row_height = max((len(cell.get_cell_lines()) for cell in row.columns)) if row.columns else 1
            for cell in row.columns:
                cell.height = max_row_height

        # determine maximum number of columns
        max_columns = max([len(row.columns) for row in self.rows])

        for column_idx in range(max_columns):
            # determine max_column_width
            row_cell_lines = [row.get_cell_lines(column_idx) for row in self.rows]
            max_column_width = max((len(line) for line in chain(*row_cell_lines)))

            # set column width in all rows
            for row in self.rows:
                if len(row.columns) > column_idx:
                    row.columns[column_idx].width = max_column_width
401268
protected function calculateDimensions()
    {
        foreach ($this->getRows() as $x => $row) {
            foreach ($row as $y => $value) {
                $this->calculateDimensionsForCell($x, $y, $value);
            }
        }
        return $this;
    }
633676
protected function getTableColumns()
    {
        if (0 === count(self::$tableColumns)) {
            $table = $this->getTable();
            $connect = $this->getConnection();
            $builder = $connect->getSchemaBuilder();
            $columns = $builder->getColumnListing($table);

            self::$tableColumns = (array)$columns;
        }
        return self::$tableColumns;
    }
1223120
public function columnCount()
    {
        $maxCol = 0;

        foreach ($this->_layout as $row => $items) {
            foreach ($items as $column => $item) {
                $maxCol = max($column, $maxCol);
            }
        }

        return $maxCol;
    }
395376
function get_min_max_width() {

    if ( !is_null($this->_min_max_cache)  )
      return $this->_min_max_cache;

    $style = $this->_frame->get_style();

    $this->_frame->normalise();

    // Add the cells to the cellmap (this will calcluate column widths as
    // frames are added)
    $this->_frame->get_cellmap()->add_frame($this->_frame);

    // Find the min/max width of the table and sort the columns into
    // absolute/percent/auto arrays
    $this->_state = array();
    $this->_state["min_width"] = 0;
    $this->_state["max_width"] = 0;

    $this->_state["percent_used"] = 0;
    $this->_state["absolute_used"] = 0;
    $this->_state["auto_min"] = 0;

    $this->_state["absolute"] = array();
    $this->_state["percent"] = array();
    $this->_state["auto"] = array();

    $columns =& $this->_frame->get_cellmap()->get_columns();
    foreach (array_keys($columns) as $i) {
      $this->_state["min_width"] += $columns[$i]["min-width"];
      $this->_state["max_width"] += $columns[$i]["max-width"];

      if ( $columns[$i]["absolute"] > 0 ) {
        $this->_state["absolute"][] = $i;
        $this->_state["absolute_used"] += $columns[$i]["absolute"];

      } else if ( $columns[$i]["percent"] > 0 ) {
        $this->_state["percent"][] = $i;
        $this->_state["percent_used"] += $columns[$i]["percent"];

      } else {
        $this->_state["auto"][] = $i;
        $this->_state["auto_min"] += $columns[$i]["min-width"];
      }
    }

    // Account for margins & padding
    $dims = array($style->border_left_width,
                  $style->border_right_width,
                  $style->padding_left,
                  $style->padding_right,
                  $style->margin_left,
                  $style->margin_right);

    if ( $style->border_collapse !== "collapse" ) 
      list($dims[]) = $style->border_spacing;

    $delta = $style->length_in_pt($dims, $this->_frame->get_containing_block("w"));

    $this->_state["min_width"] += $delta;
    $this->_state["max_width"] += $delta;

    return $this->_min_max_cache = array(
      $this->_state["min_width"], 
      $this->_state["max_width"],
      "min" => $this->_state["min_width"], 
      "max" => $this->_state["max_width"],
    );
  }
404253
public function getColumns(): array
    {
        $tSelects = isset($this->statements['selects']) === true ? $this->statements['selects'] : [];
        $tColumns = [];
        foreach ($tSelects as $key => $value) {
            if (\is_string($value)) {
                if (\is_int($key)) {
                    $tElements = explode('.', $value);
                    if (!\in_array('*', $tElements, true)) {
                        $tColumns[$tElements[1] ?? $tElements[0]] = $value;
                    }
                } elseif (\is_string($key)) {
                    $tColumns[$value] = $key;
                }
            }
        }
        return $tColumns;
    }
202222
public function getColumnSizeOptions($max = null)
    {
        return ArrayLib::valuekey(range(1, $max ? $max : $this->getNumberOfColumns()));
    }
481213
public int getColumnWidth(){
		int usableWidth = page.getWidth()-getLeftMargin()-getRightMargin()-((getColumnsPerPage()-1)*getColumnSpace());
		return usableWidth / getColumnsPerPage();
	}
1361993
public function maxColumns($size = null)
    {
        if (is_null($size)) {
            $size = $this->baseSize;
        }
        $columnAttribute = $size . 'Columns';

        $this->{$columnAttribute} = $this->getMaxColumns($size);

        return true;
    }
862943
def _calculate_column_widths(self):
        """"""
        table_width = self.get_table_width()
        lpw, rpw = self._left_padding_widths, self._right_padding_widths
        pad_widths = [(lpw[i] + rpw[i]) for i in range(self._column_count)]
        max_widths = [0 for index in range(self._column_count)]
        offset = table_width - sum(self._column_widths) + sum(pad_widths)
        self._max_table_width = max(self._max_table_width,
                                    offset + self._column_count)

        for index, column in enumerate(zip(*self._table)):
            max_length = 0
            for i in column:
                for j in to_unicode(i).split('\n'):
                    output_str = get_output_str(j, self.detect_numerics,
                                                self.numeric_precision,
                                                self.sign_mode.value)
                    max_length = max(max_length, termwidth(output_str))
            for i in to_unicode(self._column_headers[index]).split('\n'):
                output_str = get_output_str(i, self.detect_numerics,
                                            self.numeric_precision,
                                            self.sign_mode.value)
                max_length = max(max_length, termwidth(output_str))
            max_widths[index] += max_length

        sum_ = sum(max_widths)
        desired_sum = self._max_table_width - offset

        # Set flag for columns who are within their fair share
        temp_sum = 0
        flag = [0] * len(max_widths)
        for i, width in enumerate(max_widths):
            if width <= int(desired_sum / self._column_count):
                temp_sum += width
                flag[i] = 1
            else:
                # Allocate atleast 1 character width to the column
                temp_sum += 1

        avail_space = desired_sum - temp_sum
        actual_space = sum_ - temp_sum
        shrinked_columns = {}

        # Columns which exceed their fair share should be shrinked based on
        # how much space is left for the table
        for i, width in enumerate(max_widths):
            self.column_widths[i] = width
            if not flag[i]:
                new_width = 1 + int((width-1) * avail_space / actual_space)
                if new_width < width:
                    self.column_widths[i] = new_width
                    shrinked_columns[new_width] = i

        # Divide any remaining space among shrinked columns
        if shrinked_columns:
            extra = (self._max_table_width
                     - offset
                     - sum(self.column_widths))
            actual_space = sum(shrinked_columns)

            if extra > 0:
                for i, width in enumerate(sorted(shrinked_columns)):
                    index = shrinked_columns[width]
                    extra_width = int(width * extra / actual_space)
                    self.column_widths[i] += extra_width
                    if i == (len(shrinked_columns) - 1):
                        extra = (self._max_table_width
                                 - offset
                                 - sum(self.column_widths))
                        self.column_widths[index] += extra

        for i in range(self.column_count):
            self.column_widths[i] += pad_widths[i]
1173878
public function getRowAndColumnCount()
    {
        $rows = $columns = 0;
        $trs = $this->getElementsByTagName('tr');
        foreach ($trs as $tr) {
            /** @var \DOMElement $tr */
            $rowspan = $tr->getAttribute('rowspan');
            $rows += ($rowspan || 1);

            // Now look for column-related info
            $columnsInThisRow = 0;
            $cells = $tr->getElementsByTagName('td');
            foreach ($cells as $cell) {
                /** @var \DOMElement $cell */
                $colspan = $cell->getAttribute('colspan');
                $columnsInThisRow += ($colspan || 1);
            }
            $columns = max($columns, $columnsInThisRow);
        }

        return ['rows' => $rows, 'columns' => $columns];
    }
729027
protected function _calculate_width($width)
    {
        $frame = $this->_frame;
        $style = $frame->get_style();
        $w = $frame->get_containing_block("w");

        if ($style->position === "fixed") {
            $w = $frame->get_parent()->get_containing_block("w");
        }

        $rm = $style->length_in_pt($style->margin_right, $w);
        $lm = $style->length_in_pt($style->margin_left, $w);

        $left = $style->length_in_pt($style->left, $w);
        $right = $style->length_in_pt($style->right, $w);

        // Handle 'auto' values
        $dims = array($style->border_left_width,
            $style->border_right_width,
            $style->padding_left,
            $style->padding_right,
            $width !== "auto" ? $width : 0,
            $rm !== "auto" ? $rm : 0,
            $lm !== "auto" ? $lm : 0);

        // absolutely positioned boxes take the 'left' and 'right' properties into account
        if ($frame->is_absolute()) {
            $absolute = true;
            $dims[] = $left !== "auto" ? $left : 0;
            $dims[] = $right !== "auto" ? $right : 0;
        } else {
            $absolute = false;
        }

        $sum = (float)$style->length_in_pt($dims, $w);

        // Compare to the containing block
        $diff = $w - $sum;

        if ($diff > 0) {
            if ($absolute) {
                // resolve auto properties: see
                // http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width

                if ($width === "auto" && $left === "auto" && $right === "auto") {
                    if ($lm === "auto") {
                        $lm = 0;
                    }
                    if ($rm === "auto") {
                        $rm = 0;
                    }

                    // Technically, the width should be "shrink-to-fit" i.e. based on the
                    // preferred width of the content...  a little too costly here as a
                    // special case.  Just get the width to take up the slack:
                    $left = 0;
                    $right = 0;
                    $width = $diff;
                } else if ($width === "auto") {
                    if ($lm === "auto") {
                        $lm = 0;
                    }
                    if ($rm === "auto") {
                        $rm = 0;
                    }
                    if ($left === "auto") {
                        $left = 0;
                    }
                    if ($right === "auto") {
                        $right = 0;
                    }

                    $width = $diff;
                } else if ($left === "auto") {
                    if ($lm === "auto") {
                        $lm = 0;
                    }
                    if ($rm === "auto") {
                        $rm = 0;
                    }
                    if ($right === "auto") {
                        $right = 0;
                    }

                    $left = $diff;
                } else if ($right === "auto") {
                    if ($lm === "auto") {
                        $lm = 0;
                    }
                    if ($rm === "auto") {
                        $rm = 0;
                    }

                    $right = $diff;
                }

            } else {
                // Find auto properties and get them to take up the slack
                if ($width === "auto") {
                    $width = $diff;
                } else if ($lm === "auto" && $rm === "auto") {
                    $lm = $rm = round($diff / 2);
                } else if ($lm === "auto") {
                    $lm = $diff;
                } else if ($rm === "auto") {
                    $rm = $diff;
                }
            }
        } else if ($diff < 0) {
            // We are over constrained--set margin-right to the difference
            $rm = $diff;
        }

        return array(
            "width" => $width,
            "margin_left" => $lm,
            "margin_right" => $rm,
            "left" => $left,
            "right" => $right,
        );
    }