decidim-core 0.14.4 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim-core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +20 -0
- data/app/assets/images/decidim/cc-badge.png +0 -0
- data/app/assets/images/decidim/gamification/badges/continuity.svg +73 -0
- data/app/assets/images/decidim/gamification/badges/followers.svg +115 -0
- data/app/assets/images/decidim/icons.svg +1 -0
- data/app/assets/javascripts/decidim/vizzs/areachart.js.es6 +186 -208
- data/app/assets/javascripts/decidim/vizzs/linechart.js.es6 +263 -0
- data/app/assets/javascripts/decidim/vizzs/metrics.js.es6 +36 -26
- data/app/assets/javascripts/decidim/vizzs/orgchart.js.es6 +3 -2
- data/app/assets/javascripts/decidim/vizzs/rowchart.js.es6 +324 -0
- data/app/assets/stylesheets/decidim/_decidim.scss +1 -0
- data/app/assets/stylesheets/decidim/modules/_cards.scss +1 -0
- data/app/assets/stylesheets/decidim/modules/_conference-diploma.scss +75 -0
- data/app/assets/stylesheets/decidim/modules/_conference-media.scss +44 -0
- data/app/assets/stylesheets/decidim/modules/_conference-programme.scss +5 -1
- data/app/assets/stylesheets/decidim/modules/_conference-registration.scss +34 -0
- data/app/assets/stylesheets/decidim/modules/_list-request.scss +16 -0
- data/app/assets/stylesheets/decidim/modules/_modules.scss +4 -4
- data/app/assets/stylesheets/decidim/modules/_process-phase.scss +1 -0
- data/app/assets/stylesheets/decidim/modules/_reveal.scss +6 -1
- data/app/assets/stylesheets/decidim/utils/_helpers.scss +1 -1
- data/app/assets/stylesheets/decidim/{modules → vizzs}/_areachart.scss +8 -11
- data/app/assets/stylesheets/decidim/{modules → vizzs}/_chart-tooltip.scss +0 -0
- data/app/assets/stylesheets/decidim/vizzs/_linechart.scss +115 -0
- data/app/assets/stylesheets/decidim/vizzs/_rowchart.scss +77 -0
- data/app/cells/decidim/activities/show.erb +3 -0
- data/app/cells/decidim/activities_cell.rb +38 -0
- data/app/cells/decidim/activity/show.erb +21 -0
- data/app/cells/decidim/activity_cell.rb +85 -0
- data/app/cells/decidim/address/details.erb +7 -0
- data/app/cells/decidim/address/show.erb +14 -0
- data/app/cells/decidim/address_cell.rb +19 -0
- data/app/cells/decidim/author/contact.erb +1 -1
- data/app/cells/decidim/author_cell.rb +1 -0
- data/app/cells/decidim/badge/show.erb +2 -2
- data/app/cells/decidim/badge/small.erb +5 -0
- data/app/cells/decidim/badge_cell.rb +36 -14
- data/app/cells/decidim/badges/show.erb +6 -3
- data/app/cells/decidim/badges_cell.rb +4 -4
- data/app/cells/decidim/coauthorships_cell.rb +8 -2
- data/app/cells/decidim/collapsible_authors/show.erb +9 -7
- data/app/cells/decidim/content_blocks/html/show.erb +3 -0
- data/app/cells/decidim/content_blocks/html_cell.rb +11 -0
- data/app/cells/decidim/content_blocks/html_settings_form/show.erb +3 -0
- data/app/cells/decidim/content_blocks/html_settings_form_cell.rb +17 -0
- data/app/cells/decidim/content_blocks/last_activity/show.erb +17 -0
- data/app/cells/decidim/content_blocks/last_activity_cell.rb +60 -0
- data/app/cells/decidim/content_blocks/metrics/show.erb +13 -0
- data/app/cells/decidim/content_blocks/metrics_cell.rb +18 -0
- data/app/cells/decidim/content_blocks/stats/show.erb +2 -1
- data/app/cells/decidim/groups/show.erb +10 -0
- data/app/cells/decidim/groups_cell.rb +19 -0
- data/app/cells/decidim/members/show.erb +9 -0
- data/app/cells/decidim/members_cell.rb +32 -0
- data/app/cells/decidim/profile/show.erb +3 -11
- data/app/cells/decidim/profile/user_group_tabs.erb +5 -0
- data/app/cells/decidim/profile/user_tabs.erb +12 -0
- data/app/cells/decidim/profile_cell.rb +7 -2
- data/app/cells/decidim/profile_sidebar/show.erb +108 -23
- data/app/cells/decidim/profile_sidebar_cell.rb +36 -2
- data/app/cells/decidim/user_group_admin_membership_profile/footer.erb +29 -0
- data/app/cells/decidim/user_group_admin_membership_profile_cell.rb +14 -0
- data/app/cells/decidim/user_group_membership_profile/tags.erb +1 -0
- data/app/cells/decidim/user_group_membership_profile_cell.rb +8 -0
- data/app/cells/decidim/user_group_pending_invitations_list/show.erb +23 -0
- data/app/cells/decidim/user_group_pending_invitations_list_cell.rb +26 -0
- data/app/cells/decidim/user_group_pending_requests_list/show.erb +23 -0
- data/app/cells/decidim/user_group_pending_requests_list_cell.rb +26 -0
- data/app/cells/decidim/user_profile/header.erb +1 -1
- data/app/cells/decidim/user_profile_cell.rb +15 -9
- data/app/commands/decidim/accept_group_invitation.rb +43 -0
- data/app/commands/decidim/accept_user_group_join_request.rb +53 -0
- data/app/commands/decidim/create_follow.rb +6 -0
- data/app/commands/decidim/create_registration.rb +13 -23
- data/app/commands/decidim/create_user_group.rb +57 -0
- data/app/commands/decidim/delete_follow.rb +7 -0
- data/app/commands/decidim/demote_membership.rb +57 -0
- data/app/commands/decidim/destroy_account.rb +6 -0
- data/app/commands/decidim/invite_user.rb +1 -3
- data/app/commands/decidim/invite_user_to_group.rb +62 -0
- data/app/commands/decidim/join_user_group.rb +63 -0
- data/app/commands/decidim/leave_user_group.rb +41 -0
- data/app/commands/decidim/promote_membership.rb +55 -0
- data/app/commands/decidim/reject_group_invitation.rb +42 -0
- data/app/commands/decidim/reject_user_group_join_request.rb +53 -0
- data/app/commands/decidim/remove_user_from_group.rb +53 -0
- data/app/commands/decidim/update_user_group.rb +53 -0
- data/app/controllers/concerns/decidim/locale_switcher.rb +3 -3
- data/app/controllers/concerns/decidim/paginable.rb +1 -0
- data/app/controllers/decidim/application_controller.rb +7 -0
- data/app/controllers/decidim/devise/omniauth_registrations_controller.rb +1 -1
- data/app/controllers/decidim/devise/sessions_controller.rb +1 -1
- data/app/controllers/decidim/gamification/badges_controller.rb +11 -0
- data/app/controllers/decidim/group_admins_controller.rb +41 -0
- data/app/controllers/decidim/group_invites_controller.rb +74 -0
- data/app/controllers/decidim/group_members_controller.rb +59 -0
- data/app/controllers/decidim/groups_controller.rb +85 -0
- data/app/controllers/decidim/last_activities_controller.rb +46 -0
- data/app/controllers/decidim/pages_controller.rb +9 -1
- data/app/controllers/decidim/profiles_controller.rb +35 -5
- data/app/controllers/decidim/user_group_join_requests_controller.rb +69 -0
- data/app/events/decidim/demoted_membership_event.rb +28 -0
- data/app/events/decidim/invited_to_group_event.rb +33 -0
- data/app/events/decidim/join_request_accepted_event.rb +28 -0
- data/app/events/decidim/join_request_created_event.rb +28 -0
- data/app/events/decidim/join_request_rejected_event.rb +28 -0
- data/app/events/decidim/promoted_to_admin_event.rb +28 -0
- data/app/events/decidim/removed_from_group_event.rb +28 -0
- data/app/forms/decidim/account_form.rb +1 -1
- data/app/forms/decidim/invite_user_to_group_form.rb +29 -0
- data/app/forms/decidim/notifications_settings_form.rb +4 -0
- data/app/forms/decidim/registration_form.rb +0 -27
- data/app/forms/decidim/user_group_form.rb +81 -0
- data/app/helpers/decidim/component_path_helper.rb +10 -0
- data/app/helpers/decidim/filters_helper.rb +3 -2
- data/app/helpers/decidim/icon_helper.rb +3 -1
- data/app/helpers/decidim/map_helper.rb +1 -1
- data/app/jobs/decidim/metric_job.rb +14 -0
- data/app/mailers/decidim/newsletter_mailer.rb +2 -0
- data/app/mailers/decidim/notification_mailer.rb +1 -1
- data/app/models/decidim/action_log.rb +66 -0
- data/app/models/decidim/coauthorship.rb +9 -0
- data/app/models/decidim/component.rb +5 -0
- data/app/models/decidim/continuity_badge_status.rb +9 -0
- data/app/models/decidim/gamification/badge_score.rb +1 -1
- data/app/models/decidim/messaging/message.rb +1 -0
- data/app/models/decidim/metric.rb +13 -0
- data/app/models/decidim/participatory_space_private_user.rb +4 -0
- data/app/models/decidim/user.rb +14 -38
- data/app/models/decidim/user_base_entity.rb +52 -0
- data/app/models/decidim/user_group.rb +48 -9
- data/app/models/decidim/user_group_membership.rb +8 -0
- data/app/permissions/decidim/permissions.rb +21 -0
- data/app/presenters/decidim/admin_log/organization_presenter.rb +0 -2
- data/app/presenters/decidim/admin_log/participatory_space_private_user_presenter.rb +38 -0
- data/app/presenters/decidim/metric_charts_presenter.rb +53 -0
- data/app/presenters/decidim/metric_object_presenter.rb +28 -0
- data/app/presenters/decidim/user_group_presenter.rb +16 -8
- data/app/presenters/decidim/user_presenter.rb +14 -0
- data/app/queries/decidim/metric_manage.rb +59 -0
- data/app/queries/decidim/metrics/users_metric_manage.rb +26 -0
- data/app/queries/decidim/user_groups/accepted_memberships.rb +36 -0
- data/app/queries/decidim/user_groups/accepted_user_groups.rb +38 -0
- data/app/queries/decidim/user_groups/accepted_users.rb +36 -0
- data/app/queries/decidim/user_groups/admin_memberships.rb +37 -0
- data/app/queries/decidim/user_groups/invited_memberships.rb +36 -0
- data/app/queries/decidim/user_groups/manageable_user_groups.rb +39 -0
- data/app/queries/decidim/user_groups/member_memberships.rb +37 -0
- data/app/resolvers/decidim/core/metric_resolver.rb +38 -0
- data/app/services/decidim/action_logger.rb +4 -2
- data/app/services/decidim/activity_search.rb +76 -0
- data/app/services/decidim/continuity_badge_tracker.rb +64 -0
- data/app/services/decidim/resource_search.rb +0 -1
- data/app/types/decidim/core/metric_history_type.rb +17 -0
- data/app/types/decidim/core/metric_type.rb +14 -0
- data/app/types/decidim/core/session_type.rb +1 -1
- data/app/types/decidim/core/user_group_type.rb +2 -2
- data/app/views/decidim/authorization_modals/show.html.erb +40 -27
- data/app/views/decidim/devise/registrations/new.html.erb +0 -19
- data/app/views/decidim/gamification/badges/index.html.erb +42 -0
- data/app/views/decidim/group_admins/index.html.erb +18 -0
- data/app/views/decidim/group_invites/index.html.erb +27 -0
- data/app/views/decidim/group_members/index.html.erb +19 -0
- data/app/views/decidim/groups/_form.html.erb +23 -0
- data/app/views/decidim/groups/edit.html.erb +26 -0
- data/app/views/decidim/groups/new.html.erb +26 -0
- data/app/views/decidim/last_activities/_activities.html.erb +13 -0
- data/app/views/decidim/last_activities/index.html.erb +18 -0
- data/app/views/decidim/last_activities/index.js.erb +6 -0
- data/app/views/decidim/profiles/show.html.erb +1 -1
- data/app/views/layouts/decidim/_user_menu.html.erb +0 -1
- data/app/views/layouts/decidim/_wrapper.html.erb +1 -1
- data/config/initializers/devise.rb +1 -1
- data/config/initializers/foundation_rails_helper.rb +1 -0
- data/config/locales/ca.yml +325 -32
- data/config/locales/de.yml +325 -32
- data/config/locales/en.yml +325 -32
- data/config/locales/es-PY.yml +325 -32
- data/config/locales/es.yml +325 -32
- data/config/locales/eu.yml +325 -32
- data/config/locales/fi.yml +330 -37
- data/config/locales/fr.yml +325 -32
- data/config/locales/gl.yml +325 -32
- data/config/locales/hu.yml +327 -34
- data/config/locales/it.yml +325 -32
- data/config/locales/nl.yml +325 -32
- data/config/locales/pl.yml +329 -32
- data/config/locales/pt-BR.yml +326 -33
- data/config/locales/pt.yml +325 -32
- data/config/locales/ru.yml +4 -33
- data/config/locales/sv.yml +346 -53
- data/config/locales/uk.yml +4 -33
- data/config/routes.rb +27 -1
- data/db/migrate/20170128112958_change_user_groups_verified_to_timestamp.rb +11 -0
- data/db/migrate/20180705134647_create_decidim_metrics.rb +16 -0
- data/db/migrate/20180730071851_add_core_content_blocks.rb +3 -3
- data/db/migrate/20180810092428_move_organization_fields_to_hero_content_block.rb +4 -2
- data/db/migrate/20180918072506_add_visibility_to_action_logs.rb +8 -0
- data/db/migrate/20181001124950_move_users_groups_to_users_table.rb +84 -0
- data/db/migrate/20181008102144_add_badge_switch_to_organizations.rb +8 -0
- data/db/migrate/20181010044613_create_decidim_continuity_badge_statuses.rb +11 -0
- data/db/migrate/20181011080252_add_roles_to_memberships.rb +24 -0
- data/db/migrate/20181016091601_make_authors_polymorphic.rb +31 -0
- data/db/migrate/20181029112820_fix_user_follows.rb +18 -0
- data/db/migrate/20181030090144_destroy_deleted_users_follows.rb +16 -0
- data/db/seeds.rb +18 -4
- data/lib/decidim/attributes.rb +1 -0
- data/lib/decidim/attributes/localized_date.rb +16 -0
- data/lib/decidim/attributes/time_with_zone.rb +3 -1
- data/lib/decidim/authorable.rb +5 -4
- data/lib/decidim/authorization_form_builder.rb +2 -2
- data/lib/decidim/coauthorable.rb +68 -18
- data/lib/decidim/content_block_manifest.rb +7 -0
- data/lib/decidim/content_processor.rb +17 -7
- data/lib/decidim/core.rb +12 -0
- data/lib/decidim/core/engine.rb +54 -6
- data/lib/decidim/core/test/factories.rb +63 -17
- data/lib/decidim/core/test/shared_examples/coauthorable.rb +27 -9
- data/lib/decidim/core/test/shared_examples/coauthorable_interface_examples.rb +2 -2
- data/lib/decidim/core/version.rb +1 -1
- data/lib/decidim/data_portability.rb +3 -1
- data/lib/decidim/data_portability_file_reader.rb +1 -1
- data/lib/decidim/events/author_event.rb +4 -1
- data/lib/decidim/events/coauthor_event.rb +4 -1
- data/lib/decidim/faker/localized.rb +5 -4
- data/lib/decidim/form_builder.rb +18 -17
- data/lib/decidim/gamification.rb +8 -2
- data/lib/decidim/gamification/badge.rb +34 -0
- data/lib/decidim/gamification/badge_scorer.rb +29 -14
- data/lib/decidim/gamification/badge_status.rb +2 -0
- data/lib/decidim/hashtaggable.rb +1 -1
- data/lib/decidim/manifest_registry.rb +5 -3
- data/lib/decidim/metric_manifest.rb +20 -0
- data/lib/decidim/metric_registry.rb +71 -0
- data/lib/decidim/participable.rb +1 -1
- data/lib/decidim/participatory_space_resourceable.rb +0 -1
- data/lib/decidim/query_extensions.rb +19 -0
- data/lib/decidim/resourceable.rb +1 -0
- data/lib/decidim/searchable.rb +2 -1
- data/lib/tasks/decidim_metrics_tasks.rake +41 -0
- data/lib/tasks/decidim_tasks.rake +1 -0
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ca.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.es.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.fr.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.gl.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.pt.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.ru.js +1 -2
- data/vendor/assets/javascripts/datepicker-locales/foundation-datepicker.uk.js +1 -2
- data/vendor/assets/javascripts/form_datepicker.js.es6 +1 -11
- metadata +144 -23
- data/app/cells/decidim/invitations_toggle/content.erb +0 -1
- data/app/cells/decidim/invitations_toggle/label.erb +0 -1
- data/app/cells/decidim/invitations_toggle_cell.rb +0 -27
- data/app/cells/decidim/toggle/show.erb +0 -8
- data/app/cells/decidim/toggle_cell.rb +0 -42
- data/app/commands/decidim/invite_friends.rb +0 -48
- data/app/controllers/decidim/invitations_controller.rb +0 -32
- data/app/forms/decidim/invitations_form.rb +0 -37
- data/app/views/decidim/invitations/index.html.erb +0 -48
- data/app/views/devise/mailer/invite_friend.html.erb +0 -27
- data/app/views/devise/mailer/invite_friend.text.erb +0 -19
- data/lib/decidim/rectify_ext.rb +0 -32
@@ -0,0 +1,263 @@
|
|
1
|
+
/* eslint-disable max-lines, id-length, no-invalid-this, no-cond-assign, no-unused-vars, max-params, no-undefined, no-sequences, multiline-ternary, no-ternary */
|
2
|
+
/* eslint prefer-reflect: ["error", { "exceptions": ["call"] }] */
|
3
|
+
/* eslint dot-location: ["error", "property"] */
|
4
|
+
/* global d3, DATACHARTS, fetchDatacharts */
|
5
|
+
|
6
|
+
// = require d3
|
7
|
+
|
8
|
+
const renderLineCharts = () => {
|
9
|
+
// lib
|
10
|
+
const linechart = (opts = {}) => {
|
11
|
+
// remove any previous chart
|
12
|
+
$(opts.container).empty()
|
13
|
+
|
14
|
+
// parse opts
|
15
|
+
let data = opts.data
|
16
|
+
let title = opts.title
|
17
|
+
let subtitle = opts.subtitle
|
18
|
+
let container = d3.select(opts.container)
|
19
|
+
let ratio = opts.ratio
|
20
|
+
let xTickFormat = opts.xTickFormat || d3.timeFormat("%b %y")
|
21
|
+
let showTooltip = opts.tip !== "false"
|
22
|
+
|
23
|
+
// precalculation
|
24
|
+
// Explanation: get the inner keys foreach object outer values, flat the array, remove duplicates
|
25
|
+
let keys = data.map((f) => f.key)
|
26
|
+
|
27
|
+
const legendSize = 15
|
28
|
+
const headerHeight = (keys.length * legendSize * 1.2)
|
29
|
+
const gutter = 5
|
30
|
+
|
31
|
+
// set the dimensions and margins of the graph
|
32
|
+
let margin = {
|
33
|
+
top: headerHeight + (gutter * 2),
|
34
|
+
right: gutter * 2,
|
35
|
+
bottom: gutter * 6,
|
36
|
+
left: gutter * 2
|
37
|
+
}
|
38
|
+
|
39
|
+
let width = Number(container.node().getBoundingClientRect().width) - margin.left - margin.right
|
40
|
+
let height = (width / ratio) - margin.top - margin.bottom
|
41
|
+
|
42
|
+
// set the ranges
|
43
|
+
const x = d3.scaleTime().range([0, width])
|
44
|
+
const y = d3.scaleLinear().range([height, 0])
|
45
|
+
|
46
|
+
// set the scales
|
47
|
+
x.domain(d3.extent([...new Set([].concat(...data.map((f) => f.value.map((d) => d.key))))]))
|
48
|
+
// group names
|
49
|
+
y.domain(d3.extent([...new Set([].concat(...data.map((f) => f.value.map((d) => d.value))))]))
|
50
|
+
|
51
|
+
// container
|
52
|
+
let svg = container.append("svg")
|
53
|
+
.attr("width", width + margin.left + margin.right)
|
54
|
+
.attr("height", height + margin.top + margin.bottom)
|
55
|
+
|
56
|
+
let upper = svg.append("g")
|
57
|
+
.attr("transform", `translate(0,${headerHeight})`)
|
58
|
+
|
59
|
+
// title
|
60
|
+
upper.append("text")
|
61
|
+
.attr("x", 0)
|
62
|
+
.attr("y", -20)
|
63
|
+
.attr("class", "title")
|
64
|
+
.text(title)
|
65
|
+
|
66
|
+
// subtitle
|
67
|
+
upper.append("text")
|
68
|
+
.attr("class", "subtitle")
|
69
|
+
.text(subtitle)
|
70
|
+
|
71
|
+
// legend
|
72
|
+
let legend = upper.append("g")
|
73
|
+
.attr("text-anchor", "end")
|
74
|
+
.selectAll("g")
|
75
|
+
.data(keys)
|
76
|
+
.enter().append("g")
|
77
|
+
.attr("transform", (d, i, arr) => `translate(0,${-((arr.length - 1 - i) * legendSize * 1.2) - margin.top + headerHeight})`)
|
78
|
+
|
79
|
+
legend.append("rect")
|
80
|
+
.attr("x", width + margin.left + margin.right - legendSize)
|
81
|
+
.attr("width", legendSize)
|
82
|
+
.attr("height", legendSize)
|
83
|
+
.attr("class", (d, i) => `legend type-${i}`)
|
84
|
+
|
85
|
+
legend.append("text")
|
86
|
+
.attr("x", width + margin.left + margin.right - legendSize - 4)
|
87
|
+
.attr("y", legendSize / 2)
|
88
|
+
.attr("dy", "0.32em")
|
89
|
+
.attr("class", "subtitle")
|
90
|
+
.text((d) => d)
|
91
|
+
|
92
|
+
let lower = svg.append("g")
|
93
|
+
.attr("transform", `translate(0,${margin.top})`)
|
94
|
+
|
95
|
+
// background
|
96
|
+
lower.append("rect")
|
97
|
+
.attr("width", width + margin.left + margin.right)
|
98
|
+
.attr("height", height + margin.top + gutter - headerHeight)
|
99
|
+
.attr("class", "background")
|
100
|
+
|
101
|
+
// main group
|
102
|
+
let g = lower.append("g")
|
103
|
+
.attr("transform", `translate(${margin.left},${margin.top - headerHeight})`)
|
104
|
+
.attr("class", "group")
|
105
|
+
|
106
|
+
let line = d3.line()
|
107
|
+
// .curve(d3.curveBasis)
|
108
|
+
.x((d) => x(d.key))
|
109
|
+
.y((d) => y(d.value))
|
110
|
+
|
111
|
+
let cat = g.selectAll("path")
|
112
|
+
.data(data)
|
113
|
+
.enter().append("path")
|
114
|
+
.attr("d", (d) => line(d.value))
|
115
|
+
.attr("class", (d) => `line type-${keys.indexOf(d.key)}`)
|
116
|
+
|
117
|
+
// axis
|
118
|
+
let xAxis = d3.axisBottom(x)
|
119
|
+
.ticks(d3.timeMonth.every(4))
|
120
|
+
.tickSize(-height)
|
121
|
+
.tickFormat(xTickFormat)
|
122
|
+
let yAxis = d3.axisLeft(y)
|
123
|
+
.ticks(5)
|
124
|
+
|
125
|
+
let _xAxis = (xg) => {
|
126
|
+
xg.call(xAxis)
|
127
|
+
xg.select(".domain").remove()
|
128
|
+
xg.selectAll(".tick line").attr("class", "dashed")
|
129
|
+
xg.selectAll(".tick text").attr("y", gutter + 6)
|
130
|
+
}
|
131
|
+
let _yAxis = (yg) => {
|
132
|
+
yg.call(yAxis)
|
133
|
+
yg.select(".domain").remove()
|
134
|
+
yg.selectAll(".tick text").attr("text-anchor", "end").attr("x", gutter)
|
135
|
+
yg.selectAll(".tick line").attr("x1", -margin.left).attr("x2", -margin.left - 8)
|
136
|
+
}
|
137
|
+
|
138
|
+
g.append("g")
|
139
|
+
.attr("class", "x axis")
|
140
|
+
.attr("transform", `translate(0,${height})`)
|
141
|
+
.call(_xAxis)
|
142
|
+
|
143
|
+
g.append("g")
|
144
|
+
.attr("class", "y axis")
|
145
|
+
.call(_yAxis)
|
146
|
+
|
147
|
+
// tooltip
|
148
|
+
if (showTooltip) {
|
149
|
+
let tooltip = d3.select("body").append("div")
|
150
|
+
.attr("id", `${container.node().id}-tooltip`)
|
151
|
+
.attr("class", "chart-tooltip")
|
152
|
+
.style("opacity", 0)
|
153
|
+
|
154
|
+
svg
|
155
|
+
.on("mouseover", () => {
|
156
|
+
tooltip.style("opacity", 1)
|
157
|
+
})
|
158
|
+
.on("mouseout", () => {
|
159
|
+
tooltip.style("opacity", 0)
|
160
|
+
})
|
161
|
+
.on("mousemove", function() {
|
162
|
+
let x0 = x.invert(d3.mouse(this)[0])
|
163
|
+
|
164
|
+
let ge = []
|
165
|
+
data.forEach((o) => {
|
166
|
+
ge.push(o.value.find((h) => (h.key.getMonth() === x0.getMonth()) && (h.key.getFullYear() === x0.getFullYear())))
|
167
|
+
})
|
168
|
+
|
169
|
+
ge = ge.filter(Boolean)
|
170
|
+
|
171
|
+
if (ge.length) {
|
172
|
+
let html = `${ge[0].key.toLocaleDateString()}<br />`;
|
173
|
+
ge.forEach((d) => {
|
174
|
+
html += `${d.value.toLocaleString()} ${d.ref}<br />`
|
175
|
+
})
|
176
|
+
|
177
|
+
// svg position relative to document
|
178
|
+
let coords = {
|
179
|
+
x: window.pageXOffset + container.node().getBoundingClientRect().left,
|
180
|
+
y: window.pageYOffset + container.node().getBoundingClientRect().top
|
181
|
+
}
|
182
|
+
|
183
|
+
let tooltipContent = `
|
184
|
+
<div class="tooltip-content">
|
185
|
+
${html}
|
186
|
+
</div>`
|
187
|
+
|
188
|
+
tooltip.html(tooltipContent)
|
189
|
+
.style("left", `${coords.x + x(ge[0].key) + margin.left}px`)
|
190
|
+
.style("top", `${coords.y + y(ge[0].value) + margin.top}px`)
|
191
|
+
}
|
192
|
+
})
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
return $(".linechart:visible").each((i, container) => {
|
197
|
+
|
198
|
+
// Initialize dataset values
|
199
|
+
const init = (dataset) => {
|
200
|
+
const datasetDefault = {
|
201
|
+
metric: "",
|
202
|
+
title: "",
|
203
|
+
subtitle: "",
|
204
|
+
ratio: "",
|
205
|
+
tip: ""
|
206
|
+
}
|
207
|
+
return {...datasetDefault, ...dataset}
|
208
|
+
}
|
209
|
+
|
210
|
+
// OPTIONAL: Helper function to add a reference to the parent
|
211
|
+
const addRefs = (parentize) => {
|
212
|
+
for (let x = 0; x < parentize.length; x += 1) {
|
213
|
+
if (Object.prototype.hasOwnProperty.call(parentize[x], "value")) {
|
214
|
+
for (let y = 0; y < parentize[x].value.length; y += 1) {
|
215
|
+
parentize[x].value[y].ref = parentize[x].key
|
216
|
+
}
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
return parentize
|
221
|
+
}
|
222
|
+
|
223
|
+
// OPTIONAL: Helper function to preprocess the data
|
224
|
+
const parseDates = (data) => {
|
225
|
+
// format the data
|
226
|
+
data.forEach((d) => {
|
227
|
+
d.value.forEach((f) => {
|
228
|
+
f.key = d3.isoParse(f.key)
|
229
|
+
})
|
230
|
+
|
231
|
+
d.value.sort((x, y) => d3.ascending(x.key, y.key))
|
232
|
+
});
|
233
|
+
|
234
|
+
return data
|
235
|
+
}
|
236
|
+
|
237
|
+
// MANDATORY: HTML must contain which metric should it display
|
238
|
+
// If there's no data, fetch it
|
239
|
+
if (!DATACHARTS || !DATACHARTS[container.dataset.metric]) {
|
240
|
+
fetchDatacharts()
|
241
|
+
}
|
242
|
+
|
243
|
+
// Make a clone of the array of objects
|
244
|
+
let data = DATACHARTS[container.dataset.metric].map((d) => {
|
245
|
+
return { ...d }
|
246
|
+
})
|
247
|
+
|
248
|
+
if (data) {
|
249
|
+
let config = init(container.dataset)
|
250
|
+
let dataModified = parseDates(addRefs(data))
|
251
|
+
|
252
|
+
linechart({
|
253
|
+
container: `#${container.id}`,
|
254
|
+
title: config.title,
|
255
|
+
subtitle: config.subtitle,
|
256
|
+
data: dataModified,
|
257
|
+
xTickFormat: config.xTickFormat,
|
258
|
+
ratio: config.ratio.split(":").reduce((a, b) => a / b) || (4 / 3),
|
259
|
+
tip: config.tip
|
260
|
+
})
|
261
|
+
}
|
262
|
+
})
|
263
|
+
}
|
@@ -1,26 +1,36 @@
|
|
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
|
-
|
1
|
+
/* global areachart */
|
2
|
+
|
3
|
+
$(() => {
|
4
|
+
const query = (metrics) => {
|
5
|
+
let metricsQuery = `metrics(names: [${metrics.join(" ")}]) { name history { key value } }`;
|
6
|
+
return {query: `{ ${metricsQuery} }`};
|
7
|
+
}
|
8
|
+
|
9
|
+
const fetch = (metrics) => $.post("api", query(metrics))
|
10
|
+
|
11
|
+
const metrics = {};
|
12
|
+
|
13
|
+
$(".metric-chart:visible").each((index, container) => {
|
14
|
+
metrics[$(container).data("metric")] = container;
|
15
|
+
});
|
16
|
+
|
17
|
+
if (!$.isEmptyObject(metrics)) {
|
18
|
+
fetch(Object.keys(metrics)).then((response) => {
|
19
|
+
$.each(response.data.metrics, (_index, metricData) => {
|
20
|
+
let container = metrics[metricData.name];
|
21
|
+
if (metricData.history.length === 0) {
|
22
|
+
$(container).remove();
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
let info = $(container).data("info");
|
26
|
+
|
27
|
+
areachart({
|
28
|
+
container: `#${container.id}`,
|
29
|
+
data: metricData.history,
|
30
|
+
title: info.title,
|
31
|
+
objectName: info.object
|
32
|
+
});
|
33
|
+
});
|
34
|
+
});
|
35
|
+
}
|
36
|
+
});
|
@@ -661,10 +661,11 @@
|
|
661
661
|
// initialization
|
662
662
|
$orgChartContainer.each((i, container) => {
|
663
663
|
|
664
|
-
let
|
664
|
+
let $container = $(container)
|
665
|
+
let width = $container.width()
|
665
666
|
let height = width / (16 / 9)
|
666
667
|
|
667
|
-
d3.json(
|
668
|
+
d3.json($container.data("url")).then((data) => {
|
668
669
|
// Make a fake previous node if the data entry is not hierarchical
|
669
670
|
if (data instanceof Array) {
|
670
671
|
fake = true
|
@@ -0,0 +1,324 @@
|
|
1
|
+
/* eslint-disable max-lines, id-length, no-invalid-this, no-cond-assign, no-unused-vars, max-params, no-sequences, no-ternary */
|
2
|
+
/* eslint prefer-reflect: ["error", { "exceptions": ["call"] }] */
|
3
|
+
/* eslint dot-location: ["error", "property"] */
|
4
|
+
/* global d3, DATACHARTS, fetchDatacharts */
|
5
|
+
|
6
|
+
// = require d3
|
7
|
+
|
8
|
+
const renderRowCharts = () => {
|
9
|
+
// lib
|
10
|
+
const rowchart = (opts = {}) => {
|
11
|
+
// remove any previous chart
|
12
|
+
$(opts.container).empty()
|
13
|
+
|
14
|
+
// parse opts
|
15
|
+
let data = opts.data
|
16
|
+
let title = opts.title
|
17
|
+
let subtitle = opts.subtitle
|
18
|
+
let container = d3.select(opts.container)
|
19
|
+
let ratio = opts.ratio
|
20
|
+
let xTickFormat = opts.xTickFormat
|
21
|
+
let showTooltip = opts.tip !== "false"
|
22
|
+
|
23
|
+
// precalculation
|
24
|
+
// Explanation: get the inner values foreach object outer values, flat the array, remove duplicates
|
25
|
+
let maxValue = d3.max([...new Set([].concat(...data.map((f) => f.value.map((d) => d.value))))])
|
26
|
+
// Explanation: get the inner keys foreach object outer values, flat the array, remove duplicates
|
27
|
+
let keys = [...new Set([].concat(...data.map((f) => f.value.map((d) => d.key))))]
|
28
|
+
|
29
|
+
const legendSize = 15
|
30
|
+
const headerHeight = (keys.length * legendSize * 1.2)
|
31
|
+
const gutter = 5
|
32
|
+
|
33
|
+
// estimation Y-labels length
|
34
|
+
// get the mean of each label length
|
35
|
+
const getMarginLeftLengthEstimation = () => {
|
36
|
+
let avgLabelLength = data.map((f) => f.key.length).reduce((a, b) => a + b) / data.length
|
37
|
+
let initialMarginLeft = Number(container.node().getBoundingClientRect().width) * 0.25
|
38
|
+
let maxLabelLengthAllowed = Number(container.node().getBoundingClientRect().width) * 0.4
|
39
|
+
|
40
|
+
// Pre-estimated number, after testing
|
41
|
+
const longLabelEstimation = 50
|
42
|
+
|
43
|
+
return (avgLabelLength < longLabelEstimation)
|
44
|
+
? initialMarginLeft
|
45
|
+
: maxLabelLengthAllowed
|
46
|
+
}
|
47
|
+
|
48
|
+
// set the dimensions and margins of the graph
|
49
|
+
let margin = {
|
50
|
+
top: headerHeight + (gutter * 2),
|
51
|
+
right: gutter * 2,
|
52
|
+
bottom: gutter * 6,
|
53
|
+
left: getMarginLeftLengthEstimation()
|
54
|
+
}
|
55
|
+
|
56
|
+
let width = Number(container.node().getBoundingClientRect().width) - margin.left - margin.right
|
57
|
+
let height = (width / ratio) - margin.top - margin.bottom
|
58
|
+
|
59
|
+
// set the ranges
|
60
|
+
const x = d3.scaleLinear().rangeRound([0, width])
|
61
|
+
const y0 = d3.scaleBand().rangeRound([height, 0]).paddingInner(0.1)
|
62
|
+
const y1 = d3.scaleBand().padding(0.05)
|
63
|
+
|
64
|
+
// set the scales
|
65
|
+
x.domain([0, maxValue]).nice()
|
66
|
+
// group names
|
67
|
+
y0.domain(data.map((d) => d.key))
|
68
|
+
// individual values for each group
|
69
|
+
y1.domain(keys).rangeRound([0, y0.bandwidth()])
|
70
|
+
|
71
|
+
// container
|
72
|
+
let svg = container.append("svg")
|
73
|
+
.attr("width", width + margin.left + margin.right)
|
74
|
+
.attr("height", height + margin.top + margin.bottom)
|
75
|
+
|
76
|
+
let upper = svg.append("g")
|
77
|
+
.attr("transform", `translate(0,${headerHeight})`)
|
78
|
+
|
79
|
+
// title
|
80
|
+
upper.append("text")
|
81
|
+
.attr("x", 0)
|
82
|
+
.attr("y", -20)
|
83
|
+
.attr("class", "title")
|
84
|
+
.text(title)
|
85
|
+
|
86
|
+
// subtitle
|
87
|
+
upper.append("text")
|
88
|
+
.attr("class", "subtitle")
|
89
|
+
.text(subtitle)
|
90
|
+
|
91
|
+
// legend
|
92
|
+
let legend = upper.append("g")
|
93
|
+
.attr("text-anchor", "end")
|
94
|
+
.selectAll("g")
|
95
|
+
.data(keys)
|
96
|
+
.enter().append("g")
|
97
|
+
.attr("transform", (d, i, arr) => `translate(0,${-((arr.length - 1 - i) * legendSize * 1.2) - margin.top + headerHeight})`)
|
98
|
+
|
99
|
+
legend.append("rect")
|
100
|
+
.attr("x", width + margin.left + margin.right - legendSize)
|
101
|
+
.attr("width", legendSize)
|
102
|
+
.attr("height", legendSize)
|
103
|
+
.attr("class", (d, i) => `legend type-${i}`)
|
104
|
+
|
105
|
+
legend.append("text")
|
106
|
+
.attr("x", width + margin.left + margin.right - legendSize - 4)
|
107
|
+
.attr("y", legendSize / 2)
|
108
|
+
.attr("dy", "0.32em")
|
109
|
+
.attr("class", "subtitle")
|
110
|
+
.text((d) => d)
|
111
|
+
|
112
|
+
let lower = svg.append("g")
|
113
|
+
.attr("transform", `translate(0,${margin.top})`)
|
114
|
+
|
115
|
+
// background
|
116
|
+
lower.append("rect")
|
117
|
+
.attr("width", width + margin.left + margin.right)
|
118
|
+
.attr("height", height + margin.top + gutter - headerHeight)
|
119
|
+
.attr("class", "background")
|
120
|
+
|
121
|
+
// main group
|
122
|
+
let g = lower.append("g")
|
123
|
+
.attr("transform", `translate(${margin.left},${margin.top - headerHeight})`)
|
124
|
+
|
125
|
+
// axis
|
126
|
+
let xAxis = d3.axisBottom(x)
|
127
|
+
.ticks(5)
|
128
|
+
.tickSize(-height)
|
129
|
+
.tickFormat(xTickFormat)
|
130
|
+
let yAxis = d3.axisLeft(y0)
|
131
|
+
|
132
|
+
let _xAxis = (xg) => {
|
133
|
+
xg.call(xAxis)
|
134
|
+
xg.select(".domain").remove()
|
135
|
+
xg.selectAll(".tick line").attr("class", "dashed")
|
136
|
+
xg.selectAll(".tick text").attr("y", gutter + 6)
|
137
|
+
}
|
138
|
+
let _yAxis = (yg) => {
|
139
|
+
yg.call(yAxis)
|
140
|
+
yg.select(".domain").remove()
|
141
|
+
yg.selectAll(".tick line").remove()
|
142
|
+
yg.selectAll(".tick text")
|
143
|
+
.attr("class", "text-large")
|
144
|
+
.each(function() {
|
145
|
+
let text = d3.select(this)
|
146
|
+
let limitLength = margin.left - (gutter * 10)
|
147
|
+
|
148
|
+
if (text.node().getComputedTextLength() > limitLength) {
|
149
|
+
let words = text.text().split(/\s+/).reverse()
|
150
|
+
let word = ""
|
151
|
+
let line = []
|
152
|
+
let lineNumber = 1
|
153
|
+
let dy = text.attr("dy")
|
154
|
+
let tspan = text.text(null).append("tspan")
|
155
|
+
.attr("x", -9)
|
156
|
+
.attr("dy", `-${dy}`)
|
157
|
+
|
158
|
+
while (word = words.pop()) {
|
159
|
+
if (tspan.node().getComputedTextLength() > limitLength) {
|
160
|
+
|
161
|
+
if (lineNumber > 1) {
|
162
|
+
line.pop()
|
163
|
+
tspan.html(`${line.join(" ")}…`)
|
164
|
+
break
|
165
|
+
}
|
166
|
+
|
167
|
+
line.pop();
|
168
|
+
tspan.text(line.join(" "));
|
169
|
+
line = [word];
|
170
|
+
tspan = text.append("tspan")
|
171
|
+
.attr("x", -9)
|
172
|
+
.attr("dy", `${1 + (lineNumber * parseFloat(dy))}em`)
|
173
|
+
.text(word);
|
174
|
+
lineNumber += 1
|
175
|
+
}
|
176
|
+
|
177
|
+
line.push(word);
|
178
|
+
tspan.text(line.join(" "))
|
179
|
+
}
|
180
|
+
}
|
181
|
+
})
|
182
|
+
}
|
183
|
+
|
184
|
+
g.append("g")
|
185
|
+
.attr("class", "x axis")
|
186
|
+
.attr("transform", `translate(0,${height})`)
|
187
|
+
.call(_xAxis)
|
188
|
+
|
189
|
+
g.append("g")
|
190
|
+
.attr("class", "y axis")
|
191
|
+
.call(_yAxis)
|
192
|
+
|
193
|
+
// bars
|
194
|
+
let barGroup = g.append("g")
|
195
|
+
.selectAll("g")
|
196
|
+
.data(data)
|
197
|
+
.enter().append("g")
|
198
|
+
.attr("class", "group")
|
199
|
+
.attr("transform", (d) => `translate(0,${y0(d.key)})`)
|
200
|
+
|
201
|
+
barGroup.selectAll("rect")
|
202
|
+
.data((d) => d.value)
|
203
|
+
.enter().append("rect")
|
204
|
+
.attr("y", (d) => y1(d.key))
|
205
|
+
.attr("height", y1.bandwidth())
|
206
|
+
.attr("class", (d) => `line type-${keys.indexOf(d.key)}`)
|
207
|
+
.transition()
|
208
|
+
.duration(500)
|
209
|
+
.attr("width", (d) => x(d.value))
|
210
|
+
|
211
|
+
// tooltip
|
212
|
+
if (showTooltip) {
|
213
|
+
let tooltip = d3.select("body").append("div")
|
214
|
+
.attr("id", `${container.node().id}-tooltip`)
|
215
|
+
.attr("class", "chart-tooltip")
|
216
|
+
.style("opacity", 0)
|
217
|
+
|
218
|
+
barGroup.selectAll("rect")
|
219
|
+
.on("mouseover", () => {
|
220
|
+
tooltip.style("opacity", 1)
|
221
|
+
})
|
222
|
+
.on("mouseout", () => {
|
223
|
+
tooltip.style("opacity", 0)
|
224
|
+
})
|
225
|
+
.on("mousemove", function(d) {
|
226
|
+
// svg position relative to document
|
227
|
+
let coords = {
|
228
|
+
x: window.pageXOffset + container.node().getBoundingClientRect().left,
|
229
|
+
y: window.pageYOffset + container.node().getBoundingClientRect().top
|
230
|
+
}
|
231
|
+
|
232
|
+
let tooltipContent = `
|
233
|
+
<div class="tooltip-content">
|
234
|
+
${d.key}: ${d.value.toLocaleString()}
|
235
|
+
</div>`
|
236
|
+
|
237
|
+
tooltip.html(tooltipContent)
|
238
|
+
.style("left", `${coords.x + (x(d.value) / 2) + margin.left}px`)
|
239
|
+
.style("top", `${coords.y + y1(d.key) + y0(d.ref) + margin.top}px`)
|
240
|
+
})
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
244
|
+
return $(".rowchart:visible").each((i, container) => {
|
245
|
+
|
246
|
+
// Initialize dataset values
|
247
|
+
const init = (dataset) => {
|
248
|
+
const datasetDefault = {
|
249
|
+
metric: "",
|
250
|
+
title: "",
|
251
|
+
subtitle: "",
|
252
|
+
ratio: "",
|
253
|
+
percent: "",
|
254
|
+
tip: ""
|
255
|
+
}
|
256
|
+
return {...datasetDefault, ...dataset}
|
257
|
+
}
|
258
|
+
|
259
|
+
// OPTIONAL: Helper function to turn all values into percentages
|
260
|
+
const percentage = (percent) => {
|
261
|
+
// helper function to groupBy
|
262
|
+
const groupBy = (arr, by) => arr.reduce((r, v, j, a, k = v[by]) => ((r[k] || (r[k] = [])).push(v), r), {})
|
263
|
+
// get an object grouped by key
|
264
|
+
let groupByKey = groupBy([].concat(...percent.map((f) => f.value)), "key")
|
265
|
+
// get total sum of values by key
|
266
|
+
for (let cat in groupByKey) {
|
267
|
+
if (Object.prototype.hasOwnProperty.call(groupByKey, cat)) {
|
268
|
+
groupByKey[cat] = groupByKey[cat].map((f) => f.value).reduce((a, b) => a + b)
|
269
|
+
}
|
270
|
+
}
|
271
|
+
// updates every value with its respective percentage
|
272
|
+
[].concat(...percent.map((f) => f.value)).map((item) => {
|
273
|
+
item.value = (item.value / groupByKey[item.key]) * 100
|
274
|
+
return item
|
275
|
+
})
|
276
|
+
|
277
|
+
return percent
|
278
|
+
}
|
279
|
+
|
280
|
+
// OPTIONAL: Helper function to add a reference to the parent
|
281
|
+
const addRefs = (parentize) => {
|
282
|
+
for (let x = 0; x < parentize.length; x += 1) {
|
283
|
+
if (Object.prototype.hasOwnProperty.call(parentize[x], "value")) {
|
284
|
+
for (let y = 0; y < parentize[x].value.length; y += 1) {
|
285
|
+
parentize[x].value[y].ref = parentize[x].key
|
286
|
+
}
|
287
|
+
}
|
288
|
+
}
|
289
|
+
|
290
|
+
return parentize
|
291
|
+
}
|
292
|
+
|
293
|
+
// MANDATORY: HTML must contain which metric should it display
|
294
|
+
// If there's no data, fetch it
|
295
|
+
if (!DATACHARTS || !DATACHARTS[container.dataset.metric]) {
|
296
|
+
fetchDatacharts()
|
297
|
+
}
|
298
|
+
|
299
|
+
// Make a clone of the array of objects
|
300
|
+
let data = DATACHARTS[container.dataset.metric].map((d) => {
|
301
|
+
return { ...d }
|
302
|
+
})
|
303
|
+
|
304
|
+
if (data) {
|
305
|
+
let config = init(container.dataset)
|
306
|
+
let dataModified = addRefs(data)
|
307
|
+
|
308
|
+
if (config.percent === "true") {
|
309
|
+
dataModified = percentage(dataModified)
|
310
|
+
config.xTickFormat = (d) => `${d}%`
|
311
|
+
}
|
312
|
+
|
313
|
+
rowchart({
|
314
|
+
container: `#${container.id}`,
|
315
|
+
title: config.title,
|
316
|
+
subtitle: config.subtitle,
|
317
|
+
data: dataModified,
|
318
|
+
xTickFormat: config.xTickFormat,
|
319
|
+
ratio: config.ratio.split(":").reduce((a, b) => a / b) || (4 / 3),
|
320
|
+
tip: config.tip
|
321
|
+
})
|
322
|
+
}
|
323
|
+
})
|
324
|
+
}
|