javascript - 反应调整大小和缩放小部件javascript
问题描述
我想调整小部件及其内部内容的大小,同样,我也想缩放当前的小部件,我正在使用 React RND 库来调整大小,但我无法调整小部件的内部内容, 和缩放也不能正常工作
我的小部件在这里是一个绘图图,我正在使用 React-Chartjs2 库来显示该图,如果有人对此有所了解,请帮助我执行此操作
谢谢
{w_data.type == 'plot' &&
<CCol xs="6" sm="6" lg="6" style={{ "marginTop": "20px"
}}>
<Rnd
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
border: "solid 1px #ddd",
position:"relative"
}}
className={widgetIndex==index ? 'boxShadow' : ''}
default={{
x: 50,
y: 5,
width: graphStyle.width,
height: graphStyle.height,
}}
onResizeStop={(e, direction, ref, delta, position) => {
setgraphStyle({
...graphStyle,
height:ref.offsetHeight,
width:ref.offsetWidth
})
//chartReference.update()
}}
>
<CRow>
<CCol xs="6" sm="6" lg="6">
<CRow style={{'direction': 'ltr',"fontSize":"18px"}}>
{w_data.sensor_name}
</CRow>
</CCol>
{editModeView &&
<CCol xs="6" sm="6" lg="6"
style={{"margin-top": "-82px","position":"absolute"}}
>
<CRow style={{'direction': 'rtl'}}>
<CIcon name="cil-trash"
onClick={()=>{
showDeleteModal(true)
setWidgetIndex(index)
}}
/>
<CIcon
onClick={() => {
setaddWidget(false)
seteditWidget(true)
setWidgetIndex(index)
seteditWidgetType('plot')
setwidgetDataEditTime(index)
setselectGraph('plot')
setshowAddeditPopover(true)
}}
id="Popover2"
name="cil-settings" />
</CRow>
</CCol>
}
</CRow>
<div style={{ 'width':
graphStyle.width,'height': graphStyle.height}}>
{console.log("GG", graphStyle)}
<Line data={w_data.graphData}
ref={(reference) => chartReference = reference}
// width={graphStyle.width}
// height={graphStyle.height}
// onResize={(a,b)=>{
// console.log("a",a,b)
// }}
options={{
maintainAspectRatio: false,
responsive: true,
legend: {
position: 'bottom',
},
scales: {
yAxes: [{
ticks:{maxTicksLimit:5},
}],
xAxes: [{
ticks:{maxTicksLimit:5},
//type: 'realtime',
realtime: {
onRefresh: function(chart) {
console.log("chart",chart)
chart.data.datasets.forEach(function(dataset) {
dataset.data.push({
x: Date.now(),
y: Math.random()
});
});
},
delay: 2000
}
}]
},
pan: {
enabled: true,
mode: "xy",
speed:10
},
zoom: {
enabled: true,
drag:false,
mode: "xy",
limits: {
max: 1,
min: 0.5,
},
rangeMin: {
x: 2,
y: 1,
},
rangeMax: {
x: 10,
y: 150,
},
}
}}
/>
</div>
</Rnd>
</CCol>
}
</>
解决方案
推荐阅读
- ios - “没有这样的模块:AVFAudio”xcode 构建在旧机器上失败,但在新机器上工作正常
- r - R:使用 CLR 进行密度平滑,来自 robComposition 的 smoothSpline 函数
- jquery - 如果元素没有此父类,则应用 CSS
- webrtc - iceCandidate 中的 WebRTC 空字符串
- reactjs - styled-components:组件...已动态创建
- python - 尝试在设置的欢迎频道中发送欢迎消息
- typescript - 如何帮助 Typescript 推断 PropertyDecorator 工厂函数的泛型参数?
- docker - 可以通过 Windows 主机中的 IP 地址访问 Docker linux 容器吗?
- python - Python - 函数的向量比在每个元素上调用循环要慢。Numpy 比原生 Python 慢
- swift - 当响应为 html(Swift) 时,如何读取表单数据的内容