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

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

//luShareX接受一个矩阵（二维数组），绘制共享X轴视图
:::luShareX(Array : ArrayLen, DimLen, nCols, nRows, i, x)=
  Array = cast[Array, real_s],
  ArrayLen = len[Array, &DimLen, &nCols, &nRows],
  cwClearData(), 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++};

//luShareX2接受二个矩阵（二维数组），绘制共享X轴视图
//Array1和Array2列数可以不相同，但相同的列有相同的坐标轴；Array1绘制点图，Array2绘制（带标记的）折线图
:::luShareX2(Array1,Array2 : ArrayLen1, DimLen1, nCols1, nRows1, ArrayLen2, DimLen2, nCols2, nRows2, nRowsMax, i, x, k)=
{
  Array1 = cast[Array1, real_s], Array2 = cast[Array2, real_s],
  ArrayLen1 = len[Array1, &DimLen1, &nCols1, &nRows1],
  ArrayLen2 = len[Array2, &DimLen2, &nCols2, &nRows2],
  nRowsMax=which[nRows1>=nRows2 : nRows1, nRows2],
  cwClearData(), cwAttach[typeShareX], cwResizePlots(nRowsMax-1),
  x=Array1(all:0).reshape(),
  i=0, while{++i<nRows1,
    k=cwAddCurve[x, Array1(all:i).reshape(), nCols1, i-1],
    cwSetScatter[cwGetIndex(k), i-1]
  },
  x=Array2(all:0).reshape(),
  i=0, while{++i<nRows2,
    k=cwAddCurve[x, Array2(all:i).reshape(), nCols2, i-1] //, cwSetMarkerShow[true,cwGetIndex(k), i-1], cwSetMarkerFreq[1,cwGetIndex(k), i-1]
  }
};

//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++]},
  cwClearData(), 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++
  }
};
