Skip to content

Commit 5701592

Browse files
committed
feat(graph): allow zoom and pan
1 parent 42333d7 commit 5701592

File tree

5 files changed

+50
-23
lines changed

5 files changed

+50
-23
lines changed

commitlint.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const scope = [
77
"validator",
88
"metrics",
99
"panic",
10-
"sentry-api"
10+
"sentry-api",
11+
"graph"
1112
];
1213

1314
module.exports = {

controller/sentry/admin.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,7 @@ def get_chart_data(self, sentry_id):
8282

8383
threshold = project.detection_param["threshold"]
8484

85-
options = {
86-
"aspectRatio": 4,
87-
"scales": {
88-
"xAxis": {"type": "timeseries"},
89-
"series": {"position": "left"},
90-
"signal": {"position": "right", "min": 0, "max": 2},
91-
},
92-
"plugins": {"legend": {"position": "bottom"}, "title": {"display": True, "text": "Detection Result"}},
93-
"elements": {"line": {"stepped": True}, "point": {"radius": 0}},
94-
"interaction": {"mode": "index", "intersect": False},
95-
}
85+
options = settings.DEFAULT_GRAPH_OPTION
9686
data = {
9787
"datasets": [
9888
{

controller/sentry/templates/admin/chart_change_form.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
{% block extrahead %}
66
{{ block.super }}
77
{{ media }}
8+
{% vendor 'hammerjs' %}
89
{% vendor 'chartjs' %}
910
{% vendor 'chartjs-date' %}
11+
{% vendor 'chartjs-zoom' %}
1012
<script src="{% static 'admin/chart/js/adminchart.js' %}"></script>
1113
{{ adminchart_chartjs_config|json_script:"adminchart-chartjs-config" }}
1214
{% endblock %}

controller/sentry/tests/test_admin.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,7 @@ def test_project_chart(super_call: Mock, admin_with_user):
440440
],
441441
"labels": ["a", "b"],
442442
},
443-
"options": {
444-
"aspectRatio": 4,
445-
"scales": {
446-
"xAxis": {"type": "timeseries"},
447-
"series": {"position": "left"},
448-
"signal": {"position": "right", "min": 0, "max": 2},
449-
},
450-
"plugins": {"legend": {"position": "bottom"}, "title": {"display": True, "text": "Detection Result"}},
451-
"elements": {"line": {"stepped": True}, "point": {"radius": 0}},
452-
"interaction": {"mode": "index", "intersect": False},
453-
},
443+
"options": settings.DEFAULT_GRAPH_OPTION,
454444
}
455445
}
456446

controller/settings.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@
5656
}
5757
],
5858
},
59+
"chartjs-zoom": {
60+
"url": "https://cdn.jsdelivr.net/npm/[email protected]/dist/",
61+
"js": [
62+
{
63+
"path": "chartjs-plugin-zoom.min.js",
64+
"sri": "sha384-AC/SQgflSDa6sFR0rk5chlHjSLMS9fHmSE50vY7uoBiqrCWtDUXoOBCKaoQQFBrl",
65+
}
66+
],
67+
},
68+
"hammerjs": {
69+
"url": "https://cdn.jsdelivr.net/npm/[email protected]/",
70+
"js": [
71+
{
72+
"path": "hammer.min.js",
73+
"sri": "sha384-Cs3dgUx6+jDxxuqHvVH8Onpyj2LF1gKZurLDlhqzuJmUqVYMJ0THTWpxK5Z086Zm",
74+
}
75+
],
76+
},
5977
}
6078

6179

@@ -328,3 +346,29 @@
328346

329347
# hook sentry_dynamic_sampling_lib into sentry
330348
init_wrapper()
349+
350+
351+
# Graph
352+
DEFAULT_GRAPH_OPTION = {
353+
"aspectRatio": 4,
354+
"scales": {
355+
"xAxis": {"type": "timeseries"},
356+
"series": {"position": "left", "min": 0},
357+
"signal": {"position": "right", "min": 0, "max": 2},
358+
},
359+
"plugins": {
360+
"legend": {"position": "bottom"},
361+
"title": {"display": True, "text": "Detection Result"},
362+
"zoom": {
363+
"zoom": {
364+
"wheel": {"enabled": True, "modifierKey": "ctrl"},
365+
"pinch": {"enabled": True},
366+
"mode": "x",
367+
},
368+
"limits": {"xAxis": {"min": "original", "max": "original"}},
369+
"pan": {"enabled": True, "mode": "x", "modifierKey": "ctrl"},
370+
},
371+
},
372+
"elements": {"line": {"stepped": True}, "point": {"radius": 0}},
373+
"interaction": {"mode": "index", "intersect": False},
374+
}

0 commit comments

Comments
 (0)