!!!using("sys","win","math");

"
模块“ChartWnd实用函数”已经编译，可以直接使用该模块的函数。
";

//luShareX接受一个矩阵（二维数组），绘制共享X轴视图
:::luShareX(Array : ArrayLen, DimLen, nCols, nRows, i, x, k)=
  Array = cast[Array, real_s],
  ArrayLen = len[Array, &DimLen, &nCols, &nRows],
  cwResetChart(), cwAttach[typeShareX], cwResizePlots(nRows-1),
  x=Array(all:0).reshape(), i=1, while{i<nRows, cwAddCurve[x, Array(all:i).reshape(), nCols, i-1], i++};

//luPlot接受一个lu对象，绘制一元函数共享X轴图形，lu对象格式：
//lu{xMin, xMax, 绘图点数_缺省为1000, @f1, "f1曲线标记（可缺省）", @f2, "f2曲线标记（可缺省）", ... ...}
:::luPlot(me : meLen, x, nx, k, i, f, fmax, idData)=
{
  meLen = len[me],
  nx = which{me(2).vtype()==vtype(0), [k=3, me(2)], [k=2, 1000]},
  x = linspace[me(0),me(1),nx],
  fmax=0, i=k, while{i<meLen, if[vtype(@luPlot)==vtype(me(i++)), fmax++]},
  cwResetChart(), cwAttach[typeShareX], cwResizePlots(fmax),
  fmax=0, i=k, while{i<meLen,
    if[vtype(@luPlot)!=vtype(me(i)), i++, continue()],
    f = me(i++), idData=cwAddCurve[x, f(x), nx, fmax], cwSetUseLegend[true, fmax], 
    if{i<meLen, if[vtype("")==vtype(me(i)), cwSetDataTitle(me(i), cwGetIndex(idData), fmax)]},
    fmax++
  }
};
