MCPcopy Index your code
hub / github.com/plotly/plotly.py / buildPointsObject

Method buildPointsObject

js/src/widget.ts:1033–1113  ·  view source on GitHub ↗

* Build Points data structure from data supplied by the plotly_click, * plotly_hover, or plotly_select events * @param {Object} data * @returns {null|Points}

(data: any)

Source from the content-addressed store, hash-verified

1031 * @returns {null|Points}
1032 */
1033 buildPointsObject(data: any): null | Points {
1034 var pointsObject: Points;
1035 if (data.hasOwnProperty("points")) {
1036 // Most cartesian plots
1037 var pointObjects = data["points"];
1038 var numPoints = pointObjects.length;
1039
1040 var hasNestedPointObjects = true;
1041 for (let i = 0; i < numPoints; i++) {
1042 hasNestedPointObjects =
1043 hasNestedPointObjects &&
1044 pointObjects[i].hasOwnProperty("pointNumbers");
1045 if (!hasNestedPointObjects) break;
1046 }
1047 var numPointNumbers = numPoints;
1048 if (hasNestedPointObjects) {
1049 numPointNumbers = 0;
1050 for (let i = 0; i < numPoints; i++) {
1051 numPointNumbers += pointObjects[i]["pointNumbers"].length;
1052 }
1053 }
1054 pointsObject = {
1055 trace_indexes: new Array(numPointNumbers),
1056 point_indexes: new Array(numPointNumbers),
1057 xs: new Array(numPointNumbers),
1058 ys: new Array(numPointNumbers),
1059 };
1060
1061 if (hasNestedPointObjects) {
1062 var flatPointIndex = 0;
1063 for (var p = 0; p < numPoints; p++) {
1064 for (
1065 let i = 0;
1066 i < pointObjects[p]["pointNumbers"].length;
1067 i++, flatPointIndex++
1068 ) {
1069 pointsObject["point_indexes"][flatPointIndex] =
1070 pointObjects[p]["pointNumbers"][i];
1071 // also add xs, ys and traces so that the array doesn't get truncated later
1072 pointsObject["xs"][flatPointIndex] = pointObjects[p]["x"];
1073 pointsObject["ys"][flatPointIndex] = pointObjects[p]["y"];
1074 pointsObject["trace_indexes"][flatPointIndex] =
1075 pointObjects[p]["curveNumber"];
1076 }
1077 }
1078
1079 let single_trace = true;
1080 for (let i = 1; i < numPointNumbers; i++) {
1081 single_trace = single_trace && (pointsObject["trace_indexes"][i - 1] === pointsObject["trace_indexes"][i])
1082 if (!single_trace) break;
1083 }
1084 if (single_trace) {
1085 pointsObject["point_indexes"].sort((function (a, b) {
1086 return a - b
1087 }))
1088 }
1089
1090 } else {

Callers 1

Calls 1

sortMethod · 0.45

Tested by

no test coverage detected