var _assoc_map_with_ranked_keyword = { defaultOption : { "title": null, "label": "label", "child_label": "label", "class": "class", "size": "size", "children": "children", "steady": "steady", "increase": "increase", "decrease": "decrease", "colors": RenderUtil.assoc_color_table_simple, "color_table_name": null, "height": 0, // 강제 조정 안 함 "force_factor": 0.15, "xlsx": true }, example: [ { name: "예제1", description: "TM2 연관어 및 순위", sample: { "visible": true, "type": "assoc_map_with_ranked_keyword", "id": "simple_keyword.2.assoc_map", "options": { "xlsx": true, "title": "[전주의 연관 키워드]", "force_factor": 0.14, "child_label": "label", "height": 400, "class": "kind", "label": "label", "children": "children", "table_options": { "headers": [ [ "순위", { "style": {"width": "70%"}, "value": "연관어" } ] ] }, "size": "size" }, "data": { "table_data": [ [ {"class": "keyword", "value": 1}, "일상" ], [ {"class": "keyword", "value": 2}, "한옥마을" ], [ {"class": "keyword", "value": 3}, "여행" ], [ {"class": "keyword", "value": 4}, "전주한옥마을" ], [ {"class": "keyword", "value": 5}, "맛집" ], [ {"class": "keyword", "value": 6}, "광주" ], [ {"class": "keyword", "value": 7}, "서울" ], [ {"class": "keyword", "value": 8}, "카페" ] ], "assoc_data": { "children": [ {"kind": "라이프", "size": 490516, "label": "일상"}, {"kind": "장소", "size": 470867, "label": "한옥마을"}, {"kind": "라이프", "size": 361831, "label": "여행"}, {"kind": "장소", "size": 317590, "label": "전주한옥마을"}, {"kind": "장소", "size": 283781, "label": "맛집"}, {"kind": "장소", "size": 242350, "label": "광주"}, {"kind": "장소", "size": 229093, "label": "서울"}, {"kind": "장소", "size": 219229, "label": "카페"}, {"kind": "문화/여가", "size": 207986, "label": "뮤직뱅크"}, {"kind": "라이프", "size": 206855, "label": "맞팔"}, {"kind": "장소", "size": 193221, "label": "부산"}, {"kind": "장소", "size": 191219, "label": "대전"}, {"kind": "장소", "size": 180656, "label": "익산"}, {"kind": "장소", "size": 176759, "label": "군산"}, {"kind": "문화/여가", "size": 173338, "label": "사진"}, {"kind": "장소", "size": 171736, "label": "전북"}, {"kind": "라이프", "size": 155383, "label": "팔로우"}, {"kind": "라이프", "size": 153850, "label": "선팔"}, {"kind": "라이프", "size": 150362, "label": "셀스타그램"}, {"kind": "브랜드", "size": 116395, "label": "인스타그램"}, {"kind": "상품", "size": 114880, "label": "한복"}, {"kind": "라이프", "size": 109217, "label": "먹스타그램"}, {"kind": "장소", "size": 107187, "label": "인천"}, {"kind": "라이프", "size": 97832, "label": "주말"}, {"kind": "시사/경제", "size": 95040, "label": "경기"}, {"kind": "단체", "size": 94524, "label": "전북대"}, {"kind": "장소", "size": 92464, "label": "객리단길"}, {"kind": "장소", "size": 91220, "label": "울산"}, {"kind": "라이프", "size": 90502, "label": "날씨"}, {"kind": "장소", "size": 90274, "label": "청주"} ], "label": "전주" } } } } ], /* * 에러를 검사하고, 일부 잘못된 형식을 교정 * 에러가 발생하면 console.error로 에러메시지와 unit.id 출력 * 어떻게든 복구가 가능하면 복구하고 true return, 복구 불가능하면 false return */ validateData : function(unit) { var options = unit.options; if (options == null || Object.keys(options).length == 0) { console.error("options is empty : " + unit.id); //return false; // 옵션이 없는 경우 default 옵션을 넣도록 함 options = unit.options = _assoc_map_with_ranked_keyword.defaultOption; } if (unit.data == null || Object.keys(unit.data).length == 0) { console.error("data is empty : " + unit.id); return false; } // 누락된 option을 default 값으로 대체 Object.keys(_assoc_map_with_ranked_keyword.defaultOption).forEach(function(name) { if (!options.hasOwnProperty(name)) { //console.error("unit.options." + name + " does not exist : " + unit.id); unit.options[name] = _assoc_map_with_ranked_keyword.defaultOption[name]; } }); if (options.color_table_name && RenderUtil.hasOwnProperty(options.color_table_name)) unit.options.colors = RenderUtil[options.color_table_name]; return true; }, build_legend: function ($legend, unit) { var color_map = {}; // class에 대한 색상 id var max_color = unit.options.colors.length + 1; // 미지정은 options.colors.length + 1부터 할당 if (unit.options.color_map) jQuery.extend({}, unit.options.color_map); function data2class(d) { var cls = "-"; if (unit.options.class) { if (typeof d[unit.options.class] == "string") cls = d[unit.options.class]; else if (d[unit.options.class] != null) cls = JSON.stringify(d[unit.options.class]); } return cls; } $.each( unit.data.assoc_data[unit.options.children], function (i, d) { var cls = data2class(d); if (!(cls in color_map)) { var $li = $("
"); $legend.append($li); var $span = $("").addClass("g" + (max_color % unit.options.colors.length)); $li.append($span); $li.append(document.createTextNode(d[unit.options.class])); color_map[cls] = max_color % unit.options.colors.length; max_color++; if (max_color % unit.options.colors.length == 0) max_color++; } } ); }, render_legend: function ($chartDiv, unit) { var $legend = $("" + JSON.stringify(unit, null, 2) + ""); return; } var $chartDiv = $(""); if (unit.options.height) $chartDiv.css({"height": unit.options.height, "min-height": unit.options.height}); $dom.append($chartDiv); if (unit.options.title) $chartDiv.append($("").text(unit.options.title)); _assoc_map_with_ranked_keyword.render_legend($chartDiv, unit); if (unit.data.table_data) { _assoc_map_with_ranked_keyword.render_assoc_map($chartDiv, unit); _assoc_map_with_ranked_keyword.render_table($chartDiv, unit); } else _assoc_map_with_ranked_keyword.render_assoc_map($chartDiv, unit, "chart"); return $chartDiv; } }; UnitRendererFactory.add("assoc_map_with_ranked_keyword", _assoc_map_with_ranked_keyword.render); UnitRendererFactory.addExample("assoc_map_with_ranked_keyword", _assoc_map_with_ranked_keyword.example);