This commit is contained in:
yumoqing 2024-07-25 17:43:15 +08:00
parent c2bc91dc73
commit 9f1e69032f
3 changed files with 10 additions and 48 deletions

View File

@ -4,10 +4,10 @@ SOURCES=" page_data_loader.js factory.js uitypesdef.js utils.js uitype.js \
markdown_viewer.js video.js audio.js toolbar.js tab.js \ markdown_viewer.js video.js audio.js toolbar.js tab.js \
input.js registerfunction.js button.js accordion.js dataviewer.js \ input.js registerfunction.js button.js accordion.js dataviewer.js \
tree.js multiple_state_image.js dynamiccolumn.js form.js message.js conform.js \ tree.js multiple_state_image.js dynamiccolumn.js form.js message.js conform.js \
paging.js datagrid.js iframe.js cols.js echarts_ebeding.js \ paging.js datagrid.js iframe.js cols.js echartsext.js \
floaticonbar.js miniform.js wterm.js dynamicaccordion.js \ floaticonbar.js miniform.js wterm.js dynamicaccordion.js \
llm_dialog.js llm.js websocket.js datarow.js tabular.js \ llm_dialog.js llm.js websocket.js datarow.js tabular.js \
line.js " line.js pie.js bar.js "
echo ${SOURCES} echo ${SOURCES}
cat ${SOURCES} > ../dist/bricks.js cat ${SOURCES} > ../dist/bricks.js
# uglifyjs --compress --mangle -- ../dist/bricks.js > ../dist/bricks.min.js # uglifyjs --compress --mangle -- ../dist/bricks.js > ../dist/bricks.min.js

View File

@ -16,7 +16,7 @@
<script src="//cdn.bootcdn.net/ajax/libs/eruda/2.3.3/eruda.js"></script> <script src="//cdn.bootcdn.net/ajax/libs/eruda/2.3.3/eruda.js"></script>
<script>eruda.init();</script> <script>eruda.init();</script>
--> -->
<script src="{{entire_url('/bricks/3parties/echarts.min.js')}}"></script> <script type="text/javascript" src="https://registry.npmmirror.com/echarts/5.5.1/files/dist/echarts.min.js"></script>
<script src="{{entire_url('/bricks/3parties/marked.min.js')}}"></script> <script src="{{entire_url('/bricks/3parties/marked.min.js')}}"></script>
<script src="{{entire_url('/bricks/3parties/xterm.js')}}"></script> <script src="{{entire_url('/bricks/3parties/xterm.js')}}"></script>
<script src="{{entire_url('/bricks/3parties/video.min.js')}}"></script> <script src="{{entire_url('/bricks/3parties/video.min.js')}}"></script>

View File

@ -1,6 +1,6 @@
var bricks = window.bricks || {}; var bricks = window.bricks || {};
bricks.ChartLine = class extend bricks.VBox { bricks.ChartLine = class extends bricks.EchartsExt {
/* /*
{ {
data_url, data_url,
@ -12,29 +12,11 @@ bricks.ChartLine = class extend bricks.VBox {
valueFields valueFields
} }
*/ */
constructor(opts){
super(opts);
this.build_title_widget();
this.build_description_widget();
this.build_toolbar_widget();
this.nameField = opts.nameField || 'name';
this.valueFields = opts.valueField || ['value'];
this.chart = new bricks.Filler();
this.add_widget(this.chart);
schedule_once(this.build_chart, 0.1);
}
async build_chart(){
if (this.user_data){
this.build_line(this.user_data);
} else if (this.data_url){
await this.build_line_using_url();
}
}
values_from_data(data, name){ values_from_data(data, name){
var d = []; var d = [];
data.forEach(x => { data.forEach(x => {
d.push(x[name]); d.push(x[name]);
} });
return d; return d;
} }
lineinfo_from_data(data, name){ lineinfo_from_data(data, name){
@ -44,52 +26,32 @@ bricks.ChartLine = class extend bricks.VBox {
data:this.values_from_data(data, name) data:this.values_from_data(data, name)
} }
} }
build_line(data){ setup_options(data){
var n_data = []; var n_data = [];
var series = []; var series = [];
this.valueFields.forEach(v => { this.valueFields.forEach(v => {
series.push(this.lineinfo_from_data(data, v)); series.push(this.lineinfo_from_data(data, v));
} });
data.forEach(d => { data.forEach(d => {
n_data.push(d[this.nameField]); n_data.push(d[this.nameField]);
}); });
var e = this.chart.dom_element;
this.chartOBj = echarts.init(e);
var opts = { var opts = {
tooltip:{ tooltip:{
trigger:'axis' trigger:'axis'
}, },
legend:{ legend:{
data:this.valueFields data:this.valueFields
} },
xAxis:{ xAxis:{
type:'category', type:'category',
data: n_value data: n_data
}, },
yAxis:{ yAxis:{
type: 'value' type: 'value'
}, },
series:series series:series
} }
this.chartObj.setOption(opts); return opts;
this.chartObj.on('click', this.click_handle.bind(this));
}
click_handle(params){
this.bind('element_click', params);
}
async build_line_using_url(params){
if (!params) params = {};
var _params = bricks.extend({}, this.data_params);
_params = bricks.extend(_params, params);
var method = this.method || 'GET';
var jc = bricks.HttpJson();
d = jc.httpcall(this.data_url, {
method:method,
params:_params
});
if (d){
await this.build_line(d);
}
} }
} }