void TableOfReal_drawAsNumbers (TableOfReal me, Graphics graphics, long rowmin, long rowmax, int iformat, int precision) {
	fixRows (me, & rowmin, & rowmax);
	Graphics_setInner (graphics);
	Graphics_setWindow (graphics, 0.5, my numberOfColumns + 0.5, 0, 1);
	double leftMargin = getLeftMargin (graphics);   // not earlier!
	double lineSpacing = getLineSpacing (graphics);   // not earlier!
	double maxTextWidth = getMaxRowLabelWidth (me, graphics, rowmin, rowmax);
	double maxTextHeight = getMaxColumnLabelHeight (me, graphics, 1, my numberOfColumns);

	Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_BOTTOM);
	for (long icol = 1; icol <= my numberOfColumns; icol ++) {
		if (my columnLabels && my columnLabels [icol] && my columnLabels [icol] [0])
			Graphics_text (graphics, icol, 1, my columnLabels [icol]);
	}
	for (long irow = rowmin; irow <= rowmax; irow ++) {
		double y = 1 - lineSpacing * (irow - rowmin + 0.6);
		Graphics_setTextAlignment (graphics, Graphics_RIGHT, Graphics_HALF);
		if (my rowLabels && my rowLabels [irow] && my rowLabels [irow] [0])
			Graphics_text (graphics, 0.5 - leftMargin, y, my rowLabels [irow]);
		Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_HALF);
		for (long icol = 1; icol <= my numberOfColumns; icol ++) {
			wchar_t text [40];
			print4 (text, my data [irow] [icol], iformat, 0, precision);
			Graphics_text (graphics, icol, y, text);
		}
	}
	if (maxTextHeight) {
		double left = 0.5;
		if (maxTextWidth > 0.0) left -= maxTextWidth + 2 * leftMargin;
		Graphics_line (graphics, left, 1, my numberOfColumns + 0.5, 1);
	}
	Graphics_unsetInner (graphics);
}
Example #2
0
void EditDistanceTable_draw (EditDistanceTable me, Graphics graphics, int iformat, int precision, double angle) {
    long rowmin = 1, rowmax = my numberOfRows;
    Graphics_setInner (graphics);
    Graphics_setWindow (graphics, 0.5, my numberOfColumns + 0.5, 0, 1);
    double leftMargin = getLeftMargin (graphics);   // not earlier!
    double lineSpacing = getLineSpacing (graphics);   // not earlier!
    double maxTextWidth = getMaxRowLabelWidth (me, graphics, rowmin, rowmax);
    double y = 1 + 0.1 * lineSpacing;
    autoNUMmatrix<bool> onPath (1, my numberOfRows, 1, my numberOfColumns);
    for (long i = 1; i <= my warpingPath -> pathLength; i++) {
        structPairOfInteger poi = my warpingPath -> path[i];
        onPath[poi.y] [poi.x] = true;
    }

    for (long irow = my numberOfRows; irow > 0; irow --) {
        Graphics_setTextAlignment (graphics, Graphics_RIGHT, Graphics_HALF);
        if (my rowLabels && my rowLabels [irow] && my rowLabels [irow] [0])
            Graphics_text (graphics, 0.5 - leftMargin, y, my rowLabels [irow]);
        Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_HALF);
        for (long icol = 1; icol <= my numberOfColumns; icol ++) {
            char text [40];
            print4 (text, my data [irow] [icol], iformat, 0, precision);
            Graphics_setBold (graphics, onPath[irow][icol]);
            Graphics_text (graphics, icol, y, Melder_peek8to32 (text));
            if (onPath[irow][icol]) {
                Graphics_rectangle (graphics, icol-0.5, icol+0.5, y - 0.5*lineSpacing, y + 0.5*lineSpacing);
            }
        }
        y -= lineSpacing;
        Graphics_setBold (graphics, false);
    }

    double left = 0.5;
    if (maxTextWidth > 0.0) left -= maxTextWidth + 2 * leftMargin;
    Graphics_line (graphics, left, y, my numberOfColumns + 0.5, y);

    Graphics_setTextRotation (graphics, angle);
    if (angle < 0) {
        y -= 0.3*lineSpacing;
        Graphics_setTextAlignment (graphics, Graphics_LEFT, Graphics_HALF);
    } else if (angle > 0) {
        Graphics_setTextAlignment (graphics, Graphics_RIGHT, Graphics_HALF);
        y -= 0.3*lineSpacing;
    } else {
        Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_TOP);
    }
    for (long icol = 1; icol <= my numberOfColumns; icol ++) {
        if (my columnLabels && my columnLabels [icol] && my columnLabels [icol] [0])
            Graphics_text (graphics, icol, y, my columnLabels [icol]);
    }
    Graphics_setTextRotation (graphics, 0);
    y -= lineSpacing;
    Graphics_line (graphics, 0.5, y, 0.5, 1 + 0.5 * lineSpacing);
    Graphics_unsetInner (graphics);
}
void TableOfReal_drawVerticalLines (TableOfReal me, Graphics graphics, long rowmin, long rowmax) {
	long colmin = 1, colmax = my numberOfColumns;
	fixRows (me, & rowmin, & rowmax);
	Graphics_setInner (graphics);
	Graphics_setWindow (graphics, colmin - 0.5, colmax + 0.5, 0, 1);
	double lineSpacing = getLineSpacing (graphics);   // not earlier!
	double maxTextWidth = getMaxRowLabelWidth (me, graphics, rowmin, rowmax);
	double maxTextHeight = getMaxColumnLabelHeight (me, graphics, 1, my numberOfColumns);

	if (maxTextWidth > 0.0) colmin -= 1;
	for (long col = colmin + 1; col <= colmax; col ++)
		Graphics_line (graphics, col - 0.5, 1 + maxTextHeight, col - 0.5, 1 - lineSpacing * (rowmax - rowmin + 1));
	Graphics_unsetInner (graphics);
}
void TableOfReal_drawTopAndBottomLines (TableOfReal me, Graphics graphics, long rowmin, long rowmax) {
	long colmin = 1, colmax = my numberOfColumns;
	fixRows (me, & rowmin, & rowmax);
	Graphics_setInner (graphics);
	Graphics_setWindow (graphics, colmin - 0.5, colmax + 0.5, 0, 1);
	double lineSpacing = getLineSpacing (graphics);
	double maxTextWidth = getMaxRowLabelWidth (me, graphics, rowmin, rowmax);
	double maxTextHeight = getMaxColumnLabelHeight (me, graphics, 1, my numberOfColumns);

	double left = 0.5;
	if (maxTextWidth > 0.0) left -= maxTextWidth + 2 * lineSpacing;
	double right = colmax + 0.5;
	double top = 1 + maxTextHeight;
	double bottom = 1 - lineSpacing * (rowmax - rowmin + 1);
	Graphics_line (graphics, left, top, right, top);
	Graphics_line (graphics, left, bottom, right, bottom);
	Graphics_unsetInner (graphics);
}
void TableOfReal_drawAsNumbers_if (TableOfReal me, Graphics graphics, long rowmin, long rowmax, int iformat, int precision,
	const wchar_t *conditionFormula, Interpreter interpreter)
{
	try {
		autoMatrix original = TableOfReal_to_Matrix (me);
		autoMatrix conditions = original.clone ();
		fixRows (me, & rowmin, & rowmax);
		Graphics_setInner (graphics);
		Graphics_setWindow (graphics, 0.5, my numberOfColumns + 0.5, 0, 1);
		double leftMargin = getLeftMargin (graphics);   // not earlier!
		double lineSpacing = getLineSpacing (graphics);   // not earlier!
		double maxTextWidth = getMaxRowLabelWidth (me, graphics, rowmin, rowmax);
		double maxTextHeight = getMaxColumnLabelHeight (me, graphics, 1, my numberOfColumns);
		Matrix_formula (original.peek(), conditionFormula, interpreter, conditions.peek());

		Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_BOTTOM);
		for (long icol = 1; icol <= my numberOfColumns; icol ++) {
			if (my columnLabels && my columnLabels [icol] && my columnLabels [icol] [0])
				Graphics_text (graphics, icol, 1, my columnLabels [icol]);
		}
		for (long irow = rowmin; irow <= rowmax; irow ++) {
			double y = 1 - lineSpacing * (irow - rowmin + 0.6);
			Graphics_setTextAlignment (graphics, Graphics_RIGHT, Graphics_HALF);
			if (my rowLabels && my rowLabels [irow] && my rowLabels [irow] [0])
				Graphics_text (graphics, 0.5 - leftMargin, y, my rowLabels [irow]);
			Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_HALF);
			for (long icol = 1; icol <= my numberOfColumns; icol ++) if (conditions -> z [irow] [icol] != 0.0) {
				wchar_t text [40];
				print4 (text, my data [irow] [icol], iformat, 0, precision);
				Graphics_text (graphics, icol, y, text);
			}
		}
		if (maxTextHeight) {
			double left = 0.5;
			if (maxTextWidth > 0.0) left -= maxTextWidth + 2 * leftMargin;
			Graphics_line (graphics, left, 1, my numberOfColumns + 0.5, 1);
		}
		Graphics_unsetInner (graphics);
	} catch (MelderError) {
		Melder_throw (me, ": numbers not drawn.");
	}
}
void TableOfReal_drawHorizontalLines (TableOfReal me, Graphics graphics, long rowmin, long rowmax) {
	long colmin = 1, colmax = my numberOfColumns;
	fixRows (me, & rowmin, & rowmax);
	Graphics_setInner (graphics);
	Graphics_setWindow (graphics, colmin - 0.5, colmax + 0.5, 0, 1);
	double lineSpacing = getLineSpacing (graphics);
	double maxTextWidth = getMaxRowLabelWidth (me, graphics, rowmin, rowmax);
	double maxTextHeight = getMaxColumnLabelHeight (me, graphics, 1, my numberOfColumns);

	double left = 0.5;
	double top = rowmin;
	if (maxTextWidth > 0.0) left -= maxTextWidth + 2 * lineSpacing;
	if (maxTextHeight > 0.0) rowmin -= 1;
	double right = colmax + 0.5;
	for (long irow = rowmin; irow < rowmax; irow ++) {
		double y = 1 - lineSpacing * (irow - top + 1);
		Graphics_line (graphics, left, y, right, y);
	}
	Graphics_unsetInner (graphics);
}