| 194 | void tooltip::ToolTipController::OnClearInner() { this->container_->Clear(); } |
| 195 | |
| 196 | bool tooltip::ToolTipController::ShowToolTips(const util::Point &point) { |
| 197 | |
| 198 | this->container_->Clear(); |
| 199 | |
| 200 | nlohmann::json tooltipMarkerItemsArray; |
| 201 | auto timestampStart = xg::CurrentTimestampAtMM(); |
| 202 | for (std::size_t tooltipIdx = 0; tooltipIdx < this->configs_.size(); tooltipIdx++) { |
| 203 | nlohmann::json &config = this->configs_[tooltipIdx]; |
| 204 | if (!config.contains("geometryIndex")) { |
| 205 | continue; |
| 206 | } |
| 207 | auto &tooltip = this->toolTips_[tooltipIdx]; |
| 208 | auto geometryIndex = json::GetIntNumber(config, "geometryIndex"); |
| 209 | if (chart_->geoms_.size() <= geometryIndex) { |
| 210 | continue; |
| 211 | } |
| 212 | auto &geom = chart_->geoms_[geometryIndex]; |
| 213 | |
| 214 | std::string xFieldPrefix = geom->isAdjustDodge() ? "original_" : ""; |
| 215 | |
| 216 | util::Point _point = point; |
| 217 | |
| 218 | //限制point.x的坐标为数据点的最后一个坐标 |
| 219 | double maxPointX = FLT_MIN; |
| 220 | double minPointX = FLT_MAX; |
| 221 | const nlohmann::json &firstRecord = geom->GetFirstSnapRecord(chart_); |
| 222 | const nlohmann::json &lastRecord = geom->GetLastSnapRecord(chart_); |
| 223 | //在各分组中取最大的 当scale为timesharing的时候,first和last可能对调,所以min和max判断都需要 |
| 224 | if (lastRecord.contains("_x")) { |
| 225 | double lastX = json::GetNumber(lastRecord, "_x"); |
| 226 | minPointX = fmin(minPointX, lastX); |
| 227 | maxPointX = fmax(maxPointX, lastX); |
| 228 | } |
| 229 | |
| 230 | if (firstRecord.contains("_x")) { |
| 231 | double firstX = json::GetNumber(firstRecord, "_x"); |
| 232 | minPointX = fmin(minPointX, firstX); |
| 233 | maxPointX = fmax(maxPointX, firstX); |
| 234 | } |
| 235 | _point.x = fmax(fmin(_point.x, maxPointX), minPointX); |
| 236 | |
| 237 | nlohmann::json tooltipMarkerItems; |
| 238 | nlohmann::json records = geom->GetSnapRecords(chart_, _point, false); |
| 239 | for (std::size_t index = 0; index < records.size(); ++index) { |
| 240 | nlohmann::json &record = records[index]; |
| 241 | if (record.contains("_x") && record.contains("_y")) { |
| 242 | nlohmann::json tooltipItem; |
| 243 | tooltipItem["x"] = record.contains("_original_x") ? record["_original_x"] : record["_x"]; |
| 244 | tooltipItem["y"] = record["_y"]; |
| 245 | tooltipItem["color"] = record.contains("_color") ? record["_color"].get<std::string>() : GLOBAL_COLORS[0]; |
| 246 | tooltipItem["xTip"] = config["xTip"]; |
| 247 | tooltipItem["yTip"] = config["yTip"]; |
| 248 | |
| 249 | auto &nameField = config.contains("yTipField") ? json::GetString(config, "yTipField") : tooltip::_GetToolTipGroupNameField(chart_, geom); |
| 250 | auto &yScale = chart_->GetScale(nameField); |
| 251 | tooltipItem["name"] = nameField; |
| 252 | |
| 253 | if (json::GetString(config, "xPositionType") == "record") { |
no test coverage detected