| 198 | } |
| 199 | |
| 200 | void ChartBridge::CompatScale(const std::string &field, const nlohmann::json &sConfig) { |
| 201 | nlohmann::json scaleConfig(sConfig); |
| 202 | |
| 203 | |
| 204 | const auto &tickType = json::GetString(scaleConfig, "tickType"); |
| 205 | const auto &timeZoneName = json::GetString(scaleConfig, "timeZone"); |
| 206 | if (!timeZoneName.empty() && railing_) { |
| 207 | long timeZoneOffset = railing_->GetTimezoneOffset(timeZoneName); |
| 208 | scaleConfig["timeZoneOffset"] = timeZoneOffset; |
| 209 | } |
| 210 | |
| 211 | F2ASSERT(scaleConfig.is_object(), "scaleConfig is not a object"); |
| 212 | |
| 213 | if (tickType == "price") { |
| 214 | int precision = json::GetNumber(scaleConfig, "tickTypePricePrecision", 0); |
| 215 | auto item = BridgeChannel::Callback([precision, this](const std::string &functionId, const std::string ¶ms)-> const std::string { |
| 216 | auto config = json::ParseString(params); |
| 217 | auto &content = json::GetString(config, "content"); |
| 218 | config["content"] = FormatPrice(content, precision); |
| 219 | return config.dump(); |
| 220 | }); |
| 221 | scaleConfig["tick"] = item.functionId; |
| 222 | callbackFunctions_[item.functionId] = std::move(item); |
| 223 | chart_->ScaleObject(field, scaleConfig); |
| 224 | } else if(tickType == "dateTimestamp") { |
| 225 | const auto &formatter = json::GetString(scaleConfig, "tickTimestampFormatter"); |
| 226 | const auto &timeZoneName = json::GetString(scaleConfig, "timeZone", "Asia/Shanghai"); |
| 227 | auto item = BridgeChannel::Callback([formatter, timeZoneName, this](const std::string &functionId, const std::string ¶ms)-> const std::string { |
| 228 | auto config = json::ParseString(params); |
| 229 | auto &content = json::GetString(config, "content"); |
| 230 | config["content"] = FormatTime(content, timeZoneName, formatter); |
| 231 | return config.dump(); |
| 232 | }); |
| 233 | scaleConfig["tick"] = item.functionId; |
| 234 | callbackFunctions_[item.functionId] = std::move(item); |
| 235 | chart_->ScaleObject(field, scaleConfig); |
| 236 | } else if(tickType == "percent") { |
| 237 | double divisor = json::GetNumber(scaleConfig, "tickTypePercentDivisor", 1); |
| 238 | int precision = json::GetNumber(scaleConfig, "tickTypePercentPrecision", 0); |
| 239 | auto item = BridgeChannel::Callback([divisor, precision, this](const std::string &functionId, const std::string ¶ms)-> const std::string { |
| 240 | auto config = json::ParseString(params); |
| 241 | auto &content = json::GetString(config, "content"); |
| 242 | config["content"] = FormatPercent(content, divisor, precision); |
| 243 | return config.dump(); |
| 244 | }); |
| 245 | scaleConfig["tick"] = item.functionId; |
| 246 | callbackFunctions_[item.functionId] = std::move(item); |
| 247 | chart_->ScaleObject(field, scaleConfig); |
| 248 | } else { |
| 249 | if (!timeZoneName.empty()) { |
| 250 | chart_->ScaleObject(field, scaleConfig); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | std::string ChartBridge::FormatPrice(const std::string &content, int precision) { |
| 256 | double value = stod(content); |
nothing calls this directly
no test coverage detected