Category Archives: Code

Code is a question and answer site for professional and enthusiast programmers.

Amcharts Sort stackbyvalue with bullet chart

I am using stackByValue of amcharts to arranged a stack column chart . I would like to add a bullet point on each chart to check if they meet a certain target or not. Currently what happen is the bullet point is added to the stacked chart is there a way that I could do this without removing the stackByValue ?

Here is my JsFiddle: `http://jsfiddle.net/sky5rvdz/13/

$(document).ready(function() { AmCharts.addInitHandler(function(chart) { // Check if enabled if (chart.valueAxes === undefined || chart.valueAxes.length === 0 || !chart.valueAxes[0].stackByValue) return; // Disable built-in stacking chart.valueAxes[0].stackType = "none"; // Prepare all graphs for (var i = 0; i < chart.graphs.length; i++) { var graph = chart.graphs[i]; graph.originalValueField = graph.valueField; graph.valueField = graph.originalValueField + "Close"; graph.openField = graph.originalValueField + "Open"; graph.clustered = false; if (graph.labelText) graph.labelText = graph.labelText.split("[[value]]").join("[[" + graph.originalValueField + "]]"); if (graph.balloonText) graph.balloonText = graph.balloonText.split("[[value]]").join("[[" + graph.originalValueField + "]]"); } // Go through each category and order values for (var i = 0; i < chart.dataProvider.length; i++) { // Assemble intermediate array of data point items var dp = chart.dataProvider[i]; var items = []; var sum = 0; for (var x = 0; x < chart.graphs.length; x++) { var graph = chart.graphs[x]; items.push({ "graph": graph, "value": dp[graph.originalValueField] }); } var sortValue = 0; // Order according to value items.sort(function(a, b) { if (sortValue == 0) { return a.value - b.value; } else { return b.value - a.value; } }); // Calculate open and close fields var offset = 0; for (var x = 0; x < items.length; x++) { var item = items[x]; dp[item.graph.openField] = offset; dp[item.graph.valueField] = offset + dp[item.graph.originalValueField]; offset = dp[item.graph.valueField]; } } }, ["serial"]); var response = [{ "name": "Jan", "target": 2062186.74, "USA": 0, "MAN": 605873.95, "PAN": 759763.5 }, { "name": "Feb", "target": 1492210.81, "MAN": 499538.43, "PAN": 559504.95, "USA": 5850 }, { "name": "Mar", "target": 1455750, "MAN": 403715.2, "PAN": 694353.95, "USA": 0 }, { "name": "Apr", "target": 2008623.96, "USA": 0, "MAN": 409993.3, "PAN": 511030 }]; var graphs = Object.keys(response[0]).reduce(function(graphsArray, key) { if (key !== "name" && key !== "target") { graphsArray.push({ "balloonText": "<b>[[value]]</b>", "balloonFunction": function(item, graph) { var result = graph.balloonText; for (var key in item.dataContext) { if (item.dataContext.hasOwnProperty(key) && !isNaN(item.dataContext[key])) { var formatted = AmCharts.formatNumber(item.dataContext[key], { precision: chart.precision, decimalSeparator: chart.decimalSeparator, thousandsSeparator: chart.thousandsSeparator }, 2); result = result.replace("[[" + key + "]]", formatted); } } return result; }, "fillAlphas": 0.8, "labelText": "[[title]]<br>", "labelPosition": "middle", "lineAlpha": 0.3, "title": key, "type": "column", "color": "#000000", //"showAllValueLabels": true, "valueField": key }); } if (key === "target") { graphsArray.push({ "balloonText": "<b>[[value]]</b>", "balloonFunction": function(item, graph) { var result = graph.balloonText; for (var key in item.dataContext) { if (item.dataContext.hasOwnProperty(key) && !isNaN(item.dataContext[key])) { var formatted = AmCharts.formatNumber(item.dataContext[key], { precision: chart.precision, decimalSeparator: chart.decimalSeparator, thousandsSeparator: chart.thousandsSeparator }, 2); result = result.replace("[[" + key + "]]", formatted); } } return result; }, "valueAxis": "v2", "lineAlpha": 0, "bullet": "round", "bulletSize": 20, "title": "target", "type": "line", "valueField": "target" }); } return graphsArray; }, []); var chart = AmCharts.makeChart("chartdiv", { "type": "serial", "theme": "light", "legend": { "horizontalGap": 10, "maxColumns": 1, "position": "right", "useGraphSettings": true, "markerSize": 10 }, "numberFormatter": { "precision": 1, "decimalSeparator": ".", "thousandsSeparator": "," }, "dataProvider": response, "valueAxes": [{ "id": "v1", "stackType": "regular", /** * A proprietary setting `stackByValue` which is not an * official config option. It will be used by our custom * plugin */ "stackByValue": true, "axisAlpha": 0.3, "gridAlpha": 0 }, , { "id": "v2", "axisAlpha": 0.3, "gridAlpha": 0, "position": "top", "title": "Target" }], "gridAboveGraphs": true, "startDuration": 0, "graphs": graphs, "categoryField": "name", "categoryAxis": { "gridPosition": "start", "axisAlpha": 0, "gridAlpha": 0, "position": "left" }, "export": { "enabled": true } }); console.log(graphs); console.log(response); Object.keys(response[0]).forEach(key => { console.log(key) // returns the keys in an object // console.log(a[key]) // returns the appropriate value }) });

Thanks in advance!

Amcharts Sort stackbyvalue with bullet chart

Regular expression that matches the first string after a marker

Given a string like this, I would like to create a Regular Expression that captures the string “Identificador”. This string is localized, thus the problem.

As a hint, I have thought that it may be retrieved easily, because it’s the string just after the “————“. Each entry is separated by this “——-” and the first element is the string I want. So the Regex could return “Identificador” or an array of { “Identificador”, “Identificador”, “Identificador”, … } (one string for each entry).

Here is the sample input:

Administrador de arranque de firmware
-----------------------------------
Identificador           {fwbootmgr}
displayorder            {bootmgr}

Administrador de arranque de Windows
----------------------------------
Identificador           {bootmgr}
device                  partition=G:
path                    \efi\boot\bootarm.efi
description             Windows Boot Manager
locale                  en-US
inherit                 {globalsettings}
booterrorux             Simple
default                 {default}
displayorder            {838bb5a3-712f-11e8-b4ea-001a7dda710e}
                        {default}
                        {7619dcc9-fafe-11d9-b411-000476eba25f}
bootsequence            {01de5a27-8705-40db-bad6-96fa5187d4a6}
timeout                 30
displaybootmenu         Yes
processcustomactionsfirstYes
persistbootsequence     Yes

Cargador de arranque de Windows
-----------------------------
Identificador           {311b88b5-9b30-491d-bad9-167ca3e2d417}
device                  ramdisk=[F:]\PROGRAMS\UpdateOS\UpdateOS.wim,{ramdiskoptions}
path                    \windows\system32\boot\winload.efi
description             Windows Update OS (Boot from WIM)
inherit                 {bootloadersettings}
osdevice                ramdisk=[F:]\PROGRAMS\UpdateOS\UpdateOS.wim,{ramdiskoptions}
systemroot              \windows
bootmenupolicy          Standard
winpe                   Yes

Cargador de arranque de Windows
-----------------------------
Identificador           {7619dcc9-fafe-11d9-b411-000476eba25f}
device                  partition=F:
path                    \windows\system32\boot\winload.efi
description             Windows Phone
locale                  en-US
inherit                 {bootloadersettings}
bootdebug               No
nointegritychecks       Yes
osdevice                partition=F:
systemroot              \windows
bootmenupolicy          Standard
bootstatuspolicy        IgnoreAllFailures
ems                     No

Aplicaci¢n de arranque de Windows (1020000a)
------------------------------------------
Identificador           {01de5a27-8705-40db-bad6-96fa5187d4a6}
device                  partition=G:
path                    \windows\system32\boot\mobilestartup.efi
description             Mobile Startup App
inherit                 {bootloadersettings}
recoverysequence        {311b88b5-9b30-491d-bad9-167ca3e2d417}
recoveryenabled         Yes
nointegritychecks       Yes

Aplicaci¢n de arranque de Windows (1020000a)
------------------------------------------
Identificador           {0ff5f24a-3785-4aeb-b8fe-4226215b88c4}
device                  partition=G:
path                    \windows\system32\boot\ffuloader.efi
description             FFU Loader (User Invoked)
inherit                 {bootloadersettings}
custom:26000201         Yes

Aplicaci¢n de arranque de Windows (1020000a)
------------------------------------------
Identificador           {default}
device                  partition=G:
path                    \EFI\boot\BootShim.efi
description             BootShim
nointegritychecks       Yes
testsigning             Yes

Aplicaci¢n de arranque de Windows (1020000a)
------------------------------------------
Identificador           {838bb5a3-712f-11e8-b4ea-001a7dda710e}
device                  partition=G:
path                    \Windows\System32\BOOT\developermenu.efi
description             Developer Menu

Aplicaci¢n de arranque de Windows (1020000a)
------------------------------------------
Identificador           {bd8951c4-eabd-4c6f-aafb-4ddb4eb0469b}
device                  partition=G:
path                    \windows\system32\boot\resetphone.efi
description             Reset My Phone Application
inherit                 {bootloadersettings}
custom:26000206         Yes

Configuraci¢n de EMS
--------------------
Identificador           {emssettings}
bootems                 No

Configuraci¢n del depurador
---------------------------
Identificador           {dbgsettings}
description             Windows Debugger Settings

Configuraci¢n global
--------------------
Identificador           {globalsettings}
inherit                 {dbgsettings}
                        {emssettings}
bootuxtransitiontime    5000
booterrorux             Simple
extendedinput           Yes
nobootuxtext            Yes
nobootuxprogress        Yes
nobootuxfade            No
nokeyboard              Yes
mobilegraphics          Yes
custom:250000e0         1
chargethreshold         255
custom:25000511         90
bootflow                0x0
offmodecharging         No

Configuraci¢n del cargador de arranque
------------------------------------
Identificador           {bootloadersettings}
inherit                 {globalsettings}
advancedoptions         No
optionsedit             No

Opciones del disco RAM de configuraci¢n
-------------------------------------
Identificador           {ramdiskoptions}
description             Ramdisk Options
ramdisksdidevice        partition=G:
ramdisksdipath          \boot\boot.sdi

read more

finding contours of a plant root

I have an image which has roots like this:
enter image description here

I want to crop each root individually out.
I initially thought of heavy dilation followed by erosion and contour detection of the blob, but since the roots are thin, it does not work well.

I also directly applied canny edge and contour detection like this image below. It has around 62000 contours, but I cannot use it to get the outline of each root.
after canny and contour detection on above image

I also thresholded the image using HSV followed by some median blurring. But it did not reduce much noise. Further blurring only leads to losing the root features.

read more

Oracle automatically insert record in multirecord block part 2

My table looks like this:

+-------------------+
|Name               |
+-------------------+
|Name1              |
|Name2              |
|Name3              |
|Name4              |
|Name1Jr            |
|Name2Jr            |
|Name4Jr            |
+-------------------+

My multirow block looks like:

enter image description here

What I wanted to know is how can I insert a record that has the same name with Jr after I insert a name. For example, I inserted Name2, it will also insert Name2Jr into the multirow block. Like this:

enter image description here

Note: I need to get the value of the automatically inserted data from database.

I tried in WHEN-NEW-RECORD-INSTANCE trigger(the answer of Sir @Littlefoot on my last question):

if :system.trigger_record = 1 and :test.name is null then
    -- do nothing if it is the first record in a form
    null;
else
    duplicate_record;
    if substr(:test.name, -2) = 'Jr' then
        -- you've duplicated a record which already has 'Jr' at the end - don't do it
        :test.name := null;
    else       
        -- concatenate 'Jr' to the duplicated record
        :test.name := :test.name || 'Jr';
    end if;      
end if;  

read more