/****************************************************************************
 * This file is part of the project AqDiagram.
 * AqDiagram (c) by 2023 Martin Preuss, all rights reserved.
 *
 * The license for this file can be found in the file COPYING which you
 * should have received along with this file.
 ****************************************************************************/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "./w_graph_p.h"

#include "aqdiagram/graph/w_xaxis.h"
#include "aqdiagram/graph/w_yaxis.h"
#include "aqdiagram/graph/w_viewport.h"
#include "aqdiagram/graph/w_legend.h"
#include "aqdiagram/draw/w_vlayout.h"
#include "aqdiagram/draw/w_mlayout.h"
#include "aqdiagram/draw/w_label.h"
#include "aqdiagram/draw/w_drawable.h"

#include <gwenhywfar/debug.h>
#include <gwenhywfar/gwentime.h>


#define I18N(msg) msg



/* ------------------------------------------------------------------------------------------------
 * forward declarations
 * ------------------------------------------------------------------------------------------------
 */

static GWENHYWFAR_CB void _freeData(void *bp, void *p);
static void _setupObjectTree(AQDG_OBJECT *o);
static void _setupMatrix(AQDG_OBJECT *o);
static AQDG_OBJECT *_createLabel(AQDG_OBJECT *o, AQDG_OBJECT *parent, const char *name,
				 uint32_t options, const char *s, int penIdx, int fontIdx);
static AQDG_OBJECT *_createTimeLabel(AQDG_OBJECT *o, AQDG_OBJECT *parent, const char *name,
				     uint32_t options, int penIdx, int fontIdx);



/* ------------------------------------------------------------------------------------------------
 * vars
 * ------------------------------------------------------------------------------------------------
 */

static uint32_t _curveColors[]={
  AQDG_GRAPHWIDGET_COL_LIME,
  AQDG_GRAPHWIDGET_COL_BLUE,
  AQDG_GRAPHWIDGET_COL_CYAN,
  AQDG_GRAPHWIDGET_COL_MAGENTA,
  AQDG_GRAPHWIDGET_COL_GREEN,
  AQDG_GRAPHWIDGET_COL_TURQUOISE,
  AQDG_GRAPHWIDGET_COL_DEEPPINK,
  AQDG_GRAPHWIDGET_COL_NAVY
};



/* ------------------------------------------------------------------------------------------------
 * implementations
 * ------------------------------------------------------------------------------------------------
 */

GWEN_INHERIT(AQDG_OBJECT, AQDG_WIDGET_GRAPH);



AQDG_OBJECT *AQDG_GraphWidget_new(AQDG_OBJECT *parent, uint32_t options, AQDG_DRAW_CONTEXT *drawContext)
{
  AQDG_OBJECT *o;
  AQDG_WIDGET_GRAPH *xo;

  o=AQDG_VLayoutWidget_new(parent, options, drawContext);
  AQDG_Object_SetName(o, "GraphWidget");
  GWEN_NEW_OBJECT(AQDG_WIDGET_GRAPH, xo);
  GWEN_INHERIT_SETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o, xo, _freeData);

  return o;
}



GWENHYWFAR_CB void _freeData(void *bp, void *p)
{
  AQDG_WIDGET_GRAPH *xo;

  xo=(AQDG_WIDGET_GRAPH*) p;
  AQDG_Graph_free(xo->graph);
  GWEN_FREE_OBJECT(p);
}



void AQDG_GraphWidget_FinishWithGraph(AQDG_OBJECT *o, AQDG_GRAPH *graph)
{
  AQDG_DRAW_CONTEXT *dc;

  dc=AQDG_DrawableWidget_GetDrawContext(o);

  AQDG_GraphWidget_SetupForGraph(o, graph);

  AQDG_Object_ModifyBranchFlagsDown(o, AQDG_OBJECT_FLAGS_RECALC, AQDG_OBJECT_FLAGS_RECALC);
  AQDG_Object_ModifyBranchFlagsDown(o, AQDG_OBJECT_FLAGS_LAYOUT, AQDG_OBJECT_FLAGS_LAYOUT);
  AQDG_Object_Layout(o);
  AQDG_Object_Tree2_CalculateAbsPositions(o);
  AQDG_DrawableWidget_Draw(o);
  AQDG_Draw_Context_Finish(dc);
}



void AQDG_GraphWidget_SetupForGraph(AQDG_OBJECT *o, AQDG_GRAPH *graph)
{
  if (o && graph) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo) {
      xo->graph=graph;
      AQDG_DrawableWidget_SetBackgroundPenId(o, xo->penArray[AQDG_GRAPHWIDGET_PEN_IDX_BACKGROUND]);
      _setupObjectTree(o);
    }
  }
}




void _setupObjectTree(AQDG_OBJECT *o)
{
  AQDG_WIDGET_GRAPH *xo;
  const char *s;

  xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
  AQDG_DrawableWidget_SetForegroundPenId(o, xo->penArray[AQDG_GRAPHWIDGET_PEN_IDX_TITLE]);
  AQDG_DrawableWidget_SetBackgroundPenId(o, xo->penArray[AQDG_GRAPHWIDGET_PEN_IDX_BACKGROUND]);
  AQDG_DrawableWidget_SetFontId(o, xo->fontArray[AQDG_GRAPHWIDGET_FONT_IDX_SUBTITLE]);

  s=AQDG_Graph_GetTitle(xo->graph);
  if (s)
    _createLabel(o,
		 o,
		 "titleLabel",
                 AQDG_OBJECT_OPTIONS_HALIGNCENTER,
                 s,
                 AQDG_GRAPHWIDGET_PEN_IDX_TITLE,
                 AQDG_GRAPHWIDGET_FONT_IDX_TITLE);

  s=AQDG_Graph_GetSubTitle(xo->graph);
  if (s)
    _createLabel(o,
                 o,
		 "subTitleLabel",
                 AQDG_OBJECT_OPTIONS_HALIGNCENTER,
                 s,
                 AQDG_GRAPHWIDGET_PEN_IDX_SUBTITLE,
                 AQDG_GRAPHWIDGET_FONT_IDX_SUBTITLE);

  _setupMatrix(o);

  AQDG_LegendWidget_new(o, AQDG_OBJECT_OPTIONS_STRETCHX, o);
  _createTimeLabel(o,
		   o,
		   "updateLabel",
		   AQDG_OBJECT_OPTIONS_HALIGNRIGHT,
		   AQDG_GRAPHWIDGET_PEN_IDX_SUBTITLE,
		   AQDG_GRAPHWIDGET_FONT_IDX_SUBTITLE);
}



void _setupMatrix(AQDG_OBJECT *o)
{
  AQDG_WIDGET_GRAPH *xo;
  AQDG_DRAW_CONTEXT *dc;
  AQDG_OBJECT *oMatrix;
  int matrixColumns=1;

  xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
  dc=AQDG_DrawableWidget_GetDrawContext(o);

  if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_LEFT))
    matrixColumns++;
  if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_RIGHT))
    matrixColumns++;
  oMatrix=AQDG_MatrixLayoutWidgetByRows_new(o,
                                            AQDG_OBJECT_OPTIONS_STRETCHX | AQDG_OBJECT_OPTIONS_STRETCHY,
                                            AQDG_DrawableWidget_GetDrawContext(o),
                                            matrixColumns);
  /* first row: top x-axis */
  if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_TOP)) {
    if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_LEFT))
      AQDG_DrawableWidget_new(oMatrix, 0, dc);
    AQDG_XAxisWidget_new(oMatrix, AQDG_OBJECT_OPTIONS_STRETCHX, o, AQDG_GRAPH_AXISPOS_TOP);
    if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_RIGHT))
      AQDG_DrawableWidget_new(oMatrix, 0, dc);
  }

  /* middle row: left y-axis, graph, right y-axis */
  if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_LEFT))
    AQDG_YAxisWidget_new(oMatrix, AQDG_OBJECT_OPTIONS_STRETCHY, o, AQDG_GRAPH_AXISPOS_LEFT);
  AQDG_ViewportWidget_new(oMatrix, AQDG_OBJECT_OPTIONS_STRETCHX | AQDG_OBJECT_OPTIONS_STRETCHY, o);
  if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_RIGHT))
    AQDG_YAxisWidget_new(oMatrix, AQDG_OBJECT_OPTIONS_STRETCHY, o, AQDG_GRAPH_AXISPOS_RIGHT);

  /* last row: bottom x-axis */
  if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_BOTTOM)) {
    if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_LEFT))
      AQDG_DrawableWidget_new(oMatrix, 0, dc);
    AQDG_XAxisWidget_new(oMatrix, AQDG_OBJECT_OPTIONS_STRETCHX, o, AQDG_GRAPH_AXISPOS_BOTTOM);
    if (AQDG_Graph_GetAxisByIndex(xo->graph, AQDG_GRAPH_AXISPOS_RIGHT))
      AQDG_DrawableWidget_new(oMatrix, 0, dc);
  }
}



AQDG_OBJECT *_createLabel(AQDG_OBJECT *o, AQDG_OBJECT *parent, const char *name,
			  uint32_t options, const char *s, int penIdx, int fontIdx)
{
  AQDG_OBJECT *oLabel;
  int penId;
  int fontId;

  penId=AQDG_GraphWidget_GetPen(o, penIdx);
  fontId=AQDG_GraphWidget_GetFont(o, fontIdx);
  oLabel=AQDG_LabelWidget_new(o, options, AQDG_DrawableWidget_GetDrawContext(o), s);
  if (name && *name)
    AQDG_Object_SetName(oLabel, name);
  if (penId!=-1)
    AQDG_DrawableWidget_SetForegroundPenId(oLabel, penId);
  if (fontId!=-1)
    AQDG_DrawableWidget_SetFontId(oLabel, fontId);

  return oLabel;
}



AQDG_OBJECT *_createTimeLabel(AQDG_OBJECT *o, AQDG_OBJECT *parent, const char *name,
			      uint32_t options, int penIdx, int fontIdx)
{
  AQDG_OBJECT *oLabel;
  GWEN_TIME *ti;
  GWEN_BUFFER *buf;

  ti=GWEN_CurrentTime();
  buf=GWEN_Buffer_new(0, 64, 0, 1);
  GWEN_Buffer_AppendString(buf, I18N("Last update: "));
  GWEN_Time_toString(ti, "YYYY/MM/DD-hh:mm:ss", buf);
  oLabel=_createLabel(o, parent, name, options, GWEN_Buffer_GetStart(buf), penIdx, fontIdx);
  GWEN_Buffer_free(buf);
  GWEN_Time_free(ti);
  return oLabel;
}



void _presetPens(AQDG_OBJECT *o)
{
  if (o) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo) {
      int i;

      for (i=0; i<AQDG_GRAPHWIDGET_PEN_IDX_LAST; i++)
        xo->penArray[i]=-1;
    }
  }
}



void _presetFonts(AQDG_OBJECT *o)
{
  if (o) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo) {
      int i;

      for (i=0; i<AQDG_GRAPHWIDGET_FONT_IDX_LAST; i++)
        xo->fontArray[i]=-1;
    }
  }
}



void _releasePens(AQDG_OBJECT *o)
{
  if (o) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo) {
      AQDG_DRAW_CONTEXT *dc;
      int i;

      dc=AQDG_DrawableWidget_GetDrawContext(o);
      for (i=0; i<AQDG_GRAPHWIDGET_PEN_IDX_LAST; i++) {
        AQDG_Draw_Context_PenRelease(dc, xo->penArray[i]);
        xo->penArray[i]=-1;
      }
    }
  }
}



void _releaseFonts(AQDG_OBJECT *o)
{
  if (o) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo) {
      AQDG_DRAW_CONTEXT *dc;
      int i;

      dc=AQDG_DrawableWidget_GetDrawContext(o);
      for (i=0; i<AQDG_GRAPHWIDGET_FONT_IDX_LAST; i++) {
        AQDG_Draw_Context_FontRelease(dc, xo->fontArray[i]);
        xo->fontArray[i]=-1;
      }
    }
  }
}






AQDG_GRAPH *AQDG_GraphWidget_GetGraph(const AQDG_OBJECT *o)
{
  if (o) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo)
      return xo->graph;
  }
  return NULL;
}




int AQDG_GraphWidget_GetPen(const AQDG_OBJECT *o, int idx)
{
  if (o && idx<AQDG_GRAPHWIDGET_PEN_IDX_LAST) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo)
      return xo->penArray[idx];
  }

  return -1;
}



void AQDG_GraphWidget_SetPen(AQDG_OBJECT *o, int idx, int penId)
{
  if (o && idx<AQDG_GRAPHWIDGET_PEN_IDX_LAST) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo)
      xo->penArray[idx]=penId;
  }
}



int AQDG_GraphWidget_GetFont(const AQDG_OBJECT *o, int idx)
{
  if (o && idx<AQDG_GRAPHWIDGET_FONT_IDX_LAST) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo)
      return xo->fontArray[idx];
  }

  return -1;
}



void AQDG_GraphWidget_SetFont(AQDG_OBJECT *o, int idx, int fontId)
{
  if (o && idx<AQDG_GRAPHWIDGET_FONT_IDX_LAST) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo)
      xo->fontArray[idx]=fontId;
  }
}



int AQDG_GraphWidget_CreatePenFromDb(AQDG_OBJECT *o, GWEN_DB_NODE *db, const char *name, uint32_t defColor, int defWidth, int defDash)
{
  if (o) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo) {
      uint32_t frontColour;
      int lineWidth;
      int dashType;
      int rv;
      GWEN_BUFFER *nameBuf;
      int bufPos;
      AQDG_DRAW_CONTEXT *dc;

      dc=AQDG_DrawableWidget_GetDrawContext(o);

      nameBuf=GWEN_Buffer_new(0, 64, 0, 1);
      GWEN_Buffer_AppendString(nameBuf, name);
      bufPos=GWEN_Buffer_GetPos(nameBuf);

      /* RGBA */
      GWEN_Buffer_AppendString(nameBuf, "color");
      frontColour=(uint32_t)GWEN_DB_GetIntValue(db, GWEN_Buffer_GetStart(nameBuf), 0, (int)defColor);

      GWEN_Buffer_Crop(nameBuf, 0, bufPos);
      GWEN_Buffer_AppendString(nameBuf, "width");
      lineWidth=GWEN_DB_GetIntValue(db, GWEN_Buffer_GetStart(nameBuf), 0, defWidth);

      GWEN_Buffer_Crop(nameBuf, 0, bufPos);
      GWEN_Buffer_AppendString(nameBuf, "dash");
      dashType=GWEN_DB_GetIntValue(db, "dashType", 0, defDash);

      GWEN_Buffer_free(nameBuf);

      rv=AQDG_Draw_Context_PenCreate(dc, frontColour, lineWidth, dashType);
      if (rv<0) {
        DBG_INFO(AQDG_LOGDOMAIN, "here (%d)", rv);
        return rv;
      }

      return rv;
    }
  }
  return -1;
}



int AQDG_GraphWidget_CreateFontFromDb(AQDG_OBJECT *o, GWEN_DB_NODE *db, const char *name, int defaultFontSize)
{
  if (o) {
    AQDG_WIDGET_GRAPH *xo;

    xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
    if (xo) {
      const char *fontName;
      int fontSize;
      int fontSlant;
      int fontWeight;
      int rv;
      GWEN_BUFFER *nameBuf;
      int bufPos;
      AQDG_DRAW_CONTEXT *dc;

      dc=AQDG_DrawableWidget_GetDrawContext(o);

      nameBuf=GWEN_Buffer_new(0, 64, 0, 1);
      GWEN_Buffer_AppendString(nameBuf, name);
      bufPos=GWEN_Buffer_GetPos(nameBuf);

      GWEN_Buffer_AppendString(nameBuf, "name");
      fontName=GWEN_DB_GetCharValue(db, GWEN_Buffer_GetStart(nameBuf), 0, "");

      GWEN_Buffer_Crop(nameBuf, 0, bufPos);
      GWEN_Buffer_AppendString(nameBuf, "size");
      fontSize=GWEN_DB_GetIntValue(db, GWEN_Buffer_GetStart(nameBuf), 0, defaultFontSize);

      GWEN_Buffer_Crop(nameBuf, 0, bufPos);
      GWEN_Buffer_AppendString(nameBuf, "slant");
      fontSlant=AQDG_Slant_fromString(GWEN_DB_GetCharValue(db, GWEN_Buffer_GetStart(nameBuf), 0, "none"));

      GWEN_Buffer_Crop(nameBuf, 0, bufPos);
      GWEN_Buffer_AppendString(nameBuf, "weight");
      fontWeight=AQDG_Weight_fromString(GWEN_DB_GetCharValue(db, GWEN_Buffer_GetStart(nameBuf), 0, "none"));

      GWEN_Buffer_free(nameBuf);

      rv=AQDG_Draw_Context_FontCreate(dc, fontName, fontSize, fontSlant, fontWeight);
      if (rv<0) {
        DBG_INFO(AQDG_LOGDOMAIN, "here (%d)", rv);
        return rv;
      }

      return rv;
    }
  }
  return -1;
}



uint32_t AQDG_GraphWidget_GetStandardCurveColor(int idx, uint32_t defCol)
{
  if (idx<sizeof(_curveColors)/sizeof(uint32_t))
    return _curveColors[idx];
  return defCol;
}



void AQDG_GraphWidget_SetupDefaultPens(AQDG_OBJECT *o)
{
  AQDG_WIDGET_GRAPH *xo;

  xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
  if (xo) {
    AQDG_DRAW_CONTEXT *dc;

    dc=AQDG_DrawableWidget_GetDrawContext(o);
#define MKPEN(penArrayIdx, penColour, penSize, penDash) \
  xo->penArray[penArrayIdx]=AQDG_Draw_Context_PenCreate(dc, penColour, penSize, penDash);

    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_TITLE,              AQDG_GRAPHWIDGET_COL_BLACK,      2, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_SUBTITLE,           AQDG_GRAPHWIDGET_COL_BLACK,      1, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_AXISLINE,           AQDG_GRAPHWIDGET_COL_GRAY,       1, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_AXISLABEL,          AQDG_GRAPHWIDGET_COL_GRAY,       1, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_TICKLABELMAINLEVEL, AQDG_GRAPHWIDGET_COL_BLACK,      1, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_TICKLABELSUBLEVEL,  AQDG_GRAPHWIDGET_COL_BLACK,      1, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_TICKMAINLEVEL,      AQDG_GRAPHWIDGET_COL_BLACK,      1, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_TICKSUBLEVEL,       AQDG_GRAPHWIDGET_COL_BLACK,      1, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_GRAPHBACKGROUND,    AQDG_GRAPHWIDGET_COL_WHITESMOKE, 1, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_GRID1,              AQDG_GRAPHWIDGET_COL_GRAY,       1, AQDG_Dash_Format1);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_GRID2,              AQDG_GRAPHWIDGET_COL_GRAY,       1, AQDG_Dash_Format2);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_BACKGROUND,         AQDG_GRAPHWIDGET_COL_GAINSBORO,  1, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_CURVE0,             AQDG_GRAPHWIDGET_COL_GREEN,      2, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_CURVE1,             AQDG_GRAPHWIDGET_COL_BLUE,       2, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_CURVE2,             AQDG_GRAPHWIDGET_COL_RED,        2, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_CURVE3,             AQDG_GRAPHWIDGET_COL_MAGENTA,    2, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_CURVE4,             AQDG_GRAPHWIDGET_COL_ORANGE,     2, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_CURVE5,             AQDG_GRAPHWIDGET_COL_TURQUOISE,  2, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_CURVE6,             AQDG_GRAPHWIDGET_COL_DEEPPINK,   2, AQDG_Dash_None);
    MKPEN(AQDG_GRAPHWIDGET_PEN_IDX_CURVE7,             AQDG_GRAPHWIDGET_COL_NAVY,       2, AQDG_Dash_None);

#undef MKPEN

  }
}



void AQDG_GraphWidget_SetupDefaultFonts(AQDG_OBJECT *o)
{
  AQDG_WIDGET_GRAPH *xo;

  xo=GWEN_INHERIT_GETDATA(AQDG_OBJECT, AQDG_WIDGET_GRAPH, o);
  if (xo) {
    AQDG_DRAW_CONTEXT *dc;

    dc=AQDG_DrawableWidget_GetDrawContext(o);
#define MKNORMALFONT(fontArrayIdx, fontSize) \
  xo->fontArray[fontArrayIdx]=AQDG_Draw_Context_FontCreate(dc, "", fontSize, AQDG_Slant_None, AQDG_Weight_None);

    MKNORMALFONT(AQDG_GRAPHWIDGET_FONT_IDX_TITLE,     16);
    MKNORMALFONT(AQDG_GRAPHWIDGET_FONT_IDX_SUBTITLE,  12);
    MKNORMALFONT(AQDG_GRAPHWIDGET_FONT_IDX_AXISLABEL, 12);
    MKNORMALFONT(AQDG_GRAPHWIDGET_FONT_IDX_TICKLABELMAINLEVEL, 12);
    MKNORMALFONT(AQDG_GRAPHWIDGET_FONT_IDX_TICKLABELSUBLEVEL, 10);
    MKNORMALFONT(AQDG_GRAPHWIDGET_FONT_IDX_LEGEND, 11);

#undef MKNORMALFONT
  }
}



