-
Notifications
You must be signed in to change notification settings - Fork 9
/
completed-index.js
156 lines (137 loc) · 5.97 KB
/
completed-index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import React from "react";
import { createRoot } from "react-dom/client";
import * as am4core from "@amcharts/amcharts4/core";
import * as am4charts from "@amcharts/amcharts4/charts";
import * as am4plugins_timeline from "@amcharts/amcharts4/plugins/timeline";
import * as am4plugins_bullets from "@amcharts/amcharts4/plugins/bullets";
import am4themes_animated from "@amcharts/amcharts4/themes/animated";
(function () {
'use strict';
// Set Custom View's ID in .env
const customViewID = Number(process.env.VIEW_ID);
// Increment to confirm script version on Kintone
const scriptVer = 'Completed';
console.log(`\nScript version: ${scriptVer}\n\n`);
kintone.events.on('app.record.index.show', function (event) {
if (event.viewId !== customViewID) {
console.log('View ID from APP: ' + event.viewId)
console.log('VIEW_ID from env: ' + customViewID)
console.log('Not on the Custom View');
return event
}
function App() {
// Color HEX code for the political parties
const partyColor = {
'Democratic': '#2502fe',
'Democratic-Republican': '#0e7003',
'Federalist': '#e28665',
'Republican': '#e0001b',
'Unaffiliated': '#d5d5d5',
'Whig': '#ebbd50'
};
// Peak inside Kintone's data
console.log('event.records');
console.log(event.records);
// Retrieve & configure the space element below the record list's header
const spaceDiv = kintone.app.getHeaderSpaceElement();
spaceDiv.style.height = '650px';
spaceDiv.style.marginLeft = '25px';
spaceDiv.style.marginRight = '25px';
spaceDiv.style.border = 'solid';
spaceDiv.style.borderColor = '#ED7B84';
// Automatically enable all amCharts animations
am4core.useTheme(am4themes_animated);
// Create chart instance
const chart = am4core.create(spaceDiv, am4plugins_timeline.SerpentineChart);
// Space between the chart & border
chart.paddingTop = 100;
// Number of straight lines of serpentine shape
chart.levelCount = 5;
// Allow bullets to 'bleed' over the edge
chart.maskBullets = false;
// Input & Output Date format
chart.dateFormatter.inputDateFormat = 'yyyy-MM-dd';
chart.dateFormatter.dateFormat = 'yyyy-MM-dd';
// Font size
chart.fontSize = 12;
chart.tooltipContainer.fontSize = 12;
// TODO: Input Kintone data into the chart
chart.data = event.records.map((rec, index) => {
return {
// TODO: Text above the PinBullet; President's name
'text': `${rec.first.value}\n${rec.last.value}`,
// TODO: PinBullet's & time period's color; Party color
'color': partyColor[rec.party.value],
// TODO: Time period's start; Term's start
'start': rec.start.value,
// TODO: Time period's end; Term's end
'end': rec.end.value,
// TODO: Icon inside the PinBullet; President's icon
'icon': rec.image.value,
'category': '' // Timeline category; leave as empty string
}
});
console.log('chart.data');
console.log(chart.data);
// Create 1 timeline with all the US Presidents
const categoryAxis = chart.yAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = 'category';
// Axis using date & time scale
const dateAxis = chart.xAxes.push(new am4charts.DateAxis());
// Gray, dashed lines for date axis
dateAxis.renderer.line.strokeDasharray = '1,4';
dateAxis.renderer.line.strokeOpacity = 1;
// Place the label in the middle of the axis
dateAxis.renderer.labels.template.verticalCenter = 'middle';
// Series containing the US Presidents and their terms
const series = chart.series.push(new am4plugins_timeline.CurveColumnSeries());
series.dataFields.openDateX = 'start';
series.dataFields.dateX = 'end';
series.dataFields.categoryY = 'category';
series.baseAxis = categoryAxis;
// Coloring of the Presidential terms
series.columns.template.height = am4core.percent(15);
series.columns.template.propertyFields.fill = 'color';
series.columns.template.propertyFields.stroke = 'color';
series.columns.template.strokeOpacity = 0;
series.columns.template.fillOpacity = 0.6;
// Create the PinBullet (Circles)
const pinBullet = series.bullets.push(new am4plugins_bullets.PinBullet());
pinBullet.locationX = 1; //Place the PinBullet at their term's start
pinBullet.propertyFields.stroke = 'color';
pinBullet.background.propertyFields.fill = 'color';
pinBullet.image = new am4core.Image();
pinBullet.image.propertyFields.href = 'icon';
// President's name over the icon
const labelBullet = series.bullets.push(new am4charts.LabelBullet());
labelBullet.label.propertyFields.text = 'text';
labelBullet.label.textAlign = 'middle';
labelBullet.locationX = 1; // Place the labelBullet at their term's start
labelBullet.dy = -80; // Raising text above the icon
// Scrollbar used to focus the timeline
chart.scrollbarX = new am4core.Scrollbar();
chart.scrollbarX.align = 'center'
chart.scrollbarX.width = am4core.percent(75);
chart.scrollbarX.parent = chart.bottomAxesContainer;
// Year appearing when hovering over the chart axis
const cursor = new am4plugins_timeline.CurveCursor();
chart.cursor = cursor;
dateAxis.tooltipDateFormat = 'yyyy-MMM';
cursor.xAxis = dateAxis;
cursor.lineY.disabled = true; // Disable Y line highlight
// Optional - Enable export
chart.exporting.menu = new am4core.ExportMenu();
// Remove unneeded Scrollbar & tooltip
chart.scrollbarX.exportable = false;
dateAxis.tooltip.exportable = false;
}
const rootElement = document.getElementById("root");
const root = createRoot(rootElement);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
return event;
});
})();