MCPcopy Index your code
hub / github.com/bqplot/bqplot / update_legend

Method update_legend

js/src/Figure.ts:1035–1108  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1033 }
1034
1035 update_legend() {
1036 this.fig_marks.selectAll('.g_legend').remove();
1037
1038 const legend_height = 14;
1039 const legend_width = 24;
1040 const legend_location = this.model.get('legend_location');
1041
1042 const legend_g = this.fig_marks.append('g').attr('class', 'g_legend');
1043
1044 let count = 1;
1045 let max_label_len = 1;
1046
1047 if (this.mark_views !== undefined && this.mark_views !== null) {
1048 Promise.all(this.mark_views.views).then((views) => {
1049 views.forEach((mark_view: any) => {
1050 if (mark_view.model.get('display_legend')) {
1051 const child_count = mark_view.draw_legend(
1052 legend_g,
1053 0,
1054 count * (legend_height + 2),
1055 0,
1056 legend_height + 2
1057 );
1058 count = count + child_count[0];
1059 max_label_len = child_count[1]
1060 ? Math.max(max_label_len, child_count[1])
1061 : max_label_len;
1062 }
1063 });
1064
1065 const coords = this.get_legend_coords(
1066 legend_location,
1067 legend_width,
1068 (count + 1) * (legend_height + 2),
1069 0
1070 );
1071 if (count !== 1) {
1072 legend_g
1073 .insert('g', ':first-child')
1074 .attr('class', 'axis')
1075 .append('rect')
1076 .attr('y', (legend_height + 2) / 2.0)
1077 .attr('x', -0.5 * (legend_height + 2))
1078 .attr('width', max_label_len + 2 + 'em')
1079 .attr('height', count * (legend_height + 2));
1080 }
1081 max_label_len =
1082 legend_location === 'top-right' ||
1083 legend_location === 'right' ||
1084 legend_location === 'bottom-right'
1085 ? -(max_label_len + 2)
1086 : 1;
1087 const em = 16;
1088 legend_g.attr(
1089 'transform',
1090 'translate(' +
1091 String(coords[0] + max_label_len * em) +
1092 ' ' +

Callers 2

renderImplMethod · 0.95
relayoutImplMethod · 0.95

Calls 4

get_legend_coordsMethod · 0.95
applyStylesFunction · 0.90
removeMethod · 0.45
draw_legendMethod · 0.45

Tested by

no test coverage detected