zbTip method

dynamic zbTip(
  1. dynamic x,
  2. dynamic y,
  3. dynamic w,
  4. dynamic h,
  5. dynamic zb,
  6. dynamic tipy,
)

Implementation

zbTip(x, y, w, h, zb, tipy) {
  var txtPath = [];
  var iconPath = [];
  double padding = 10;
  if (chartData.kDataL > 0) {
    int i = 0;
    String tipName = ""; //展示文字名字
    String showStr = ""; //展示文字
    double showStrW = 0; //展示文字宽度
    Map showStrSize = {};//展示文字尺寸
    var obj = {};
    int lineI = Tools.max(0, kStopI - 1);
    var curIndicatorPro = indicator.config[zb];
    var curIndicatorData = zbData[zb];
    //kMouseI 在绘制十字线的时候会计算,十字线停止绘制后会调整成-1
    if (kMouseI >= kStartI && kMouseI < kStopI) {
      lineI = kMouseI;
    }
    for (var dd in curIndicatorData.keys) {
      if (Tools.isNaN(curIndicatorData[dd][lineI])) {
        if (curIndicatorData[dd][lineI] is Map) {
          obj[dd] = curIndicatorData[dd][lineI];
        } else {
          obj[dd] = "-";
        }
      } else {
        obj[dd] = Tools.toFixed(curIndicatorData[dd][lineI],
            klineState.widget.propertys['priceDigits']);
      }
    }
    double stry = y + tipy+3; //绘制y坐标
    double strx = x + padding/2; //绘制x坐标
    dynamic p = '';
    dynamic v = 0; // 参数和值
    var index = 0;
    if (zb == null) {
    } else if (zb == Indicator['MA']) {
      for (i = 0; i < curIndicatorPro['title']['value'].length; i++) {
        tipName = curIndicatorPro['title']['value'][i];
        p = curIndicatorPro['params'][i]['value']; //参数
        v = obj[tipName]??'-'; //值
        showStr = "MA$p:$v";
        strx += showStrW;
        txtPath.add([
          showStr,
          strx,
          stry,
          {'color': curIndicatorPro['style'][tipName]['color']}
        ]);
        showStrSize = zbTipTxtW("MA$p:","$v",curIndicatorPro['style']['NAME'],padding);
        showStrW = showStrSize['width'];
      }
    } else if (zb == Indicator['RSI']) {
      showStr = curIndicatorPro['title']['name'];
      txtPath.add([
        showStr,
        strx,
        stry,
        {'color': curIndicatorPro['style']['NAME']['color']}
      ]);
      showStrSize = zbTipTxtW("",showStr,curIndicatorPro['style']['NAME'],padding);
      showStrW = showStrSize['width'];
      for (i = 0; i < 3; i++) {
        strx += showStrW;
        index = i + 1;
        p = curIndicatorPro['params'][i]['value'];
        v = obj["RSI$index"];
        showStr = "RSI$p:$v";
        txtPath.add([
          showStr,
          strx,
          stry,
          {'color': curIndicatorPro['style']["RSI$index"]['color']}
        ]);
        showStrSize = zbTipTxtW("RSI$p:","$v",curIndicatorPro['style']['NAME'],padding);
        showStrW = showStrSize['width'];
      }
    } else if (zb == Indicator['VOLUME']) {
      dynamic vol = 0;
      if (obj["VOL"] is String) {
        v = obj['VOL'];
      } else {
        v = obj['VOL']['volume'];
      }
      v = Tools.toFixed(v, klineState.widget.propertys['amountDigits']);
      showStr = "VOL:$v";
      txtPath.add([
        showStr,
        strx,
        stry,
        {'color': curIndicatorPro['style']['VOL']['color']}
      ]);
      showStrSize = zbTipTxtW("VOL:","$v",curIndicatorPro['style']['NAME'],padding);
      showStrW = showStrSize['width'];
      for (i = 0; i < 2; i++) {
        index = i + 1;
        p = curIndicatorPro['params'][i]['value'];
        if (obj["MAVOL$index"] == "-") {
          vol = '-';
          showStr = "MAVOL$p:$vol";
        } else {
          vol = Tools.toFixed(obj["MAVOL$index"], 0);
          showStr = "MAVOL$p:$vol";
        }
        strx += showStrW;
        txtPath.add([
          showStr,
          strx,
          stry,
          {'color': curIndicatorPro['style']["MAVOL$index"]['color']}
        ]);
        showStrSize = zbTipTxtW("MAVOL$p:","$vol",curIndicatorPro['style']['NAME'],padding);
        showStrW = showStrSize['width'];
      }
    } else {
      showStr = curIndicatorPro['title']['name'];
      if (showStr != "") {
        txtPath.add([
          showStr,
          strx,
          stry,
          {'color': curIndicatorPro['style']['NAME']['color']}
        ]);
        showStrSize = zbTipTxtW("",showStr,curIndicatorPro['style']['NAME'],padding);
        showStrW = showStrSize['width'];
      }
      for (i = 0; i < curIndicatorPro['title']['value'].length; i++) {
        p = curIndicatorPro['title']['value'][i];
        var c = curIndicatorPro['style'][p]['color'];
        v = '-';
        showStr = "$p:$v";
        if (obj.containsKey(p)) {
          //如果有这个属性对应的数据
          v = obj[p];
          showStr = "$p:$v";
          if (p == "MACD") {
            if (num.parse(v) > 0) {
              c = style[ColorType['upColor']];
            } //上涨
            else {
              c = style[ColorType['downColor']];
            } //下跌
          }
        }
        strx += showStrW;
        txtPath.add([
          showStr,
          strx,
          stry,
          {'color': c}
        ]);
        showStrSize = zbTipTxtW("$p:","$v",curIndicatorPro['style']['NAME'],padding);
        showStrW = showStrSize['width'];
      }
    }
    //增加指标设置按钮
    if(zb != null){
      Map data = zbSetIcon(strx+showStrW,stry+(showStrSize['height']??zbTipH)/2);
      iconPath = data['iconPath'];
      zbSetDataPoint.add(
        {
          'zb':zb,
          'size':data['size'],
          'data':curIndicatorPro
        }
      );
    }
  }
  return {'txtPath':txtPath,'iconPath':iconPath};
}