gtk / cairo-chart

SSH Git

To clone this repository:

git clone git@git.backbone.ws:gtk/cairo-chart.git

To push to this repository:

# Add a new remote
git remote add origin git@git.backbone.ws:gtk/cairo-chart.git

# Push the master branch to the newly added origin, and configure
# this remote and branch as the default:
git push -u origin master

# From now on you can push master to the "origin" remote with:
git push

Commit: #002e995

Parent: #82aa857

Fixes #139: Cut lines when they are outside of the chart grid.

avatar Kolan Sh 12 days ago

Summary

  • src/Chart.vala (91) ------+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
908 908 / (s.axis_y.max - s.axis_y.min) * (s.place.y_high - s.place.y_low));
909 909 }
910 910
911 protected virtual bool point_in_rect (Point p, double x0, double x1, double y0, double y1) {
912 if ( (x0 <= p.x <= x1 || x1 <= p.x <= x0)
913 && (y0 <= p.y <= y1 || y1 <= p.y <= y0))
914 return true;
915 return false;
916 }
917
918 protected virtual bool point_in_plot_area (Point p) {
919 if (point_in_rect (p, plot_area_x_min, plot_area_x_max, plot_area_y_min, plot_area_y_max))
920 return true;
921 return false;
922 }
923
924 protected virtual bool hcross (Point a1, Point a2, Float128 h_x1, Float128 h_x2, Float128 h_y, out Float128 x) {
925 x = 0;
926 if (a1.y == a2.y) return false;
927 if (a1.y >= h_y && a2.y >= h_y || a1.y <= h_y && a2.y <= h_y) return false;
928 x = a1.x + (a2.x - a1.x) * (h_y - a1.y) / (a2.y - a1.y);
929 if (h_x1 <= x <= h_x2 || h_x2 <= x <= h_x1)
930 return true;
931 return false;
932 }
933
934 protected virtual bool vcross (Point a1, Point a2, Float128 v_x, Float128 v_y1, Float128 v_y2, out Float128 y) {
935 y = 0;
936 if (a1.x == a2.x) return false;
937 if (a1.x >= v_x && a2.x >= v_x || a1.x <= v_x && a2.x <= v_x) return false;
938 y = a1.y + (a2.y - a1.y) * (v_x - a1.x) / (a2.x - a1.x);
939 if (v_y1 <= y <= v_y2 || v_y2 <= y <= v_y1)
940 return true;
941 return false;
942 }
943
911 944 delegate int PointComparator(Point a, Point b);
912 945 void sort_points(Point[] points, PointComparator compare) {
913 946 for(var i = 0; i < points.length; ++i) {
954 954 }
955 955 }
956 956
957 protected virtual bool cut_line (Point a, Point b, out Point c, out Point d) {
958 int ncross = 0;
959 Float128 x = 0, y = 0;
960 Point pc[4];
961 if (hcross(a, b, plot_area_x_min, plot_area_x_max, plot_area_y_min, out x))
962 pc[ncross++] = Point(x, plot_area_y_min);
963 if (hcross(a, b, plot_area_x_min, plot_area_x_max, plot_area_y_max, out x))
964 pc[ncross++] = Point(x, plot_area_y_max);
965 if (vcross(a, b, plot_area_x_min, plot_area_y_min, plot_area_y_max, out y))
966 pc[ncross++] = Point(plot_area_x_min, y);
967 if (vcross(a, b, plot_area_x_max, plot_area_y_min, plot_area_y_max, out y))
968 pc[ncross++] = Point(plot_area_x_max, y);
969 c = a;
970 d = b;
971 if (ncross == 0) {
972 if (point_in_plot_area (a) && point_in_plot_area (b))
973 return true;
974 return false;
975 }
976 if (ncross >= 2) {
977 c = pc[0]; d = pc[1];
978 return true;
979 }
980 if (ncross == 1) {
981 if (point_in_plot_area (a)) {
982 c = a;
983 d = pc[0];
984 return true;
985 } else if (point_in_plot_area (b)) {
986 c = b;
987 d = pc[0];
988 return true;
989 }
990 }
991 return false;
992 }
993
957 994 protected virtual void draw_series () {
958 995 for (int si = 0; si < series.length; ++si) {
959 996 var s = series[si];
1013 1013 break;
1014 1014 }
1015 1015 set_line_style(s.line_style);
1016 // move to s.points[0]
1017 context.move_to (get_scr_x(s, points[0].x), get_scr_y(s, points[0].y));
1018 1016 // draw series line
1019 for (int i = 1; i < points.length; ++i)
1020 context.line_to (get_scr_x(s, points[i].x), get_scr_y(s, points[i].y));
1017 for (int i = 1; i < points.length; ++i) {
1018 Point c, d;
1019 if (cut_line (Point(get_scr_x(s, points[i - 1].x), get_scr_y(s, points[i - 1].y)),
1020 Point(get_scr_x(s, points[i].x), get_scr_y(s, points[i].y)),
1021 out c, out d)) {
1022 context.move_to (c.x, c.y);
1023 context.line_to (d.x, d.y);
1024 }
1025 }
1021 1026 context.stroke();
1022 for (int i = 0; i < points.length; ++i)
1023 draw_marker_at_pos(s.marker_type, get_scr_x(s, points[i].x), get_scr_y(s, points[i].y));
1027 for (int i = 0; i < points.length; ++i) {
1028 var x = get_scr_x(s, points[i].x);
1029 var y = get_scr_y(s, points[i].y);
1030 if (point_in_plot_area (Point (x, y)))
1031 draw_marker_at_pos(s.marker_type, x, y);
1032 }
1024 1033 }
1025 1034 }
1026 1035

Comments