我们正在从 clojurescript 渲染数据映射,它的行为很奇怪。数据映射具有从 clojurescript 传递的元素,但它正在以宽度和高度 = 0 呈现。
<div id="cash-balance-globe" class="cash-balance-globe tile-date-info" style="width: 361px;height: 187px;">
<svg width="0" data-width="0" class="datamap" height="0" style="overflow: hidden;"><g id="" class="datamaps-subunits">
传入元素的代码是:
(defn cash-balance-globe
^{:externs [[globe.render] [globe.highlightBubble]]}
[cash-balance-by-country selected-country-atom]
(let [globe-data (doall (map #(assoc %
:name (get % "country")
:value (get % "balance")) cash-balance-by-country))]
(letfn [(reagent-render [] (let [country-selected? (not (nil? @selected-country-atom))
selected-country-cash-balance (first (filter #(= (:name %) @selected-country-atom) globe-data))]
[:div
(if country-selected?
[selected-country-breakdown-table selected-country-cash-balance]
[:div "Select country to see detail"])
[:div {:id "cash-balance-globe"
:class "cash-balance-globe tile-date-info"
:style {:width "360px" :height "187px"}}]]))
(component-did-mount [] (let [set-selected-country (fn [x]
(reset! selected-country-atom
(get (js->clj x) "name")))
globe-container (js/document.getElementById "cash-balance-globe")]
(.. js/globe
(render globe-container (clj->js globe-data) set-selected-country popup-template #js [7 20]))
(when (not (nil? @selected-country-atom))
(.. js/globe
(highlightBubble @selected-country-atom globe-container)))
))]
(r/create-class
{:reagent-render reagent-render
:component-did-mount component-did-mount}))))
此处调用的 globe.js 具有如下渲染功能:
ns.render = function(container, countriesData, onCountrySelect, popupText, radiusRange) {
var values = function(d) { return d.value; };
var radiusScale = d3.scale.linear()
.domain([0,d3.max(countriesData, values)])
.range(radiusRange);
var globalMap = new Datamap({
element: container,
scope:'world',
geographyConfig: {
borderColor:'#818181',
popupOnHover: false,
highlightOnHover: false
},
fills: countryFills()
});
我们被困在这几天了。它在页面重新呈现时起作用,仅在第一次不起作用时。
此外,渲染函数正在获取具有正确宽度和高度的 div 元素,我们通过 console.log 检查