Skip to content

Commit 4034084

Browse files
authored
feat: charts options support (#236)
1 parent 8f66b06 commit 4034084

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

src/unfold/static/unfold/js/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const submitSearch = () => {
9797
/*************************************************************
9898
* Chart
9999
*************************************************************/
100-
const CHART_OPTIONS = {
100+
const DEFAULT_CHART_OPTIONS = {
101101
animation: false,
102102
barPercentage: 1,
103103
base: 0,
@@ -197,6 +197,7 @@ const renderCharts = () => {
197197
const ctx = chart.getContext("2d");
198198
const data = chart.dataset.value;
199199
const type = chart.dataset.type;
200+
const options = chart.dataset.options;
200201

201202
if (!data) {
202203
return;
@@ -206,7 +207,7 @@ const renderCharts = () => {
206207
new Chart(ctx, {
207208
type: type || "bar",
208209
data: JSON.parse(chart.dataset.value),
209-
options: CHART_OPTIONS,
210+
options: options ? JSON.parse(options) : DEFAULT_CHART_OPTIONS,
210211
})
211212
);
212213
});

src/unfold/templates/admin/change_form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
{% csrf_token %}
6666

6767
{% if actions_detail %}
68-
<div class="bg-gray-50 flex justify-end mb-4 p-3 rounded-md dark:bg-gray-800">
68+
<div class="bg-gray-50 flex justify-end -mt-6 mb-4 p-3 rounded-md dark:bg-gray-800">
6969
{% for action in actions_detail %}
7070
<a href="{{ action.path }}" class="bg-white text-gray-500 border cursor-pointer flex font-medium items-center px-3 py-2 mr-3 rounded-md shadow-sm text-sm dark:bg-gray-900 dark:border dark:border-gray-700 dark:text-gray-400"
7171
{% for attr_name, attr_value in action.attrs.items %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="relative w-full{% if class %} {{ class }}{% endif %}">
2-
<canvas class="chart" data-type="bar" data-value="{{ data }}" {% if width %}width="{{ width }}"{% endif %} {% if height %}height="{{ height }}"{% endif %}></canvas>
2+
<canvas class="chart" {% if options %}data-options="{{ options }}"{% endif %} data-type="bar" data-value="{{ data }}" {% if width %}width="{{ width }}"{% endif %} {% if height %}height="{{ height }}"{% endif %}></canvas>
33
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="relative w-full{% if class %} {{ class }}{% endif %}">
2-
<canvas class="chart" data-type="line" data-value="{{ data }}" {% if width %}width="{{ width }}"{% endif %} {% if height %}height="{{ height }}"{% endif %}></canvas>
2+
<canvas class="chart" {% if options %}data-options="{{ options }}"{% endif %} data-type="line" data-value="{{ data }}" {% if width %}width="{{ width }}"{% endif %} {% if height %}height="{{ height }}"{% endif %}></canvas>
33
</div>

0 commit comments

Comments
 (0)