Skip to content

Commit a23cd1c

Browse files
committed
update chartConfig, fix viewer chart test
1 parent afd2f45 commit a23cd1c

File tree

3 files changed

+143
-26
lines changed

3 files changed

+143
-26
lines changed

lib/viewer/chartConfig.js

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,45 @@ WOQLChartConfig.prototype.constructor = Config.ViewConfig;
1313

1414
WOQLChartConfig.prototype.prettyPrint = function(){
1515
var str = "view = View.chart();\n";
16-
str += this.getBasicPrettyPrint();
17-
for(var i = 0; i<this.rules.length ; i++){
16+
for(var i = 0; i<this.rules.length ; i++){
1817
str += "view." + this.rules[i].prettyPrint() + "\n";
1918
}
19+
if(typeof this.margin() != "undefined"){
20+
str += "view.margin(" + this.margin() + ")\n";
21+
}
22+
if(typeof this.title() != "undefined"){
23+
str += "view.title('" + this.title() + "')\n";
24+
}
25+
if(typeof this.description() != "undefined"){
26+
str += "view.description('" + this.description() + "')\n";
27+
}
28+
if(typeof this.layout() != "undefined"){
29+
str += "view.layout('" + this.layout() + "')\n";
30+
}
31+
32+
str += this.getBasicPrettyPrint();
2033
return str;
2134
}
2235

2336
WOQLChartConfig.prototype.json = function(){
24-
let mj = {"chart" :this.getBasicJSON(), "rules": this.getRulesJSON()};
37+
/*
38+
*general properties
39+
*/
40+
var conf = {};
41+
if(typeof this.margin() != "undefined"){
42+
conf['margin'] = this.margin();
43+
}
44+
if(typeof this.title() != "undefined"){
45+
conf['title'] = this.title();
46+
}
47+
if(typeof this.description() != "undefined"){
48+
conf['description'] = this.description();
49+
}
50+
if(typeof this.layout() != "undefined"){
51+
conf['layout'] = this.layout();
52+
}
53+
54+
let mj = {"chart" :conf, "rules": this.getRulesJSON()};
2555
return mj;
2656
}
2757

@@ -34,8 +64,57 @@ WOQLChartConfig.prototype.loadJSON = function(config, rules){
3464
jr.push(nr);
3565
}
3666
this.rules = jr;
67+
if(typeof config.margin != "undefined"){
68+
this.margin(config.margin);
69+
}
70+
if(typeof config.title != "undefined"){
71+
this.title(config.title);
72+
}
73+
if(typeof config.description != "undefined"){
74+
this.description(config.description);
75+
}
76+
if(typeof config.layout != "undefined"){
77+
this.layout(config.layout);
78+
}
79+
}
80+
81+
WOQLChartConfig.prototype.title = function(title){
82+
if(typeof title == "undefined"){
83+
return this._title;
84+
}
85+
this._title = title;
86+
return this;
87+
}
88+
89+
WOQLChartConfig.prototype.description=function(description){
90+
if(description){
91+
this._description=description;
92+
return this
93+
}
94+
return this._description;
95+
}
96+
97+
//layout "vertical" | "horizontal"
98+
WOQLChartConfig.prototype.layout=function(layout){
99+
if(layout){
100+
this._layout=layout;
101+
return this
102+
}
103+
return this._layout;
104+
}
105+
106+
107+
//default is { top: 10, right: 30, left: 0, bottom: 0 }
108+
WOQLChartConfig.prototype.margin=function(marginObj){
109+
if(marginObj){
110+
this._margin=marginObj;
111+
return this
112+
}
113+
114+
return this._margin;
37115
}
38116

117+
39118
WOQLChartConfig.prototype.create = function(client){
40119
var wqt = new WOQLChartConfig(client, this);
41120
return wqt;
@@ -122,6 +201,19 @@ WOQLChartRule.prototype.label = function(label){
122201
return this.rule.label;
123202
}
124203

204+
/*
205+
*line is the default value
206+
* 'line' | 'square' | 'rect'| 'circle' | 'cross' | 'diamond' | 'square' | 'star' | 'triangle' | 'wye' | 'none'
207+
*/
208+
209+
WOQLChartRule.prototype.legendType = function(legendType){
210+
if(legendType){
211+
this.rule.legendType = legendType;
212+
return this;
213+
}
214+
return this.rule.legendType;
215+
}
216+
125217

126218
WOQLChartRule.prototype.fill=function(color){
127219
if(color){

test/viewer.spec.js

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -191,30 +191,54 @@ describe('Viewer rules', function () {
191191
it('check the View Chart Rules',function(){
192192
const config=View.chart();
193193
var rend = function(){alert("r")};
194-
config.bar("a", "b").literal(true).type("xdd:coordinatePolygon").value(32).size(43).icon({}).color([0,0,0]).text("hello").border({}).renderer("world").render(rend).click(rend).hover(rend).args({}).hidden(true).
195-
fill([1,2,3]).stroke(["a", "b", "c"]).strokeWidth(34).dot(false).labelRotate(32.1).axisType("Bar").axisDomain([]);
194+
195+
/*config.bar("a", "b").literal(true).type("xdd:coordinatePolygon").value(32).size(43).icon({}).color([0,0,0]).text("hello").border({}).renderer("world").render(rend).click(rend).hover(rend).args({}).hidden(true).
196+
fill([1,2,3]).stroke(["a", "b", "c"]).strokeWidth(34).dot(false).labelRotate(32.1).type("Bar").axisDomain([]);*/
197+
config.title("MY CHART TEST").layout("vertical");
198+
config.bar("a").legendType('square').label('my bar').fill("#00ff00").stroke("#ff0000").strokeWidth(34);
196199

197-
const jsonObj= {chart: {}, rules: [{pattern: {literal : true, scope: "Bar", type: ["xdd:coordinatePolygon"], value: [32], variables: ['v:a', "v:b"]},
198-
rule: {
199-
args: {},
200-
border: {},
201-
click: rend,
202-
color: [0,0,0],
203-
domain: [],
204-
dot: false,
205-
fill: [1,2,3],
206-
hidden: true,
207-
hover: rend,
208-
icon: {},
209-
labelRotate: 32.1,
210-
render: rend,
211-
renderer:"world",
212-
size: 43,
213-
stroke: ["a", "b", "c"],
214-
strokeWidth: 34,
215-
text: "hello",
216-
}
217-
}]};
200+
config.xAxis("b").labelRotate(32.1).type('number').axisDomain(['dataMin - 1', 'dataMax + 1'])
201+
202+
const jsonObj= {"chart":{
203+
"title":"MY CHART TEST",
204+
"layout":"vertical"
205+
},
206+
"rules":[
207+
{
208+
"pattern":{
209+
"scope":"Bar",
210+
"variables":[
211+
"v:a"
212+
]
213+
},
214+
"rule":{
215+
"legendType":"square",
216+
"label":"my bar",
217+
"fill":"#00ff00",
218+
"stroke":"#ff0000",
219+
"strokeWidth":34
220+
}
221+
},
222+
{
223+
"pattern":{
224+
"scope":"XAxis",
225+
"variables":[
226+
"v:b"
227+
]
228+
},
229+
"rule":{
230+
"labelRotate":32.1,
231+
"type":"number",
232+
"domain":[
233+
"dataMin - 1",
234+
"dataMax + 1"
235+
]
236+
}
237+
}
238+
]
239+
}
240+
241+
//console.log(JSON.stringify(config.json()));
218242
const serial = config.json();
219243
expect(serial).to.eql(jsonObj);
220244
const nt = View.loadConfig(serial);

test/woqlChart.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('woqlChart config', function () {
1818
,"rule":{"label":"Day","type":"number"}}]}
1919

2020

21+
2122
console.log(JSON.stringify(woqlChart.json()));
2223

2324
})

0 commit comments

Comments
 (0)